Repository navigation
Retire provider bridges after their final thread ends - #2773
Merged
Merged
Conversation
ymichael
added a commit
that referenced
this pull request
Sep 1, 2026
## Human comments ## What was wrong PR #2773 correctly retires a provider bridge after its final thread ends, but the shared process manager did not record that retirement while it was in progress. A same-key `ensureProvider` could therefore reuse the bridge being terminated; the new thread would reject immediately or briefly start and then lose its provider when the old bridge exited. Review exposed two full-shutdown ordering cases: a retirement-blocked start could spawn after the shutdown sweep, and waiting for that replacement to finish initialization could exceed the daemon's 15-second exit grace because provider RPC initialization waits up to 30 seconds. ## What changed The provider process manager now memoizes same-key retirement promises. New starts wait for retirement before selecting or spawning a bridge, and concurrent shutdown callers share the active retirement. Full runtime shutdown becomes terminal before any lifecycle wait: retirement-blocked or later ensures fulfill without spawning, while already-initializing starts treat shutdown as superseding their internal RPC wait. Shutdown then terminates every process already visible to its sweep. Final-thread retirement, bridge reuse while another thread remains, and later cold resume remain unchanged. The change is internal to `@bb/agent-runtime`; no daemon wire contract, protocol version, public API, CLI, or configuration changed. ## How you verified - Added a regression that overlaps same-key provider shutdown and ensure. It failed before the production change with `Provider "fake" is not running` and passes afterward with a distinct surviving replacement process. - Added a regression that overlaps retirement, a same-key ensure with a three-second delayed initialization response, and full shutdown. It was red because shutdown took the full initialization delay; it is green within the one-second bound, all calls fulfill, and no provider remains. A post-shutdown ensure also fulfills without recreating a provider. - `pnpm exec turbo run test typecheck --filter=@bb/agent-runtime --force` — 22 files / 318 tests passed; typecheck passed. - GitHub CI run `33459198901` — all non-skipped jobs passed, including Linux AppImage lifecycle smoke. - `git diff --check origin/main...HEAD` — passed. - Rebased and reran validation on `origin/main` at `fb05e93ff5ad4f58831e804b973f2de790557afa`. Completes the lifecycle coordination missed by #2773. Tagging @slopcop for re-review of head `0ab3801d24d4d8c04e9cc1bff808357cb0f07d70`. > AGENT GENERATED
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
The runtime retired only a superseded provider bridge after its final thread ended. It kept the current bridge active with no threads.
What changed
The runtime now stops each provider bridge after its final thread ends. It keeps a shared bridge active while another thread uses it. A later request starts a new bridge and restores the session. This change also removes the superseded-only retirement method. The stale bridge check remains for bridges that never owned a thread. This change does not alter the host daemon protocol.
How you verified
The lifecycle tests now cover final-thread stop, failed session creation, idle session release, ACP, Codex, and replacement bridge resume. These checks failed before the change because the current bridge stayed active.
pnpm exec turbo run test --filter=@bb/agent-runtime --force(316 tests passed)pnpm exec turbo run typecheck --filter=@bb/agent-runtimegit diff --checkFixes #2308