fix(server): reconcile orphaned provider sessions #7719
main fromrefs/pull/7719/head·merged by maria-rcks View on GitHubwhat changed#
- reconcile projected provider sessions that did not survive a server restart before opening the command gate
- mark orphaned sessions as
error, clear stale active turns, and stop persisted runtime bindings without losing resume cursors or runtime payload - isolate provider inventory, directory, and per-thread dispatch failures so startup still completes
- add focused and temporary-sqlite restart regressions for luna's stuck
startingstate
why#
an oom or restart can leave durable orchestration state in starting or running after the provider process is gone. recent null-turn messages then keep settle and snooze blocked, and the stale runtime binding prevents clean recovery.
this repairs that split-brain state immediately on restart while leaving genuinely live provider sessions alone.
fixes #6560
verification#
vp test run apps/server/src/provider apps/server/src/orchestration apps/server/src/serverRuntimeStartup.test.ts apps/server/src/serverRuntimeStartup.reconcile.test.ts(801 passed, 6 skipped; one unrelated provider-registry timing test passed on focused rerun)vp test run apps/server/src/serverRuntimeStartup.test.ts apps/server/src/serverRuntimeStartup.reconcile.test.ts apps/server/integration/orphanedProviderSessionStartup.integration.test.ts(13 passed)vp run --filter t3 typecheckunder node 24.13.1vp lint apps/server/src/serverRuntimeStartup.ts apps/server/src/serverRuntimeStartup.reconcile.test.ts apps/server/integration/orphanedProviderSessionStartup.integration.test.tsvp fmt --check apps/server/src/serverRuntimeStartup.ts apps/server/src/serverRuntimeStartup.reconcile.test.ts apps/server/integration/orphanedProviderSessionStartup.integration.test.tsgit diff --check
checklist#
- this pr is small and focused
- i explained what changed and why
request provenance#
- requested by: @maria-rcks
Note
Medium Risk Touches server startup and durable session/projection state. Failures are isolated so one bad thread should not abort startup, but incorrect orphan detection could mark live sessions as error.
Overview
After a restart, projected sessions that are still starting/running (or have a stale activeTurnId) but have no live provider process are repaired before the command gate opens.
reconcileProviderSessions marks those sessions error with a fixed last-error, clears the active turn, and stops directory bindings while keeping resume cursors. Live sessions are left alone. Per-thread directory and dispatch failures are retried once then logged so one bad entity cannot block later repairs or global startup; interruption is still propagated.
This unblocks settle, snooze, and new turns that were stuck after OOM/restart split-brain. Unit and sqlite restart tests cover multi-orphan repair, retry-then-continue, and inventory-read failure.
Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 757f62f8efd17f2a0f38de1abdaa1cc2ece99450. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).Note
Add reconcileProviderSessions startup phase to repair orphaned provider sessions after restart#
- Adds a new
provider-sessions.reconcilestartup phase in serverRuntimeStartup.ts that runs after reactors start. It reads live session IDs fromProviderService.listSessions, compares them against the command read model, and identifies orphaned threads whose provider session is no longer live. - For each orphaned thread, it stops the
ProviderSessionDirectorybinding (setting status tostopped, clearingruntimePayload.activeTurnIdwhile preserving other fields likeresumeCursor) and dispatches athread.session.setcommand to mark the session aserrorwithactiveTurnIdset to null. - Projection dispatch is retried once on transient failure; persistent failures are logged as warnings and do not abort startup. Interruptions are rethrown. If the provider inventory cannot be read, reconciliation is skipped entirely.
- Adds unit tests in serverRuntimeStartup.reconcile.test.ts and an integration test in orphanedProviderSessionStartup.integration.test.ts covering retry-success, persistent-failure continuation, and post-reconciliation command behavior.
- Adds a guideline in effect-service-conventions.md for multi-entity startup reconciliation: preserve interruption, retry transient per-entity failures, and isolate persistent failures.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
Approvability#
Verdict: Not approved
Macroscope's review found this PR not approvable — This PR modifies a
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules)..macroscope/configuration file, which controls Macroscope review behavior and requires human review. Additionally, the production changes add new server startup reconciliation logic that modifies runtime behavior for orphaned provider sessions.maria-rcks merged this0929907
maria-rcks closed this
Sign in to join this conversation.
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline:
21e80a0· PR result:757f62f· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.