Skip to content

Send to an idle thread rejected with "exited unexpectedly (code 0)" when another thread with a different skill catalog starts in the same environment #7116

Closed

Description

@salemsayed

Summary

A message sent to an idle Claude Code thread is rejected with Provider "claude-code" exited unexpectedly (code 0), ... (signal SIGTERM), has exited (code 0) or is not running when another thread in the same environment starts its provider session at the same moment with a different skill catalog. Both threads' freshly spawned bridge processes are shut down about 0.2 s after they start, and both commands fail. I expected both threads to start their sessions and the message to be delivered.

Versions and environment

  • bb-app 0.48.2-nightly.41887169877.1 via npm (upstream 298e5d0); the code path is unchanged on main at fa30b0a7d, where the runtime-level reproduction below was run.
  • Ubuntu 26.04.1 LTS, Node v24.22.1, Claude Code 2.1.318.
  • Host daemon and server on the same machine, threads in a project-checkout environment shared by several threads.
  • Composer Predictions plugin installed. It configures its hidden helper thread with skills: [] and every other thread with its composer-predictions skill, so the helper's injected skill catalog differs from the thread it predicts for, in the same environment. Any two threads whose skill catalogs differ trigger the same path.

Steps to reproduce

Live, with Composer Predictions installed:

  1. bb thread spawn --project <project> --provider claude-code --model claude-sonnet-5-5 --reasoning-level low --title "race" --prompt "For every message, reply with one short line only and use no tools."
  2. bb composer-predictions regenerate <thread> (marks the thread watched, so every idle starts a hidden prediction helper in the same environment).
  3. Repeat ten times: bb thread tell <thread> "reply one", then bb thread wait <thread>, then immediately bb thread tell <thread> "reply two".

6 of 10 second messages were rejected. With a delay of about 10 s instead of "immediately" they are delivered. A message dispatched within a few milliseconds of idle (a queued message) is not affected, because the thread's turn starts before the helper's start runs.

Without any plugin, at the exact code path: two startThread calls on one createAgentRuntime with different skillRoots, started together, fail 10 of 10 times on main (harness and command in the linked pull request).

Expected vs actual

Actual, bb thread log of the thread:

client/turn/rejected  {"reason":"command_failed","message":"Provider \"claude-code\" exited unexpectedly (code 0)"}
system/error          {"code":"thread_command_failed","message":"Command turn.submit failed","detail":"Provider \"claude-code\" exited unexpectedly (code 0)"}

Host daemon log in the same 10 ms:

online host RPC failed  type=turn.submit    Provider "claude-code" exited unexpectedly (code 0)
online host RPC failed  type=thread.start   Provider "claude-code" is not running

Process timeline (bridge pids polled every 20 ms, relative to the thread going idle):

+2.234  second message requested
+2.654  thread's Claude Code CLI exits
+2.680  thread's bridge exits; two new bridges spawn (+2.680, +2.707), one per skill catalog
+2.882  turn.submit fails, thread.start (helper) fails
+2.893  both new bridges exit

Expected: both sessions start and the message is delivered.

Evidence

Observed, then confirmed in code:

  1. The helper's thread.start arrives while the thread is idle, its skill catalog differs, and nothing is in flight, so RuntimeManager replaces the environment's runtime (this part is Changing a plugin's skills replaces every idle Codex thread's runtime at its next turn and kills the thread's background commands #6301's mechanism):
    private async replaceEntryForSkillCatalog(
  2. In the new runtime the thread's resume and the helper's start run together. Skill roots are part of the process key, so they get two bridge processes:
    function resolveProviderProcessKey(
    args: ResolveProviderProcessKeyArgs,
    ): string {
    const roots = args.skillRoots ?? skillRoots;
    for (const root of roots) {
    if (!path.isAbsolute(root.path)) {
    throw new Error(
    `Agent runtime skill root "${root.id}" must use an absolute path: ${root.path}`,
    );
    }
    }
    const catalogKey =
    roots.length === 0
    ? ""
    : `#skills:${createHash("sha256").update(JSON.stringify(roots)).digest("hex")}`;
    return `${args.providerId}#bridge:${bridgeLaunchProcessKey(args.bridgeLaunch)}${catalogKey}`;
  3. Each ensureProvider ends with retireStaleBridgeProcesses, which shuts down every other process of the same provider that has no registered thread:
    await this.retireStaleBridgeProcesses(args);
    }
    private async retireStaleBridgeProcesses(
    args: EnsureRuntimeProviderArgs,
    ): Promise<void> {
    this.currentProcessKeyByProviderId.set(args.providerId, args.processKey);
    const staleKeys = [...this.processes.entries()]
    .filter(
    ([processKey, providerProcess]) =>
    processKey !== args.processKey &&
    providerProcess.providerId === args.providerId &&
    providerProcess.identity.threadIds.size === 0,
    )
    .map(([processKey]) => processKey);
    for (const processKey of staleKeys) {
    await this.shutdownProvider({ processKey, providerId: args.providerId });
    }
    }
  4. A thread is registered only after ensureProvider returns, and that return waits for the sweep's own shutdowns:
    await runtime.ensureProvider({
    providerId,
    bridgeLaunch,
    skillRoots: sessionSkillRoots,
    });
    const proc = providerProcesses.requireProviderProcess({
    processKey,
    providerId,
    });
    assertProviderSupportsExecutionOptions({
    adapter: proc.adapter,
    options: execOpts,
    providerId,
    });
    const resolvedEnvironment = resolveRuntimeThreadEnvironment({
    contributedEnv,
    environmentId,
    projectId,
    threadId,
    });
    threadIdentityRegistry.registerThreadProvider({
    providerId,
    providerState: proc.identity,
    threadId,
    });

So each sweep sees the other's fresh bridge with zero threads and retires it. A victim that was still initializing dies from SIGTERM before its handler is installed (signal SIGTERM); an initialized one exits gracefully (code 0, or has exited (code 0) when the lookup lands between exit and close).

The sweep was written for bridges superseded by a plugin update (a new artifact hash). Processes for other skill catalogs of the same bridge launch are not superseded. #6479 changes the filter to compare the bridge launch key for this reason; its description lists this case ("main killed a sibling catalog's freshly spawned process before its thread arrived").

Frequency on one server over four days of logs: 7 rejected sends on long-lived threads (worker-result relays, follow-up nudges, a child-completed notice). Each was sent 0.9 to 3.9 s after a thread in the same environment went idle; in two of them a prediction helper thread in that environment failed or started in the same second (helpers are deleted after use, so successful ones leave no record). Each left the thread in error until a later message; the provider-retry plugin skips them as not retryable.

What you ruled out

Suggested priority and effort

High: it hits any setup where two threads of one provider with different skill catalogs share an environment (Composer Predictions makes that every watched thread), the message is lost unless something retries it, and the fix is a one-line filter change.

AGENT GENERATED

Activity

  1. added theissue type on Nov 5, 2026
  2. added
    host
    providers
    provider-claude-code
    confirmed-repro
    on Nov 5, 2026
  3. bb-slop-cop commented on Nov 5, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification: Bug · High priority · Low effort. Labels: host, providers, provider-claude-code, confirmed-repro.
    • Verdict: REPRODUCED · high root-cause confidence. Reproduction and root-cause report.
    • Cause: stale-bridge retirement mistakes a not-yet-registered sibling with a different skill catalog for an obsolete process and shuts it down.
    • Evidence: the new runtime.catalog-concurrency.test.ts fails on trusted main in two clean checkouts; same-catalog controls pass. Depending on scheduling, one or both starts fail. All 38 relevant existing tests and the package typecheck pass. The exact test and logs are inline in the report; live Claude/plugin behavior was not exercised.
    • No duplicate PR: open #7117 already links this issue. Its diff was reviewed statically; its branch was not executed.

    AGENT GENERATED

  4. added a commit that references this issue on Nov 5, 2026
    7dbb66b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-reprohostprovider-claude-codeproviders

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions