From 54e63625ad2a4d083a94a2a76a42d02276f0ea88 Mon Sep 17 00:00:00 2001 From: spoukyii <61633921+spoukyii@users.noreply.github.com> Date: Sat, 21 Nov 2026 18:08:43 -0800 Subject: [PATCH 1/2] test(antigravity): a continuation run that ends without starting leaves no background work Bug: The previous provider is still running background agents or commands, and switching would end them. --- .../Adapters/AntigravityAdapterV2.test.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts index fca472c6c433e..77a282c415beb 100644 --- a/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts @@ -1319,6 +1319,34 @@ describe("AntigravityAdapterV2 work after the prompt ends", () => { }).pipe(Effect.provide(layerSession)), ); + it.effect("leaves no background work when the continuation run ends without starting", () => + Effect.gen(function* () { + const { session, command, offers, send, startTurn, throughTerminal } = + yield* openSessionWithRunningCommand({ IsDaemon: true, WaitMsBeforeAsync: 500 }); + yield* startTurn(1, false); + yield* throughTerminal; + yield* send({ + sessionUpdate: "tool_call_update", + ...command, + status: "completed", + rawOutput: { output: "Command exited with code 0.", exit_code: 0 }, + }); + assert.lengthOf(offers, 1, "the finished daemon must wake the thread"); + yield* offers[0]!.dispatchIfCurrent!(Effect.void); + assert.isTrue(yield* session.hasPendingBackgroundWork!, "the queued continuation is owed"); + + assert.isDefined( + offers[0]!.onRunEndedWithoutStarting, + "a cancelled queued continuation must release its wake", + ); + yield* offers[0]!.onRunEndedWithoutStarting!(); + assert.isFalse( + yield* session.hasPendingBackgroundWork!, + "Stop on the queued continuation must let the thread switch providers", + ); + }).pipe(Effect.provide(layerSession)), + ); + // Frames as agy 1.5.11 sent them for `run_command` with `WaitMsBeforeAsync`: the prompt returns // end_turn while the command runs, and the agent replies when the command finishes. it.effect("keeps the run open while a command the agent waits for still runs", () => From 32b5533ea4eeb38e04422d9d561d16e1ada52cff Mon Sep 17 00:00:00 2001 From: spoukyii <61633921+spoukyii@users.noreply.github.com> Date: Sat, 21 Nov 2026 18:08:47 -0800 Subject: [PATCH 2/2] fix(acp): stopping a queued continuation lets the thread switch providers An ACP wake latched continuationRequested and kept its wake buffer until the continuation run started. When Stop cancelled that run while it was still queued, as it is behind a usage limit, nothing released the latch, so hasPendingBackgroundWork stayed true and every provider switch or fresh session was refused until the server restarted. The request now passes onRunEndedWithoutStarting, as the Claude and OpenCode adapters do, and drops the wake traffic the unstarted run would have drained. Bug: The previous provider is still running background agents or commands, and switching would end them. --- packages/provider-acp/src/server/adapter.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/provider-acp/src/server/adapter.ts b/packages/provider-acp/src/server/adapter.ts index e214a51586f4c..0574939e5feda 100644 --- a/packages/provider-acp/src/server/adapter.ts +++ b/packages/provider-acp/src/server/adapter.ts @@ -5234,6 +5234,20 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( } }), ), + // Drops the wake traffic the unstarted run would have drained, as its start does. + onRunEndedWithoutStarting: () => + continuationPermit.withPermit( + Effect.gen(function* () { + if ((yield* Ref.get(continuationGeneration)) !== generation) return; + yield* Ref.update(continuationGeneration, (value) => value + 1); + yield* Ref.set(continuationRequested, false); + yield* Ref.set(wakeBuffer, []); + yield* Ref.update(wakeReports, ({ reports, offered }) => ({ + reports: new Map([...reports].filter(([key]) => !offered.has(key))), + offered: noWakeReports.offered, + })); + }), + ), dispatchIfCurrent: (effect) => continuationPermit.withPermit( Effect.gen(function* () {