Repository navigation
fix(server): ACP turns recover in a fresh session when session/load loses the agent's connection - #46058
fix(server): ACP turns recover in a fresh session when session/load loses the agent's connection#46058juliusmarminge wants to merge 2 commits into
Conversation
…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>
ApprovabilityVerdict: Approved at 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. |
Thread transfer impact✅ Thread transfer remains within every enforced ceiling.
Other scenariosAll 64 scenario measurements match All 64 scenario measurements
Baseline: Scenario and decoded snapshot size10 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. |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
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.
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:
Tests
vp test run src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts -t "native session"(before fix): 1 failed (the [Bug]: ACPstartTurnmissesrecoverLostNativeSessionwhensession/loadfails withAcpTransportError#46045 repro), 6 passedvp test run src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts(after fix): 112 passedvp test run src/orchestration-v2/ProviderTurnStartService.test.ts: 108 passedvp run check:changed: format, lint, knip, graphql, typecheck (3 packages) and tests (3 files, 222 tests) all passNot in this change
AcpProtocolParseErroron 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.AcpSpawnErrorwhen 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
Run by the t3code factory in T3 Code.