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 <[email protected]>
This commit is contained in:
Julius Marmingeandcodex committed 2026-08-14 11:23:25 +02:00
1 parent 4d7d87c3d9
commit b13febf528
2 files changed
+19 -14

No files matched your search

@@ -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),
);
});
@@ -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`,