fix(antigravity): keep swarm workers alive after the prompt ends #39905
Closedfriedman-max(GitHub profile, opens in a new tab)wants to merge 8 commits into
main fromrefs/pull/39905/headopened View on GitHubfriedman-max(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:L
juliusmarminge added labelstakeover:in-progress
- @@ -426,0 +428,21 @@428+ }),429+ ),430+ }),431+ ),432+);433+434+function swarmWorkerAtWork(transcript: string): boolean {435+ const lines = transcript.split("\n");436+ const results: Array<boolean> = [];437+ for (let index = lines.length - 1; index >= 0; index -= 1) {438+ const step = Option.getOrUndefined(decodeTranscriptLine(lines[index]));439+ if (index === lines.length - 1 && step?.type === "ERROR_MESSAGE") return false;440+ if (step?.type === "GENERIC") {441+ results.push(step.status === "DONE");442+ continue;443+ }444+ if (step?.type !== "PLANNER_RESPONSE" || step.status !== "DONE") return true;445+ const calls = step.tool_calls ?? [];446+ if (calls.length === 0) return results.length > 0;447+ const wait = calls.findIndex((call) => call.name === "swarm_wait");448+ return wait < 0 || results.length < calls.length || !results[results.length - 1 - wait];@@ -2701,8 +2704,9 @@27012704 // has no prompt, so nothing else ends it.27022705 const held = yield* Ref.get(activeTurn);27032706 if (2704- flavor.toolOutlivesPrompt === undefined ||2707+ (flavor.toolOutlivesPrompt === undefined &&2708+ flavor.detachedWorkOutlivingPrompt === undefined) ||27052709 held === null ||27062710 !held.promptSettled ||27072711 held.finalized ||2708- !hasDeferredBackgroundWork(held)2712+ !(held.detachedWorkPending || hasDeferredBackgroundWork(held))
Pushedf5f5048
- @@ -8687,8 +8695,15 @@8695+ context.backgroundFinalizeGeneration === generation &&8696+ !hasDeferredBackgroundWork(context);8697+ const readDetachedWork = Effect.fn("AcpAdapterV2.readDetachedWork")(function* () {8698+ if (flavor.detachedWorkOutlivingPrompt === undefined) return true;8699+ const pending = yield* flavor.detachedWorkOutlivingPrompt(context.nativeThreadId);8700+ if (!canFinalize()) return false;8701+ context.detachedWorkPending = pending;8702+ return true;8703+ });8704+ if (!(yield* readDetachedWork())) return;86878705 yield* Effect.gen(function* () {86888706 yield* Effect.sleep(debounce);8689- if (8690- context.finalized ||8691- context.interrupted ||8692- context.backgroundFinalizeGeneration !== generation8693- ) {8694- return;8707+ if (!canFinalize()) return;8708+ // Wait one more debounce after the work stops, for the last worker's wake.8709+ while (context.detachedWorkPending) {@@ -8687,8 +8697,15 @@8697+ const readDetachedWork = Effect.fn("AcpAdapterV2.readDetachedWork")(function* () {8698+ if (flavor.detachedWorkOutlivingPrompt === undefined) return true;8699+ const pending = yield* flavor.detachedWorkOutlivingPrompt(context.nativeThreadId);8700+ if (!canFinalize()) return false;8701+ context.detachedWorkPending = pending;8702+ return true;8703+ });8704+ if (!(yield* readDetachedWork())) return;86878705 yield* Effect.gen(function* () {86888706 yield* Effect.sleep(debounce);8689- if (8690- context.finalized ||8691- context.interrupted ||8692- context.backgroundFinalizeGeneration !== generation8693- ) {8694- return;8707+ if (!canFinalize()) return;8708+ // Wait one more debounce after the work stops, for the last worker's wake.8709+ while (context.detachedWorkPending) {8710+ if (!(yield* readDetachedWork())) return;8711+ yield* Effect.sleep(debounce);@@ -9114,3 +9131,12 @@91149131 }91159132 yield* idleReportedSubagents(context);91169133 if (context.finalized) return;9134+ if (9135+ defersFinalizeForBackgroundWork &&9136+ status === "completed" &&9137+ flavor.detachedWorkOutlivingPrompt !== undefined9138+ ) {9139+ context.detachedWorkPending = yield* flavor.detachedWorkOutlivingPrompt(9140+ context.nativeThreadId,9141+ );9142+ if (context.detachedWorkPending) yield* scheduleDeferredFinalize(context);
Pushed0641775
juliusmarminge added labelstakeover:blocked
juliusmarminge removed labelstakeover:ready
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
copilot-pull-request-reviewer[bot](GitHub profile, opens in a new tab) reviewed
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.