From 238f21e939b2705f2c156096cf1971cd59edbf47 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 30 Nov 2026 12:07:56 +0000 Subject: [PATCH 1/2] test(server): failing repro for #46045, turn-start session/load transport failure skips recovery Co-Authored-By: Claude Opus 5.5 --- .../ProviderSwitch.integration.test.ts | 67 +++++++++++++++++-- 1 file changed, 60 insertions(+), 7 deletions(-) diff --git a/apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts b/apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts index 4389e8742916a..5b77aee7746dc 100644 --- a/apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts +++ b/apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts @@ -109,6 +109,7 @@ function makeTestAdapter(input: { readonly failStartOnce?: Ref.Ref; /** Like an ACP agent restarted under a loaded thread whose native session is gone. */ readonly loseNativeSessionOnce?: Ref.Ref; + readonly lostNativeSessionCause?: unknown; readonly refuseStarts?: Ref.Ref; readonly refusalCause?: unknown; readonly failInjectionOnce?: Ref.Ref; @@ -318,13 +319,15 @@ function makeTestAdapter(input: { threadId: turnInput.threadId, providerThreadId: turnInput.providerThread.id, runId: turnInput.runId, - cause: EffectAcpErrors.AcpRequestError.fromProtocolError( - { - code: -32603, - message: `Session not found: ${turnInput.providerThread.nativeThreadRef?.nativeId}`, - }, - { method: "session/load" }, - ), + cause: + input.lostNativeSessionCause ?? + EffectAcpErrors.AcpRequestError.fromProtocolError( + { + code: -32603, + message: `Session not found: ${turnInput.providerThread.nativeThreadRef?.nativeId}`, + }, + { method: "session/load" }, + ), }); if ( input.refuseStarts !== undefined && @@ -2324,6 +2327,56 @@ describe("orchestration v2 provider switching", () => { }), ); + // regression: #46045 the agent's stdout broke during session/load at turn start. + it.live( + "recovers in a fresh native session when session/load at turn start fails in transport", + () => + Effect.gen(function* () { + const capturedTurns = yield* Ref.make>([]); + const loseNativeSessionOnce = yield* Ref.make(false); + yield* unverifiedReplacementHarness( + "lost-native-session-transport", + [ + makeTestAdapter({ + instanceId: GROK_MODEL_SELECTION.instanceId, + driver: GROK_DRIVER, + capabilities: AcpProviderCapabilitiesV2, + modelSelection: GROK_MODEL_SELECTION, + responseByRunOrdinal: {}, + capturedTurns, + loseNativeSessionOnce, + lostNativeSessionCause: new EffectAcpErrors.AcpTransportError({ + detail: "Antigravity sent a protocol line that is too large.", + cause: new Error("protocol line too large"), + }), + nativeThreadGeneration: yield* Ref.make(0), + }), + ], + ({ orchestrator, dispatchRequest, awaitSettled }) => + Effect.gen(function* () { + yield* dispatchRequest(1, GROK_MODEL_SELECTION); + yield* awaitSettled(1); + yield* Ref.set(loseNativeSessionOnce, true); + yield* dispatchRequest(2, GROK_MODEL_SELECTION); + yield* awaitSettled(2); + + const projection = yield* orchestrator.getThreadProjection(threadId); + const run2 = projection.runs.at(-1)!; + const failure = projection.turnItems.findLast((item) => item.type === "error"); + assert.equal( + run2.status, + "completed", + `turn 2 failed: ${failure?.type === "error" ? failure.failure.message : "no error item"}`, + ); + const turns = yield* Ref.get(capturedTurns); + assert.equal(turns.length, 2); + assert.notEqual(turns[1]!.nativeThreadId, turns[0]!.nativeThreadId); + assert.isNotEmpty(replacementRecordsFor(projection, run2.id)); + }), + ); + }), + ); + // regression: #44152 a retry after the replacement failed to open prompted the lost session. it.live("keeps recovering after the replacement session fails to open", () => Effect.gen(function* () { From 8f8cfc5763e68fd570e8a54aab85817ab4310873 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 30 Nov 2026 12:18:26 +0000 Subject: [PATCH 2/2] fix(server): ACP turns recover in a fresh session when session/load loses the agent's connection Co-Authored-By: Claude Opus 5.5 --- .../src/orchestration-v2/ProviderTurnStartService.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts index 7c048f40b8cb3..c09b5d3e01251 100644 --- a/apps/server/src/orchestration-v2/ProviderTurnStartService.ts +++ b/apps/server/src/orchestration-v2/ProviderTurnStartService.ts @@ -285,8 +285,16 @@ const NATIVE_SESSION_LOAD_METHODS: ReadonlySet = new Set([ const isAcpRequestError = Schema.is(EffectAcpErrors.AcpRequestError); +// A lost connection names no method; startTurn fails before the prompt, so the reload never finished. +const ACP_CONNECTION_LOST_TAGS = [ + "AcpTransportError", + "AcpProcessExitedError", + "AcpInputStreamEndedError", +] as const; + const nativeSessionLoadFailed = (error: unknown): boolean => (isAcpRequestError(error) && NATIVE_SESSION_LOAD_METHODS.has(error.method)) || + ACP_CONNECTION_LOST_TAGS.some((tag) => Predicate.isTagged(error, tag)) || (Predicate.hasProperty(error, "cause") && nativeSessionLoadFailed(error.cause)); /**