From b13febf52889432acb3cdaeb8c90fd006c95259a Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 20 Jul 2026 16:47:44 +0200 Subject: [PATCH] fix(acp): release turns after interrupt timeout Clears the timed-out turn with an identity guard so a late completion cannot clobber a newer active turn. Addresses https://github.com/pingdotgg/t3code/pull/2829#discussion_r3483533894 Co-authored-by: codex --- .../Adapters/AcpAdapterV2.test.ts | 32 +++++++++++-------- .../orchestration-v2/Adapters/AcpAdapterV2.ts | 1 + 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts index c53fa28710..ee9578dd93 100644 --- a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts @@ -458,7 +458,7 @@ describe("AcpAdapterV2", () => { }).pipe(Effect.provide(testLayer), Effect.scoped), ); - it.effect("does not release an ACP turn when cancellation is not acknowledged", () => + it.effect("releases an ACP turn when cancellation times out", () => Effect.gen(function* () { const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner; const fileSystem = yield* FileSystem.FileSystem; @@ -538,19 +538,23 @@ describe("AcpAdapterV2", () => { const interruptError = yield* Fiber.join(interruptFiber); assert.equal(interruptError._tag, "ProviderAdapterInterruptError"); - const secondTurnError = yield* runtime - .startTurn( - makeTurnInput({ - threadId, - providerThread, - instanceId, - runtimePolicy, - now, - ordinal: 2, - }), - ) - .pipe(Effect.flip); - assert.equal(secondTurnError._tag, "ProviderAdapterTurnStartError"); + yield* runtime.startTurn( + makeTurnInput({ + threadId, + providerThread, + instanceId, + runtimePolicy, + now, + ordinal: 2, + }), + ); + yield* Stream.fromQueue(protocolEvents).pipe( + Stream.filter( + (event) => + event.direction === "outgoing" && rawProtocolMethod(event) === "session/prompt", + ), + Stream.runHead, + ); }).pipe(Effect.provide(testLayer), Effect.scoped), ); }); diff --git a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.ts index 88dd28ba0d..e5fc50d3b2 100644 --- a/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.ts @@ -2379,6 +2379,7 @@ export function makeAcpAdapterV2(options: AcpAdapterV2Options): ProviderAdapterV Effect.timeoutOption("10 seconds"), ); if (Option.isNone(stopped)) { + yield* Ref.update(activeTurn, (current) => (current === context ? null : current)); return yield* new ProviderAdapterProtocolError({ driver, detail: `ACP provider turn ${turnInput.providerTurnId} did not acknowledge cancellation before the interrupt timeout`,