← reports

#5927 · Automation CLI rejects unresolved execution options

BugPriority: MediumEffort: Mediumcli · plugins · automationsIssue #59272026-10-20 · base bd93d18896bab97c950c4fa3451b621c1e0569c1

Verdict: REPRODUCED · Root-cause confidence: high · Reproduction label: confirmed-repro.

1. TL;DR

The automation creation handler refuses an agent prompt unless both execution flags are explicit. A real calling thread and remembered project defaults do not help: the handler rejects the request before looking up either source. A regression test through the real loopback HTTP server, bundled plugin entry, registered CLI, SDK, and SQLite persistence reproduces the rejection. A control with both flags creates a paused automation successfully, ruling out a broken plugin install or unavailable provider registry. The same agent repeated the test in a second clean checkout at the same trusted commit.

2. Claims vs findings

ClaimStatusEvidence
Missing execution flags reject an agent automation despite calling-thread context.VerifiedA real stored idle thread has provider codex and model override gpt-5; the actual HTTP CLI endpoint returns exit code 1.
Supplying both flags works.VerifiedThe positive control returns exit code 0 and a disabled persisted automation with the selected provider/model.
Omitting just one flag also fails.VerifiedProvider-only and model-only variants hit the same guard in both runs.
Terminal context can use default execution options.Rejection verified; successful fallback not exercisedA no-thread request still fails even with real remembered project defaults populated. User-wide fallback and live provider model catalogs were not exercised.
A failed external CLI invocation leaves an error in a live conversation.Not exercised end to endThe report tests the endpoint used by the CLI proxy, not an external CLI subprocess or conversation rendering.

3. Environment

4. Minimal reproduction

  1. Clone the trusted repository and check out the recorded commit in a fresh directory:
    git clone https://github.com/get-bb/bb.git bb-repro
    cd bb-repro
    git checkout --detach bd93d18896bab97c950c4fa3451b621c1e0569c1
    pnpm install --frozen-lockfile --prefer-offline
    pnpm exec turbo run build build:types --filter=@get-bb/plugin-sdk
    pnpm exec turbo run build
  2. Save the complete test below to apps/server/test/services/plugins/automations-execution-repro.test.ts. It starts the repository's isolated real server, enables the bundled Automations plugin, seeds a calling thread and remembered defaults, and sends HTTP requests through the registered plugin CLI.
  3. Run:
    pnpm exec turbo run test --filter=@bb/server -- test/services/plugins/automations-execution-repro.test.ts

Expected product behavior: all creation requests return exit code 0 and persist disabled agent automations using the explicit or inherited execution options. Actual: the explicit control succeeds; all four requests with omitted execution flags return exit code 1 and the same missing_required error. The regression test deliberately asserts the desired behavior, so its failure on the unchanged base is the reproduction, not a passing fix test.

Expected: exitCode = 0
Actual:   exitCode = 1
Error:    Agent automations require --provider and --model alongside --prompt.

Complete regression test

import {
  createThread,
  setThreadExecutionOverride,
  upsertProjectExecutionDefaults,
} from "@bb/db";
import { PERSONAL_PROJECT_ID } from "@bb/domain";
import { expect, it } from "vitest";
import { z } from "zod";
import { startTestServer } from "../../helpers/test-app.js";

const cliResultSchema = z.object({
  exitCode: z.number(),
  stdout: z.string().optional(),
  stderr: z.string().optional(),
});

it("creates paused agent automations with execution flags omitted", async () => {
  const server = await startTestServer();
  try {
    server.pluginService.bindSdk({ baseUrl: server.baseUrl });
    const entry = await server.pluginService.install("builtin:automations", {
      kind: "root",
    });
    expect(entry.status, entry.statusDetail ?? undefined).toBe("running");
    const thread = createThread(server.db, server.deps.hub, {
      projectId: PERSONAL_PROJECT_ID,
      providerId: "codex",
      status: "idle",
    });
    setThreadExecutionOverride(server.db, {
      threadId: thread.id,
      modelOverride: "gpt-5",
    });
    upsertProjectExecutionDefaults(server.db, {
      projectId: PERSONAL_PROJECT_ID,
      providerId: "codex",
      model: "gpt-5",
      reasoningLevel: "medium",
      permissionMode: "auto",
      serviceTier: "default",
    });

    async function create(options: {
      name: string;
      flags: string[];
      threadId?: string;
    }) {
      const response = await fetch(
        `${server.baseUrl}/api/v1/plugins/automations/cli`,
        {
          method: "POST",
          headers: { "content-type": "application/json" },
          body: JSON.stringify({
            argv: [
              "create",
              "--project",
              PERSONAL_PROJECT_ID,
              "--name",
              options.name,
              "--in",
              "2h",
              "--prompt",
              "Inspect repository status",
              "--disabled",
              "--json",
              ...options.flags,
            ],
            ...(options.threadId ? { threadId: options.threadId } : {}),
          }),
        },
      );
      const body: unknown = await response.json();
      expect(response.status, JSON.stringify(body)).toBe(200);
      return cliResultSchema.parse(body);
    }

    const control = await create({
      name: "Explicit execution control",
      flags: ["--provider", "codex", "--model", "gpt-5"],
      threadId: thread.id,
    });
    expect(control.exitCode, JSON.stringify(control)).toBe(0);
    const storedControl: unknown = JSON.parse(control.stdout ?? "null");
    expect(storedControl).toMatchObject({
      enabled: false,
      execution: { providerId: "codex", model: "gpt-5" },
    });
    console.log("Explicit control: exitCode=0; disabled automation persisted");

    for (const scenario of [
      {
        name: "Thread without execution flags",
        flags: [],
        threadId: thread.id,
      },
      {
        name: "Thread without model flag",
        flags: ["--provider", "codex"],
        threadId: thread.id,
      },
      {
        name: "Thread without provider flag",
        flags: ["--model", "gpt-5"],
        threadId: thread.id,
      },
      { name: "Terminal without execution flags", flags: [] },
    ]) {
      const result = await create(scenario);
      console.log(JSON.stringify({ scenario: scenario.name, ...result }));
      expect
        .soft(result.exitCode, `${scenario.name}: ${JSON.stringify(result)}`)
        .toBe(0);
      if (result.exitCode === 0) {
        const stored: unknown = JSON.parse(result.stdout ?? "null");
        expect.soft(stored).toMatchObject({
          enabled: false,
          execution: { providerId: "codex", model: "gpt-5" },
        });
      }
    }
  } finally {
    await server.pluginService.stop();
    await server.close();
  }
}, 60_000);

The test is embedded rather than linked to an artifact directory, in accordance with the public reports repository policy. It adds no dependency, changes no production source, never runs a scheduled automation, and closes its server and plugin runtime.

5. Root cause

In plugins/automations/src/cli.ts:639, buildExecution reads only the option values and unconditionally rejects either missing field before constructing an environment or calling provider validation:

if (hasAgent) {
  const provider = options.provider;
  const model = options.model;
  if (!provider || !model) {
    throw cliError(
      "Agent automations require --provider and --model alongside --prompt.",
      "missing_required",
    );
  }
  ...
}

The CLI proxy forwards calling-thread context, and the server CLI route preserves that context. The creation handler passes it into buildExecution, but no execution-default lookup occurs on the agent path before the guard. Thus this is missing default resolution in the plugin handler, not missing transport context.

The server already exposes remembered project execution defaults and resolved execution options for an existing thread. Their existence explains how a plugin could obtain typed defaults, but this report does not assert that calling them alone fully implements every provider-routing edge case.

6. Proposed fix

Resolve omitted creation-time provider/model values through the existing SDK defaults before enforcing a complete execution configuration. Explicit flags must win; an inherited model must belong to the selected provider. Keep persisted execution fully resolved and retain provider availability, environment routing, permission validation, and partial-update semantics. Update CLI help and the owning skill together. Verify thread overrides, remembered project defaults, user/provider defaults, cross-provider overrides, unavailable model catalogs, and requests outside a thread.

No production fix was attempted: GitHub metadata confirms that an open pull request already closes this issue. Opening another would duplicate that work.

7. Linked PR review

PR #5928 is open and draft and explicitly lists issue #5927 in its closing references. Its metadata and diff were read only as untrusted review data; its branch, scripts, and tests were never checked out or executed.

Static assessment: the diff replaces the observed guard with SDK-based provider/model resolution and adds CLI documentation and harness cases. This targets the verified cause rather than hiding the error. Verdict: static-only; not a readiness approval. The real-server regression in this report ran only on trusted main, not on the proposed implementation. Provider catalogs, environment-specific routing, cross-provider inheritance, and update behavior remain review/test requirements; no validated PR defect is claimed.

8. Related issues

The investigation is limited to issue #5927. Existing Type, Priority, Effort, and labels were preserved; no duplicate issue or pull request was opened.

9. Verification

The same agent performed the second run; this is repeat verification, not independent review. A new detached checkout was created at bd93d18896bab97c950c4fa3451b621c1e0569c1, installed with the frozen lockfile, and built successfully. Before the reproduction, its only untracked source was this newly authored test; production code matched the trusted base. A fresh real server, temporary data directory, and loopback port were allocated by the test harness.

git worktree add --detach SECOND_CHECKOUT bd93d18896bab97c950c4fa3451b621c1e0569c1
cd SECOND_CHECKOUT
pnpm install --frozen-lockfile --prefer-offline
pnpm exec turbo run build build:types --filter=@get-bb/plugin-sdk
pnpm exec turbo run build
pnpm exec turbo run test --force --filter=@bb/server -- test/services/plugins/automations-execution-repro.test.ts

--force prevents a cached test result from standing in for the second execution. Both final runs passed the explicit-flags control and failed all four desired-behavior assertions with exactly the same error. No root-cause correction was necessary after the second run. The terminal case is intentionally scoped to prepopulated remembered defaults; it does not establish live provider model-catalog fallback.

10. Appendix

Observed output, path-free excerpt

first checkout:
Explicit control: exitCode=0; disabled automation persisted
Thread without execution flags: exitCode=1; Agent automations require --provider and --model alongside --prompt.
Thread without model flag: exitCode=1; Agent automations require --provider and --model alongside --prompt.
Thread without provider flag: exitCode=1; Agent automations require --provider and --model alongside --prompt.
Terminal without execution flags: exitCode=1; Agent automations require --provider and --model alongside --prompt.
Test Files  1 failed (1)
Tests  1 failed (1)

second checkout:
Explicit control: exitCode=0; disabled automation persisted
Thread without execution flags: exitCode=1; Agent automations require --provider and --model alongside --prompt.
Thread without model flag: exitCode=1; Agent automations require --provider and --model alongside --prompt.
Thread without provider flag: exitCode=1; Agent automations require --provider and --model alongside --prompt.
Terminal without execution flags: exitCode=1; Agent automations require --provider and --model alongside --prompt.
Test Files  1 failed (1)
Tests  1 failed (1)

Each failure's JSON output carries error.code = "missing_required"; stderr carries the exact error above. The command exits 1 because the desired-behavior assertions fail. Raw local build/test logs remain outside this public repository. The published excerpt preserves the relevant observed exit codes and messages but omits machine-specific output.

Trust boundary: issue text and linked PR data were treated only as claims. No issue-supplied command, patch, script, test, branch, attachment, or external link was executed or fetched. The regression was authored from trusted main source and repository test helpers. No visual screenshot is required for this server-side validation defect.