From 83afa0132a17c1cd778f6a497b40243a2adafb82 Mon Sep 17 00:00:00 2001 From: nullStack65 <112618179+nullStack65@users.noreply.github.com> Date: Mon, 23 Nov 2026 05:57:47 +0000 Subject: [PATCH] fix(acp): keep the late-permission wake bound to its own turn (CLO-1067) The dispatcher can attach the next turn while offerContinuationRun is still returning, so reading turnAttached afterwards returned the new turn's deferred and the detached permission request waited on the wrong turn until it timed out. Capture the deferred before the offer. Adds a regression test: a late workspace edit wakes only the bound ACP session. Without the fix it times out at 120s; with it all 29 AntigravityAdapterV2 tests pass (Node 26.13.1). Refs: CLO-1067 Source-Patch: CLO-1067 detached-edit.patch sha256 07c7e978d76a1218c95c73f2525de615a9c78c90fc8fc6333ccb05b64547fedf Model: claude-opus-5-5 Task: fix Agent: Claude Code (CLO-1067 lane) Lane: magpie Harness: t3/claude Model-family: Claude Opus Model-generation: 5.5 Skills-SHA: unknown (source unavailable) Co-Authored-By: Claude Opus 5.5 --- .../Adapters/AntigravityAdapterV2.test.ts | 48 ++++++++++++++++++- packages/provider-acp/src/server/adapter.ts | 4 +- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts index e87b96f990466..9c356a178a34c 100644 --- a/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts @@ -1028,12 +1028,19 @@ const openSessionWithRunningCommand = Effect.fn("openSessionWithRunningCommand") let terminate: AntigravityAdapterV2RuntimeInput["onTermination"]; const usage = { sessionUpdate: "usage_update", used: 9000, size: 1048576 } as const; const offers: Array = []; + const firstOffer = yield* Deferred.make(); const instanceId = ProviderInstanceId.make("antigravity-wake-test"); const threadId = ThreadId.make("thread-antigravity-wake"); const adapter = yield* makeAntigravityAdapterV2({ instanceId, selfInvocation: yield* resolveSelfInvocation(), - continuationRequests: { offer: (request) => Effect.sync(() => void offers.push(request)) }, + continuationRequests: { + offer: (request) => + Effect.sync(() => void offers.push(request)).pipe( + Effect.andThen(Deferred.succeed(firstOffer, undefined)), + Effect.asVoid, + ), + }, makeRuntime: (input) => { terminate = input.onTermination; return makeAntigravityAcpRuntime({ @@ -1183,6 +1190,7 @@ const openSessionWithRunningCommand = Effect.fn("openSessionWithRunningCommand") command, usage, offers, + firstOffer: Deferred.await(firstOffer), send, startTurn, until, @@ -1211,6 +1219,44 @@ const openSessionWithRunningCommand = Effect.fn("openSessionWithRunningCommand") }); describe("AntigravityAdapterV2 work after the prompt ends", () => { + it.effect("wakes for a late workspace edit only on the bound ACP session", () => + Effect.gen(function* () { + const { startTurn, throughTerminal, requestPermission, firstOffer, offers } = + yield* openSessionWithRunningCommand({ IsDaemon: true, WaitMsBeforeAsync: 500 }); + yield* startTurn(1, false); + yield* throughTerminal; + + const edit = (sessionId: string) => + requestPermission( + { + sessionId, + toolCall: { + toolCallId: "edit-1", + kind: "edit", + title: "Edit workspace file", + locations: [{ path: `${process.cwd()}/example.ts` }], + }, + options: [ + { optionId: "allow", kind: "allow_once", name: "Allow" }, + { optionId: "deny", kind: "reject_once", name: "Deny" }, + ], + }, + { requestId: `request-${sessionId}`, method: "session/request_permission" }, + ); + + assert.deepEqual(yield* edit("unbound-session"), { outcome: { outcome: "cancelled" } }); + assert.lengthOf(offers, 0); + const pendingEdit = yield* edit("mock-session-1").pipe(Effect.forkScoped()); + yield* firstOffer; + assert.lengthOf(offers, 1); + yield* offers[0]!.dispatchIfCurrent!(Effect.void); + yield* startTurn(2, true); + assert.deepEqual(yield* Fiber.join(pendingEdit), { + outcome: { outcome: "selected", optionId: "allow" }, + }); + }).pipe(Effect.provide(layerSession)), + ); + // agy sets `IsDaemon` on a command it does not wait for. When it exits, the agent replies // with no prompt open. it.effect("continues in one run when a finished daemon wakes the agent", () => diff --git a/packages/provider-acp/src/server/adapter.ts b/packages/provider-acp/src/server/adapter.ts index 3d554708a6e72..fd19f4c602ffd 100644 --- a/packages/provider-acp/src/server/adapter.ts +++ b/packages/provider-acp/src/server/adapter.ts @@ -5511,10 +5511,12 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( generation, Effect.gen(function* () { if (yield* Ref.get(stoppedRunQuarantine)) return false; + // The dispatcher can attach the next turn before its offer returns. + const attached = turnAttached; if ((yield* Ref.get(activeTurn)) !== null) return null; const sessionId = yield* Ref.get(activeSessionId); if (sessionId !== null) yield* offerContinuationRun(sessionId); - return turnAttached; + return attached; }), ); if (Option.isNone(waiting)) return yield* Effect.never;