Skip to content

Commit 950754d

Browse files
committed
fix(acp): remediate CodeRabbit review feedback on hydration state and notice parsing
1 parent dd41a62 commit 950754d

3 files changed

Lines changed: 58 additions & 15 deletions

File tree

‎apps/server/src/provider/acp/AntigravityProtocol.test.ts‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,19 @@ describe("Antigravity background tasks", () => {
689689
{ taskId: "task-123", status: "completed", appendOutput: 'Task "task-123" cancelled.' },
690690
]);
691691

692+
// manage_task kill failed with error does not mark completed
693+
expect(
694+
extractAntigravityBackgroundTaskCompletion({
695+
toolCallId: "call-kill-failed",
696+
title: "manage_task",
697+
status: "completed",
698+
data: {
699+
rawInput: { Action: "kill", TaskId: "task-123" },
700+
rawOutput: "Error: Task not found",
701+
},
702+
}),
703+
).toEqual([]);
704+
692705
// manage_task status shows completed
693706
expect(
694707
extractAntigravityBackgroundTaskCompletion({
@@ -774,10 +787,23 @@ describe("Antigravity background tasks", () => {
774787
},
775788
]);
776789

777-
// Task was canceled
790+
// Task was canceled even if inner output mentions exit codes
791+
expect(
792+
extractAntigravityBackgroundToolMutation(
793+
'Task id "task-xyz" was canceled with result:\nStep was canceled: context canceled by manage_task\nOutput:\nThe command exited with code 1.',
794+
),
795+
).toEqual([
796+
{
797+
taskId: "task-xyz",
798+
status: "completed",
799+
appendOutput: expect.stringContaining("task-xyz"),
800+
},
801+
]);
802+
803+
// Task finished with exit 0 even if inner command output prints exit codes
778804
expect(
779805
extractAntigravityBackgroundToolMutation(
780-
'Task id "task-xyz" was canceled with result:\nStep was canceled: context canceled by manage_task',
806+
'Task id "task-xyz" finished with result:\nThe command exited with code 0.\nOutput:\nNote: previous sub-command exited with code 1\nDone.',
781807
),
782808
).toEqual([
783809
{

‎apps/server/src/provider/acp/AntigravityProtocol.ts‎

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,13 @@ export function extractAntigravityBackgroundTaskId(toolCall: AcpToolCallState):
571571
const outputText = extractAntigravityToolOutputText(toolCall);
572572
if (outputText !== undefined) {
573573
const match =
574-
/running as a background task with task id:\s*([^\s\r\n]+)/i.exec(outputText) ??
575-
/scheduled task with (?:task )?id:\s*([^\s\r\n]+)/i.exec(outputText) ??
576-
/background task with task id:\s*([^\s\r\n]+)/i.exec(outputText);
574+
/(?:^|\n)(?:Tool is )?running as a background task with task id:\s*([^\s\r\n]+)/i.exec(
575+
outputText,
576+
) ??
577+
/(?:^|\n)(?:Scheduled|Tool scheduled) task with (?:task )?id:\s*([^\s\r\n]+)/i.exec(
578+
outputText,
579+
) ??
580+
/(?:^|\n)(?:Tool )?background task with task id:\s*([^\s\r\n]+)/i.exec(outputText);
577581
if (match?.[1]) {
578582
// Strip only trailing punctuation such as quotes, commas, dots
579583
return match[1].replace(/["',.]+$/, "").trim();
@@ -613,11 +617,13 @@ export function extractAntigravityBackgroundTaskCompletion(
613617
const action = typeof rawInput?.Action === "string" ? rawInput.Action.toLowerCase() : "";
614618

615619
if (action === "kill" || /kill/i.test(title)) {
616-
if (toolCall.status === "completed" || /cancelled|killed/i.test(outputText)) {
617-
const taskId =
618-
taskIdFromInput ??
619-
/Task "([^"]+)"\s+(?:cancelled|killed)/i.exec(outputText)?.[1] ??
620-
/Task id "([^"]+)"\s+(?:was canceled|finished)/i.exec(outputText)?.[1];
620+
const killMatch =
621+
/(?:^|\n)Task "([^"]+)"\s+(?:cancelled|killed)\b/i.exec(outputText) ??
622+
/(?:^|\n)Task id "([^"]+)"\s+was canceled\b/i.exec(outputText);
623+
const hasSuccessfulKillNotice = killMatch !== null;
624+
const isExplicitKillError = /(?:failed|error|not found|no task)/i.test(outputText);
625+
if ((toolCall.status === "completed" && !isExplicitKillError) || hasSuccessfulKillNotice) {
626+
const taskId = taskIdFromInput ?? killMatch?.[1];
621627
if (taskId) {
622628
return [
623629
{
@@ -685,13 +691,24 @@ export function extractAntigravityBackgroundToolMutation(text: string): Readonly
685691
if (taskFinishedMatch?.[1] && taskFinishedMatch[2]) {
686692
const taskId = taskFinishedMatch[1].replace(/["',.]+$/, "").trim();
687693
const kind = taskFinishedMatch[2].toLowerCase();
688-
const hasFailedExitCode = /command exited with code\s+([1-9]\d*)/i.test(text);
689-
const status: "completed" | "failed" =
690-
kind === "failed" || hasFailedExitCode ? "failed" : "completed";
694+
let status: "completed" | "failed";
695+
if (kind === "was canceled") {
696+
status = "completed";
697+
} else if (kind === "failed") {
698+
status = "failed";
699+
} else {
700+
const resultPrefix = text.slice(taskFinishedMatch.index + taskFinishedMatch[0].length);
701+
const outputIdx = resultPrefix.search(/(?:^|\n)Output:/i);
702+
const header = outputIdx !== -1 ? resultPrefix.slice(0, outputIdx) : resultPrefix;
703+
const hasFailedExitCode =
704+
/(?:^|\n)(?:The command exited with code\s+([1-9]\d*)|Exit code:\s*([1-9]\d*)|Status:\s*FAILED)/i.test(
705+
header,
706+
);
707+
status = hasFailedExitCode ? "failed" : "completed";
708+
}
691709
results.push({ taskId, status, appendOutput: text });
692710
return results;
693711
}
694-
695712
const taskCancelledMatch = /(?:^|\n)Task "([^"]+)"\s+(?:cancelled|killed)\b/i.exec(text);
696713
if (taskCancelledMatch?.[1]) {
697714
results.push({

‎packages/provider-acp/src/server/adapter.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5510,7 +5510,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
55105510
? ("failed" as const)
55115511
: ("completed" as const);
55125512
if (flavor.backgroundNoticesAreTerminal === true) {
5513-
yield* clearAwaitingBackgroundHydration(context, mutation.taskId);
5513+
context.awaitingBackgroundHydration.delete(mutation.taskId);
55145514
} else if (nextStatus !== "inProgress") {
55155515
yield* markAwaitingBackgroundHydration(context, mutation.taskId);
55165516
nextStatus = "inProgress";

0 commit comments

Comments
 (0)