fix(antigravity): keep native ACP swarm runs active and stream worker subagents #40368
Closedpatrick-toulme(GitHub profile, opens in a new tab)wants to merge 7 commits into
main fromrefs/pull/40368/headopened View on GitHubpatrick-toulme(GitHub profile, opens in a new tab) linked this to fix #39886
tanstack-source added labelsbug
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
juliusmarminge added labelstakeover:in-progress
- @@ -50,4 +54,21 @@54+ name: Schema.optional(Schema.String),55+ role: Schema.optional(Schema.String),56+ brief: Schema.optional(Schema.String),57+ n: Schema.optional(Schema.Number),58+ tasks: Schema.optional(Schema.Array(Schema.String)),59+});5060 // agy 1.5 launches one child per call with a flat input; earlier releases send a batch.5161 const decodeLaunchInput = Schema.decodeUnknownOption(5262 Schema.Union([Schema.Struct({ Subagents: Schema.NonEmptyArray(LaunchInput) }), LaunchInput]),5363 );64+const decodeSwarmAddInput = Schema.decodeUnknownOption(SwarmAddInput);65+66+function swarmAddLaunches(input: unknown): ReadonlyArray<AntigravityChildLaunch> | undefined {67+ const decoded = Option.getOrUndefined(decodeSwarmAddInput(input));68+ if (decoded === undefined || decoded.action.trim().toLowerCase() !== "add") return undefined;69+ const baseName = decoded.name?.trim().replace(/^@/, "") ?? "";70+ const brief = decoded.brief?.trim() ?? "";71+ const tasks = decoded.tasks ?? [];72+ const requestedCount =73+ decoded.n !== undefined && Number.isFinite(decoded.n) ? Math.trunc(decoded.n) : 0;74+ const count = Math.max(tasks.length, requestedCount, 1);@@ -0,0 +225,21 @@225+ if (tracked === undefined) {226+ tracked = {227+ nativeTaskId,228+ name: member.name,229+ conversationId,230+ toolCallId: callId,231+ status: "running",232+ latestReport: session.latestPostsByAgent.get(nameKey) ?? null,233+ lastBrief: "",234+ sawIdleOrReport: session.latestPostsByAgent.has(nameKey),235+ };236+ session.membersByConversationId.set(conversationId, tracked);237+ session.membersByName.set(nameKey, tracked);238+ } else if (tracked.toolCallId === null && callId !== null) {239+ tracked.toolCallId = callId;240+ }241+242+ const latestPost = session.latestPostsByAgent.get(nameKey) ?? tracked.latestReport;243+ if (latestPost !== null) {244+ tracked.latestReport = latestPost;245+ tracked.sawIdleOrReport = true;@@ -3677,3 +3817,8 @@36773817 const turnItemOrdinal =36783818 existing?.turnItemOrdinal ?? (yield* resolveItemOrdinal(context, nativeTaskId));36793819 const taskStatus = update.status;3820+ if (reopeningIdle && existing !== undefined) {3821+ yield* flushSubagentAssistant(existing);3822+ yield* writeSubagentThought(existing, true);3823+ existing.terminalStatusProjected = false;3824+ existing.assistantText = "";@@ -5993,19 +6157,2 @@5993- if (event._tag !== "ToolCallUpdated") continue;5994- const toolCall = flavor.normalizeToolCall?.(event.toolCall) ?? event.toolCall;5995- const subagentUpdate = extractSubagentUpdate(toolCall);5996- if (subagentUpdate !== undefined) {5997- if (5998- subagentUpdate.nativeTaskId === nativeTaskId ||5999- subagentUpdate.childSessionId === notification.sessionId6000- ) {6001- yield* emitSubagent(context, subagentUpdate);6002- }6003- continue;6004- }6005- yield* projectSubagentTool(6006- subagent,6007- notification.sessionId,6008- toolCall,6009- undefined,6010- context,6011- );6157+ if (subagent !== undefined) {6158+ yield* projectSubagentNotification(subagent, notification, context);@@ -6884,0 +7057,21 @@7057+ });7058+7059+ const upsertSubagentFromExtension = Effect.fnUntraced(function* (notice: {7060+ readonly sessionId: string;7061+ readonly subagent: AcpAdapterV2SubagentUpdate;7062+ readonly allowReopenFromIdle?: boolean | undefined;7063+ }) {7064+ const allowReopenFromIdle = notice.allowReopenFromIdle === true;7065+ const update = notice.subagent;7066+ const context = yield* Ref.get(activeTurn);7067+ if (7068+ context !== null &&7069+ !context.finalized &&7070+ !context.interrupted &&7071+ context.nativeThreadId === notice.sessionId7072+ ) {7073+ yield* applyExtensionSubagentToTurn(context, update, allowReopenFromIdle);7074+ return;7075+ }7076+ if (acpSubagentStatusIsTerminal(update.status)) {7077+ if (update.childSessionId !== null) {@@ -7629,3 +7868,19 @@76297868 yield* finishSubagentFromNotice(notice);76307869 }),76317870 ).pipe(Effect.asVoid),7871+ upsertSubagent: (notice) =>7872+ runRuntimeCallbackAtGeneration(7873+ handlerGeneration,7874+ Effect.gen(function* () {7875+ if (yield* Ref.get(stoppedRunQuarantine)) return;7876+ if ((yield* Ref.get(activeSessionId)) !== notice.sessionId) return;7877+ yield* upsertSubagentFromExtension(notice);7878+ }),7879+ ).pipe(Effect.asVoid),7880+ setExternalBackgroundWork: (notice) =>7881+ runRuntimeCallbackAtGeneration(7882+ handlerGeneration,7883+ Effect.gen(function* () {7884+ if (yield* Ref.get(stoppedRunQuarantine)) return;7885+ if ((yield* Ref.get(activeSessionId)) !== notice.sessionId) return;7886+ externalBackgroundWorkActive = notice.active;
Pushedeb8e642
Pushedefa964d
- @@ -6884,0 +7066,21 @@7066+ const allowReopenFromIdle = notice.allowReopenFromIdle === true;7067+ const update = notice.subagent;7068+ const context = yield* Ref.get(activeTurn);7069+ if (7070+ context !== null &&7071+ !context.finalized &&7072+ !context.interrupted &&7073+ context.nativeThreadId === notice.sessionId7074+ ) {7075+ yield* applyExtensionSubagentToTurn(context, update, allowReopenFromIdle);7076+ return;7077+ }7078+ if (acpSubagentStatusIsTerminal(update.status)) {7079+ yield* Ref.update(pendingExtensionSubagents, (current) =>7080+ current.filter(7081+ (entry) =>7082+ entry.subagent.nativeTaskId !== update.nativeTaskId &&7083+ (update.childSessionId === null ||7084+ entry.subagent.childSessionId !== update.childSessionId),7085+ ),7086+ );
juliusmarminge added labelstakeover:needs-julius
juliusmarminge removed labelstakeover:in-progress
Pushed8ac645a
- @@ -3482,7 +3574,19 @@3574+ mode: "append" | "replace",3575+ ) {3576+ if (text.length === 0) return;3577+ subagent.thoughtText = mode === "replace" ? text : `${subagent.thoughtText}${text}`;3578+ yield* writeSubagentThought(subagent, false);3579+ });3580+34823581 const projectSubagentNotification = Effect.fnUntraced(function* (34833582 subagent: ActiveAcpSubagent,34843583 notification: EffectAcpSchema.SessionNotification,34853584 owner: ActiveAcpTurn,3486- ) {3585+ ): Effect.fn.Return<void> {34873586 const update = notification.update;3488- if (update.sessionUpdate === "agent_message_chunk") {3587+ if (update.sessionUpdate === "tool_call" || update.sessionUpdate === "tool_call_update") {3588+ yield* writeSubagentThought(subagent, true);3589+ const nativeTaskId = subagent.task.nativeTaskRef?.nativeId ?? String(subagent.task.id);3590+ for (const event of parseSessionUpdateEvent(notification).events) {3591+ if (event._tag !== "ToolCallUpdated") continue;3592+ if (event.toolCall.status !== undefined && event.toolCall.status !== "pending") {@@ -6884,0 +7227,21 @@7227+ update.status,7228+ update.result,7229+ {7230+ project:7231+ carryover !== null &&7232+ carryover.sessionId === notice.sessionId &&7233+ carryover.projectsLateTerminals,7234+ },7235+ );7236+ }7237+ return;7238+ }7239+ if (postSettleContinuationEnabled && wakeContinuation) {7240+ yield* Ref.update(pendingExtensionSubagents, (current) => [7241+ ...current.filter(7242+ (entry) =>7243+ entry.subagent.nativeTaskId !== update.nativeTaskId &&7244+ (update.childSessionId === null ||7245+ entry.subagent.childSessionId !== update.childSessionId),7246+ ),7247+ { subagent: update, allowReopenFromIdle },@@ -7629,3 +8056,10 @@76298056 yield* finishSubagentFromNotice(notice);76308057 }),76318058 ).pipe(Effect.asVoid),8059+ upsertSubagent: (notice) =>8060+ runRuntimeCallbackAtGeneration(8061+ handlerGeneration,8062+ Effect.gen(function* () {8063+ if (yield* Ref.get(stoppedRunQuarantine)) return;8064+ const expectedSessionId =8065+ (yield* Ref.get(activeSessionId)) ?? (yield* Ref.get(loadingSessionId));@@ -0,0 +408,21 @@408+ sessionId: notification.sessionId,409+ activeBackgroundWork: session.busy,410+ subagents,411+ };412+ },413+414+ hasLiveSwarm(sessionId) {415+ return sessions.has(sessionId);416+ },417+418+ childPermissionWorkspaces(request) {419+ const roots = new Set<string>();420+ for (const container of [421+ unknownRecord(request._meta),422+ unknownRecord(request.toolCall._meta),423+ ]) {424+ const antigravity = unknownRecord(container?.antigravity);425+ if (antigravity === undefined) continue;426+ const primary =427+ typeof antigravity.workspace === "string" ? nonEmpty(antigravity.workspace) : undefined;428+ if (primary !== undefined) roots.add(primary);@@ -1287,3 +1287,20 @@12871287 };12881288 }128912891290+export interface AcpChildRequestTarget {1291+ readonly childSessionId: string;1292+ readonly toolCallId: string | null;1293+ readonly workerLabel: string | null;1294+}1295+1296+export function extractAcpChildRequestTarget(input: {1297+ readonly meta?: unknown;1298+ readonly toolCallMeta?: unknown;1299+ readonly fallbackToolCallId?: string | undefined;1300+}): AcpChildRequestTarget | undefined {1301+ const fromMeta = (candidate: unknown) => {1302+ if (!isRecord(candidate)) return undefined;1303+ const antigravity = candidate.antigravity;1304+ return isRecord(antigravity) ? antigravity : undefined;1305+ };1306+ const ag = fromMeta(input.meta) ?? fromMeta(input.toolCallMeta);
Pushedc234ad5
- @@ -9486,3 +9987,10 @@94869987 }94879988 yield* Ref.set(activeTurn, context);94889989 yield* Ref.set(stoppedRunQuarantine, false);9990+ const queuedExtensionSubagents = yield* Ref.modify(9991+ pendingExtensionSubagents,9992+ (current) => [9993+ current.filter((entry) => entry.sessionId === requestedSessionId),9994+ current.filter((entry) => entry.sessionId !== requestedSessionId),9995+ ],9996+ );@@ -0,0 +75,21 @@75+ name: string;76+ role: string;77+ conversationId: string;78+ toolCallId: string | null;79+ status: AcpAdapterV2SubagentUpdate["status"];80+ latestReport: string | null;81+ lastBrief: string;82+ sawIdleOrReport: boolean;83+ readonly workspaces: Set<string>;84+}85+86+interface TrackedSwarmSession {87+ busy: boolean;88+ readonly membersByConversationId: Map<string, TrackedSwarmMember>;89+ readonly membersByName: Map<string, TrackedSwarmMember>;90+ readonly latestPostsByAgent: Map<string, string>;91+ readonly briefsByMention: Map<string, string>;92+}93+94+function isNonRootWorkspacePath(candidate: string): boolean {95+ const normalized = candidate.replaceAll("\\", "/").replace(/\/+$/, "");
Pushed82a5523
github-actions[bot](GitHub profile, opens in a new tab) added labelsneeds-rebase
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Note
Reviews paused#
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
Walkthrough
The change adds native Antigravity swarm support across tool recognition, worker tracking, child-session discovery, and ACP turn handling. It keeps turns active while tracked worker or coordinator activity remains and adds child-targeted permission and workspace handling.
Changes: Native Antigravity Swarm
apps/server/src/provider/acp/AntigravityProtocol.ts,apps/server/src/provider/acp/AntigravityProtocol.test.tsaddcalls as subagents. It extracts child-session and model details from swarm-add calls.apps/server/src/provider/acp/AntigravityChildWork.ts,apps/server/src/provider/acp/AntigravityChildWork.test.tsswarm:task IDs, and excludes killed or parked workers from active work.packages/provider-acp/src/server/antigravitySwarm.ts,packages/provider-acp/src/server/adapter.ts,packages/provider-acp/package.json,apps/server/src/provider/acp/AntigravitySwarm.ts,apps/server/src/provider/acp/AntigravitySwarm.test.tsapps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.ts,packages/provider-acp-registry/src/server/adapter.ts,apps/server/src/provider/acp/AntigravityAcpSupport.ts,apps/server/src/provider/Drivers/AntigravityDriver.test.tspackages/provider-acp/src/server/adapter.ts,apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.tspackages/provider-acp/src/server/runtimeModel.ts,packages/provider-acp/src/server/clientPolicy.ts,packages/provider-acp/src/server/adapter.ts,apps/server/src/provider/acp/AntigravitySwarm.test.tsEstimated code review effort: 4 (Complex) | ~60 minutes
Change: Bug fix · Severity of issue fixed: Medium
Sequence Diagram(s)#
Possibly related issues
Possibly related PRs
Suggested labels:
bugfixSuggested reviewers:
juliusmarminge,macroscopeappMerge Risk:
High · previous review
c234aThis change keeps Antigravity swarm runs active and shows workers as subagents. Several correctness problems remain: a worker-reported workspace path like /tmp/.. can widen write approval beyond the intended directory, a stale queued update can leave a worker stuck as running, and buffered worker output can be lost when another session starts a turn. These should be fixed before merge.
Pre-merge checks:
4
#39886. Verification lists the checks ru…#39886is the only active directly linked target. Its coding requirement is that Antigravity swarm workers keep running after the coordinator prompt turn ends, and that their reports reach the p…#39886and in the PR objectives:- Capability negotiation and roster/board notification handling (AntigravityAdapte…
Full details: Title check
Explanation
The title names the main change: native ACP swarm runs are kept active and worker subagents are streamed, and the changeset covers both parts. It follows a conventional commit format, uses plain language, and is one sentence of 11 words.
Full details: Description check
Explanation
The description follows the template. It has Problem, Change, Scope, and Verification sections. The Problem and Change sections are specific. Scope links issue
#39886. Verification lists the checks run and the live end-to-end results. The template's optional agent-model line is missing, and the Verification section does not name a model or harness. The author also did not state any untested areas.Full details: Linked Issues check
Explanation
Issue
#39886is the only active directly linked target. Its coding requirement is that Antigravity swarm workers keep running after the coordinator prompt turn ends, and that their reports reach the parent instead of being killed by session close.Evidence from the whole-PR summary (mergeBase dd941b9 to head c234ad5):
The incremental changes since the previous review keep this lifecycle behavior. The agy 1.5.13 fallback path is covered by unit tests and a fixture, not by a live run in this assessment. The live verification reported in the PR description was run against a native-swarm build and is not independently verified here.
Full details: Out of Scope Changes check
Explanation
The changed areas connect to swarm worker lifecycle, presentation, or permissions in
#39886and in the PR objectives:Finishing Touches
Generate unit tests (beta)