fix(server): threads mid-turn continue after a restart on every provider #14182
t3code/codex-turn-mapping fromrefs/pull/14182/head·merged by juliusmarminge View on GitHubAddresses #13331 (item 1).
With "Continue threads after restarts" on, a Codex, Claude, Cursor or ACP thread that was mid-turn when the server restarted is cancelled and left for a manual continue. restartContinuationRun only keeps a live turn when its provider session is "running", but only the OpenCode and Pi adapters ever write that status. Codex, Claude, Cursor and ACP create the session as "ready" and never promote it; ProviderSessionManager persists only "stopped" / "error" on release.
What changed#
restartContinuationRun now rules out a live turn only when the session is "stopped" or "error". That is the same "live session" test recovery itself (ProviderRuntimeRecoveryService), ProjectionStore and ProviderSwitchService already use. The other gates are unchanged: the run must be running, the provider thread active with a strong native ref, and a provider turn for the run's active attempt must be running.
OpenCode's "waiting" (pending permission/question) now qualifies too. That thread was mid-turn, so resuming it is the intended behavior.
Verification#
- New test
continues a live turn whose session the adapter never marked runninginRestartContinuation.test.ts: fails on the base branch (starting: expected undefined to equal 'run:restart'), passes with the fix. It coversstarting/ready/running/waiting(continue) andstopped/error(don't). vp test run src/orchestration-v2/RestartContinuation.test.ts src/orchestration-v2/ProviderRuntimeRecoveryService.test.ts src/orchestration-v2/ProjectionRecovery.test.ts: 30 passed.vp exec tsc --noEmit -p .inapps/server: no errors.vp linton both touched files: clean.- Not run: a live restart against a real provider. Adapter session statuses were checked from source (
CodexAdapterV2.tsproviderSession(),ClaudeAdapterV2.ts,CursorAdapterV2.ts,AcpAdapterV2.tsall set"ready"; onlyOpenCodeAdapterV2.ts/PiAdapterV2.tsemit"running").
Model: Claude Opus 5.5 (Claude Code)
🤖 Generated with Claude Code
- 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:XS
Approvability#
Verdict: Approved at
3680767Macroscope's review found this PR approvable — This is a tightly scoped restart-recovery bug fix: it broadens an existing session-status check so mid-turn continuations work for all supported providers while retaining the stopped/error safeguards. A focused regression test covers the accepted and rejected states.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
ℹ️ No successful
mainbaseline artifact is available yet. This run establishes the initial measurement.Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire — 4.9 KiB — 6.8 KiB ✅ Codex Thread snapshot wire — 3.7 KiB — 4.9 KiB ✅ Codex Live turn WebSocket wire — 1.2 KiB — 2.0 KiB ✅ Codex Live turn WebSocket decoded — 20.4 KiB — 29.3 KiB ✅ Codex Live turn messages — 2 — 8 ✅ Claude Total thread wire — 4.9 KiB — 6.8 KiB ✅ Claude Thread snapshot wire — 3.7 KiB — 4.9 KiB ✅ Claude Live turn WebSocket wire — 1.2 KiB — 2.0 KiB ✅ Claude Live turn WebSocket decoded — 20.7 KiB — 29.3 KiB ✅ Claude Live turn messages — 1 — 8 ✅ Baseline: unavailable · PR result:
3680767· 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.
- Codex decoded thread snapshot: 106.1 KiB
- Claude decoded thread snapshot: 106.4 KiB
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.
juliusmarminge merged this2b9a4ad
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes