fix(antigravity): swarm runs stay active until workers report #40626
Closedt3dotgg(GitHub profile, opens in a new tab)wants to merge 11 commits into
main fromrefs/pull/40626/headopened View on GitHubt3dotgg(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
- @@ -2507,0 +2768,21 @@2768+ update: {2769+ sessionUpdate: "agent_thought_chunk",2770+ content: { type: "text", text: "Reviewing UI routes." },2771+ },2772+ });2773+ yield* onSessionUpdate!({2774+ sessionId: alphaSessionId,2775+ update: {2776+ sessionUpdate: "tool_call",2777+ toolCallId: "alpha-tool-1",2778+ kind: "execute",2779+ title: "pnpm test",2780+ status: "completed",2781+ rawInput: { CommandLine: "pnpm test" },2782+ rawOutput: { combinedOutput: "ok" },2783+ },2784+ });2785+2786+ // Turn stays open past deferred-finalize debounce and protects the session from idle eviction.2787+ yield* TestClock.adjust("5 seconds");2788+ yield* Effect.yieldNow;@@ -2507,0 +2850,21 @@2850+ const subagentsByTitle = () => {2851+ const map = new Map<2852+ string,2853+ Extract<2854+ ProviderAdapter.ProviderAdapterV2Event,2855+ { type: "subagent.updated" }2856+ >["subagent"]2857+ >();2858+ for (const event of collected) {2859+ if (event.type === "subagent.updated") {2860+ map.set(event.subagent.title ?? event.subagent.id, event.subagent);2861+ }2862+ }2863+ return map;2864+ };2865+ const alphaAfterTurn1 = subagentsByTitle().get("@alpha");2866+ const betaAfterTurn1 = subagentsByTitle().get("@beta");2867+ assert.equal(alphaAfterTurn1?.status, "idle");2868+ assert.equal(alphaAfterTurn1?.result, "Frontend passed.");2869+ assert.equal(betaAfterTurn1?.status, "idle");2870+ assert.equal(betaAfterTurn1?.result, "Backend passed.");@@ -294,3 +353,9 @@294353 promptInactivityTimeout: "15 minutes",295354 reportsPerTurnPromptUsage: true,296355 geminiPromptUsage: true,356+ subagentsOutlivingPrompt: Effect.fn("AntigravityAdapterV2.subagentsOutlivingPrompt")(357+ function* ({ sessionId, nativeTaskIds }) {358+ const { runningSwarmTaskIds, unmanagedTaskIds } = swarmTracker.partitionTaskIds(359+ sessionId,360+ nativeTaskIds,361+ );@@ -3481,0 +3563,21 @@3563+ updatedAt: now,3564+ type: "reasoning",3565+ text: subagent.thoughtText,3566+ streaming: !completed,3567+ },3568+ });3569+ if (completed) {3570+ subagent.thoughtSegmentIndex += 1;3571+ subagent.thoughtText = "";3572+ subagent.thoughtStartedAt = null;3573+ }3574+ });3575+3576+ const appendSubagentThought = Effect.fnUntraced(function* (3577+ subagent: ActiveAcpSubagent,3578+ text: string,3579+ mode: "append" | "replace",3580+ ) {3581+ if (text.length === 0) return;3582+ subagent.thoughtText = mode === "replace" ? text : `${subagent.thoughtText}${text}`;3583+ yield* writeSubagentThought(subagent, false);@@ -6884,0 +7158,21 @@7158+ if (update.childSessionId !== null && allowReopenFromIdle) {7159+ const knownInTurn =7160+ context.subagents.get(update.nativeTaskId) ??7161+ context.subagentsBySessionId.get(update.childSessionId);7162+ if (knownInTurn === undefined) {7163+ const dormant = (yield* Ref.get(dormantSubagentsByChildSessionId)).get(7164+ update.childSessionId,7165+ );7166+ if (dormant !== undefined) {7167+ const nativeId = dormant.task.nativeTaskRef?.nativeId ?? update.nativeTaskId;7168+ context.subagents.set(nativeId, dormant);7169+ context.subagentsBySessionId.set(update.childSessionId, dormant);7170+ yield* Ref.update(dormantSubagentsByChildSessionId, (current) => {7171+ const next = new Map(current);7172+ next.delete(update.childSessionId!);7173+ return next;7174+ });7175+ }7176+ }7177+ }7178+ yield* emitSubagent(context, update, { allowReopenFromIdle });@@ -6884,0 +7207,21 @@7207+ }7208+ const isSameQueuedWorker = (entry: {7209+ sessionId: string;7210+ subagent: AcpAdapterV2SubagentUpdate;7211+ }) =>7212+ entry.sessionId === notice.sessionId &&7213+ (entry.subagent.nativeTaskId === update.nativeTaskId ||7214+ (update.childSessionId !== null &&7215+ entry.subagent.childSessionId === update.childSessionId));7216+ if (acpSubagentStatusIsTerminal(update.status)) {7217+ const queued = yield* Ref.modify(pendingExtensionSubagents, (current) => [7218+ current.find(isSameQueuedWorker),7219+ current.filter((entry) => !isSameQueuedWorker(entry)),7220+ ]);7221+ if (update.childSessionId !== null) {7222+ yield* cancelPendingChildRuntimeRequests(update.childSessionId);7223+ const dormant = (yield* Ref.get(dormantSubagentsByChildSessionId)).get(7224+ update.childSessionId,7225+ );7226+ if (dormant !== undefined) {7227+ pendingBetweenTurnChildNotifications.delete(update.childSessionId);@@ -6884,0 +7233,21 @@7233+ yield* Ref.update(dormantSubagentsByChildSessionId, (current) => {7234+ const next = new Map(current);7235+ next.delete(update.childSessionId!);7236+ return next;7237+ });7238+ }7239+ return;7240+ }7241+ const carryover = yield* Ref.get(carryoverSubagents);7242+ const handledByCarryover = yield* updateCarryoverSubagentStatus(7243+ update.childSessionId,7244+ update.status,7245+ update.result,7246+ {7247+ project:7248+ carryover !== null &&7249+ carryover.sessionId === notice.sessionId &&7250+ carryover.projectsLateTerminals,7251+ },7252+ );7253+ if (!handledByCarryover && queued !== undefined) {@@ -7310,4 +7714,6 @@73107714 }73117715 const trackedTurn = yield* Ref.get(activeTurn);73127716 const params =7313- trackedTurn !== null && nativeParams.sessionId === (yield* Ref.get(activeSessionId))7717+ trackedTurn !== null &&7718+ childTarget === undefined &&7719+ nativeParams.sessionId === (yield* Ref.get(activeSessionId))@@ -9514,3 +10045,7 @@951410045 driver,951510046 providerThread: activeProviderThread,951610047 });10048+ const queuedChildNotifications = new Map(pendingBetweenTurnChildNotifications);10049+ pendingBetweenTurnChildNotifications.clear();10050+ for (const [childId, frames] of queuedChildNotifications) {10051+ context.pendingSubagentNotifications.set(childId, frames);@@ -0,0 +312,21 @@312+ for (const member of notification.members) {313+ const conversationId = nonEmpty(member.conversationId);314+ const role = resolveMemberRole(member.name, member.role);315+ if (conversationId === undefined || role === "coordinator") continue;316+ const housekeeping = isHousekeepingRole(role);317+ const nameKey = member.name.trim().toLowerCase();318+ const callId = nonEmpty(member.toolCallId) ?? null;319+320+ let tracked = session.membersByConversationId.get(conversationId);321+ const nativeTaskId = `${ANTIGRAVITY_SWARM_TASK_PREFIX}${conversationId}`;322+ if (tracked === undefined) {323+ tracked = {324+ nativeTaskId,325+ name: member.name,326+ role,327+ conversationId,328+ toolCallId: callId,329+ status: "running",330+ latestReport: session.latestPostsByAgent.get(nameKey) ?? null,331+ lastBrief: "",332+ sawIdleOrReport: member.hadActivity === true || session.latestPostsByAgent.has(nameKey),@@ -1289,0 +1301,21 @@1301+ for (const candidate of [input.meta, input.toolCallMeta]) {1302+ if (!isRecord(candidate)) continue;1303+ const ag = candidate.antigravity;1304+ if (!isRecord(ag)) continue;1305+ const swarm = isRecord(ag.swarm) ? ag.swarm : undefined;1306+ const childSessionId =1307+ (typeof ag.childSessionId === "string" && ag.childSessionId.trim()) ||1308+ (typeof swarm?.workerSessionId === "string" && swarm.workerSessionId.trim()) ||1309+ "";1310+ if (childSessionId.length === 0) continue;1311+ const toolCallId =1312+ (typeof ag.workerToolCallId === "string" && ag.workerToolCallId.trim()) ||1313+ (typeof input.fallbackToolCallId === "string" && input.fallbackToolCallId.trim()) ||1314+ null;1315+ const workerName =1316+ (typeof swarm?.workerName === "string" && swarm.workerName.trim().replace(/^@/, "")) ||1317+ (typeof ag.agentName === "string" && ag.agentName.trim().replace(/^@/, "")) ||1318+ "";1319+ const role = typeof ag.role === "string" ? ag.role.trim() : "";1320+ const workerLabel = workerName.length > 0 ? `@${workerName}` : role.length > 0 ? role : null;1321+ return { childSessionId, toolCallId, workerLabel };
Pushedc9e4a6c
Pushedfdef507
- @@ -6888,0 +7196,21 @@7196+ if (update.childSessionId === null) return;7197+ const attached = context.subagentsBySessionId.get(update.childSessionId);7198+ const frames = context.pendingSubagentNotifications.get(update.childSessionId);7199+ if (attached === undefined || frames === undefined) return;7200+ context.pendingSubagentNotifications.delete(update.childSessionId);7201+ for (const frame of frames) {7202+ yield* projectSubagentNotification(attached, frame, context);7203+ }7204+ });7205+ if (7206+ update.status === "completed" ||7207+ update.status === "failed" ||7208+ update.status === "cancelled"7209+ ) {7210+ yield* drainAttachedFrames();7211+ const ended =7212+ context.subagents.get(update.nativeTaskId) ??7213+ (update.childSessionId === null7214+ ? undefined7215+ : context.subagentsBySessionId.get(update.childSessionId));7216+ if (ended !== undefined) yield* terminalizeSubagentTools(ended);@@ -6888,0 +7252,21 @@7252+ sessionId: string;7253+ subagent: AcpAdapterV2SubagentUpdate;7254+ }) =>7255+ entry.sessionId === notice.sessionId &&7256+ (entry.subagent.nativeTaskId === update.nativeTaskId ||7257+ (update.childSessionId !== null &&7258+ entry.subagent.childSessionId === update.childSessionId));7259+ if (acpSubagentStatusIsTerminal(update.status)) {7260+ const queued = yield* Ref.modify(pendingExtensionSubagents, (current) => [7261+ current.find(isSameQueuedWorker),7262+ current.filter((entry) => !isSameQueuedWorker(entry)),7263+ ]);7264+ if (update.childSessionId !== null) {7265+ yield* cancelPendingChildRuntimeRequests(update.childSessionId);7266+ const dormant = (yield* Ref.get(dormantSubagentsByChildSessionId)).get(7267+ update.childSessionId,7268+ );7269+ if (dormant !== undefined) {7270+ // A parked worker keeps its buffered frames for the turn that wakes it.7271+ if (update.status !== "idle") {7272+ pendingBetweenTurnChildNotifications.delete(update.childSessionId);@@ -9518,3 +10101,15 @@951810101 driver,951910102 providerThread: activeProviderThread,952010103 });10104+ const queuedChildNotifications = new Map(pendingBetweenTurnChildNotifications);10105+ pendingBetweenTurnChildNotifications.clear();10106+ for (const [childId, frames] of queuedChildNotifications) {10107+ const live = context.pendingSubagentNotifications.get(childId) ?? [];10108+ context.pendingSubagentNotifications.set(childId, [...frames, ...live]);10109+ }10110+ for (const queued of queuedExtensionSubagents) {10111+ yield* applyExtensionSubagentToTurn(10112+ context,10113+ queued.subagent,10114+ queued.allowReopenFromIdle,10115+ );@@ -0,0 +416,21 @@416+ notification.coordinatorPendingWake === true;417+418+ return {419+ sessionId: notification.sessionId,420+ activeBackgroundWork: session.busy,421+ subagents,422+ };423+ },424+425+ hasLiveSwarm(sessionId) {426+ return sessions.has(sessionId);427+ },428+429+ childPermissionWorkspaces(request) {430+ const session = sessions.get(request.sessionId);431+ if (session === undefined) return [];432+ const roots = new Set<string>();433+ for (const container of [434+ unknownRecord(request._meta),435+ unknownRecord(request.toolCall._meta),436+ ]) {
Pushedbb81e05
- @@ -9518,3 +10111,5 @@951810111 driver,951910112 providerThread: activeProviderThread,952010113 });10114+ const queuedChildNotifications = new Map(pendingBetweenTurnChildNotifications);10115+ pendingBetweenTurnChildNotifications.clear();@@ -9520,0 +10121,21 @@10121+ // A live update for this worker in this turn is newer than the queued one.10122+ const touched = liveExtensionWorkers.get(context);10123+ if (10124+ touched !== undefined &&10125+ (touched.has(queued.subagent.nativeTaskId) ||10126+ (queued.subagent.childSessionId !== null &&10127+ touched.has(queued.subagent.childSessionId)))10128+ )10129+ continue;10130+ yield* applyExtensionSubagentToTurn(10131+ context,10132+ queued.subagent,10133+ queued.allowReopenFromIdle,10134+ );10135+ }10136+ for (const [childId, frames] of context.pendingSubagentNotifications) {10137+ const subagent = context.subagentsBySessionId.get(childId);10138+ if (subagent === undefined) continue;10139+ context.pendingSubagentNotifications.delete(childId);10140+ for (const frame of frames) {10141+ yield* projectSubagentNotification(subagent, frame, context);@@ -0,0 +201,21 @@201+ request: EffectAcpSchema.RequestPermissionRequest,202+ ) => ReadonlyArray<string>;203+ readonly partitionTaskIds: (204+ sessionId: string,205+ nativeTaskIds: ReadonlyArray<string>,206+ ) => {207+ readonly runningSwarmTaskIds: ReadonlyArray<string>;208+ readonly unmanagedTaskIds: ReadonlyArray<string>;209+ };210+}211+212+export function registerAntigravitySwarmExtension(213+ tracker: AntigravitySwarmTracker,214+ context: AcpAdapterV2ExtensionContext,215+) {216+ return context.runtime.handleExtNotification(217+ ANTIGRAVITY_SWARM_NOTIFICATION_METHOD,218+ AntigravitySwarmNotification,219+ (notification) =>220+ Effect.gen(function* () {221+ const mutation = tracker.applyNotification(notification);@@ -0,0 +356,21 @@356+ }357+358+ const latestPost = session.latestPostsByAgent.get(nameKey) ?? tracked.latestReport;359+ if (latestPost !== null) {360+ tracked.latestReport = latestPost;361+ tracked.sawIdleOrReport = true;362+ }363+364+ const nextStatus = mapSwarmMemberStatus(member.state, tracked.sawIdleOrReport);365+ if (nextStatus === "idle") {366+ tracked.sawIdleOrReport = true;367+ }368+ if (!housekeeping && (nextStatus === "running" || nextStatus === "pending")) {369+ runningWorkerCount += 1;370+ }371+ // Rosters keep listing finished workers; re-emitting one would re-create it in a later turn.372+ const alreadyReported =373+ tracked.status === nextStatus &&374+ (nextStatus === "completed" || nextStatus === "failed" || nextStatus === "cancelled");375+ tracked.status = nextStatus;376+ if (alreadyReported) continue;
Pushed050b991
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.

Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Other scenarios#
All 64 scenario measurements match
main.All 64 scenario measurements
short turn resumeWebSocket decodedshort turn resumeWebSocket messageslong turn running, cold openHTTP decodedlong turn running, cold openrowslong turn running, history pageHTTP decodedlong turn running, history pagerowslong turn finished, cold openHTTP decodedlong turn finished, cold openrowslong turn finished, socket cold openWebSocket decodedlong turn finished, socket cold openWebSocket messageslong turn finished, socket cold openrowslong turn finished, work pageHTTP decodedlong turn finished, work pagerowsidle thread resumeWebSocket decodedidle thread resumeWebSocket messagesfleet shell snapshotHTTP decodedfleet shell snapshotrowsfleet shell subscribeWebSocket decodedfleet shell subscribeWebSocket messagesfleet shell resume checkHTTP decodedfleet shell resume checkrowsstale shell reloadHTTP decodedstale shell reloadrowsstale shell resumeWebSocket decodedstale shell resumeWebSocket messagesstale todo list cold openHTTP decodedstale todo list cold openrowsstale todo list cold opennodesstale todo list cold opensubagentsstale todo list cold openplansstale todo list cold openproviderTurnsstale todo list cold opencheckpointsshort turn resumeWebSocket decodedshort turn resumeWebSocket messageslong turn running, cold openHTTP decodedlong turn running, cold openrowslong turn running, history pageHTTP decodedlong turn running, history pagerowslong turn finished, cold openHTTP decodedlong turn finished, cold openrowslong turn finished, socket cold openWebSocket decodedlong turn finished, socket cold openWebSocket messageslong turn finished, socket cold openrowslong turn finished, work pageHTTP decodedlong turn finished, work pagerowsidle thread resumeWebSocket decodedidle thread resumeWebSocket messagesfleet shell snapshotHTTP decodedfleet shell snapshotrowsfleet shell subscribeWebSocket decodedfleet shell subscribeWebSocket messagesfleet shell resume checkHTTP decodedfleet shell resume checkrowsstale shell reloadHTTP decodedstale shell reloadrowsstale shell resumeWebSocket decodedstale shell resumeWebSocket messagesstale todo list cold openHTTP decodedstale todo list cold openrowsstale todo list cold opennodesstale todo list cold opensubagentsstale todo list cold openplansstale todo list cold openproviderTurnsstale todo list cold opencheckpointsBaseline:
047fb5b· PR result:050b991· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.