fix(antigravity): reactivate parked swarm workers and stream live transcripts #46929
Mergeditsthecsguy(GitHub profile, opens in a new tab)merged 5 commits into
main fromrefs/pull/46929/headmerged by juliusmarminge View on GitHubtanstack-source added labelsbug
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- @@ -3399,0 +3519,21 @@3519+ yield* send(usage);3520+ yield* TestClock.adjust("3 seconds");3521+ const turn1Tail = yield* until((event) => event.type === "turn.terminal");3522+ const turn1LastSubagent = [...turn1Prompt, ...turn1Tail].findLast(3523+ (event) => event.type === "subagent.updated",3524+ );3525+ assert.equal(3526+ turn1LastSubagent?.type === "subagent.updated" ? turn1LastSubagent.subagent.status : null,3527+ "idle",3528+ );3529+3530+ // Turn 2 wakes the existing parked worker via post_message; members.json flips back to working.3531+ yield* startTurn(2, false);3532+ yield* writeMembers("working");3533+ yield* send({3534+ sessionUpdate: "tool_call",3535+ toolCallId: "call_post_round2",3536+ kind: "other",3537+ title: "Run post_message",3538+ status: "completed",3539+ rawInput: { text: "@author please run round 2" },@@ -3399,0 +3557,21 @@3557+ RunId.make("run-antigravity-wake-2"),3558+ );3559+3560+ // Append Round 2 transcript entries while the reactivated follower is running.3561+ yield* writeTranscript([3562+ ...roundOneSteps,3563+ {3564+ step_index: 2,3565+ type: "SYSTEM_MESSAGE",3566+ status: "DONE",3567+ content:3568+ "<SYSTEM_MESSAGE>\n[Message] sender=mock-session-1 content=@author please run round 2\n</SYSTEM_MESSAGE>",3569+ },3570+ {3571+ step_index: 3,3572+ type: "PLANNER_RESPONSE",3573+ status: "DONE",3574+ content: "Round 2 verified.",3575+ },3576+ ]);3577+ yield* TestClock.adjust("1 second");@@ -3399,0 +3617,21 @@3617+ rawOutput: { conversation_id: "worker-2", name: "helper" },3618+ });3619+ yield* send({3620+ sessionUpdate: "agent_message_chunk",3621+ content: { type: "text", text: "Helper spawned." },3622+ });3623+ const helperEvents = yield* until((event) =>3624+ JSON.stringify(event).includes("Helper spawned."),3625+ );3626+ const helperUpdates = helperEvents.flatMap((event) =>3627+ event.type === "subagent.updated" &&3628+ event.subagent.nativeTaskRef?.nativeId === "call_swarm_helper"3629+ ? [event.subagent]3630+ : [],3631+ );3632+ assert.isFalse(3633+ helperUpdates.some((subagent) => subagent.status === "idle"),3634+ "an in-flight swarm add must not idle before its launch tool call completes",3635+ );3636+ assert.isNotNull(3637+ helperUpdates.at(-1)?.providerThreadId,@@ -1608,11 +1608,14 @@1608- const reported = new Set(1609- (await readInbox(profileRoot, input.rootSessionId)).map((message) =>1610- // A child that ends its turn without send_message is reported by the runtime's1611- // "has gone idle" notice, which names the child only in its metadata.1612- message.sender === "system" ? message.sourceMetadata?.conversationId : message.sender,1613- ),1614- );1608+ if (profileRoot === undefined) return [];1609+ const detachedChildIds = await listDetachedChildIds(profileRoot, input.rootSessionId);16151610 const swarmMembers = await readDiskSwarmMembersByConversationId(16161611 profileRoot,16171612 input.rootSessionId,16181613 );1614+ if (detachedChildIds === undefined && swarmMembers.size === 0) return [];1615+ const childIds = new Set<string>();1616+ for (const convId of swarmMembers.keys()) {1617+ if (childIds.size >= MAX_DETACHED_CHILDREN) break;1618+ childIds.add(convId);1619+ }1620+ for (const convId of detachedChildIds ?? []) {1621+ if (childIds.size >= MAX_DETACHED_CHILDREN) break;@@ -1619,5 +1635,19 @@1635+ return reported;1636+ };1637+ const taskIdsByChildSessionId = new Map<string, Array<string>>();1638+ if (input.childSessionIds !== undefined) {1639+ for (const [taskId, childSessionId] of input.childSessionIds) {1640+ if (!input.toolCallIds.includes(taskId)) continue;1641+ const list = taskIdsByChildSessionId.get(childSessionId);1642+ if (list === undefined) taskIdsByChildSessionId.set(childSessionId, [taskId]);1643+ else list.push(taskId);1644+ }1645+ }16191646 const atWork = new Set<string>();16201647 for (const childId of childIds) {1621- if (reported.has(childId)) continue;16221648 const swarmMember = swarmMembers.get(childId);1623- if (swarmMember?.killed === true || swarmMember?.parked === true) continue;1649+ if (swarmMember !== undefined) {1650+ // Swarm workers report board notices into the coordinator inbox while still active;1651+ // live roster state in members.json takes precedence over historical inbox entries.1652+ if (swarmMember.killed || swarmMember.parked || swarmMember.stopped) continue;1653+ } else if ((await getReported()).has(childId)) {@@ -4715,3 +4730,4 @@47154730 Effect.succeed([] as ReadonlyArray<AcpSubagentTranscriptEntry>),47164731 ),47174732 );4733+ if (stop !== undefined && (yield* Deferred.isDone(stop))) return false;@@ -4842 +4875,20 @@4842- const changed = yield* drainSubagentTranscript(subagent, false);4875+ const changed = yield* drainSubagentTranscript(subagent, false, stop);4876+ if (yield* Deferred.isDone(stop)) break;4877+ if (changed && flavor.subagentsOutlivingPrompt !== undefined) {4878+ yield* runtimeCallbackPermit.withPermit(4879+ Effect.gen(function* () {4880+ if ((yield* Deferred.isDone(stop)) || (yield* Ref.get(stoppedRunQuarantine))) {4881+ return;4882+ }4883+ const current = yield* Ref.get(activeTurn);4884+ if (4885+ current === null ||4886+ current.finalized ||4887+ current.interrupted ||4888+ current.nativeThreadId !== subagent.rootSessionId4889+ ) {4890+ return;4891+ }4892+ yield* reconcileOutlivingSubagents(current, {4893+ allowIdle: !current.promptSettled,4894+ });@@ -5591,0 +5699,21 @@5699+ if (subagent.task.status === "idle" && atWork.has(taskId)) {5700+ idleOutlivingSubagents.get(subagent.rootSessionId)?.delete(taskId);5701+ yield* stopSubagentTranscriptFollower(subagent);5702+ if (subagent.task.runId !== context.input.runId) {5703+ subagent.task = {5704+ ...subagent.task,5705+ runId: context.input.runId,5706+ parentNodeId: context.input.rootNodeId,5707+ };5708+ subagent.providerTurnId = context.providerTurnId;5709+ subagent.turnItemOrdinal = yield* resolveItemOrdinal(context, taskId);5710+ }5711+ subagent.task = {5712+ ...subagent.task,5713+ status: "running",5714+ result: null,5715+ completedAt: null,5716+ };5717+ subagent.terminalStatusProjected = false;5718+ subagent.assistantText = "";5719+ subagent.lastTranscriptEntryKinds.clear();@@ -11154,4 +11327,4 @@1115411327 context.promptSettled = true;1115511328 context.promptSettledStatus = "completed";1115611329 // The replayed reply ended before the prompt counted as settled.11157- yield* idleReportedSubagents(context);11330+ yield* reconcileOutlivingSubagents(context);
Pushed3676a98
- @@ -4757,10 +4776,17 @@47574776 subagent: ActiveAcpSubagent,47584777 ) {47594778 const stop = subagent.transcriptFollowerStop;4779+ subagent.transcriptFollowerStop = undefined;4780+ subagent.transcriptFollowerStarted = false;47604781 if (stop !== undefined) {47614782 yield* Deferred.succeed(stop, undefined).pipe(Effect.ignore);47624783 }47634784 const trailingStop = subagent.transcriptTrailingDrainStop;4785+ subagent.transcriptTrailingDrainStop = undefined;4786+ subagent.transcriptTrailingDrainStarted = false;4787+ trailingTranscriptDrains.delete(subagent);47644788 if (trailingStop !== undefined) {47654789 yield* Deferred.succeed(trailingStop, undefined).pipe(Effect.ignore);47664790 }4791+ if (stop !== undefined || trailingStop !== undefined) {4792+ yield* subagent.transcriptDrainPermit.withPermit(Effect.void);
juliusmarminge added labelstakeover:in-progress
Pushed0191e77
- @@ -3399,0 +4353,21 @@4353+ // Park the worker: trailing transcript drain starts and deferred finalize arms.4354+ yield* writeMembers("mentions");4355+ yield* send(usage);4356+ yield* until(4357+ (event) =>4358+ event.type === "subagent.updated" &&4359+ event.subagent.nativeTaskRef?.nativeId === "call_swarm_author" &&4360+ event.subagent.status === "idle",4361+ );4362+ assert.equal(yield* Queue.take(scheduledFinalizes), "3000 millis");4363+4364+ // Pause the first trailing transcript poll while it holds transcriptDrainPermit.4365+ yield* Ref.set(trailingTranscriptGate.armed, true);4366+ yield* TestClock.adjust("500 millis");4367+ yield* Deferred.await(trailingTranscriptGate.reached);4368+4369+ // Start reactivation; it blocks in stopSubagentTranscriptFollower waiting on the permit.4370+ yield* writeMembers("working");4371+ const reconcileFiber = yield* send(usage).pipe(Effect.forkScoped);4372+ yield* Deferred.await(trailingTranscriptGate.reconcileChecked);4373+ yield* Effect.yieldNow;@@ -5591,0 +5751,21 @@5751+ subagent.task.status !== candidate.status ||5752+ subagent.lifecycleEpoch !== candidate.epoch5753+ ) {5754+ continue;5755+ }5756+ if (canIdleSubagent(taskId, subagent)) {5757+ if (atWork.has(taskId)) continue;5758+ yield* emitSubagent(context, {5759+ nativeTaskId: taskId,5760+ prompt: subagent.task.prompt,5761+ title: subagent.task.title,5762+ model: subagent.task.model,5763+ status: "idle",5764+ childSessionId: subagent.childSessionId,5765+ result: null,5766+ });5767+ continue;5768+ }5769+ if (subagent.task.status === "idle" && atWork.has(taskId)) {5770+ yield* stopSubagentTranscriptFollower(subagent);5771+ if (!(yield* isTurnActive)) return;@@ -5591,0 +5758,21 @@5758+ yield* emitSubagent(context, {5759+ nativeTaskId: taskId,5760+ prompt: subagent.task.prompt,5761+ title: subagent.task.title,5762+ model: subagent.task.model,5763+ status: "idle",5764+ childSessionId: subagent.childSessionId,5765+ result: null,5766+ });5767+ continue;5768+ }5769+ if (subagent.task.status === "idle" && atWork.has(taskId)) {5770+ yield* stopSubagentTranscriptFollower(subagent);5771+ if (!(yield* isTurnActive)) return;5772+ if (5773+ subagent.task.status !== candidate.status ||5774+ subagent.lifecycleEpoch !== candidate.epoch5775+ ) {5776+ continue;5777+ }5778+ idleOutlivingSubagents.get(subagent.rootSessionId)?.delete(taskId);
Pushed89d571c
- @@ -3399,0 +3680,21 @@3680+ JSON.stringify(event).includes("Helper spawned."),3681+ );3682+ const helperUpdates = helperEvents.flatMap((event) =>3683+ event.type === "subagent.updated" &&3684+ event.subagent.nativeTaskRef?.nativeId === "call_swarm_helper"3685+ ? [event.subagent]3686+ : [],3687+ );3688+ assert.isAbove(3689+ helperUpdates.length,3690+ 0,3691+ "expected subagent.updated events for the sibling swarm add",3692+ );3693+ assert.isFalse(3694+ helperUpdates.some((subagent) => subagent.status === "idle"),3695+ "an in-flight swarm add must not idle before its launch tool call completes",3696+ );3697+ assert.isString(3698+ helperUpdates.at(-1)?.providerThreadId,3699+ "completed sibling swarm add must still bind its childSessionId",3700+ );@@ -3399,0 +3855,21 @@3855+3856+ // Stop Turn 2 and release the mock prompt so finalize completes.3857+ const interruptFiber = yield* session3858+ .interruptTurn({3859+ providerThread,3860+ providerTurnId: turn2Row.providerTurn.id,3861+ requestRuntimeRestart: true,3862+ })3863+ .pipe(Effect.forkScoped);3864+ yield* releaseSteer;3865+ yield* Fiber.join(interruptFiber);3866+ yield* until((event) => event.type === "turn.terminal");3867+ yield* Queue.clear(events);3868+3869+ // Transcript writes after Stop must NOT emit late child items.3870+ yield* writeTranscript([3871+ ...roundOneSteps,3872+ { step_index: 2, type: "PLANNER_RESPONSE", status: "DONE", content: "Late leak." },3873+ ]);3874+ yield* TestClock.adjust("5 seconds");3875+ const leaked = yield* Queue.clear(events);@@ -3399,0 +4021,21 @@4021+ yield* until(4022+ (event) =>4023+ event.type === "turn_item.updated" &&4024+ event.turnItem.type === "assistant_message" &&4025+ event.turnItem.text === "Round 2 done after prompt settlement.",4026+ );4027+ // Root updates share the follower's callback permit, so this echo means the follower4028+ // finished its file reads and is waiting on the test clock before the clock moves.4029+ yield* send({4030+ sessionUpdate: "agent_message_chunk",4031+ content: { type: "text", text: "Waiting on @author after settle." },4032+ });4033+ yield* until((event) => JSON.stringify(event).includes("Waiting on @author after settle."));4034+ yield* send(usage);4035+ yield* releaseSteer;4036+ yield* Queue.take(promptSettledWithBackgroundWork);4037+4038+ // The worker parks without any further root usage_update or tool call.4039+ yield* writeMembers("mentions");4040+ yield* TestClock.adjust("5 seconds");4041+ assert.equal(yield* Queue.take(scheduledFinalizes), "3000 millis");@@ -3399,0 +4223,21 @@4223+ (event) =>4224+ event.type === "turn_item.updated" &&4225+ event.turnItem.threadId === childThreadId &&4226+ event.turnItem.type === "assistant_message" &&4227+ event.turnItem.text === "Round 1 completed.",4228+ ),4229+ 0,4230+ );4231+4232+ let pending = true;4233+ let lastResult: string | null = null;4234+ for (let attempt = 0; attempt < 3 && pending; attempt += 1) {4235+ const batch = yield* until((event) => event.type === "subagent.updated");4236+ const updated = batch.findLast((event) => event.type === "subagent.updated");4237+ if (updated?.type === "subagent.updated") {4238+ lastResult = updated.subagent.result;4239+ }4240+ pending = yield* runKeepsIngesting;4241+ }4242+ assert.isFalse(pending);4243+ assert.equal(lastResult, "Late Round 2 reply.");
juliusmarminge added labelstakeover:ready
juliusmarminge removed labelstakeover:in-progress
juliusmarminge merged thisc1cb1f6
juliusmarminge closed this
juliusmarminge removed labelstakeover:ready
Sign in to join this conversation.


macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes