fix(server): Grok runs finish when background commands end in the turn #17144
Closedhcaiano(GitHub profile, opens in a new tab)wants to merge 6 commits into
main fromrefs/pull/17144/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:XL
- apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.ts line 3184OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -3158,4 +3175,10 @@31583175 }31593176 const target =31603177 targetToolCallId !== undefined ? context.tools.get(targetToolCallId) : undefined;3161- if (target !== undefined && target.toolCallId !== toolCall.toolCallId) {3178+ const targetStatus = target === undefined ? undefined : toolStatus(target.status);3179+ // A row `task_completed` already finished holds the final output;3180+ // the agent's later poll of the same task must not append it again.3181+ if (3182+ target !== undefined &&3183+ target.toolCallId !== toolCall.toolCallId &&3184+ (targetStatus === "pending" || targetStatus === "running")
coderabbitai[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge added labelsmacroscope-review
- packages/provider-grok/src/server/xaiAcpExtension.ts lines 419 to 419OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -391,4 +413,7 @@391413 const title = titleKey(toolCall);392414 const rawInput = unknownRecord(toolCall.data.rawInput);393415 const variant = nonEmptyString(rawInput?.variant)?.toLowerCase();394- if (!title.includes("kill_command_or_subagent") && variant !== "kill") return [];416+ // Grok 1.0.46 sends the `KillTask` variant and retitles the finished call417+ // `kill <id> (killed)`.418+ const isKill =419+ title.includes("kill_command_or_subagent") || variant === "kill" || variant === "killtask";
- packages/provider-acp/src/server/adapter.ts line 3158Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -3137,5 +3150,9 @@31373150 // that case; likelihood is low because mid-turn monitor ends31383151 // normally arrive as reminder mutations that force inProgress, and31393152 // re-reports are documented post-settle traffic.3153+ //3154+ // An end Grok reported out of band (`task_completed`) is not3155+ // evidence the agent read it; only its own poll or kill is.31403156 if (31413157 !context.promptSettled &&3158+ options?.endReportedOutOfBand !== true &&packages/provider-acp/src/server/adapter.ts lines 3218 to 3219Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -3191,4 +3208,11 @@31913208 }31923209 const target =31933210 targetToolCallId !== undefined ? context.tools.get(targetToolCallId) : undefined;3194- if (target !== undefined && target.toolCallId !== toolCall.toolCallId) {3211+ const targetStatus = target === undefined ? undefined : toolStatus(target.status);3212+ const targetEnded = targetStatus === "completed" || targetStatus === "failed";3213+ if (3214+ target !== undefined &&3215+ target.toolCallId !== toolCall.toolCallId &&3216+ targetEnded &&3217+ backgroundCompletion.appendOutput.length > 0 &&3218+ toolOutputText(target).trim() !== backgroundCompletion.appendOutput.trim()packages/provider-grok/src/server/xaiAcpExtension.ts line 439OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -395,8 +421,19 @@395421 if (toolCall.status !== "completed") return [];396422 const taskIds: string[] = [];397423 const push = (value: unknown) => {398424 const id = nonEmptyString(value);399425 if (id !== undefined) taskIds.push(id);400426 };401- if (Array.isArray(rawInput?.task_ids)) {402- for (const entry of rawInput.task_ids) push(entry);427+ // A structured result names each task's outcome; only a confirmed end428+ // (`killed`, or `already_exited` for a task that finished first) counts.429+ const multiResults = unknownRecord(unknownRecord(toolCall.data.rawOutput)?.MultiResult)?.results;430+ const singleResult = getOutputResult(toolCall);431+ const results = Array.isArray(multiResults)432+ ? multiResults.flatMap((value) => {433+ const result = unknownRecord(value);434+ return result === undefined ? [] : [result];435+ })436+ : singleResult === undefined437+ ? []438+ : [singleResult];439+ if (results.length > 0) {
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
- @@ -3191,4 +3208,10 @@31913208 }31923209 const target =31933210 targetToolCallId !== undefined ? context.tools.get(targetToolCallId) : undefined;3194- if (target !== undefined && target.toolCallId !== toolCall.toolCallId) {3211+ const targetStatus = target === undefined ? undefined : toolStatus(target.status);3212+ const targetEnded = targetStatus === "completed" || targetStatus === "failed";3213+ if (3214+ target !== undefined &&3215+ target.toolCallId !== toolCall.toolCallId &&3216+ targetEnded &&3217+ backgroundCompletion.status !== "running" &&
maria-rcks closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed