Skip to content

fix(server): ACP turns recover in a fresh session when session/load loses the agent's connection - #46058

Open
juliusmarminge wants to merge 2 commits into
mainfrom
factory/issue-46045
Open

juliusmarminge wants to merge 2 commits into
mainfrom
factory/issue-46045

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

If an ACP agent lost its connection while T3 Code was reloading its session at the start of a turn (its process crashed or its output broke), the turn failed with "The provider could not start this turn". Only the user's next message recovered. These failures now get the same handling as a session/load error the agent reports itself: the turn continues in a fresh native session and the earlier conversation is handed over.

Fixes #46045

Reproduction on main

Commit 8b60977 (origin/main). Ran a real server: T3CODE_DEV_SEED=0 GOOGLE_GEMINI_BASE_URL=<hub> node apps/server/src/bin.ts serve --base-dir <fresh dir>, with Antigravity enabled in Gemini API key mode (synthetic key) through settings.json, and real agy 1.5.20 from PATH, model gemini-3.8-flash. Used the CLI (t3 thread start/send --wait --json). Turn 1 ran a 17.5 MB shell command and completed. agy 1.5.20 trims tool output in what it sends over ACP, so replaying it on session/load stayed under the 16 MiB line limit, and the report's oversized-line trigger could not be recreated through the hub. To force a transport-level failure during activation anyway, I stopped the thread's agy child, using a PID that I confirmed belonged to my own server. Turn 2 then went startTurn -> session/load and succeeded. I stopped agy again and ran a watcher that SIGKILLs the new agy process the moment it opens conversations/.db, which happens during session/load. Turn N ('Reply KIWI') failed: the trace showed session/load Failure 'RpcClientDefect: ACP protocol terminated' -> AcpAdapterV2.startTurn Failure -> ProviderTurnStartService.recoverLostNativeSession span ran for 1 ms and returned without recovering. The CLI showed status failed, 'The provider could not start this turn: the provider process exited after signal SIGKILL', and no 'Recovering provider context in a fresh native session' was logged. The cause chain was ProviderAdapterTurnStartError -> AcpProcessExitedError, which is a sibling of the reporter's AcpTransportError and equally not an AcpRequestError. Turn N+1 ('Reply LEMON') went through AcpAdapterV2.resumeThread, as the report says. It loaded and completed because my crash was one-off; the reporter's oversized line repeats, so their resume failed and recovered. Failing test pushed on factory/repro-46045: ProviderSwitch.integration.test.ts 'recovers in a fresh native session when session/load at turn start fails in transport' fails on main with 'turn 2 failed: The provider could not start this turn...'. The existing #44152 test (AcpRequestError) passes. As a temporary check, letting nativeSessionLoadFailed also accept AcpTransportError made the new test pass; that edit was reverted.

Evidence

Real Linux server and CLI, real agy 1.5.20, Gemini 3.8 Flash via API-key mode; separate fresh databases. On each commit, start a real server with T3CODE_DEV_SEED=0, a fresh database, and Antigravity enabled in Gemini API-key mode. Create a project and thread through the CLI. Send 'Remember the word ORCHARD. Reply READY only.' Stop the owned agy process and send 'Reply READY only.' to warm the saved-session path. Stop the replacement agy, then send 'Reply KIWI, then the word I asked you to remember.' Watch strace of the real replacement process's stdin and SIGKILL it when it reads session/load. The same strace wrapper adds 100 ms read-syscall delays on both sides so the interruption lands before the load response. Verify session/load fails with AcpProcessExitedError before a new prompt. Base: failed turn, CLI exit 1, no fresh-session recovery. Head: recovery logged, CLI exit 0, reply 'KIWI ORCHARD'.

Captures are 1440×900 dark terminal-output recordings rendered from timestamped real driver stdout, preserving its original timing; they are not web UI screenshots. Both final frames and sampled video frames were inspected.

Before After
8b609772ef 8f8cfc5763
Before: failed turn without recovery After: recovered turn remembers ORCHARD
Before recording After recording
Before protocol and CLI result After protocol and CLI result

Reproduction and seed driver · Timestamped stdout recorder

The oversized-stdout AcpTransportError trigger was not exercised; this demonstrates the real process-crash sibling, AcpProcessExitedError, during session/load.

Not shown:

  • The reporter's oversized stdout (>16 MiB) AcpTransportError trigger was not reproduced; the evidence demonstrates the supplied real-process crash alternative, AcpProcessExitedError, during session/load.
  • session/resume failures and other ACP providers were not separately exercised.

Tests

  • vp test run src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts -t "native session" (before fix): 1 failed (the [Bug]: ACP startTurn misses recoverLostNativeSession when session/load fails with AcpTransportError #46045 repro), 6 passed
  • vp test run src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts (after fix): 112 passed
  • vp test run src/orchestration-v2/ProviderTurnStartService.test.ts: 108 passed
  • vp run check:changed: format, lint, knip, graphql, typecheck (3 packages) and tests (3 files, 222 tests) all pass

Not in this change

  • AcpProtocolParseError on a session/load response (the agent sent a malformed reply) still does not trigger turn-start recovery; that is an agent protocol violation, not a lost connection.
  • An AcpSpawnError when the runtime restarts before activation still fails the turn instead of recovering, since a fresh session would need the same spawn.

Who did the work

  • Written by Claude Opus 5.5, in Claude Code
  • Reviewed by GPT-6.1 Sol, in Codex, and by Claude Opus 5.5, each on its own
  • Proof captured by GPT-6.1 Sol and checked by Claude Opus 5.5

Run by the t3code factory in T3 Code.

juliusmarminge and others added 2 commits November 30, 2026 12:07
…port failure skips recovery

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…oses the agent's connection

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Nov 30, 2026
@macroscopeapp

macroscopeapp Bot commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at 8f8cfc5

Macroscope's review found this PR approvable — ACP connection-loss failures now use existing fresh-session recovery instead of leaving the turn failed. Existing current-attempt, pending-work, and single-fallback safeguards limit the recovery’s reach.

You can add or adjust custom eligibility rules. Learn more.

@github-actions

Copy link
Copy Markdown
Contributor

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅
Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅
Codex Live turn WebSocket decoded 21.5 KiB 21.5 KiB 0 B (0.0%) 24.4 KiB ✅
Codex Live turn messages 1 1 0 (0.0%) 8 ✅
Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅
Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅
Claude Live turn WebSocket decoded 21.9 KiB 21.9 KiB 0 B (0.0%) 24.4 KiB ✅
Claude Live turn messages 1 1 0 (0.0%) 8 ✅

Other scenarios

All 64 scenario measurements match main.

All 64 scenario measurements
Provider Scenario Metric Main baseline This PR Impact PR ceiling
Codex short turn resume WebSocket decoded 10.5 KiB 10.5 KiB 0 B (0.0%) 12.7 KiB ✅
Codex short turn resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex long turn running, cold open HTTP decoded 281.7 KiB 281.7 KiB 0 B (0.0%) 302.7 KiB ✅
Codex long turn running, cold open rows 75 75 0 (0.0%) 75 ✅
Codex long turn running, history page HTTP decoded 92.4 KiB 92.4 KiB 0 B (0.0%) 107.4 KiB ✅
Codex long turn running, history page rows 75 75 0 (0.0%) 75 ✅
Codex long turn finished, cold open HTTP decoded 381.5 KiB 381.5 KiB 0 B (0.0%) 410.2 KiB ✅
Codex long turn finished, cold open rows 151 151 0 (0.0%) 151 ✅
Codex long turn finished, socket cold open WebSocket decoded 381.6 KiB 381.6 KiB 0 B (0.0%) 410.2 KiB ✅
Codex long turn finished, socket cold open WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex long turn finished, socket cold open rows 151 151 0 (0.0%) 151 ✅
Codex long turn finished, work page HTTP decoded 186.2 KiB 186.2 KiB 0 B (0.0%) 200.2 KiB ✅
Codex long turn finished, work page rows 150 150 0 (0.0%) 150 ✅
Codex idle thread resume WebSocket decoded 65 B 65 B 0 B (0.0%) 200 B ✅
Codex idle thread resume WebSocket messages 1 1 0 (0.0%) 1 ✅
Codex fleet shell snapshot HTTP decoded 42.4 KiB 42.4 KiB 0 B (0.0%) 53.7 KiB ✅
Codex fleet shell snapshot rows 27 27 0 (0.0%) 27 ✅
Codex fleet shell subscribe WebSocket decoded 65 B 65 B 0 B (0.0%) 200 B ✅
Codex fleet shell subscribe WebSocket messages 1 1 0 (0.0%) 1 ✅
Codex fleet shell resume check HTTP decoded 18 B 18 B 0 B (0.0%) 100 B ✅
Codex fleet shell resume check rows 0 0 0 0 ✅
Codex stale shell reload HTTP decoded 42.4 KiB 42.4 KiB 0 B (0.0%) 53.7 KiB ✅
Codex stale shell reload rows 27 27 0 (0.0%) 27 ✅
Codex stale shell resume WebSocket decoded 140 B 140 B 0 B (0.0%) 400 B ✅
Codex stale shell resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Codex stale todo list cold open HTTP decoded 72.4 KiB 72.4 KiB 0 B (0.0%) 83.0 KiB ✅
Codex stale todo list cold open rows 75 75 0 (0.0%) 75 ✅
Codex stale todo list cold open nodes 2 2 0 (0.0%) 4 ✅
Codex stale todo list cold open subagents 2 2 0 (0.0%) 4 ✅
Codex stale todo list cold open plans 1 1 0 (0.0%) 2 ✅
Codex stale todo list cold open providerTurns 1 1 0 (0.0%) 2 ✅
Codex stale todo list cold open checkpoints 1 1 0 (0.0%) 2 ✅
Claude short turn resume WebSocket decoded 10.6 KiB 10.6 KiB 0 B (0.0%) 12.7 KiB ✅
Claude short turn resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude long turn running, cold open HTTP decoded 283.3 KiB 283.3 KiB 0 B (0.0%) 302.7 KiB ✅
Claude long turn running, cold open rows 75 75 0 (0.0%) 75 ✅
Claude long turn running, history page HTTP decoded 93.4 KiB 93.4 KiB 0 B (0.0%) 107.4 KiB ✅
Claude long turn running, history page rows 75 75 0 (0.0%) 75 ✅
Claude long turn finished, cold open HTTP decoded 384.2 KiB 384.2 KiB 0 B (0.0%) 410.2 KiB ✅
Claude long turn finished, cold open rows 151 151 0 (0.0%) 151 ✅
Claude long turn finished, socket cold open WebSocket decoded 384.3 KiB 384.3 KiB 0 B (0.0%) 410.2 KiB ✅
Claude long turn finished, socket cold open WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude long turn finished, socket cold open rows 151 151 0 (0.0%) 151 ✅
Claude long turn finished, work page HTTP decoded 188.1 KiB 188.1 KiB 0 B (0.0%) 200.2 KiB ✅
Claude long turn finished, work page rows 150 150 0 (0.0%) 150 ✅
Claude idle thread resume WebSocket decoded 66 B 66 B 0 B (0.0%) 200 B ✅
Claude idle thread resume WebSocket messages 1 1 0 (0.0%) 1 ✅
Claude fleet shell snapshot HTTP decoded 43.0 KiB 43.0 KiB 0 B (0.0%) 53.7 KiB ✅
Claude fleet shell snapshot rows 27 27 0 (0.0%) 27 ✅
Claude fleet shell subscribe WebSocket decoded 66 B 66 B 0 B (0.0%) 200 B ✅
Claude fleet shell subscribe WebSocket messages 1 1 0 (0.0%) 1 ✅
Claude fleet shell resume check HTTP decoded 18 B 18 B 0 B (0.0%) 100 B ✅
Claude fleet shell resume check rows 0 0 0 0 ✅
Claude stale shell reload HTTP decoded 43.0 KiB 43.0 KiB 0 B (0.0%) 53.7 KiB ✅
Claude stale shell reload rows 27 27 0 (0.0%) 27 ✅
Claude stale shell resume WebSocket decoded 140 B 140 B 0 B (0.0%) 400 B ✅
Claude stale shell resume WebSocket messages 2 2 0 (0.0%) 2 ✅
Claude stale todo list cold open HTTP decoded 73.4 KiB 73.4 KiB 0 B (0.0%) 83.0 KiB ✅
Claude stale todo list cold open rows 75 75 0 (0.0%) 75 ✅
Claude stale todo list cold open nodes 2 2 0 (0.0%) 4 ✅
Claude stale todo list cold open subagents 2 2 0 (0.0%) 4 ✅
Claude stale todo list cold open plans 1 1 0 (0.0%) 2 ✅
Claude stale todo list cold open providerTurns 1 1 0 (0.0%) 2 ✅
Claude stale todo list cold open checkpoints 1 1 0 (0.0%) 2 ✅

Baseline: 661a9ed · PR result: 8f8cfc5 · Source CI: success

Scenario 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: 108.5 KiB
  • Claude decoded thread snapshot: 108.8 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The native-session failure check now recognizes tagged ACP transport, process-exit, and input-stream-ended errors. An integration test verifies recovery in a different native session after a transport error.

Changes: ACP Session Recovery

Layer / File(s) Summary
Detect ACP failures and verify recovery
apps/server/src/orchestration-v2/ProviderTurnStartService.ts, apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts
The failure check recognizes additional ACP error types and continues to inspect nested causes. The integration test injects a transport error and verifies recovery in another native session with replacement bookkeeping.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: grenmango51, voltcrash, srkrnmgda

Merge Risk: Minimal · up to 8f8cf

When the ACP agent connection drops during session load at turn start, the turn now recovers in a fresh native session with conversation handoff, rather than failing and needing another message. No concrete merge-blocking risk was identified, and the new integration test covers the changed path.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: ACP turns that lose the agent connection during session/load now recover in a fresh native session. It follows the conventional commit form and fits the linked issue #…
Linked Issues check Passed [#46045] Requirement: a transport-level failure during ACP session/load or session/resume at turn start must reach recoverLostNativeSession on the same turn, not surface as a turn-start failure. At he…
Out of Scope Changes check Passed The described changes are limited to nativeSessionLoadFailed in ProviderTurnStartService.ts (adds the ACP connection-lost tag list) and to the ProviderSwitch integration test helper and new test (opti…
Description check Passed The description explains the problem (an ACP agent connection lost during session/load at turn start made the turn fail with "The provider could not start this turn") and the change (transport-loss, p…
Full details: Title check

Explanation

The title names the main change: ACP turns that lose the agent connection during session/load now recover in a fresh native session. It follows the conventional commit form and fits the linked issue #46045 and the code change to nativeSessionLoadFailed. It is specific, at 96 characters it is slightly long but still clear.

Full details: Linked Issues check

Explanation

[#46045] Requirement: a transport-level failure during ACP session/load or session/resume at turn start must reach recoverLostNativeSession on the same turn, not surface as a turn-start failure. At head, apps/server/src/orchestration-v2/ProviderTurnStartService.ts defines ACP_CONNECTION_LOST_TAGS (AcpTransportError, AcpProcessExitedError, AcpInputStreamEndedError). nativeSessionLoadFailed now returns true for these tags, and it still searches nested causes. The #46045 failure chain was ProviderAdapterTurnStartError -> AcpTransportError, so the cause walk now reaches a match. The existing AcpRequestError check for session/load and session/resume is unchanged. The PR adds an integration test (ProviderSwitch.integration.test.ts, transport error during session/load at turn start) that checks recovery into a new native session with handoff bookkeeping. The PR reports this test failed on main and passes after the change. I could not read the test file or the full diff, so the test result rests on the PR description. Explicitly excluded cases (AcpProtocolParseError, AcpSpawnError) are not required by #46045 as written.

Full details: Out of Scope Changes check

Explanation

The described changes are limited to nativeSessionLoadFailed in ProviderTurnStartService.ts (adds the ACP connection-lost tag list) and to the ProviderSwitch integration test helper and new test (optional lostNativeSessionCause, default unchanged). All of these support the #46045 objective. No unrelated subsystem changes are described. The unverified part is that the method-less tag match applies only during activation before the prompt, as the code comment states. I did not confirm the call-site gating because the diff could not be read.

Full details: Description check

Explanation

The description explains the problem (an ACP agent connection lost during session/load at turn start made the turn fail with "The provider could not start this turn") and the change (transport-loss, process-exit, and input-stream-ended errors now trigger recovery in a fresh native session). It links the issue (#46045) and gives a detailed reproduction, evidence, and test results. It covers the template's Problem, Change, Scope, and Verification sections. Minor gaps: the Scope section does not state a clear bug-fix classification beyond the linked issue, and the author's test commands are listed, so verification is well supported. The description also includes a 'Who did the work' attribution, which the template asks for when an agent was used. The description is thorough and mostly complete.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 661a9ed and 8f8cfc5.

Files selected for processing: 2

  • apps/server/src/orchestration-v2/ProviderTurnStartService.ts
  • apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: ACP startTurn misses recoverLostNativeSession when session/load fails with AcpTransportError

1 participant