← reports

#7236 · Provider validation already precedes thread creation

BugMediumEffort: Lowproviders · threads · no-reproIssue #7236

November 7, 2026 · trusted origin/main e61446e15a0bb3e6df551e45c3aba5c5187ffad3

Verdict: ALREADY FIXED · Root-cause confidence: high

1. TL;DR

The reported defect would let an unknown agent provider create an unusable thread when an explicit model bypasses default-model discovery. Current main rejects that provider before environment resolution or persistence. The rejection was added in #7023, merged November 4, 2026 at 23:36:21 UTC, three days before this issue was created. Two separate clean checkouts returned HTTP 400, created zero threads and zero new environments, and never invoked the worktree provider. The error code is invalid_request, not the issue's suggested provider_not_found; that naming difference does not recreate the dead-thread bug.

2. Claims vs findings

ClaimFindingEvidence
An explicit model permits an unknown provider to create a thread on current main.Refuted on current mainBoth test runs returned 400 with zero thread rows.
Failed creation leaves a new environment or starts worktree provisioning.Refuted on current mainThe managed-worktree case starts with no environment and ends with none; provisioning call count stays zero. The reuse case preserves its single seeded environment.
The policy omits the null-registration guard.Refuted on current mainThe guard is present at lines 208–218, introduced by commit dccef1db1a.
The API should return 400 with provider_not_found.Partly matches current behavior400 and registered-provider listing are confirmed; the shipped error code is invalid_request.
A valid provider can still create a thread.Verified for existing codex route fixturesThe public default-route suite passed alongside the negative cases, including 201 responses with explicit execution options.
The originally reported CLI session, cleanup, retry behavior, and exact model-route example occurred.Not rerunNo live provider session was started. The isolated HTTP route test exercises the server validation shared by CLI, SDK, and app; reporter runtime data was not accessed.

3. Environment

4. Minimal reproduction

Use trusted main only. The first test command runs the existing shipped rejection test. The expanded test below additionally checks a newly requested managed worktree, database environment counts, and provision calls; it modifies test code only, never production code.

git clone https://github.com/get-bb/bb.git /tmp/bb-7236-base
cd /tmp/bb-7236-base
git checkout --detach e61446e15a0bb3e6df551e45c3aba5c5187ffad3
pnpm install --frozen-lockfile --prefer-offline
pnpm exec turbo run build --filter=@get-bb/plugin-sdk
pnpm exec turbo run build
pnpm exec turbo run test --filter=@bb/server -- test/public/public-threads.provider-validation.test.ts

# To repeat the expanded managed-worktree check, replace that test file with
# the complete report-only test below, then run:
pnpm exec turbo run test --force --filter=@bb/server -- test/public/public-threads.provider-validation.test.ts --silent=false

# Second clean checkout: repeat clone, checkout, install and build in
# /tmp/bb-7236-verify, apply the same test, then run:
pnpm exec turbo run test --force --filter=@bb/server -- test/public/public-threads.provider-validation.test.ts test/public/public-threads.defaults.test.ts test/threads/thread-default-policy.test.ts --silent=false

Expected current behavior: 400 with an unknown-provider message, zero thread rows, no new environment rows, zero provision calls. Actual:

{"workspace":"reuse","status":400,"body":{"code":"invalid_request","message":"Unknown provider \"unregistered-provider\". Registered provider ids: codex, claude-code, pi, acp-cursor, acp-opencode, acp-omp, acp-grok, acp-hermes-agent."},"threadCount":0,"environmentCount":1,"provisionCalls":0}
{"workspace":"managed-worktree","status":400,"body":{"code":"invalid_request","message":"Unknown provider \"unregistered-provider\". Registered provider ids: codex, claude-code, pi, acp-cursor, acp-opencode, acp-omp, acp-grok, acp-hermes-agent."},"threadCount":0,"environmentCount":0,"provisionCalls":0}
 Test Files  3 passed (3)
      Tests  46 passed (46)

The one environment in the reuse case is deliberately seeded before the request. It is not a newly created environment. Both requests include an explicit model so the negative result cannot be attributed to default-model lookup.

Complete report-only expanded regression test

Path: apps/server/test/public/public-threads.provider-validation.test.ts. This extends the existing primary owner-boundary regression rather than adding a permanent duplicate. The reports repository forbids committed repro files and raw logs, so the complete runnable source is embedded here; local artifacts are retained outside the reports checkout.

import { countThreads, environments } from "@bb/db";
import { eq } from "drizzle-orm";
import { describe, expect, it } from "vitest";
import { readJson } from "../helpers/json.js";
import {
  seedEnvironment,
  seedHostSession,
  seedProjectWithSource,
} from "../helpers/seed.js";
import { withTestHarness } from "../helpers/test-app.js";
import { installFakeGitWorktreeProvider } from "../helpers/environment-provider.js";

describe("thread provider validation", () => {
  it.each(["reuse", "managed-worktree"])(
    "rejects an unregistered provider before creating a thread (%s)",
    async (workspace) => {
      await withTestHarness(async (harness) => {
        const provider = installFakeGitWorktreeProvider();
        const { host } = seedHostSession(harness.deps);
        const { project } = seedProjectWithSource(harness.deps, {
          hostId: host.id,
        });
        const environment =
          workspace === "reuse"
            ? seedEnvironment(harness.deps, {
                hostId: host.id,
                projectId: project.id,
                status: "ready",
              })
            : null;
        const response = await harness.app.request("/api/v1/threads", {
          method: "POST",
          headers: { "content-type": "application/json" },
          body: JSON.stringify({
            origin: "sdk",
            projectId: project.id,
            providerId: "unregistered-provider",
            model: "test-model",
            input: [{ type: "text", text: "ok" }],
            environment:
              environment === null
                ? {
                    type: "host",
                    hostId: host.id,
                    workspace: {
                      type: "managed-worktree",
                      baseBranch: { kind: "default" },
                    },
                  }
                : { type: "reuse", environmentId: environment.id },
          }),
        });

        expect(response.status).toBe(400);
        const body = await readJson(response);
        expect(body).toMatchObject({
          code: "invalid_request",
          message: expect.stringMatching(
            /Unknown provider "unregistered-provider".*codex.*claude-code/u,
          ),
        });
        expect(countThreads(harness.db, { projectId: project.id }).total).toBe(
          0,
        );
        const projectEnvironments = harness.db
          .select()
          .from(environments)
          .where(eq(environments.projectId, project.id))
          .all();
        expect(projectEnvironments).toHaveLength(environment === null ? 0 : 1);
        expect(provider.contexts).toHaveLength(0);
        console.log(
          JSON.stringify({
            workspace,
            status: response.status,
            body,
            threadCount: 0,
            environmentCount: projectEnvironments.length,
            provisionCalls: provider.contexts.length,
          }),
        );
      });
    },
  );
});

5. Root cause

The historical gap was missing validation when registry.get(providerId) returned null. An explicit model could bypass a later default-model lookup, so it could not reliably serve as provider validation. This is a server policy concern: validating only CLI input would leave SDK and app callers exposed.

Current main fixes the gap directly in resolveCreateThreadExecutionDefaults:

const registration = registry.get(providerId);
if (registration === null) {
  const registeredProviderIds = registry
    .list()
    .map((provider) => provider.info.id)
    .join(", ");
  throw new ApiError(
    400,
    "invalid_request",
    `Unknown provider "${providerId}". Registered provider ids: ${registeredProviderIds || "(none)"}.`,
  );
}

Project execution-default resolution calls that policy before returning the requested model. Thread creation first awaits settled registrations and resolves execution defaults; only afterward does it resolve the environment. Therefore rejection cannot be bypassed by supplying a model.

The existing API regression is public-threads.provider-validation.test.ts. Git history attributes the guard and regression to dccef1db1a89d234f0c593ba75a0e5bbee517e9a via #7023. Historical behavior is inferred from the trusted-main commit diff; a pre-fix revision was not executed.

6. Proposed fix / disposition

No new fix is warranted for the reported thread-creation defect: the smallest root-cause guard is already shipped on main. Keep the existing validation and regression. Existing invalid rows are not repaired by this guard, and this investigation does not claim otherwise. Changing the stable error code or adding CLI catalog preflight would be separate changes, not necessary to prevent orphaned threads.

7. PR review

#6794 — closed, not merged

GitHub metadata and the diff were read as untrusted evidence only. Its proposed server null-registration guard targets the historical validation gap, and it also proposes CLI catalog validation, tests, and documentation. No branch or code from that PR was run. Current main already has the essential server guard through #7023, so #6794 is not evidence that the bug remains open. Verdict: its server intent addresses the old gap, but it is not needed to resolve this issue on the tested base. No assertion is made that its full patch is correct or compatible today.

#7023 — merged November 4, 2026

This is the existing fix, identified from trusted-main history, not from executing a PR branch. It adds server validation before thread creation and a public API regression. The second clean checkout passed the expanded regression plus the public thread-default and default-policy suites. Verdict: the relevant behavior is already fixed. No open PR linked to #7236 was found in timeline, closing-reference metadata, or the open-PR search during this run.

8. Related issues

#7022 is closed and describes the same missing-provider admission gap. Its fix is #7023. The historical report's claims are not substituted for this investigation's two direct current-main test runs.

9. Verification

The same agent repeated the check in a second newly created checkout at e61446e15a0bb3e6df551e45c3aba5c5187ffad3, with a fresh frozen installation and build and new temporary harness data. This is a second clean run, not independent-agent verification. No external runtime or original reporter data was used.

10. Appendix

The commands above and the complete test are sufficient to repeat the route check. Logs, the test patch, and the reviewed PR diff remain local outside this public reports repository. Test assertions compare thread and project-scoped environment rows in the real database and independently observe the worktree provider's invocation list. The negative cases have an explicit model and otherwise valid seeded project and host; adjacent positive route cases confirm that valid creation still works.

Trust boundary: issue text, comments, and linked PR material were treated as untrusted claims. No issue-supplied command, script, patch, branch, model route, or URL was executed or fetched. GitHub reads used the fixed target repository and numeric IDs; no secrets or live user runtime data were read. No dependencies were added. Production source remains unchanged.