From 1b2e4ccd83097c0e1196ce4d9b4ff013be8b777b Mon Sep 17 00:00:00 2001 From: MaxFriedman123 Date: Fri, 20 Nov 2026 16:36:35 -0500 Subject: [PATCH 1/6] fix(antigravity): keep swarm workers alive after the prompt ends --- .../Adapters/AntigravityAdapterV2.test.ts | 83 ++++++++++++-- .../Adapters/AntigravityAdapterV2.ts | 3 + .../src/provider/acp/AntigravityChildWork.ts | 105 ++++++++++++++---- packages/provider-acp/src/server/adapter.ts | 46 ++++++-- 4 files changed, 196 insertions(+), 41 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..2f100fab0a7bc 100644 --- a/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts @@ -998,6 +998,7 @@ const openSessionWithRunningCommand = Effect.fn("openSessionWithRunningCommand") detachedChildProfile?: string, /** agy 1.5.11 answers a steered prompt once the next one arrives, which runs to `releaseSteer`. */ steering?: { readonly agentVersion: string; readonly holdsFirstPrompt: boolean }, + initialTool?: EffectAcpSchema.SessionUpdate, ) { const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner; const path = yield* Path.Path; @@ -1075,16 +1076,17 @@ const openSessionWithRunningCommand = Effect.fn("openSessionWithRunningCommand") return { stopReason: "end_turn" as const }; } yield* send( - detachedChildProfile === undefined - ? { sessionUpdate: "tool_call", ...command, status: "in_progress" } - : { - sessionUpdate: "tool_call", - toolCallId: "call_research", - kind: "other", - title: "Run invoke_subagent", - status: "completed", - rawInput: { TypeName: "research", Role: "Researcher", Prompt: "Read it" }, - }, + initialTool ?? + (detachedChildProfile === undefined + ? { sessionUpdate: "tool_call", ...command, status: "in_progress" } + : { + sessionUpdate: "tool_call", + toolCallId: "call_research", + kind: "other", + title: "Run invoke_subagent", + status: "completed", + rawInput: { TypeName: "research", Role: "Researcher", Prompt: "Read it" }, + }), ); yield* send({ sessionUpdate: "agent_message_chunk", @@ -1211,6 +1213,67 @@ const openSessionWithRunningCommand = Effect.fn("openSessionWithRunningCommand") }); describe("AntigravityAdapterV2 work after the prompt ends", () => { + it.live("keeps the run open for swarm workers after the launch tool completes", () => + Effect.gen(function* () { + const fs = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const profile = yield* fs.makeTempDirectoryScoped({ prefix: "t3-antigravity-swarm-" }); + const brain = path.join(profile, "antigravity-acp", "brain"); + const swarm = path.join(brain, "mock-session-1", ".system_generated", "swarm"); + const logs = path.join(brain, "worker-1", ".system_generated", "logs"); + const transcript = path.join(logs, "transcript.jsonl"); + yield* fs.makeDirectory(swarm, { recursive: true }); + yield* fs.makeDirectory(logs, { recursive: true }); + yield* fs.writeFileString( + path.join(swarm, "members.json"), + JSON.stringify({ + members: { + coordinator: { conversation_id: "mock-session-1", wake_mode: "working" }, + worker: { conversation_id: "worker-1", wake_mode: "working" }, + }, + }), + ); + yield* fs.writeFileString( + transcript, + JSON.stringify({ step_index: 0, type: "SYSTEM_MESSAGE", status: "DONE" }) + "\n", + ); + const { offers, send, startTurn, throughPromptSettled, throughTerminal, usage } = + yield* openSessionWithRunningCommand({}, profile, undefined, { + sessionUpdate: "tool_call", + toolCallId: "call_swarm", + kind: "other", + title: "Run swarm", + status: "completed", + rawInput: { action: "add", name: "worker", brief: "Check the chart" }, + }); + + yield* startTurn(1, false); + yield* throughPromptSettled; + yield* fs.writeFileString( + transcript, + [ + { + step_index: 1, + type: "PLANNER_RESPONSE", + status: "DONE", + tool_calls: [{ name: "swarm_wait" }], + }, + { step_index: 2, type: "GENERIC", status: "DONE" }, + ] + .map((step) => JSON.stringify(step)) + .join("\n") + "\n", + ); + yield* send({ + sessionUpdate: "agent_message_chunk", + content: { type: "text", text: "The swarm checked the chart." }, + }); + yield* send(usage); + const events = yield* throughTerminal; + assert.include(JSON.stringify(events), "The swarm checked the chart."); + assert.lengthOf(offers, 0, "the worker report stays in the original run"); + }).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/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.ts b/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.ts index 77ab7136e678d..73adee60df9a7 100644 --- a/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.ts +++ b/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.ts @@ -32,6 +32,7 @@ import { import { ANTIGRAVITY_SUBAGENT_BATCH_TITLE, antigravitySubagentLaunches, + antigravitySwarmAtWork, describeAntigravitySubagentLaunches, readAntigravityChildrenAtWork, } from "../../provider/acp/AntigravityChildWork.ts"; @@ -298,6 +299,8 @@ export function makeAntigravityAcpAdapterFlavor( : { watchPromptOutcome: (sessionId: string) => watchAntigravityPromptOutcome(profileDirectory, sessionId), + detachedWorkOutlivingPrompt: (sessionId: string) => + antigravitySwarmAtWork(profileDirectory, sessionId), subagentsOutlivingPrompt: ({ sessionId, nativeTaskIds }) => readAntigravityChildrenAtWork({ profileDirectory, diff --git a/apps/server/src/provider/acp/AntigravityChildWork.ts b/apps/server/src/provider/acp/AntigravityChildWork.ts index 625062b5368b3..485fd3a6d2887 100644 --- a/apps/server/src/provider/acp/AntigravityChildWork.ts +++ b/apps/server/src/provider/acp/AntigravityChildWork.ts @@ -367,32 +367,24 @@ function transcriptSteps( ); } -/** Reads the tail of the transcript at the named child's own unlinked profile path. */ -async function readChildTranscript( +async function readTranscriptTail( profileRoot: string, - child: InvokeRecord["children"][number], - prompt: string, + conversationId: string, + logUri: string | undefined, byteCap: number, ) { const expected = ( await antigravityManagedPath( profileRoot, - [ - "antigravity-acp", - "brain", - child.conversationId, - ".system_generated", - "logs", - "transcript.jsonl", - ], + ["antigravity-acp", "brain", conversationId, ".system_generated", "logs", "transcript.jsonl"], "file", ) )?.path; if (expected === undefined) return undefined; - if (child.logUri !== undefined) { + if (logUri !== undefined) { let named: string; try { - named = NodeURL.fileURLToPath(child.logUri); + named = NodeURL.fileURLToPath(logUri); } catch { return undefined; } @@ -414,16 +406,50 @@ async function readChildTranscript( let lineStart = 0; if (tailStart > 0) { const newline = bytes.indexOf(0x0a); - if (newline === -1) return { steps: [], truncated: true }; + if (newline === -1) return { contents: "", truncated: true }; lineStart = newline + 1; } const contents = bytes.toString("utf8", lineStart); - return { steps: transcriptSteps(contents, prompt), truncated: tailStart > 0 }; + return { contents, truncated: tailStart > 0 }; } finally { await handle.close(); } } +const decodeSwarmRoster = Schema.decodeUnknownOption( + Schema.fromJsonString( + Schema.Struct({ + members: Schema.Record( + Schema.String, + Schema.Struct({ + conversation_id: Schema.String, + killed: Schema.optional(Schema.Boolean), + wake_mode: Schema.optional(Schema.String), + }), + ), + }), + ), +); + +function swarmWorkerAtWork(transcript: string): boolean { + const lines = transcript.split("\n"); + const results: Array = []; + for (let index = lines.length - 1; index >= 0; index -= 1) { + const step = Option.getOrUndefined(decodeTranscriptLine(lines[index])); + if (index === lines.length - 1 && step?.type === "ERROR_MESSAGE") return false; + if (step?.type === "GENERIC") { + results.push(step.status === "DONE"); + continue; + } + if (step?.type !== "PLANNER_RESPONSE" || step.status !== "DONE") return true; + const calls = step.tool_calls ?? []; + if (calls.length === 0) return results.length > 0; + const wait = calls.findIndex((call) => call.name === "swarm_wait"); + return wait < 0 || results.length < calls.length || !results[results.length - 1 - wait]; + } + return true; +} + class AntigravityChildWorkReadError extends Schema.TaggedError()( "AntigravityChildWorkReadError", { cause: Schema.Defect() }, @@ -433,6 +459,42 @@ class AntigravityChildWorkReadError extends Schema.TaggedError { + const root = await antigravityProfileRoot(profileDirectory); + if (root === undefined) return false; + const file = await antigravityManagedPath( + root, + ["antigravity-acp", "brain", sessionId, ".system_generated", "swarm", "members.json"], + "file", + ); + if (file === undefined || file.info.size > MAX_STEP_BYTES) return false; + const roster = Option.getOrUndefined( + decodeSwarmRoster(await NodeFSP.readFile(file.path, "utf8")), + ); + if (roster === undefined) return false; + const workers = Object.values(roster.members); + if (workers.length > MAX_DETACHED_CHILDREN) return false; + for (const worker of workers) { + const id = worker.conversation_id; + if (worker.killed || id === sessionId || !NATIVE_ID.test(id)) continue; + const tail = await readTranscriptTail(root, id, undefined, MAX_STEP_BYTES); + const contents = tail?.contents.trimEnd(); + if (contents ? swarmWorkerAtWork(contents) : worker.wake_mode === "working") return true; + } + return false; + }; + return yield* Effect.tryPromise({ + try: read, + catch: (cause) => new AntigravityChildWorkReadError({ cause }), + }).pipe(Effect.orElseSucceed(() => false)); +}); + /** Children a subagent tool call launched, proven by the parent's own session record. */ export const readAntigravityChildWork = Effect.fn("readAntigravityChildWork")(function* (input: { readonly profileDirectory: string; @@ -477,17 +539,20 @@ export const readAntigravityChildWork = Effect.fn("readAntigravityChildWork")(fu ); return Promise.all( children.map(async (child, index) => { - const transcript = await readChildTranscript( + const transcript = await readTranscriptTail( profileRoot, - child, - launches[index]?.prompt ?? "", + child.conversationId, + child.logUri, byteCap, ).catch(() => undefined); return { conversationId: child.conversationId, role: launches[index]?.role ?? "", prompt: launches[index]?.prompt ?? "", - steps: transcript?.steps ?? null, + steps: + transcript === undefined + ? null + : transcriptSteps(transcript.contents, launches[index]?.prompt ?? ""), truncated: transcript?.truncated ?? false, }; }), diff --git a/packages/provider-acp/src/server/adapter.ts b/packages/provider-acp/src/server/adapter.ts index a78c40556381f..191e54d1228d8 100644 --- a/packages/provider-acp/src/server/adapter.ts +++ b/packages/provider-acp/src/server/adapter.ts @@ -526,6 +526,8 @@ export interface AcpAdapterV2Flavor { cwd: string, ) => Effect.Effect; readonly subagentsIdleOnTurnCompletion?: boolean; + /** Checks native work that has no running ACP tool or subagent item. */ + readonly detachedWorkOutlivingPrompt?: (sessionId: string) => Effect.Effect; /** * Subagents the agent goes on running after its prompt, with no update when one ends. Asked * when the prompt ends and when a reply the agent started by itself ends; the native task ids @@ -1676,6 +1678,7 @@ interface ActiveAcpTurn { readonly promptStarted: Deferred.Deferred; promptUsage: EffectAcpSchema.Usage | undefined; backgroundFinalizeGeneration: number; + detachedWorkPending: boolean; /** `replyEndsWithUsageUpdate`: output arrived and its closing `usage_update` has not. */ replyOpen: boolean; /** The agent's own id for this turn's prompt, from `forkFromTurn.nativeTurnId`. */ @@ -2701,11 +2704,12 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( // has no prompt, so nothing else ends it. const held = yield* Ref.get(activeTurn); if ( - flavor.toolOutlivesPrompt === undefined || + (flavor.toolOutlivesPrompt === undefined && + flavor.detachedWorkOutlivingPrompt === undefined) || held === null || !held.promptSettled || held.finalized || - !hasDeferredBackgroundWork(held) + !(held.detachedWorkPending || hasDeferredBackgroundWork(held)) ) return; for (const tool of held.tools.values()) { @@ -8675,16 +8679,25 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( const debounce = context.replyOpen ? ACP_OPEN_REPLY_QUIET_LIMIT : ACP_DEFERRED_FINALIZE_DEBOUNCE; + const canFinalize = () => + context.promptSettled && + !context.finalized && + !context.interrupted && + context.backgroundFinalizeGeneration === generation && + !hasDeferredBackgroundWork(context); yield* Effect.gen(function* () { - yield* Effect.sleep(debounce); - if ( - context.finalized || - context.interrupted || - context.backgroundFinalizeGeneration !== generation - ) { - return; + while (true) { + yield* Effect.sleep(debounce); + if (!canFinalize()) return; + const wasPending = context.detachedWorkPending; + if (flavor.detachedWorkOutlivingPrompt !== undefined) { + const pending = yield* flavor.detachedWorkOutlivingPrompt(context.nativeThreadId); + if (!canFinalize()) return; + context.detachedWorkPending = pending; + } + // Allow the last worker's wake to arrive after its native work has stopped. + if (!context.detachedWorkPending && !wasPending) break; } - if (hasDeferredBackgroundWork(context)) return; const status = context.promptSettledStatus ?? "completed"; yield* finalizeTurn(context, status); }).pipe(Effect.forkIn(sessionScope), Effect.asVoid); @@ -9068,10 +9081,20 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( } yield* idleReportedSubagents(context); if (context.finalized) return; + if ( + defersFinalizeForBackgroundWork && + status === "completed" && + flavor.detachedWorkOutlivingPrompt !== undefined + ) { + context.detachedWorkPending = yield* flavor.detachedWorkOutlivingPrompt( + context.nativeThreadId, + ); + if (context.detachedWorkPending) yield* scheduleDeferredFinalize(context); + } if ( defersFinalizeForBackgroundWork && !context.interrupted && - hasDeferredBackgroundWork(context) + (context.detachedWorkPending || hasDeferredBackgroundWork(context)) ) { yield* closeTextStreams(context); yield* ( @@ -9312,6 +9335,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( promptStarted, promptUsage: undefined, backgroundFinalizeGeneration: 0, + detachedWorkPending: false, replyOpen: false, nativePromptId: undefined, lastProgressAt: 0, From f5f504841c904a5c022706f2b28747307448f9ea Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 20 Nov 2026 21:49:37 +0000 Subject: [PATCH 2/6] fix(antigravity): read swarm work before the deferred-finalize sleep Checking the swarm board before each debounce keeps the same hold and one-debounce grace after the last worker stops, and lets the swarm test run on the test clock instead of six seconds of wall time. Co-Authored-By: Claude Opus 5.5 --- .../Adapters/AntigravityAdapterV2.test.ts | 5 ++++- packages/provider-acp/src/server/adapter.ts | 22 +++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts index 2f100fab0a7bc..3a13df82e78bc 100644 --- a/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts @@ -1213,7 +1213,8 @@ const openSessionWithRunningCommand = Effect.fn("openSessionWithRunningCommand") }); describe("AntigravityAdapterV2 work after the prompt ends", () => { - it.live("keeps the run open for swarm workers after the launch tool completes", () => + // A swarm launch completes at once; only the board and the worker's transcript show the work. + it.effect("keeps the run open for swarm workers after the launch tool completes", () => Effect.gen(function* () { const fs = yield* FileSystem.FileSystem; const path = yield* Path.Path; @@ -1249,6 +1250,7 @@ describe("AntigravityAdapterV2 work after the prompt ends", () => { yield* startTurn(1, false); yield* throughPromptSettled; + yield* TestClock.adjust("10 minutes"); yield* fs.writeFileString( transcript, [ @@ -1268,6 +1270,7 @@ describe("AntigravityAdapterV2 work after the prompt ends", () => { content: { type: "text", text: "The swarm checked the chart." }, }); yield* send(usage); + yield* TestClock.adjust("3 seconds"); const events = yield* throughTerminal; assert.include(JSON.stringify(events), "The swarm checked the chart."); assert.lengthOf(offers, 0, "the worker report stays in the original run"); diff --git a/packages/provider-acp/src/server/adapter.ts b/packages/provider-acp/src/server/adapter.ts index 1faecc7d6aced..8614215f71ebb 100644 --- a/packages/provider-acp/src/server/adapter.ts +++ b/packages/provider-acp/src/server/adapter.ts @@ -8694,18 +8694,22 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( !context.interrupted && context.backgroundFinalizeGeneration === generation && !hasDeferredBackgroundWork(context); + const readDetachedWork = Effect.fn("AcpAdapterV2.readDetachedWork")(function* () { + if (flavor.detachedWorkOutlivingPrompt === undefined) return true; + const pending = yield* flavor.detachedWorkOutlivingPrompt(context.nativeThreadId); + if (!canFinalize()) return false; + context.detachedWorkPending = pending; + return true; + }); + if (!(yield* readDetachedWork())) return; yield* Effect.gen(function* () { - while (true) { + yield* Effect.sleep(debounce); + if (!canFinalize()) return; + // Wait one more debounce after the work stops, for the last worker's wake. + while (context.detachedWorkPending) { + if (!(yield* readDetachedWork())) return; yield* Effect.sleep(debounce); if (!canFinalize()) return; - const wasPending = context.detachedWorkPending; - if (flavor.detachedWorkOutlivingPrompt !== undefined) { - const pending = yield* flavor.detachedWorkOutlivingPrompt(context.nativeThreadId); - if (!canFinalize()) return; - context.detachedWorkPending = pending; - } - // Allow the last worker's wake to arrive after its native work has stopped. - if (!context.detachedWorkPending && !wasPending) break; } const status = context.promptSettledStatus ?? "completed"; yield* finalizeTurn(context, status); From 86fcb570abbe814aab7a343760178c5efcb50b0a Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 20 Nov 2026 22:02:29 +0000 Subject: [PATCH 3/6] fix(antigravity): re-read swarm work after every debounce A run now finalizes only after two idle reads in a row, so swarm work that starts during the last debounce still holds it open. The prompt's settle path also keeps the run deferred on its own first read. Co-Authored-By: Claude Opus 5.5 --- packages/provider-acp/src/server/adapter.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/provider-acp/src/server/adapter.ts b/packages/provider-acp/src/server/adapter.ts index 8614215f71ebb..7b623f3d83f17 100644 --- a/packages/provider-acp/src/server/adapter.ts +++ b/packages/provider-acp/src/server/adapter.ts @@ -8703,13 +8703,13 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( }); if (!(yield* readDetachedWork())) return; yield* Effect.gen(function* () { - yield* Effect.sleep(debounce); - if (!canFinalize()) return; - // Wait one more debounce after the work stops, for the last worker's wake. - while (context.detachedWorkPending) { - if (!(yield* readDetachedWork())) return; + while (true) { yield* Effect.sleep(debounce); if (!canFinalize()) return; + // Finalize only on two idle reads in a row, so the last worker's wake can arrive. + const wasPending = context.detachedWorkPending; + if (!(yield* readDetachedWork())) return; + if (!context.detachedWorkPending && !wasPending) break; } const status = context.promptSettledStatus ?? "completed"; yield* finalizeTurn(context, status); @@ -9131,20 +9131,22 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* ( } yield* idleReportedSubagents(context); if (context.finalized) return; + let detachedWorkSeen = false; if ( defersFinalizeForBackgroundWork && status === "completed" && flavor.detachedWorkOutlivingPrompt !== undefined ) { - context.detachedWorkPending = yield* flavor.detachedWorkOutlivingPrompt( + detachedWorkSeen = yield* flavor.detachedWorkOutlivingPrompt( context.nativeThreadId, ); - if (context.detachedWorkPending) yield* scheduleDeferredFinalize(context); + context.detachedWorkPending = detachedWorkSeen; + if (detachedWorkSeen) yield* scheduleDeferredFinalize(context); } if ( defersFinalizeForBackgroundWork && !context.interrupted && - (context.detachedWorkPending || hasDeferredBackgroundWork(context)) + (detachedWorkSeen || hasDeferredBackgroundWork(context)) ) { yield* closeTextStreams(context); yield* ( From be271eb9b70553d7bbea9eec8fa31961c6549dec Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 21 Nov 2026 00:27:52 +0000 Subject: [PATCH 4/6] test(antigravity): use a live swarm worker's parked transcript shape Co-Authored-By: Claude Opus 5.5 --- .../src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts b/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts index 3a13df82e78bc..06ee9649a5b4a 100644 --- a/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts +++ b/apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts @@ -1258,9 +1258,10 @@ describe("AntigravityAdapterV2 work after the prompt ends", () => { step_index: 1, type: "PLANNER_RESPONSE", status: "DONE", - tool_calls: [{ name: "swarm_wait" }], + tool_calls: [{ name: "post_message" }, { name: "swarm_wait" }], }, { step_index: 2, type: "GENERIC", status: "DONE" }, + { step_index: 3, type: "GENERIC", status: "DONE" }, ] .map((step) => JSON.stringify(step)) .join("\n") + "\n", From fcc38af4b9cc4eaa6d37b46731cfed44c7ab9f3d Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 21 Nov 2026 00:37:43 +0000 Subject: [PATCH 5/6] fix(antigravity): keep a parked swarm worker at work while a sibling call runs Co-Authored-By: Claude Opus 5.5 --- .../provider/acp/AntigravityChildWork.test.ts | 50 +++++++++++++++++++ .../src/provider/acp/AntigravityChildWork.ts | 12 +++-- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/apps/server/src/provider/acp/AntigravityChildWork.test.ts b/apps/server/src/provider/acp/AntigravityChildWork.test.ts index 21783cbae1d3d..db4712a8beb61 100644 --- a/apps/server/src/provider/acp/AntigravityChildWork.test.ts +++ b/apps/server/src/provider/acp/AntigravityChildWork.test.ts @@ -10,6 +10,7 @@ import * as Path from "effect/Path"; import { ANTIGRAVITY_SUBAGENT_BATCH_TITLE, antigravitySubagentLaunches, + antigravitySwarmAtWork, describeAntigravitySubagentLaunches, readAntigravityChildrenAtWork, readAntigravityChildWork, @@ -540,6 +541,55 @@ it.layer(NodeServices.layer)("readAntigravityChildWork", (it) => { }), ); + it.effect("counts a parked swarm worker at work only while a sibling call still runs", () => + Effect.gen(function* () { + const fs = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const profile = yield* fs.makeTempDirectoryScoped({ prefix: "t3-agy-swarm-" }); + const brain = path.join(profile, "antigravity-acp", "brain"); + const swarm = path.join(brain, ROOT, ".system_generated", "swarm"); + const logs = path.join(brain, CHILD, ".system_generated", "logs"); + yield* fs.makeDirectory(swarm, { recursive: true }); + yield* fs.makeDirectory(logs, { recursive: true }); + yield* fs.writeFileString( + path.join(swarm, "members.json"), + JSON.stringify({ + members: { + coordinator: { conversation_id: ROOT, wake_mode: "mentions" }, + writer: { conversation_id: CHILD, wake_mode: "mentions" }, + }, + }), + ); + // agy 1.5.13 parks a worker with swarm_wait after the call it ran beside it. + const parked = (sibling: string, siblingStatus: string) => + fs.writeFileString( + path.join(logs, "transcript.jsonl"), + [ + { step_index: 0, type: "SYSTEM_MESSAGE", status: "DONE" }, + { + step_index: 1, + type: "PLANNER_RESPONSE", + status: "DONE", + tool_calls: [{ name: sibling }, { name: "swarm_wait" }], + }, + { step_index: 2, type: "GENERIC", status: siblingStatus }, + { step_index: 3, type: "GENERIC", status: "DONE" }, + ] + .map((step) => JSON.stringify(step)) + .join("\n") + "\n", + ); + + for (const [sibling, status, atWork] of [ + ["post_message", "DONE", false], + ["run_command", "ERROR", false], + ["run_command", "RUNNING", true], + ] as const) { + yield* parked(sibling, status); + expect(yield* antigravitySwarmAtWork(profile, ROOT), `${sibling} ${status}`).toBe(atWork); + } + }), + ); + it.effect("shares one transcript budget across the batch", () => Effect.gen(function* () { const filler = JSON.stringify({ diff --git a/apps/server/src/provider/acp/AntigravityChildWork.ts b/apps/server/src/provider/acp/AntigravityChildWork.ts index 485fd3a6d2887..3be120752c71b 100644 --- a/apps/server/src/provider/acp/AntigravityChildWork.ts +++ b/apps/server/src/provider/acp/AntigravityChildWork.ts @@ -433,19 +433,25 @@ const decodeSwarmRoster = Schema.decodeUnknownOption( function swarmWorkerAtWork(transcript: string): boolean { const lines = transcript.split("\n"); - const results: Array = []; + const results: Array = []; for (let index = lines.length - 1; index >= 0; index -= 1) { const step = Option.getOrUndefined(decodeTranscriptLine(lines[index])); if (index === lines.length - 1 && step?.type === "ERROR_MESSAGE") return false; if (step?.type === "GENERIC") { - results.push(step.status === "DONE"); + results.push(step.status); continue; } if (step?.type !== "PLANNER_RESPONSE" || step.status !== "DONE") return true; const calls = step.tool_calls ?? []; if (calls.length === 0) return results.length > 0; const wait = calls.findIndex((call) => call.name === "swarm_wait"); - return wait < 0 || results.length < calls.length || !results[results.length - 1 - wait]; + // A sibling call that failed has ended; one still running keeps the worker at work. + return ( + wait < 0 || + results.length < calls.length || + results[results.length - 1 - wait] !== "DONE" || + results.some((status) => status !== "DONE" && status !== "ERROR") + ); } return true; } From 99461bb66a3edcb2b5ae920ec104da04cfcc4601 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 21 Nov 2026 03:01:16 +0000 Subject: [PATCH 6/6] fix(antigravity): count a swarm worker's background task as work agy 1.5.13 moves a long worker command such as `sleep 120` to a background task, and the worker then ends its reply with no tool call. The swarm read treated that worker as idle, so the run settled seconds after the launch prompt. A worker now stays at work while its transcript shows a background task with no finish message. Co-Authored-By: Claude Opus 5.5 --- .../provider/acp/AntigravityChildWork.test.ts | 63 ++++++++++++------- .../src/provider/acp/AntigravityChildWork.ts | 21 ++++++- 2 files changed, 62 insertions(+), 22 deletions(-) diff --git a/apps/server/src/provider/acp/AntigravityChildWork.test.ts b/apps/server/src/provider/acp/AntigravityChildWork.test.ts index db4712a8beb61..592849984bad7 100644 --- a/apps/server/src/provider/acp/AntigravityChildWork.test.ts +++ b/apps/server/src/provider/acp/AntigravityChildWork.test.ts @@ -541,7 +541,7 @@ it.layer(NodeServices.layer)("readAntigravityChildWork", (it) => { }), ); - it.effect("counts a parked swarm worker at work only while a sibling call still runs", () => + it.effect("counts a parked swarm worker at work only while its calls or tasks run", () => Effect.gen(function* () { const fs = yield* FileSystem.FileSystem; const path = yield* Path.Path; @@ -560,32 +560,53 @@ it.layer(NodeServices.layer)("readAntigravityChildWork", (it) => { }, }), ); - // agy 1.5.13 parks a worker with swarm_wait after the call it ran beside it. - const parked = (sibling: string, siblingStatus: string) => + const writeSteps = (steps: ReadonlyArray) => fs.writeFileString( path.join(logs, "transcript.jsonl"), - [ - { step_index: 0, type: "SYSTEM_MESSAGE", status: "DONE" }, - { - step_index: 1, - type: "PLANNER_RESPONSE", - status: "DONE", - tool_calls: [{ name: sibling }, { name: "swarm_wait" }], - }, - { step_index: 2, type: "GENERIC", status: siblingStatus }, - { step_index: 3, type: "GENERIC", status: "DONE" }, - ] - .map((step) => JSON.stringify(step)) + [{ step_index: 0, type: "SYSTEM_MESSAGE", status: "DONE" }, ...steps] + .map((step, index) => JSON.stringify({ ...step, step_index: index })) .join("\n") + "\n", ); + // agy 1.5.13 parks a worker with swarm_wait after the call it ran beside it. + const parked = (sibling: string, siblingStatus: string) => [ + { + type: "PLANNER_RESPONSE", + status: "DONE", + tool_calls: [{ name: sibling }, { name: "swarm_wait" }], + }, + { type: "GENERIC", status: siblingStatus }, + { type: "GENERIC", status: "DONE" }, + ]; + // A long command moves to a background task and the worker's reply ends without a call. + const task = `${CHILD}/task-2`; + const backgrounded = [ + { type: "PLANNER_RESPONSE", status: "DONE", tool_calls: [{ name: "run_command" }] }, + { + type: "GENERIC", + status: "RUNNING", + content: `Tool is running as a background task with task id: ${task}\nTask Description: sleep 120`, + }, + { type: "PLANNER_RESPONSE", status: "DONE", content: "Waiting for sleep 120." }, + ]; + const finished = { + type: "SYSTEM_MESSAGE", + status: "DONE", + content: `[Message] sender=${task} content=Task id "${task}" finished with result:\nCommand exited with code 0.`, + }; - for (const [sibling, status, atWork] of [ - ["post_message", "DONE", false], - ["run_command", "ERROR", false], - ["run_command", "RUNNING", true], + for (const [label, steps, atWork] of [ + ["post_message DONE", parked("post_message", "DONE"), false], + ["run_command ERROR", parked("run_command", "ERROR"), false], + ["run_command RUNNING", parked("run_command", "RUNNING"), true], + ["background task running", backgrounded, true], + [ + "background task finished", + [...backgrounded, finished, ...parked("post_message", "DONE")], + false, + ], ] as const) { - yield* parked(sibling, status); - expect(yield* antigravitySwarmAtWork(profile, ROOT), `${sibling} ${status}`).toBe(atWork); + yield* writeSteps(steps); + expect(yield* antigravitySwarmAtWork(profile, ROOT), label).toBe(atWork); } }), ); diff --git a/apps/server/src/provider/acp/AntigravityChildWork.ts b/apps/server/src/provider/acp/AntigravityChildWork.ts index 3be120752c71b..3c916397bf54c 100644 --- a/apps/server/src/provider/acp/AntigravityChildWork.ts +++ b/apps/server/src/provider/acp/AntigravityChildWork.ts @@ -431,12 +431,31 @@ const decodeSwarmRoster = Schema.decodeUnknownOption( ), ); +const BACKGROUND_TASK = /running as a background task with task id: (\S+)/; + +/** agy parks a worker whose command went to a background task until the task's finish message. */ +function backgroundTaskRunning(lines: ReadonlyArray): boolean { + const running = new Set(); + for (const line of lines) { + const step = Option.getOrUndefined(decodeTranscriptLine(line)); + const content = step?.content ?? ""; + const started = step?.type === "GENERIC" ? BACKGROUND_TASK.exec(content)?.[1] : undefined; + if (started !== undefined) running.add(started); + if (step?.type !== "SYSTEM_MESSAGE") continue; + for (const id of running) if (content.includes(`Task id "${id}"`)) running.delete(id); + } + return running.size > 0; +} + function swarmWorkerAtWork(transcript: string): boolean { const lines = transcript.split("\n"); const results: Array = []; + if (Option.getOrUndefined(decodeTranscriptLine(lines.at(-1)))?.type === "ERROR_MESSAGE") { + return false; + } + if (backgroundTaskRunning(lines)) return true; for (let index = lines.length - 1; index >= 0; index -= 1) { const step = Option.getOrUndefined(decodeTranscriptLine(lines[index])); - if (index === lines.length - 1 && step?.type === "ERROR_MESSAGE") return false; if (step?.type === "GENERIC") { results.push(step.status); continue;