Repository navigation
Stop concurrent session starts from retiring each other's new bridge - #7117
Merged
ymichael merged 1 commit intoNov 5, 2026
Merged
Conversation
…nch siblings Two threads of one provider whose skill catalogs differ get different process keys in the same environment runtime. When both start or resume at once, each ensureProvider's stale sweep retired the other's freshly spawned bridge before its thread was registered, and both commands failed with "exited unexpectedly (code 0 | signal SIGTERM)", "has exited (code 0)" or "is not running". Only a process whose bridge launch key (artifact digest, capabilities, bridge options) differs is superseded now, the filter get-bb#6479 also carries. Processes of the same launch are still released after their last thread ends. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
When two threads of one provider whose injected skill catalogs differ start or resume their sessions at the same time in one environment runtime, each one's
ensureProviderretires the other's freshly spawned bridge, and both commands fail. Skill roots are part of the process key (packages/agent-runtime/src/runtime.ts:365-380), so the two threads get two bridge processes.ensureProviderends withretireStaleBridgeProcesses(packages/agent-runtime/src/runtime-provider-process.ts:254-273), which shuts down every other process of the same provider with no registered thread. A thread is registered only afterensureProviderreturns (packages/agent-runtime/src/runtime.ts:1549-1574), and that return waits for the sweep's own shutdowns, so each sweep sees the other's new bridge with zero threads. The victim either dies from SIGTERM while still initializing (exited unexpectedly (signal SIGTERM)) or exits gracefully once initialized (exited unexpectedly (code 0), orhas exited (code 0)when the lookup lands between exit and close); the other command then reportsis not running.In practice this hits Claude Code threads with Composer Predictions installed: its hidden helper gets
skills: [], every other thread gets its skill, and the helper starts about a second after a watched thread goes idle. A message sent to that thread, or to another idle thread in the same environment, about 0.5 to 4 s after the idle is rejected. On one server this lost 7 sends on long-lived threads in four days, and 6 of 10 sends in a controlled repro.The sweep exists to retire bridges superseded by a plugin update (a new artifact hash). Bridges for another skill catalog of the same bridge launch are not superseded; they are released when their last thread ends. #6479 makes the same change to this filter as part of its larger session-config rework ("main killed a sibling catalog's freshly spawned process before its thread arrived"). This PR takes only that filter, so the crash can be fixed while #6479 is open; it applies to
mainon its own and the hunk matches #6479's, so either can rebase over the other.What changed
packages/agent-runtime/src/runtime-provider-process.ts: each process records its bridge launch key (bridgeLaunchProcessKey: artifact digest, capabilities, bridge options) when it is spawned.retireStaleBridgeProcessesretires only a threadless process of the same provider whose bridge launch key differs from the one being ensured. Processes of the same launch with another skill catalog are left to the existing release-after-last-thread path.packages/agent-runtime/src/runtime.process-lifecycle.test.ts:SUPERSEDING_BRIDGE_LAUNCH, as in Reconcile provider session tools and skills in one place, declared per bridge #6479). Before, it only changed the process key string while reusing the same launch, which no longer counts as superseded.startThreadcalls on one runtime with differentskillRoots; both must be hosted afterwards.HOST_DAEMON_PROTOCOL_VERSIONchange.How you verified
New test without the production change (
main'sruntime-provider-process.ts): fails withProviderProcessExitedError: Provider "scripted" exited unexpectedly (signal SIGTERM); the other 35 tests in the file pass. With the change: 36/36.pnpm exec turbo run test --filter=@bb/agent-runtime --force: 23 files, 307 tests passed.pnpm exec turbo run typecheck lint --filter=@bb/agent-runtime --filter=@bb/host-daemon --force: 7/7 tasks passed.oxfmt --checkon the test file reports the existingoom_score_adjtest from Let the OOM killer take agent work before bb #7039, unchanged onmain; the new code is formatter output and that hunk is left alone.Standalone reproduction at the same code path, ten fresh runtimes per run, on
mainatfa30b0a7d: 0/10 without the change (every run lost one or both threads withexited unexpectedly (code 0),(signal SIGTERM)oris not running), 10/10 with it./tmp/sibling-start-race.mts
Live, on a bb-app 0.48.2 nightly (upstream
298e5d0): the daemon bundle built from298e5d0without the change is byte-identical to the shippedhost-daemon/dist/daemon-bundle.mjs; with the change it differs only by this filter. The live reproduction (send to a watched Claude Code thread the moment it goes idle, Composer Predictions installed) failed 6 of 10 sends before. The patched daemon has not been deployed there yet.Fixes #7116