fix(antigravity): wait for background command and subagent results #37489
ClosedQ3yp(GitHub profile, opens in a new tab)wants to merge 7 commits into
main fromrefs/pull/37489/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- @@ -9683,0 +9848,21 @@9848+ providerThread,9849+ taskIds,9850+ awaited,9851+ }) {9852+ const sessionId = yield* nativeThreadId(driver, providerThread);9853+ const context = yield* Ref.get(activeTurn);9854+ const uniqueTaskIds = [...new Set(taskIds)];9855+ if (9856+ context === null ||9857+ context.nativeThreadId !== sessionId ||9858+ context.finalized ||9859+ context.interrupted9860+ ) {9861+ return { matched: [] };9862+ }9863+ if (!awaited) {9864+ const openTools = unreleasedOpenForegroundTools(context);9865+ if (openTools.length === 0) {9866+ return { matched: [] };9867+ }9868+ for (const tool of openTools) {@@ -8859 +8939,20 @@8859- Deferred.succeed(context.promptWireSettled, undefined).pipe(Effect.asVoid),8939+ const runPromptLoop = Effect.gen(function* () {8940+ if (compactSession !== undefined) {8941+ yield* Deferred.succeed(context.promptDispatched, undefined);8942+ yield* compactSession.compact(runtime, requestedSessionId);8943+ return {8944+ result: { stopReason: "end_turn" } satisfies EffectAcpSchema.PromptResponse,8945+ hiddenFailure: undefined,8946+ };8947+ }8948+ let currentPrompt: ReadonlyArray<EffectAcpSchema.ContentBlock> = promptParts!.prompt;8949+ let isInitialPrompt = true;8950+ let continuations = 0;8951+ const maxContinuations = flavor.foregroundCommandWait?.maxContinuations ?? 24;8952+8953+ while (true) {8954+ const checkPromptOutcome =8955+ flavor.watchPromptOutcome === undefined8956+ ? undefined8957+ : yield* flavor.watchPromptOutcome(requestedSessionId);8958+ context.promptSentAt = yield* Clock.currentTimeMillis;
- @@ -1,4 +1,4 @@11 {22 "claudeSystemAppendBytes": 5930,33 "codexAdditionalContextBytes": 7324,4- "mcpToolListJsonBytes": 497364+ "mcpToolListJsonBytes": 49743@@ -8861,0 +8991,21 @@8991+ (tool) =>8992+ promptParts?.hasT3Mcp === true || extractSubagentUpdate(tool) === undefined,8993+ ),8994+ ),8995+ );8996+ if (openTools.length === 0) {8997+ return { result, hiddenFailure };8998+ }8999+9000+ if (continuations >= 1) {9001+ yield* waitUntilForegroundToolsSettle(context, "10 seconds");9002+ if (context.interrupted || context.finalized) {9003+ return { result, hiddenFailure };9004+ }9005+ }9006+9007+ const toolsForPrompt = yield* runtimeCallbackPermit.withPermit(9008+ Effect.gen(function* () {9009+ yield* closeTextStreams(context);9010+ const remaining = unreleasedOpenForegroundTools(context);9011+ return remaining.length > 0 ? remaining : openTools;@@ -9683,0 +9849,21 @@9849+ taskIds,9850+ awaited,9851+ }) {9852+ const sessionId = yield* nativeThreadId(driver, providerThread);9853+ const context = yield* Ref.get(activeTurn);9854+ const uniqueTaskIds = [...new Set(taskIds)];9855+ if (9856+ context === null ||9857+ context.nativeThreadId !== sessionId ||9858+ context.finalized ||9859+ context.interrupted9860+ ) {9861+ return { matched: [] };9862+ }9863+ if (!awaited) {9864+ const openTools = unreleasedOpenForegroundTools(context);9865+ if (openTools.length === 0) {9866+ return { matched: [] };9867+ }9868+ for (const tool of openTools) {9869+ context.releasedForegroundToolIds.add(tool.toolCallId);
tanstack-source added labelsbug
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- @@ -189,0 +242,21 @@242+ message(bytes, STEP_PLANNER_RESPONSE) ?? new Uint8Array(),243+ PLANNER_TOOL_CALLS,244+ ).flatMap((call) => {245+ const callId = text(call, 1);246+ return callId === undefined ? [] : [callId];247+ }),248+ )(payload);249+ if (calls?.length === 1) owners.set(calls[0]!, id);250+ }251+ let bytes = 0;252+ let rows = 0;253+ // Cortex step types: RUN_COMMAND=21, INVOKE_SUBAGENT=127, GENERIC=132 (exa.cortex_pb).254+ for (const row of database255+ .prepare(256+ "SELECT step_payload FROM steps WHERE step_type IN (21, 127, 132) AND step_format = 0 AND length(step_payload) <= ? ORDER BY idx DESC",257+ )258+ .iterate(MAX_STEP_BYTES)) {259+ const payload = payloadOf(row);260+ if (payload === undefined) continue;261+ bytes += payload.length;262+ if (++rows > MAX_INVOKE_ROWS || bytes > MAX_SCAN_BYTES) break;
- @@ -189,0 +229,21 @@229+ if (step?.[1] !== rootSessionId) continue;230+ const payload = payloadOf(231+ database232+ .prepare(233+ "SELECT step_payload FROM steps WHERE idx = ? AND step_format = 0 AND length(step_payload) <= ?",234+ )235+ .get(Number(step[2]), MAX_STEP_BYTES),236+ );237+ const calls =238+ payload === undefined239+ ? []240+ : safely((bytes) =>241+ messages(242+ message(bytes, STEP_PLANNER_RESPONSE) ?? new Uint8Array(),243+ PLANNER_TOOL_CALLS,244+ ).flatMap((call) => {245+ const callId = text(call, 1);246+ return callId === undefined ? [] : [callId];247+ }),248+ )(payload);249+ if (calls?.length === 1) owners.set(calls[0]!, id);@@ -189,0 +243,21 @@243+ PLANNER_TOOL_CALLS,244+ ).flatMap((call) => {245+ const callId = text(call, 1);246+ return callId === undefined ? [] : [callId];247+ }),248+ )(payload);249+ if (calls?.length === 1) owners.set(calls[0]!, id);250+ }251+ let bytes = 0;252+ let rows = 0;253+ // Cortex step types: RUN_COMMAND=21, INVOKE_SUBAGENT=127, GENERIC=132 (exa.cortex_pb).254+ for (const row of database255+ .prepare(256+ "SELECT idx, metadata FROM steps WHERE step_type IN (21, 127, 132) AND step_format = 0 AND length(metadata) <= ? ORDER BY idx DESC",257+ )258+ .iterate(MAX_STEP_BYTES)) {259+ const metadata = row.metadata;260+ if (!(metadata instanceof Uint8Array)) continue;261+ const callId = safely((data) => text(message(data, METADATA_TOOL_CALL), 1))(metadata);262+ const owner = callId === undefined ? undefined : owners.get(callId);263+ if (owner === undefined || result.has(owner)) continue;@@ -8891 +9010,20 @@8891- ),9010+ );9011+ isInitialPrompt = false;9012+ if (flavor.reportsPerTurnPromptUsage === true && !context.finalized) {9013+ context.promptUsage = mergeAcpPromptUsage(context.promptUsage, result.usage);9014+ }9015+ const hiddenFailure =9016+ checkPromptOutcome === undefined ||9017+ context.interrupted ||9018+ result.stopReason === "error" ||9019+ result.stopReason === "cancelled"9020+ ? undefined9021+ : yield* checkPromptOutcome(result);9022+9023+ if (9024+ flavor.foregroundCommandWait === undefined ||9025+ context.interrupted ||9026+ context.finalized ||9027+ hiddenFailure !== undefined ||9028+ result.stopReason !== "end_turn" ||9029+ continuations >= maxContinuations@@ -8891,0 +9014,21 @@9014+ }9015+ const hiddenFailure =9016+ checkPromptOutcome === undefined ||9017+ context.interrupted ||9018+ result.stopReason === "error" ||9019+ result.stopReason === "cancelled"9020+ ? undefined9021+ : yield* checkPromptOutcome(result);9022+9023+ if (9024+ flavor.foregroundCommandWait === undefined ||9025+ context.interrupted ||9026+ context.finalized ||9027+ hiddenFailure !== undefined ||9028+ result.stopReason !== "end_turn" ||9029+ continuations >= maxContinuations9030+ ) {9031+ return { result, hiddenFailure };9032+ }9033+9034+ const openTools = yield* runtimeCallbackPermit.withPermit(
- @@ -189,0 +245,21 @@245+ PLANNER_TOOL_CALLS,246+ ).map((call) => ({247+ id: text(call, 1),248+ name: text(call, 2),249+ args: text(call, 3),250+ })),251+ )(payload);252+ const candidates = calls?.filter((call) =>253+ command254+ ? call.name === "run_command"255+ : call.name === "invoke_subagent" || call.name === "start_subagent",256+ );257+ const matches =258+ candidates?.length === 1259+ ? candidates260+ : candidates?.filter(261+ (call) =>262+ call.args !== undefined &&263+ input !== undefined &&264+ Option.exists(decodeArgument(call.args), (args) =>265+ NodeUtil.isDeepStrictEqual(args, input),@@ -9725,0 +9909,21 @@9909+ ? {}9910+ : {9911+ awaitBackgroundTasks: Effect.fn("AcpAdapterV2.awaitBackgroundTasks")(function* ({9912+ providerThread,9913+ taskIds,9914+ awaited,9915+ }) {9916+ const sessionId = yield* nativeThreadId(driver, providerThread);9917+ const context = yield* Ref.get(activeTurn);9918+ const uniqueTaskIds = [...new Set(taskIds)];9919+ if (9920+ context === null ||9921+ context.nativeThreadId !== sessionId ||9922+ context.finalized ||9923+ context.interrupted9924+ ) {9925+ return { matched: [] };9926+ }9927+ const wait = flavor.foregroundCommandWait!;9928+ const tools = [...context.tools.values()].filter(9929+ wait.isForegroundCommand ?? ((tool) => tool.kind === "execute"),
Pushede1599a8
juliusmarminge added labelstakeover:in-progress
Q3yp(GitHub profile, opens in a new tab) closed this
juliusmarminge added labelstakeover:blocked
juliusmarminge removed labelstakeover:in-progress
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed