From 9af95d6537ed9c34315b708b600c26eccb2b619f Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 09:45:50 +0000 Subject: [PATCH 01/31] Keep Antigravity ACP turns open for reactive wakeups --- src/adapters/acp.ts | 82 ++++++++++++++++++++- src/adapters/antigravity.ts | 1 + test/antigravity-steering-native.test.ts | 40 ++++++++++ test/antigravity-steering.node.test.ts | 66 +++++++++++++++++ test/fixtures/fake-antigravity-steering.mjs | 68 +++++++++++++++++ 5 files changed, 253 insertions(+), 4 deletions(-) diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index 8f1037ac..fa6a5997 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -141,6 +141,14 @@ export class Acp implements Adapter { protected resumeWithoutReplay = false; /** Report each turn's cumulative token usage from prompt responses. */ protected reportsUsage = false; + /** agy can return end_turn before its background work wakes the model. */ + protected waitsForReactiveTurns = false; + private reactiveTools = new Set(); + private reactiveEnd = false; + private reactiveUsage = false; + get reusable() { + return !(this.reactiveEnd && this.cancelling); + } /** Prompt requests open in the current turn. A steering agent answers an * earlier request when it folds a later one into the same turn; the turn * ends only when the last open request settles. */ @@ -592,6 +600,9 @@ export class Acp implements Adapter { this.messageId = randomUUID(); this.turnUsage = undefined; this.earlierEnd = false; + this.reactiveTools.clear(); + this.reactiveEnd = false; + this.reactiveUsage = false; const expected = this.echoOf(value).trim(); this.promptEcho = undefined; this.promptEchoed = expected @@ -618,8 +629,20 @@ export class Acp implements Adapter { (result) => { const last = --this.openPrompts === 0; this.addUsage(result); - if (!last && result.stopReason === "end_turn") this.earlierEnd = true; - if (!last || this.closed || this.terminalReported) return; + if (this.closed || this.terminalReported) return; + if (result.stopReason === "end_turn") { + if (!last) this.earlierEnd = true; + if ( + !this.cancelling && + this.waitsForReactiveTurns && + (this.reactiveTools.size || this.permissions.size) + ) { + this.reactiveEnd = true; + this.reactiveUsage = false; + return; + } + } + if (!last) return; this.terminalReported = true; const limited = ["max_tokens", "max_turn_requests"].includes( result.stopReason, @@ -642,9 +665,16 @@ export class Acp implements Adapter { (error: unknown) => { const last = --this.openPrompts === 0; if (!last || this.closed || this.terminalReported) return; - this.terminalReported = true; // A rejected steering input that never joined the turn does not // undo the turn's own normal end. + if ( + this.reactiveEnd && + (this.cancelling || (steer && !this.steerJoined)) + ) { + this.finishReactiveTurn(); + return; + } + this.terminalReported = true; if (steer && !this.steerJoined && this.earlierEnd) { this.emit({ type: "status", @@ -665,12 +695,32 @@ export class Acp implements Adapter { }, ) .finally(() => { - if (this.openPrompts) return; + if (this.openPrompts || !this.terminalReported) return; this.active = false; this.cancelPermissions(); }); return request; } + private finishReactiveTurn() { + if ( + this.closed || + this.terminalReported || + !this.reactiveEnd || + this.openPrompts || + (!this.cancelling && + (!this.reactiveUsage || + this.reactiveTools.size || + this.permissions.size)) + ) + return; + this.terminalReported = true; + this.active = false; + this.emit({ + type: "status", + status: this.cancelling ? "interrupted" : "completed", + recoverable: !this.cancelling, + }); + } private addUsage(result: unknown) { if (!this.reportsUsage) return; const usage = z @@ -786,6 +836,7 @@ export class Acp implements Adapter { this.cancelPermissions(); if (!this.closed && this.session && this.connection && this.active) await this.connection.cancel({ sessionId: this.session }); + this.finishReactiveTurn(); } async answer( id: string, @@ -1102,6 +1153,7 @@ export class Acp implements Adapter { if (!choices.length) return Promise.resolve({ outcome: { outcome: "cancelled" } }); const id = randomUUID(); + this.reactiveUsage = false; return new Promise((resolve) => { this.permissions.set(id, { choices: new Set(choices.map((choice) => choice.optionId)), @@ -1170,6 +1222,7 @@ export class Acp implements Adapter { return; } if (u.sessionUpdate === "agent_message_chunk") { + this.reactiveUsage = false; if (!this.loading && u.content.type === "text") this.emit({ type: "delta", @@ -1178,10 +1231,31 @@ export class Acp implements Adapter { }); return; } + if (u.sessionUpdate === "usage_update" && this.reactiveEnd) { + // agy 1.5.14 sends this after a reactive pass but sends no second + // prompt response. A pass that leaves more work open can wake again. + this.reactiveUsage = !this.reactiveTools.size && !this.permissions.size; + if (!this.cancelling) this.finishReactiveTurn(); + return; + } if ( u.sessionUpdate === "tool_call" || u.sessionUpdate === "tool_call_update" ) { + if (this.waitsForReactiveTurns && !this.loading) { + const input = u.rawInput; + const daemon = + input && + typeof input === "object" && + "IsDaemon" in input && + input.IsDaemon === true; + if (daemon || u.status === "completed" || u.status === "failed") { + this.reactiveTools.delete(u.toolCallId); + } else if (u.sessionUpdate === "tool_call") { + this.reactiveTools.add(u.toolCallId); + this.reactiveUsage = false; + } + } const old = this.toolItems.get(u.toolCallId); const title = text(u.title) || old?.title || "ACP tool"; const memoryTool = diff --git a/src/adapters/antigravity.ts b/src/adapters/antigravity.ts index 588c96dd..88da91e7 100644 --- a/src/adapters/antigravity.ts +++ b/src/adapters/antigravity.ts @@ -29,6 +29,7 @@ class AntigravityAcp extends Acp { protected override requireWorkspaceTools = false; protected override resumeWithoutReplay = true; protected override reportsUsage = true; + protected override waitsForReactiveTurns = true; override capabilities = { approvals: true, questions: false, diff --git a/test/antigravity-steering-native.test.ts b/test/antigravity-steering-native.test.ts index fe433de8..18adb562 100644 --- a/test/antigravity-steering-native.test.ts +++ b/test/antigravity-steering-native.test.ts @@ -404,6 +404,46 @@ it("steers a running turn through agy acp without a restart or replaying the tas ]); }); +it("publishes the result only after Antigravity's reactive work and approval finish", async () => { + process.env.LOOP_TEST_AGY_MODE = "reactive"; + const { run } = task("agy-reactive"); + const before = prompts().length; + const execution = sessions.execute( + claim("antigravity-fixture", (candidate) => candidate.id === run.id)!, + ); + const checkpoint = () => + db + .prepare("SELECT stage,output FROM agent_checkpoints WHERE run_id=?") + .get(run.id); + const decision = () => + db + .prepare( + "SELECT id FROM native_decisions WHERE run_id=? AND state='pending'", + ) + .get(run.id) as { id: string } | undefined; + try { + await until(() => !!decision()); + expect(checkpoint()).toMatchObject({ output: "" }); + expect(checkpoint()).not.toMatchObject({ stage: "done" }); + expect(ownedRun(run.id, OWNER).state).toBe("awaiting_approval"); + await sessions.decisions.answer(decision()!.id, "reactive-approval", { + choice: "allow", + }); + expect(await execution).toMatchObject({ kind: "finished" }); + expect(checkpoint()).toMatchObject({ + stage: "done", + output: expect.stringContaining("Done."), + }); + expect(prompts().slice(before)).toEqual([ + "Saved fixture instructions\n\nExplicit task", + ]); + } finally { + delete process.env.LOOP_TEST_AGY_MODE; + await sessions.interrupt(run.id); + await execution; + } +}); + it("replaces an idle ACP session after refreshing workspace-tool support while retaining native context", async () => { const { run } = task("agy-acp-upgrade"); const before = await sessions.session(run); diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index 329271b2..a769fb7b 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -41,6 +41,72 @@ const statuses = (events: AdapterEvent[]) => const complete = (events: AdapterEvent[]) => events.filter((e) => e.type === "status" && e.status === "completed"); +test("Antigravity waits through successive reactive passes and approvals", async (t) => { + const requests = fixture(t); + process.env.LOOP_TEST_AGY_MODE = "reactive"; + const events: AdapterEvent[] = []; + const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => + events.push(e), + ); + t.after(() => adapter.dispose()); + await adapter.start(); + await adapter.prompt("Run background work"); + await until(() => events.some((e) => e.type === "request")); + const approval = events.find((e) => e.type === "request")!; + assert.deepEqual(statuses(events), ["ready"]); + assert.deepEqual( + events.flatMap((e) => (e.type === "delta" ? [e.text] : [])), + ["Waiting.", "Waiting again."], + ); + await adapter.answer(approval.request.id, { choice: "allow" }); + await until(() => complete(events).length === 1); + assert.deepEqual(statuses(events), ["ready", "completed"]); + assert.deepEqual( + events.flatMap((e) => (e.type === "delta" ? [e.text] : [])), + ["Waiting.", "Waiting again.", "Done."], + ); + assert.deepEqual(prompts(requests), ["Run background work"]); + await adapter.prompt("Next turn"); + await until(() => complete(events).length === 2); +}); + +test("Antigravity completes normally with only a daemon still running", async (t) => { + fixture(t); + process.env.LOOP_TEST_AGY_MODE = "daemon-only"; + const events: AdapterEvent[] = []; + const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => + events.push(e), + ); + t.after(() => adapter.dispose()); + await adapter.start(); + await adapter.prompt("Start a daemon"); + await until(() => complete(events).length === 1); + assert.deepEqual(statuses(events), ["ready", "completed"]); +}); + +for (const stop of ["cancel", "dispose"] as const) + test(`Antigravity ${stop} can stop a turn waiting for a reactive wakeup`, async (t) => { + const requests = fixture(t); + process.env.LOOP_TEST_AGY_MODE = "reactive-stalled"; + const events: AdapterEvent[] = []; + const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => + events.push(e), + ); + t.after(() => adapter.dispose()); + await adapter.start(); + await adapter.prompt("Wait for background work"); + await until(() => events.some((e) => e.type === "usage")); + assert.deepEqual(statuses(events), ["ready"]); + await adapter[stop](); + if (stop === "cancel") { + await until(() => requests().some((r) => r.acp === "session/cancel")); + assert.deepEqual(statuses(events), ["ready", "interrupted"]); + assert.equal(adapter.reusable, false); + } else { + assert.deepEqual(statuses(events), ["ready"]); + } + }); + for (const version of ["1.5.2", "1.5.9"]) test(`Antigravity ${version} waits for delayed discovery before framing a slash-leading steer`, async (t) => { const requests = fixture(t); diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index 0f56cc0f..cbe79403 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -128,6 +128,72 @@ const finish = (sessionId, stopReason = "end_turn") => { let permission = 0; const permissions = new Map(); +function reactiveTurn(sessionId, mode) { + const tool = (toolCallId, rawInput) => + update(sessionId, { + sessionUpdate: "tool_call", + toolCallId, + title: toolCallId, + status: "in_progress", + rawInput, + }); + const complete = (toolCallId, status = "completed") => + update(sessionId, { + sessionUpdate: "tool_call_update", + toolCallId, + status, + }); + const message = (text) => + update(sessionId, { + sessionUpdate: "agent_message_chunk", + content: { type: "text", text }, + }); + const reportUsage = () => + update(sessionId, { sessionUpdate: "usage_update", used: 20, size: 100 }); + + tool("daemon", { IsDaemon: true }); + if (mode !== "daemon-only") + tool("background", { + CommandLine: "sleep 5", + IsDaemon: false, + WaitMsBeforeAsync: 500, + }); + message(mode === "daemon-only" ? "Daemon started." : "Waiting."); + reportUsage(); + finish(sessionId); + if (mode !== "reactive") return; + + reportUsage(); // Even a usage update following end_turn leaves open work. + setTimeout(() => { + complete("background"); + tool("subagent", {}); + message("Waiting again."); + reportUsage(); + setTimeout(() => { + complete("subagent", "failed"); + tool("follow-up", {}); + const id = `perm-${++permission}`; + permissions.set(id, (result) => { + if (result.outcome.outcome !== "selected") return; + complete("follow-up"); + message("Done."); + reportUsage(); + }); + send({ + id, + method: "session/request_permission", + params: { + sessionId, + toolCall: { toolCallId: "follow-up", title: "Reactive approval" }, + options: [ + { optionId: "allow", name: "Allow once", kind: "allow_once" }, + ], + }, + }); + }, 30); + }, 30); +} + createInterface({ input: process.stdin }).on("line", (line) => { const req = JSON.parse(line); if (req.jsonrpc !== "2.0") process.exit(92); @@ -280,6 +346,8 @@ createInterface({ input: process.stdin }).on("line", (line) => { 300, ); } else echo(); + if (["reactive", "reactive-stalled", "daemon-only"].includes(outcome())) + return reactiveTurn(sessionId, outcome()); if (outcome() === "hang") return; if (text.includes("[slow]")) { update(sessionId, { From c6f631e044d30351cb48839638d3a709696ae50b Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 09:50:51 +0000 Subject: [PATCH 02/31] Bound unconfirmed Antigravity reactive completions --- src/adapters/acp.ts | 70 ++++++++++++++++++--- test/antigravity-steering.node.test.ts | 57 +++++++++++++++++ test/fixtures/fake-antigravity-steering.mjs | 34 ++++++++-- 3 files changed, 147 insertions(+), 14 deletions(-) diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index fa6a5997..4cd3ab79 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -73,6 +73,7 @@ function matchEcho(echo: Echo, chunk: string) { } // agy echoes a prompt within a second of receiving it. const ECHO_WAIT = 5000; +const REACTIVE_IDLE_MS = 60_000; const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms).unref()); const text = (value: unknown) => @@ -146,8 +147,10 @@ export class Acp implements Adapter { private reactiveTools = new Set(); private reactiveEnd = false; private reactiveUsage = false; + private reactiveIdle?: NodeJS.Timeout; + private reactiveTimedOut = false; get reusable() { - return !(this.reactiveEnd && this.cancelling); + return !this.reactiveTimedOut && !(this.reactiveEnd && this.cancelling); } /** Prompt requests open in the current turn. A steering agent answers an * earlier request when it folds a later one into the same turn; the turn @@ -249,6 +252,7 @@ export class Acp implements Adapter { ); this.child = child; child.once("error", () => { + clearTimeout(this.reactiveIdle); this.end(); this.cancelPermissions(); if (!this.closed && !this.terminalReported) { @@ -266,6 +270,7 @@ export class Acp implements Adapter { }); child.stderr.resume(); child.once("exit", () => { + clearTimeout(this.reactiveIdle); this.end(); const memory = nativeMemoryFailure(child); this.modeConfirmation?.reject(memory || new Error("ACP agent exited")); @@ -589,6 +594,7 @@ export class Acp implements Adapter { !this.connection || !this.session || this.active || + !this.reusable || this.pendingSettingWrites ) throw new Error("ACP session is unavailable or busy"); @@ -619,6 +625,7 @@ export class Acp implements Adapter { /** Sends one prompt request in the current turn. Only the last open request * to settle reports the turn's terminal status. */ private send(value: string, steer = false) { + clearTimeout(this.reactiveIdle); this.openPrompts++; const request = this.connection!.prompt({ sessionId: this.session!, @@ -635,10 +642,12 @@ export class Acp implements Adapter { if ( !this.cancelling && this.waitsForReactiveTurns && - (this.reactiveTools.size || this.permissions.size) + (this.reactiveEnd || + this.reactiveTools.size || + this.permissions.size) ) { this.reactiveEnd = true; - this.reactiveUsage = false; + this.finishReactiveTurn(); return; } } @@ -696,29 +705,48 @@ export class Acp implements Adapter { ) .finally(() => { if (this.openPrompts || !this.terminalReported) return; + clearTimeout(this.reactiveIdle); this.active = false; this.cancelPermissions(); }); return request; } private finishReactiveTurn() { + clearTimeout(this.reactiveIdle); if ( this.closed || this.terminalReported || !this.reactiveEnd || this.openPrompts || - (!this.cancelling && - (!this.reactiveUsage || - this.reactiveTools.size || - this.permissions.size)) + (!this.cancelling && (this.reactiveTools.size || this.permissions.size)) ) return; + if (!this.cancelling && !this.reactiveUsage) { + // Usage sent while work is still open can mark a yield to another + // wakeup. Give agy time to acknowledge the settled pass before + // retiring it with partial output. + this.reactiveIdle = setTimeout(() => { + this.reactiveTimedOut = true; + this.reportReactiveEnd( + "interrupted", + "Antigravity did not confirm the end of its reactive turn.", + ); + }, REACTIVE_IDLE_MS).unref(); + return; + } + this.reportReactiveEnd(this.cancelling ? "interrupted" : "completed"); + } + private reportReactiveEnd( + status: "interrupted" | "completed", + detail?: string, + ) { this.terminalReported = true; this.active = false; this.emit({ type: "status", - status: this.cancelling ? "interrupted" : "completed", - recoverable: !this.cancelling, + status, + detail, + recoverable: status === "completed", }); } private addUsage(result: unknown) { @@ -832,6 +860,7 @@ export class Acp implements Adapter { } async cancel() { this.cancelling = true; + clearTimeout(this.reactiveIdle); this.finishCommandDiscovery(false); this.cancelPermissions(); if (!this.closed && this.session && this.connection && this.active) @@ -856,9 +885,11 @@ export class Acp implements Adapter { outcome: { outcome: "selected", optionId: answer.choice }, }); this.emit({ type: "resolved", id }); + if (this.reactiveEnd && !this.cancelling) this.finishReactiveTurn(); } async dispose() { this.closed = true; + clearTimeout(this.reactiveIdle); this.creatingSession = false; this.startupCommands = undefined; this.finishCommandDiscovery(false); @@ -1154,6 +1185,7 @@ export class Acp implements Adapter { return Promise.resolve({ outcome: { outcome: "cancelled" } }); const id = randomUUID(); this.reactiveUsage = false; + clearTimeout(this.reactiveIdle); return new Promise((resolve) => { this.permissions.set(id, { choices: new Set(choices.map((choice) => choice.optionId)), @@ -1229,6 +1261,16 @@ export class Acp implements Adapter { id: this.messageId, text: text(u.content.text), }); + if (this.reactiveEnd && !this.cancelling) this.finishReactiveTurn(); + return; + } + if ( + u.sessionUpdate === "agent_thought_chunk" && + this.reactiveEnd && + !this.cancelling + ) { + this.reactiveUsage = false; + this.finishReactiveTurn(); return; } if (u.sessionUpdate === "usage_update" && this.reactiveEnd) { @@ -1242,18 +1284,22 @@ export class Acp implements Adapter { u.sessionUpdate === "tool_call" || u.sessionUpdate === "tool_call_update" ) { + let reactiveWorkChanged = false; if (this.waitsForReactiveTurns && !this.loading) { const input = u.rawInput; + const title = u.title ?? this.toolItems.get(u.toolCallId)?.title; const daemon = + (title === "run_command" || title === "schedule") && input && typeof input === "object" && "IsDaemon" in input && input.IsDaemon === true; if (daemon || u.status === "completed" || u.status === "failed") { - this.reactiveTools.delete(u.toolCallId); + reactiveWorkChanged = this.reactiveTools.delete(u.toolCallId); } else if (u.sessionUpdate === "tool_call") { this.reactiveTools.add(u.toolCallId); this.reactiveUsage = false; + reactiveWorkChanged = true; } } const old = this.toolItems.get(u.toolCallId); @@ -1270,6 +1316,8 @@ export class Acp implements Adapter { }; this.toolItems.set(u.toolCallId, item); this.emit({ type: "item", item }); + if (reactiveWorkChanged && this.reactiveEnd && !this.cancelling) + this.finishReactiveTurn(); return; } const kind = u.kind ?? this.toolKinds.get(u.toolCallId); @@ -1488,6 +1536,8 @@ export class Acp implements Adapter { }, this.loading, ); + if (reactiveWorkChanged && this.reactiveEnd && !this.cancelling) + this.finishReactiveTurn(); return; } if (u.sessionUpdate === "plan") { diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index a769fb7b..8d779963 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -84,6 +84,63 @@ test("Antigravity completes normally with only a daemon still running", async (t assert.deepEqual(statuses(events), ["ready", "completed"]); }); +test("Antigravity keeps accepting reactive output after overlapping prompts end", async (t) => { + const requests = fixture(t); + process.env.LOOP_TEST_AGY_MODE = "reactive-steering"; + const events: AdapterEvent[] = []; + const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => + events.push(e), + ); + t.after(() => adapter.dispose()); + await adapter.start(); + await adapter.prompt("Run background work"); + await until(() => events.some((e) => e.type === "delta")); + await adapter.steer!("Keep going"); + await until(() => complete(events).length === 1); + assert.deepEqual( + events.flatMap((e) => (e.type === "delta" ? [e.text] : [])), + ["Waiting.", "Done."], + ); + assert.deepEqual(prompts(requests), ["Run background work", "Keep going"]); +}); + +test( + "Antigravity interrupts a settled reactive pass without a final usage update", + { timeout: 5000 }, + async (t) => { + fixture(t); + process.env.LOOP_TEST_AGY_MODE = "reactive-reordered"; + const events: AdapterEvent[] = []; + let settle!: () => void; + const settled = new Promise((resolve) => { + settle = resolve; + }); + const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => { + events.push(e); + if ( + e.type === "activity" && + e.activity.kind === "tool" && + e.activity.id === "background" && + e.activity.patch.status === "completed" + ) + settle(); + }); + t.after(() => adapter.dispose()); + await adapter.start(); + t.mock.timers.enable({ apis: ["setTimeout"] }); + try { + await adapter.prompt("Run background work"); + await settled; + assert.deepEqual(statuses(events), ["ready"]); + t.mock.timers.tick(60_000); + assert.deepEqual(statuses(events), ["ready", "interrupted"]); + assert.equal(adapter.reusable, false); + } finally { + t.mock.timers.reset(); + } + }, +); + for (const stop of ["cancel", "dispose"] as const) test(`Antigravity ${stop} can stop a turn waiting for a reactive wakeup`, async (t) => { const requests = fixture(t); diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index cbe79403..75d8b00d 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -127,13 +127,14 @@ const finish = (sessionId, stopReason = "end_turn") => { }; let permission = 0; const permissions = new Map(); +let endReactiveSteer; function reactiveTurn(sessionId, mode) { - const tool = (toolCallId, rawInput) => + const tool = (toolCallId, rawInput, title = toolCallId) => update(sessionId, { sessionUpdate: "tool_call", toolCallId, - title: toolCallId, + title, status: "in_progress", rawInput, }); @@ -151,7 +152,7 @@ function reactiveTurn(sessionId, mode) { const reportUsage = () => update(sessionId, { sessionUpdate: "usage_update", used: 20, size: 100 }); - tool("daemon", { IsDaemon: true }); + tool("daemon", { IsDaemon: true }, "run_command"); if (mode !== "daemon-only") tool("background", { CommandLine: "sleep 5", @@ -160,7 +161,27 @@ function reactiveTurn(sessionId, mode) { }); message(mode === "daemon-only" ? "Daemon started." : "Waiting."); reportUsage(); + if (mode === "reactive-steering") { + endReactiveSteer = (request) => { + finish(sessionId); + complete("background"); + reply(request.id, { stopReason: "end_turn" }); + setTimeout(() => { + message("Done."); + reportUsage(); + }, 30); + }; + return; + } finish(sessionId); + if (mode === "reactive-reordered") { + setTimeout(() => { + message("Done."); + reportUsage(); + complete("background"); + }, 30); + return; + } if (mode !== "reactive") return; reportUsage(); // Even a usage update following end_turn leaves open work. @@ -250,6 +271,11 @@ createInterface({ input: process.stdin }).on("line", (line) => { case "session/prompt": { const text = req.params.prompt[0].text; if (open.length) { + if (endReactiveSteer) { + const finishSteering = endReactiveSteer; + endReactiveSteer = undefined; + return finishSteering(req); + } // A prompt during a running turn steers it. if (mode === "steer-limit") { // No echo, and the turn stops at a limit. @@ -346,7 +372,7 @@ createInterface({ input: process.stdin }).on("line", (line) => { 300, ); } else echo(); - if (["reactive", "reactive-stalled", "daemon-only"].includes(outcome())) + if (outcome()?.startsWith("reactive") || outcome() === "daemon-only") return reactiveTurn(sessionId, outcome()); if (outcome() === "hang") return; if (text.includes("[slow]")) { From 74f6998b2954c43224070d80d79be467df080eee Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 09:54:20 +0000 Subject: [PATCH 03/31] Resolve stalled Antigravity tools and answered steering --- src/adapters/acp.ts | 60 +++++++++++++++++---- test/antigravity-steering.node.test.ts | 48 +++++++++++++++++ test/fixtures/fake-antigravity-steering.mjs | 11 +++- 3 files changed, 108 insertions(+), 11 deletions(-) diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index 4cd3ab79..9be27cc1 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -74,6 +74,7 @@ function matchEcho(echo: Echo, chunk: string) { // agy echoes a prompt within a second of receiving it. const ECHO_WAIT = 5000; const REACTIVE_IDLE_MS = 60_000; +const REACTIVE_WORK_MS = 60 * 60_000; const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms).unref()); const text = (value: unknown) => @@ -148,6 +149,7 @@ export class Acp implements Adapter { private reactiveEnd = false; private reactiveUsage = false; private reactiveIdle?: NodeJS.Timeout; + private reactiveWork?: NodeJS.Timeout; private reactiveTimedOut = false; get reusable() { return !this.reactiveTimedOut && !(this.reactiveEnd && this.cancelling); @@ -165,6 +167,7 @@ export class Acp implements Adapter { private steering = false; /** The steering input's echo arrived, so it joined the running turn. */ private steerJoined = false; + private steerOutput = false; /** An earlier request of this turn ended it normally. */ private earlierEnd = false; private end!: () => void; @@ -253,6 +256,7 @@ export class Acp implements Adapter { this.child = child; child.once("error", () => { clearTimeout(this.reactiveIdle); + clearTimeout(this.reactiveWork); this.end(); this.cancelPermissions(); if (!this.closed && !this.terminalReported) { @@ -271,6 +275,7 @@ export class Acp implements Adapter { child.stderr.resume(); child.once("exit", () => { clearTimeout(this.reactiveIdle); + clearTimeout(this.reactiveWork); this.end(); const memory = nativeMemoryFailure(child); this.modeConfirmation?.reject(memory || new Error("ACP agent exited")); @@ -626,6 +631,8 @@ export class Acp implements Adapter { * to settle reports the turn's terminal status. */ private send(value: string, steer = false) { clearTimeout(this.reactiveIdle); + clearTimeout(this.reactiveWork); + this.reactiveWork = undefined; this.openPrompts++; const request = this.connection!.prompt({ sessionId: this.session!, @@ -644,7 +651,13 @@ export class Acp implements Adapter { this.waitsForReactiveTurns && (this.reactiveEnd || this.reactiveTools.size || - this.permissions.size) + this.permissions.size) && + !( + steer && + this.steerOutput && + !this.reactiveTools.size && + !this.permissions.size + ) ) { this.reactiveEnd = true; this.finishReactiveTurn(); @@ -706,6 +719,8 @@ export class Acp implements Adapter { .finally(() => { if (this.openPrompts || !this.terminalReported) return; clearTimeout(this.reactiveIdle); + clearTimeout(this.reactiveWork); + this.reactiveWork = undefined; this.active = false; this.cancelPermissions(); }); @@ -718,24 +733,40 @@ export class Acp implements Adapter { this.terminalReported || !this.reactiveEnd || this.openPrompts || - (!this.cancelling && (this.reactiveTools.size || this.permissions.size)) + (!this.cancelling && this.permissions.size) ) return; + if (!this.cancelling && this.reactiveTools.size) { + this.reactiveWork ??= setTimeout( + () => + this.timeoutReactiveTurn( + "Antigravity did not settle its background tools within an hour.", + ), + REACTIVE_WORK_MS, + ).unref(); + return; + } + clearTimeout(this.reactiveWork); + this.reactiveWork = undefined; if (!this.cancelling && !this.reactiveUsage) { // Usage sent while work is still open can mark a yield to another // wakeup. Give agy time to acknowledge the settled pass before // retiring it with partial output. - this.reactiveIdle = setTimeout(() => { - this.reactiveTimedOut = true; - this.reportReactiveEnd( - "interrupted", - "Antigravity did not confirm the end of its reactive turn.", - ); - }, REACTIVE_IDLE_MS).unref(); + this.reactiveIdle = setTimeout( + () => + this.timeoutReactiveTurn( + "Antigravity did not confirm the end of its reactive turn.", + ), + REACTIVE_IDLE_MS, + ).unref(); return; } this.reportReactiveEnd(this.cancelling ? "interrupted" : "completed"); } + private timeoutReactiveTurn(detail: string) { + this.reactiveTimedOut = true; + this.reportReactiveEnd("interrupted", detail); + } private reportReactiveEnd( status: "interrupted" | "completed", detail?: string, @@ -828,6 +859,7 @@ export class Acp implements Adapter { throw new NotDelivered("ACP session is busy."); beforeDispatch?.(); this.steerJoined = false; + this.steerOutput = false; const echoed = new Promise((resolve) => { if (expected) this.echo = { @@ -861,6 +893,8 @@ export class Acp implements Adapter { async cancel() { this.cancelling = true; clearTimeout(this.reactiveIdle); + clearTimeout(this.reactiveWork); + this.reactiveWork = undefined; this.finishCommandDiscovery(false); this.cancelPermissions(); if (!this.closed && this.session && this.connection && this.active) @@ -890,6 +924,7 @@ export class Acp implements Adapter { async dispose() { this.closed = true; clearTimeout(this.reactiveIdle); + clearTimeout(this.reactiveWork); this.creatingSession = false; this.startupCommands = undefined; this.finishCommandDiscovery(false); @@ -1186,6 +1221,8 @@ export class Acp implements Adapter { const id = randomUUID(); this.reactiveUsage = false; clearTimeout(this.reactiveIdle); + clearTimeout(this.reactiveWork); + this.reactiveWork = undefined; return new Promise((resolve) => { this.permissions.set(id, { choices: new Set(choices.map((choice) => choice.optionId)), @@ -1255,12 +1292,15 @@ export class Acp implements Adapter { } if (u.sessionUpdate === "agent_message_chunk") { this.reactiveUsage = false; - if (!this.loading && u.content.type === "text") + if (!this.loading && u.content.type === "text") { + if (this.steerJoined && this.openPrompts && u.content.text.trim()) + this.steerOutput = true; this.emit({ type: "delta", id: this.messageId, text: text(u.content.text), }); + } if (this.reactiveEnd && !this.cancelling) this.finishReactiveTurn(); return; } diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index 8d779963..05586178 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -104,6 +104,54 @@ test("Antigravity keeps accepting reactive output after overlapping prompts end" assert.deepEqual(prompts(requests), ["Run background work", "Keep going"]); }); +test("Antigravity completes an answered steering prompt without waiting for a reactive usage update", async (t) => { + fixture(t); + process.env.LOOP_TEST_AGY_MODE = "reactive-steered-answer"; + const events: AdapterEvent[] = []; + const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => + events.push(e), + ); + t.after(() => adapter.dispose()); + await adapter.start(); + await adapter.prompt("Run background work"); + await adapter.steer!("Keep going"); + await until(() => complete(events).length === 1, 3000); + assert.deepEqual(statuses(events), ["ready", "completed"]); + assert.equal(adapter.reusable, true); +}); + +test( + "Antigravity interrupts an unattended reactive tool that never settles", + { timeout: 5000 }, + async (t) => { + fixture(t); + process.env.LOOP_TEST_AGY_MODE = "reactive-stalled"; + const events: AdapterEvent[] = []; + let endPrompt!: () => void; + const promptEnded = new Promise((resolve) => { + endPrompt = resolve; + }); + const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => { + events.push(e); + if (e.type === "usage") endPrompt(); + }); + t.after(() => adapter.dispose()); + await adapter.start(); + t.mock.timers.enable({ apis: ["setTimeout"] }); + try { + await adapter.prompt("Run background work"); + await promptEnded; + t.mock.timers.tick(60_000); + assert.deepEqual(statuses(events), ["ready"]); + t.mock.timers.tick(59 * 60_000); + assert.deepEqual(statuses(events), ["ready", "interrupted"]); + assert.equal(adapter.reusable, false); + } finally { + t.mock.timers.reset(); + } + }, +); + test( "Antigravity interrupts a settled reactive pass without a final usage update", { timeout: 5000 }, diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index 75d8b00d..688df1e8 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -161,10 +161,19 @@ function reactiveTurn(sessionId, mode) { }); message(mode === "daemon-only" ? "Daemon started." : "Waiting."); reportUsage(); - if (mode === "reactive-steering") { + if (mode === "reactive-steering" || mode === "reactive-steered-answer") { endReactiveSteer = (request) => { finish(sessionId); complete("background"); + if (mode === "reactive-steered-answer") { + update(sessionId, { + sessionUpdate: "user_message_chunk", + content: { type: "text", text: request.params.prompt[0].text }, + }); + message("Done."); + reply(request.id, { stopReason: "end_turn" }); + return; + } reply(request.id, { stopReason: "end_turn" }); setTimeout(() => { message("Done."); From 22ad84ce339017bc17cb900c96a395bcda86e54e Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 09:57:49 +0000 Subject: [PATCH 04/31] Keep the reactive watchdog active through steering --- src/adapters/acp.ts | 77 +++++++++------------ test/antigravity-steering.node.test.ts | 77 ++++++++++++--------- test/fixtures/fake-antigravity-steering.mjs | 15 ++-- 3 files changed, 86 insertions(+), 83 deletions(-) diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index 9be27cc1..9e6d1923 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -74,7 +74,7 @@ function matchEcho(echo: Echo, chunk: string) { // agy echoes a prompt within a second of receiving it. const ECHO_WAIT = 5000; const REACTIVE_IDLE_MS = 60_000; -const REACTIVE_WORK_MS = 60 * 60_000; +const REACTIVE_WATCHDOG_MS = 60 * 60_000; const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms).unref()); const text = (value: unknown) => @@ -149,7 +149,7 @@ export class Acp implements Adapter { private reactiveEnd = false; private reactiveUsage = false; private reactiveIdle?: NodeJS.Timeout; - private reactiveWork?: NodeJS.Timeout; + private reactiveWatchdog?: NodeJS.Timeout; private reactiveTimedOut = false; get reusable() { return !this.reactiveTimedOut && !(this.reactiveEnd && this.cancelling); @@ -167,7 +167,6 @@ export class Acp implements Adapter { private steering = false; /** The steering input's echo arrived, so it joined the running turn. */ private steerJoined = false; - private steerOutput = false; /** An earlier request of this turn ended it normally. */ private earlierEnd = false; private end!: () => void; @@ -256,7 +255,7 @@ export class Acp implements Adapter { this.child = child; child.once("error", () => { clearTimeout(this.reactiveIdle); - clearTimeout(this.reactiveWork); + clearTimeout(this.reactiveWatchdog); this.end(); this.cancelPermissions(); if (!this.closed && !this.terminalReported) { @@ -275,7 +274,7 @@ export class Acp implements Adapter { child.stderr.resume(); child.once("exit", () => { clearTimeout(this.reactiveIdle); - clearTimeout(this.reactiveWork); + clearTimeout(this.reactiveWatchdog); this.end(); const memory = nativeMemoryFailure(child); this.modeConfirmation?.reject(memory || new Error("ACP agent exited")); @@ -631,8 +630,6 @@ export class Acp implements Adapter { * to settle reports the turn's terminal status. */ private send(value: string, steer = false) { clearTimeout(this.reactiveIdle); - clearTimeout(this.reactiveWork); - this.reactiveWork = undefined; this.openPrompts++; const request = this.connection!.prompt({ sessionId: this.session!, @@ -646,18 +643,14 @@ export class Acp implements Adapter { if (this.closed || this.terminalReported) return; if (result.stopReason === "end_turn") { if (!last) this.earlierEnd = true; + // An echoed steer and its text can be an interim update. Once + // a reactive wait begins, require the reactive usage boundary. if ( !this.cancelling && this.waitsForReactiveTurns && (this.reactiveEnd || this.reactiveTools.size || - this.permissions.size) && - !( - steer && - this.steerOutput && - !this.reactiveTools.size && - !this.permissions.size - ) + this.permissions.size) ) { this.reactiveEnd = true; this.finishReactiveTurn(); @@ -719,8 +712,8 @@ export class Acp implements Adapter { .finally(() => { if (this.openPrompts || !this.terminalReported) return; clearTimeout(this.reactiveIdle); - clearTimeout(this.reactiveWork); - this.reactiveWork = undefined; + clearTimeout(this.reactiveWatchdog); + this.reactiveWatchdog = undefined; this.active = false; this.cancelPermissions(); }); @@ -728,27 +721,23 @@ export class Acp implements Adapter { } private finishReactiveTurn() { clearTimeout(this.reactiveIdle); - if ( - this.closed || - this.terminalReported || - !this.reactiveEnd || - this.openPrompts || - (!this.cancelling && this.permissions.size) - ) - return; - if (!this.cancelling && this.reactiveTools.size) { - this.reactiveWork ??= setTimeout( - () => - this.timeoutReactiveTurn( - "Antigravity did not settle its background tools within an hour.", - ), - REACTIVE_WORK_MS, - ).unref(); + if (this.closed || this.terminalReported || !this.reactiveEnd) return; + if (this.cancelling) { + if (!this.openPrompts) this.reportReactiveEnd("interrupted"); return; } - clearTimeout(this.reactiveWork); - this.reactiveWork = undefined; - if (!this.cancelling && !this.reactiveUsage) { + if (this.permissions.size) return; + // The reactive wait stays bounded even if a concurrent steer never + // answers. Human approval time does not count against the watchdog. + this.reactiveWatchdog ??= setTimeout( + () => + this.timeoutReactiveTurn( + "Antigravity did not finish its reactive turn within an hour.", + ), + REACTIVE_WATCHDOG_MS, + ).unref(); + if (this.openPrompts || this.reactiveTools.size) return; + if (!this.reactiveUsage) { // Usage sent while work is still open can mark a yield to another // wakeup. Give agy time to acknowledge the settled pass before // retiring it with partial output. @@ -761,7 +750,7 @@ export class Acp implements Adapter { ).unref(); return; } - this.reportReactiveEnd(this.cancelling ? "interrupted" : "completed"); + this.reportReactiveEnd("completed"); } private timeoutReactiveTurn(detail: string) { this.reactiveTimedOut = true; @@ -771,6 +760,9 @@ export class Acp implements Adapter { status: "interrupted" | "completed", detail?: string, ) { + clearTimeout(this.reactiveIdle); + clearTimeout(this.reactiveWatchdog); + this.reactiveWatchdog = undefined; this.terminalReported = true; this.active = false; this.emit({ @@ -859,7 +851,6 @@ export class Acp implements Adapter { throw new NotDelivered("ACP session is busy."); beforeDispatch?.(); this.steerJoined = false; - this.steerOutput = false; const echoed = new Promise((resolve) => { if (expected) this.echo = { @@ -893,8 +884,8 @@ export class Acp implements Adapter { async cancel() { this.cancelling = true; clearTimeout(this.reactiveIdle); - clearTimeout(this.reactiveWork); - this.reactiveWork = undefined; + clearTimeout(this.reactiveWatchdog); + this.reactiveWatchdog = undefined; this.finishCommandDiscovery(false); this.cancelPermissions(); if (!this.closed && this.session && this.connection && this.active) @@ -924,7 +915,7 @@ export class Acp implements Adapter { async dispose() { this.closed = true; clearTimeout(this.reactiveIdle); - clearTimeout(this.reactiveWork); + clearTimeout(this.reactiveWatchdog); this.creatingSession = false; this.startupCommands = undefined; this.finishCommandDiscovery(false); @@ -1221,8 +1212,8 @@ export class Acp implements Adapter { const id = randomUUID(); this.reactiveUsage = false; clearTimeout(this.reactiveIdle); - clearTimeout(this.reactiveWork); - this.reactiveWork = undefined; + clearTimeout(this.reactiveWatchdog); + this.reactiveWatchdog = undefined; return new Promise((resolve) => { this.permissions.set(id, { choices: new Set(choices.map((choice) => choice.optionId)), @@ -1293,8 +1284,6 @@ export class Acp implements Adapter { if (u.sessionUpdate === "agent_message_chunk") { this.reactiveUsage = false; if (!this.loading && u.content.type === "text") { - if (this.steerJoined && this.openPrompts && u.content.text.trim()) - this.steerOutput = true; this.emit({ type: "delta", id: this.messageId, diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index 05586178..dc1e3924 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -104,9 +104,9 @@ test("Antigravity keeps accepting reactive output after overlapping prompts end" assert.deepEqual(prompts(requests), ["Run background work", "Keep going"]); }); -test("Antigravity completes an answered steering prompt without waiting for a reactive usage update", async (t) => { +test("Antigravity keeps accepting reactive output after echoing and acknowledging a steer", async (t) => { fixture(t); - process.env.LOOP_TEST_AGY_MODE = "reactive-steered-answer"; + process.env.LOOP_TEST_AGY_MODE = "reactive-steer-ack"; const events: AdapterEvent[] = []; const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => events.push(e), @@ -117,40 +117,49 @@ test("Antigravity completes an answered steering prompt without waiting for a re await adapter.steer!("Keep going"); await until(() => complete(events).length === 1, 3000); assert.deepEqual(statuses(events), ["ready", "completed"]); - assert.equal(adapter.reusable, true); + assert.deepEqual( + events.flatMap((e) => (e.type === "delta" ? [e.text] : [])), + ["Waiting.", "Acknowledged.", "Done."], + ); }); -test( - "Antigravity interrupts an unattended reactive tool that never settles", - { timeout: 5000 }, - async (t) => { - fixture(t); - process.env.LOOP_TEST_AGY_MODE = "reactive-stalled"; - const events: AdapterEvent[] = []; - let endPrompt!: () => void; - const promptEnded = new Promise((resolve) => { - endPrompt = resolve; - }); - const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => { - events.push(e); - if (e.type === "usage") endPrompt(); - }); - t.after(() => adapter.dispose()); - await adapter.start(); - t.mock.timers.enable({ apis: ["setTimeout"] }); - try { - await adapter.prompt("Run background work"); - await promptEnded; - t.mock.timers.tick(60_000); - assert.deepEqual(statuses(events), ["ready"]); - t.mock.timers.tick(59 * 60_000); - assert.deepEqual(statuses(events), ["ready", "interrupted"]); - assert.equal(adapter.reusable, false); - } finally { - t.mock.timers.reset(); - } - }, -); +for (const mode of ["reactive-stalled", "reactive-stalled-steer"]) + test( + `Antigravity bounds the wait for ${mode}`, + { timeout: 5000 }, + async (t) => { + fixture(t); + process.env.LOOP_TEST_AGY_MODE = mode; + const events: AdapterEvent[] = []; + let endPrompt!: () => void; + const promptEnded = new Promise((resolve) => { + endPrompt = resolve; + }); + const adapter = new Antigravity( + { ...options, version: "1.5.14" }, + (e) => { + events.push(e); + if (e.type === "usage") endPrompt(); + }, + ); + t.after(() => adapter.dispose()); + await adapter.start(); + t.mock.timers.enable({ apis: ["setTimeout"] }); + try { + await adapter.prompt("Run background work"); + await promptEnded; + if (mode === "reactive-stalled-steer") + await adapter.steer!("Keep going"); + t.mock.timers.tick(60_000); + assert.deepEqual(statuses(events), ["ready"]); + t.mock.timers.tick(59 * 60_000); + assert.deepEqual(statuses(events), ["ready", "interrupted"]); + assert.equal(adapter.reusable, false); + } finally { + t.mock.timers.reset(); + } + }, + ); test( "Antigravity interrupts a settled reactive pass without a final usage update", diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index 688df1e8..fa768e93 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -161,18 +161,16 @@ function reactiveTurn(sessionId, mode) { }); message(mode === "daemon-only" ? "Daemon started." : "Waiting."); reportUsage(); - if (mode === "reactive-steering" || mode === "reactive-steered-answer") { + if (mode === "reactive-steering" || mode === "reactive-steer-ack") { endReactiveSteer = (request) => { finish(sessionId); complete("background"); - if (mode === "reactive-steered-answer") { + if (mode === "reactive-steer-ack") { update(sessionId, { sessionUpdate: "user_message_chunk", content: { type: "text", text: request.params.prompt[0].text }, }); - message("Done."); - reply(request.id, { stopReason: "end_turn" }); - return; + message("Acknowledged."); } reply(request.id, { stopReason: "end_turn" }); setTimeout(() => { @@ -279,6 +277,13 @@ createInterface({ input: process.stdin }).on("line", (line) => { return finish(sessionId, "cancelled"); case "session/prompt": { const text = req.params.prompt[0].text; + if (turn === 1 && mode === "reactive-stalled-steer") { + update(sessionId, { + sessionUpdate: "user_message_chunk", + content: { type: "text", text }, + }); + return; + } if (open.length) { if (endReactiveSteer) { const finishSteering = endReactiveSteer; From 6ee1ed466456978cba72a0ed5c51805935ce6d88 Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 10:00:41 +0000 Subject: [PATCH 05/31] Ignore stale reactive usage and settle cancellation --- src/adapters/acp.ts | 26 ++++++++++----------- test/antigravity-steering.node.test.ts | 18 ++++++++++++++ test/fixtures/fake-antigravity-steering.mjs | 1 + 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index 9e6d1923..e9c0e91e 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -147,7 +147,6 @@ export class Acp implements Adapter { protected waitsForReactiveTurns = false; private reactiveTools = new Set(); private reactiveEnd = false; - private reactiveUsage = false; private reactiveIdle?: NodeJS.Timeout; private reactiveWatchdog?: NodeJS.Timeout; private reactiveTimedOut = false; @@ -612,7 +611,6 @@ export class Acp implements Adapter { this.earlierEnd = false; this.reactiveTools.clear(); this.reactiveEnd = false; - this.reactiveUsage = false; const expected = this.echoOf(value).trim(); this.promptEcho = undefined; this.promptEchoed = expected @@ -719,11 +717,11 @@ export class Acp implements Adapter { }); return request; } - private finishReactiveTurn() { + private finishReactiveTurn(confirmed = false) { clearTimeout(this.reactiveIdle); if (this.closed || this.terminalReported || !this.reactiveEnd) return; if (this.cancelling) { - if (!this.openPrompts) this.reportReactiveEnd("interrupted"); + this.reportReactiveEnd("interrupted"); return; } if (this.permissions.size) return; @@ -737,7 +735,7 @@ export class Acp implements Adapter { REACTIVE_WATCHDOG_MS, ).unref(); if (this.openPrompts || this.reactiveTools.size) return; - if (!this.reactiveUsage) { + if (!confirmed) { // Usage sent while work is still open can mark a yield to another // wakeup. Give agy time to acknowledge the settled pass before // retiring it with partial output. @@ -888,9 +886,12 @@ export class Acp implements Adapter { this.reactiveWatchdog = undefined; this.finishCommandDiscovery(false); this.cancelPermissions(); - if (!this.closed && this.session && this.connection && this.active) - await this.connection.cancel({ sessionId: this.session }); - this.finishReactiveTurn(); + try { + if (!this.closed && this.session && this.connection && this.active) + await this.connection.cancel({ sessionId: this.session }); + } finally { + this.finishReactiveTurn(); + } } async answer( id: string, @@ -1210,7 +1211,6 @@ export class Acp implements Adapter { if (!choices.length) return Promise.resolve({ outcome: { outcome: "cancelled" } }); const id = randomUUID(); - this.reactiveUsage = false; clearTimeout(this.reactiveIdle); clearTimeout(this.reactiveWatchdog); this.reactiveWatchdog = undefined; @@ -1282,7 +1282,6 @@ export class Acp implements Adapter { return; } if (u.sessionUpdate === "agent_message_chunk") { - this.reactiveUsage = false; if (!this.loading && u.content.type === "text") { this.emit({ type: "delta", @@ -1298,15 +1297,15 @@ export class Acp implements Adapter { this.reactiveEnd && !this.cancelling ) { - this.reactiveUsage = false; this.finishReactiveTurn(); return; } if (u.sessionUpdate === "usage_update" && this.reactiveEnd) { // agy 1.5.14 sends this after a reactive pass but sends no second // prompt response. A pass that leaves more work open can wake again. - this.reactiveUsage = !this.reactiveTools.size && !this.permissions.size; - if (!this.cancelling) this.finishReactiveTurn(); + // A usage update that arrived during an open request cannot certify a + // later steering response. Evaluate it at arrival and never latch it. + if (!this.cancelling) this.finishReactiveTurn(true); return; } if ( @@ -1327,7 +1326,6 @@ export class Acp implements Adapter { reactiveWorkChanged = this.reactiveTools.delete(u.toolCallId); } else if (u.sessionUpdate === "tool_call") { this.reactiveTools.add(u.toolCallId); - this.reactiveUsage = false; reactiveWorkChanged = true; } } diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index dc1e3924..30b2884c 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -161,6 +161,24 @@ for (const mode of ["reactive-stalled", "reactive-stalled-steer"]) }, ); +test("Antigravity cancels a reactive turn with an outstanding steering request", async (t) => { + const requests = fixture(t); + process.env.LOOP_TEST_AGY_MODE = "reactive-stalled-steer"; + const events: AdapterEvent[] = []; + const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => + events.push(e), + ); + t.after(() => adapter.dispose()); + await adapter.start(); + await adapter.prompt("Run background work"); + await until(() => events.some((e) => e.type === "usage")); + await adapter.steer!("Keep going"); + await adapter.cancel(); + await until(() => requests().some((r) => r.acp === "session/cancel")); + assert.deepEqual(statuses(events), ["ready", "interrupted"]); + assert.equal(adapter.reusable, false); +}); + test( "Antigravity interrupts a settled reactive pass without a final usage update", { timeout: 5000 }, diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index fa768e93..6a17de08 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -171,6 +171,7 @@ function reactiveTurn(sessionId, mode) { content: { type: "text", text: request.params.prompt[0].text }, }); message("Acknowledged."); + reportUsage(); // This usage precedes the still-open steering response. } reply(request.id, { stopReason: "end_turn" }); setTimeout(() => { From 201be0184e53821ca219049826d1bf342e014bf8 Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 10:03:56 +0000 Subject: [PATCH 06/31] Track Antigravity wakeups across early tool settlement --- src/adapters/acp.ts | 46 ++++++++++++++++----- test/antigravity-steering.node.test.ts | 34 +++++++++++++++ test/fixtures/fake-antigravity-steering.mjs | 35 +++++++++++++--- 3 files changed, 99 insertions(+), 16 deletions(-) diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index e9c0e91e..e709538f 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -146,12 +146,14 @@ export class Acp implements Adapter { /** agy can return end_turn before its background work wakes the model. */ protected waitsForReactiveTurns = false; private reactiveTools = new Set(); + private backgroundTools = new Set(); + private pendingWakeup = false; private reactiveEnd = false; private reactiveIdle?: NodeJS.Timeout; private reactiveWatchdog?: NodeJS.Timeout; - private reactiveTimedOut = false; + private retireReactiveSession = false; get reusable() { - return !this.reactiveTimedOut && !(this.reactiveEnd && this.cancelling); + return !this.retireReactiveSession; } /** Prompt requests open in the current turn. A steering agent answers an * earlier request when it folds a later one into the same turn; the turn @@ -610,6 +612,8 @@ export class Acp implements Adapter { this.turnUsage = undefined; this.earlierEnd = false; this.reactiveTools.clear(); + this.backgroundTools.clear(); + this.pendingWakeup = false; this.reactiveEnd = false; const expected = this.echoOf(value).trim(); this.promptEcho = undefined; @@ -647,6 +651,7 @@ export class Acp implements Adapter { !this.cancelling && this.waitsForReactiveTurns && (this.reactiveEnd || + this.pendingWakeup || this.reactiveTools.size || this.permissions.size) ) { @@ -660,19 +665,20 @@ export class Acp implements Adapter { const limited = ["max_tokens", "max_turn_requests"].includes( result.stopReason, ); + const interrupted = + this.cancelling || limited || result.stopReason === "cancelled"; + if ( + interrupted && + (this.reactiveEnd || this.pendingWakeup || this.reactiveTools.size) + ) + this.retireReactiveSession = true; this.emit({ type: "status", - status: - this.cancelling || - ["cancelled", "max_tokens", "max_turn_requests"].includes( - result.stopReason, - ) - ? "interrupted" - : "completed", + status: interrupted ? "interrupted" : "completed", detail: limited ? "ACP turn stopped at the agent's limit." : undefined, - recoverable: true, + recoverable: !this.retireReactiveSession, }); }, (error: unknown) => { @@ -751,7 +757,6 @@ export class Acp implements Adapter { this.reportReactiveEnd("completed"); } private timeoutReactiveTurn(detail: string) { - this.reactiveTimedOut = true; this.reportReactiveEnd("interrupted", detail); } private reportReactiveEnd( @@ -761,6 +766,7 @@ export class Acp implements Adapter { clearTimeout(this.reactiveIdle); clearTimeout(this.reactiveWatchdog); this.reactiveWatchdog = undefined; + if (status === "interrupted") this.retireReactiveSession = true; this.terminalReported = true; this.active = false; this.emit({ @@ -1283,6 +1289,8 @@ export class Acp implements Adapter { } if (u.sessionUpdate === "agent_message_chunk") { if (!this.loading && u.content.type === "text") { + if (u.content.text.trim() && !this.reactiveTools.size) + this.pendingWakeup = false; this.emit({ type: "delta", id: this.messageId, @@ -1324,8 +1332,24 @@ export class Acp implements Adapter { input.IsDaemon === true; if (daemon || u.status === "completed" || u.status === "failed") { reactiveWorkChanged = this.reactiveTools.delete(u.toolCallId); + // A background-capable call can settle just before the response + // that yielded to it. Keep watching until the model answers again. + if (this.backgroundTools.delete(u.toolCallId) && !daemon) + this.pendingWakeup = true; } else if (u.sessionUpdate === "tool_call") { this.reactiveTools.add(u.toolCallId); + if ( + (title === "run_command" && + input && + typeof input === "object" && + "WaitMsBeforeAsync" in input && + typeof input.WaitMsBeforeAsync === "number" && + input.WaitMsBeforeAsync >= 0) || + title === "invoke_subagent" || + title === "schedule" || + title === "run_workflow" + ) + this.backgroundTools.add(u.toolCallId); reactiveWorkChanged = true; } } diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index 30b2884c..f6b6bbef 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -104,6 +104,40 @@ test("Antigravity keeps accepting reactive output after overlapping prompts end" assert.deepEqual(prompts(requests), ["Run background work", "Keep going"]); }); +for (const mode of ["reactive-before-end", "reactive-sync-answer"]) + test(`Antigravity handles an async-capable tool that settles before end_turn in ${mode}`, async (t) => { + fixture(t); + process.env.LOOP_TEST_AGY_MODE = mode; + const events: AdapterEvent[] = []; + const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => + events.push(e), + ); + t.after(() => adapter.dispose()); + await adapter.start(); + await adapter.prompt("Run background work"); + await until(() => complete(events).length === 1, 3000); + assert.deepEqual( + events.flatMap((e) => (e.type === "delta" ? [e.text] : [])), + ["Waiting.", "Done."], + ); + }); + +test("Antigravity retires the live session when a steering limit interrupts reactive work", async (t) => { + fixture(t); + process.env.LOOP_TEST_AGY_MODE = "reactive-steer-limit"; + const events: AdapterEvent[] = []; + const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => + events.push(e), + ); + t.after(() => adapter.dispose()); + await adapter.start(); + await adapter.prompt("Run background work"); + await assert.rejects(adapter.steer!("Keep going"), /max_tokens/); + assert.deepEqual(statuses(events), ["ready", "interrupted"]); + assert.equal(adapter.reusable, false); + await assert.rejects(adapter.prompt("Next turn"), /unavailable/); +}); + test("Antigravity keeps accepting reactive output after echoing and acknowledging a steer", async (t) => { fixture(t); process.env.LOOP_TEST_AGY_MODE = "reactive-steer-ack"; diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index 6a17de08..06151c51 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -154,13 +154,38 @@ function reactiveTurn(sessionId, mode) { tool("daemon", { IsDaemon: true }, "run_command"); if (mode !== "daemon-only") - tool("background", { - CommandLine: "sleep 5", - IsDaemon: false, - WaitMsBeforeAsync: 500, - }); + tool( + "background", + { + CommandLine: "sleep 5", + IsDaemon: false, + WaitMsBeforeAsync: 500, + }, + "run_command", + ); message(mode === "daemon-only" ? "Daemon started." : "Waiting."); reportUsage(); + if (mode === "reactive-before-end" || mode === "reactive-sync-answer") { + complete("background"); + if (mode === "reactive-sync-answer") { + message("Done."); + finish(sessionId); + } else { + finish(sessionId); + setTimeout(() => { + message("Done."); + reportUsage(); + }, 30); + } + return; + } + if (mode === "reactive-steer-limit") { + endReactiveSteer = (request) => { + finish(sessionId); + reply(request.id, { stopReason: "max_tokens" }); + }; + return; + } if (mode === "reactive-steering" || mode === "reactive-steer-ack") { endReactiveSteer = (request) => { finish(sessionId); From 0220b60dab18cf26ac1f6ff9c7766f459f41d598 Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 10:07:03 +0000 Subject: [PATCH 07/31] Require pending wakeups to answer and preserve watchdog budget --- src/adapters/acp.ts | 29 ++++++++++----- test/antigravity-steering.node.test.ts | 40 +++++++++++++++++++++ test/fixtures/fake-antigravity-steering.mjs | 21 ++++++++++- 3 files changed, 81 insertions(+), 9 deletions(-) diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index e709538f..e1dbf19d 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -151,6 +151,8 @@ export class Acp implements Adapter { private reactiveEnd = false; private reactiveIdle?: NodeJS.Timeout; private reactiveWatchdog?: NodeJS.Timeout; + private reactiveWatchdogStarted = 0; + private reactiveBudget = REACTIVE_WATCHDOG_MS; private retireReactiveSession = false; get reusable() { return !this.retireReactiveSession; @@ -615,6 +617,7 @@ export class Acp implements Adapter { this.backgroundTools.clear(); this.pendingWakeup = false; this.reactiveEnd = false; + this.reactiveBudget = REACTIVE_WATCHDOG_MS; const expected = this.echoOf(value).trim(); this.promptEcho = undefined; this.promptEchoed = expected @@ -733,13 +736,16 @@ export class Acp implements Adapter { if (this.permissions.size) return; // The reactive wait stays bounded even if a concurrent steer never // answers. Human approval time does not count against the watchdog. - this.reactiveWatchdog ??= setTimeout( - () => - this.timeoutReactiveTurn( - "Antigravity did not finish its reactive turn within an hour.", - ), - REACTIVE_WATCHDOG_MS, - ).unref(); + if (!this.reactiveWatchdog) { + this.reactiveWatchdogStarted = Date.now(); + this.reactiveWatchdog = setTimeout( + () => + this.timeoutReactiveTurn( + "Antigravity did not finish its reactive turn within an hour.", + ), + this.reactiveBudget, + ).unref(); + } if (this.openPrompts || this.reactiveTools.size) return; if (!confirmed) { // Usage sent while work is still open can mark a yield to another @@ -1218,6 +1224,12 @@ export class Acp implements Adapter { return Promise.resolve({ outcome: { outcome: "cancelled" } }); const id = randomUUID(); clearTimeout(this.reactiveIdle); + if (this.reactiveWatchdog) + this.reactiveBudget = Math.max( + 0, + this.reactiveBudget - + Math.max(0, Date.now() - this.reactiveWatchdogStarted), + ); clearTimeout(this.reactiveWatchdog); this.reactiveWatchdog = undefined; return new Promise((resolve) => { @@ -1313,7 +1325,8 @@ export class Acp implements Adapter { // prompt response. A pass that leaves more work open can wake again. // A usage update that arrived during an open request cannot certify a // later steering response. Evaluate it at arrival and never latch it. - if (!this.cancelling) this.finishReactiveTurn(true); + if (!this.cancelling && !this.pendingWakeup) + this.finishReactiveTurn(true); return; } if ( diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index f6b6bbef..c03b8163 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -213,6 +213,46 @@ test("Antigravity cancels a reactive turn with an outstanding steering request", assert.equal(adapter.reusable, false); }); +test( + "Antigravity pauses the reactive budget during approval and resumes with the remaining time", + { timeout: 5000 }, + async (t) => { + fixture(t); + process.env.LOOP_TEST_AGY_MODE = "reactive-budget"; + const events: AdapterEvent[] = []; + let endPrompt!: () => void; + const promptEnded = new Promise((resolve) => { + endPrompt = resolve; + }); + let requestApproval!: (id: string) => void; + const approval = new Promise((resolve) => { + requestApproval = resolve; + }); + const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => { + events.push(e); + if (e.type === "usage") endPrompt(); + if (e.type === "request") requestApproval(e.request.id); + }); + t.after(() => adapter.dispose()); + await adapter.start(); + t.mock.timers.enable({ apis: ["setTimeout", "Date"] }); + try { + await adapter.prompt("Run background work"); + await promptEnded; + t.mock.timers.tick(59 * 60_000); + await adapter.steer!("Keep going"); + const decisionId = await approval; + t.mock.timers.tick(60 * 60_000); + assert.deepEqual(statuses(events), ["ready"]); + await adapter.answer(decisionId, { choice: "allow" }); + t.mock.timers.tick(60_000); + assert.deepEqual(statuses(events), ["ready", "interrupted"]); + } finally { + t.mock.timers.reset(); + } + }, +); + test( "Antigravity interrupts a settled reactive pass without a final usage update", { timeout: 5000 }, diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index 06151c51..6917d30f 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -172,6 +172,7 @@ function reactiveTurn(sessionId, mode) { finish(sessionId); } else { finish(sessionId); + reportUsage(); // A settled tool still has a pending wakeup. setTimeout(() => { message("Done."); reportUsage(); @@ -303,11 +304,29 @@ createInterface({ input: process.stdin }).on("line", (line) => { return finish(sessionId, "cancelled"); case "session/prompt": { const text = req.params.prompt[0].text; - if (turn === 1 && mode === "reactive-stalled-steer") { + if ( + turn === 1 && + ["reactive-stalled-steer", "reactive-budget"].includes(mode) + ) { update(sessionId, { sessionUpdate: "user_message_chunk", content: { type: "text", text }, }); + if (mode === "reactive-budget") + send({ + id: `perm-${++permission}`, + method: "session/request_permission", + params: { + sessionId, + toolCall: { + toolCallId: "background", + title: "Reactive approval", + }, + options: [ + { optionId: "allow", name: "Allow once", kind: "allow_once" }, + ], + }, + }); return; } if (open.length) { From 1a1641d0ce9f54318b3e2137fda029c7fa03f15d Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 10:11:05 +0000 Subject: [PATCH 08/31] Handle delayed ACP tool metadata and blocked cancellation --- src/adapters/acp.ts | 42 +++++++++++---------- test/antigravity-steering.node.test.ts | 31 +++++++++++++++ test/fixtures/fake-antigravity-steering.mjs | 21 ++++++----- 3 files changed, 65 insertions(+), 29 deletions(-) diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index e1dbf19d..d9ad21a0 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -898,12 +898,12 @@ export class Acp implements Adapter { this.reactiveWatchdog = undefined; this.finishCommandDiscovery(false); this.cancelPermissions(); - try { - if (!this.closed && this.session && this.connection && this.active) - await this.connection.cancel({ sessionId: this.session }); - } finally { - this.finishReactiveTurn(); - } + const notification = + !this.closed && this.session && this.connection && this.active + ? this.connection.cancel({ sessionId: this.session }) + : undefined; + this.finishReactiveTurn(); + await notification; } async answer( id: string, @@ -1301,8 +1301,7 @@ export class Acp implements Adapter { } if (u.sessionUpdate === "agent_message_chunk") { if (!this.loading && u.content.type === "text") { - if (u.content.text.trim() && !this.reactiveTools.size) - this.pendingWakeup = false; + if (u.content.text.trim()) this.pendingWakeup = false; this.emit({ type: "delta", id: this.messageId, @@ -1343,6 +1342,21 @@ export class Acp implements Adapter { typeof input === "object" && "IsDaemon" in input && input.IsDaemon === true; + if ( + !daemon && + (u.sessionUpdate === "tool_call" || + this.reactiveTools.has(u.toolCallId)) && + ((title === "run_command" && + input && + typeof input === "object" && + "WaitMsBeforeAsync" in input && + typeof input.WaitMsBeforeAsync === "number" && + input.WaitMsBeforeAsync >= 0) || + title === "invoke_subagent" || + title === "schedule" || + title === "run_workflow") + ) + this.backgroundTools.add(u.toolCallId); if (daemon || u.status === "completed" || u.status === "failed") { reactiveWorkChanged = this.reactiveTools.delete(u.toolCallId); // A background-capable call can settle just before the response @@ -1351,18 +1365,6 @@ export class Acp implements Adapter { this.pendingWakeup = true; } else if (u.sessionUpdate === "tool_call") { this.reactiveTools.add(u.toolCallId); - if ( - (title === "run_command" && - input && - typeof input === "object" && - "WaitMsBeforeAsync" in input && - typeof input.WaitMsBeforeAsync === "number" && - input.WaitMsBeforeAsync >= 0) || - title === "invoke_subagent" || - title === "schedule" || - title === "run_workflow" - ) - this.backgroundTools.add(u.toolCallId); reactiveWorkChanged = true; } } diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index c03b8163..417e0023 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -3,6 +3,7 @@ import assert from "node:assert/strict"; import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs"; import { tmpdir } from "node:os"; import { join, resolve } from "node:path"; +import { ClientSideConnection } from "@agentclientprotocol/sdk"; import { Antigravity } from "../src/adapters/antigravity.js"; import type { AdapterEvent } from "../src/adapters/events.js"; import { NotDelivered, type Options } from "../src/adapters/types.js"; @@ -213,6 +214,36 @@ test("Antigravity cancels a reactive turn with an outstanding steering request", assert.equal(adapter.reusable, false); }); +test("Antigravity reports interruption before a blocked cancel notification settles", async (t) => { + fixture(t); + process.env.LOOP_TEST_AGY_MODE = "reactive-stalled"; + const events: AdapterEvent[] = []; + const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => + events.push(e), + ); + t.after(() => adapter.dispose()); + await adapter.start(); + await adapter.prompt("Run background work"); + await until(() => events.some((e) => e.type === "usage")); + let deliver!: () => void; + t.mock.method( + ClientSideConnection.prototype, + "cancel", + () => + new Promise((resolve) => { + deliver = resolve; + }), + ); + const cancelled = adapter.cancel(); + try { + assert.deepEqual(statuses(events), ["ready", "interrupted"]); + assert.equal(adapter.reusable, false); + } finally { + deliver(); + await cancelled; + } +}); + test( "Antigravity pauses the reactive budget during approval and resumes with the remaining time", { timeout: 5000 }, diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index 6917d30f..2b70e761 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -138,11 +138,12 @@ function reactiveTurn(sessionId, mode) { status: "in_progress", rawInput, }); - const complete = (toolCallId, status = "completed") => + const complete = (toolCallId, status = "completed", rawInput) => update(sessionId, { sessionUpdate: "tool_call_update", toolCallId, status, + rawInput, }); const message = (text) => update(sessionId, { @@ -156,17 +157,19 @@ function reactiveTurn(sessionId, mode) { if (mode !== "daemon-only") tool( "background", - { - CommandLine: "sleep 5", - IsDaemon: false, - WaitMsBeforeAsync: 500, - }, + mode === "reactive-before-end" + ? undefined + : { + CommandLine: "sleep 5", + IsDaemon: false, + WaitMsBeforeAsync: 500, + }, "run_command", ); message(mode === "daemon-only" ? "Daemon started." : "Waiting."); reportUsage(); if (mode === "reactive-before-end" || mode === "reactive-sync-answer") { - complete("background"); + complete("background", "completed", { WaitMsBeforeAsync: 500 }); if (mode === "reactive-sync-answer") { message("Done."); finish(sessionId); @@ -221,7 +224,7 @@ function reactiveTurn(sessionId, mode) { reportUsage(); // Even a usage update following end_turn leaves open work. setTimeout(() => { complete("background"); - tool("subagent", {}); + tool("subagent", {}, "invoke_subagent"); message("Waiting again."); reportUsage(); setTimeout(() => { @@ -230,8 +233,8 @@ function reactiveTurn(sessionId, mode) { const id = `perm-${++permission}`; permissions.set(id, (result) => { if (result.outcome.outcome !== "selected") return; - complete("follow-up"); message("Done."); + complete("follow-up"); reportUsage(); }); send({ From 4e67356d9abf78af98afeddc6cb84da79bb12416 Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 10:15:27 +0000 Subject: [PATCH 09/31] Settle reactive completion after observed Antigravity wire ordering --- src/adapters/acp.ts | 61 ++++++++++++++++----- test/antigravity-steering-native.test.ts | 2 +- test/antigravity-steering.node.test.ts | 17 +++++- test/fixtures/fake-antigravity-steering.mjs | 20 +++++-- 4 files changed, 79 insertions(+), 21 deletions(-) diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index d9ad21a0..42cbd3d5 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -75,6 +75,7 @@ function matchEcho(echo: Echo, chunk: string) { const ECHO_WAIT = 5000; const REACTIVE_IDLE_MS = 60_000; const REACTIVE_WATCHDOG_MS = 60 * 60_000; +const REACTIVE_SETTLE_MS = 5_000; const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms).unref()); const text = (value: unknown) => @@ -146,7 +147,8 @@ export class Acp implements Adapter { /** agy can return end_turn before its background work wakes the model. */ protected waitsForReactiveTurns = false; private reactiveTools = new Set(); - private backgroundTools = new Set(); + private backgroundTools = new Map(); + private toolStartedAt = new Map(); private pendingWakeup = false; private reactiveEnd = false; private reactiveIdle?: NodeJS.Timeout; @@ -615,6 +617,7 @@ export class Acp implements Adapter { this.earlierEnd = false; this.reactiveTools.clear(); this.backgroundTools.clear(); + this.toolStartedAt.clear(); this.pendingWakeup = false; this.reactiveEnd = false; this.reactiveBudget = REACTIVE_WATCHDOG_MS; @@ -760,7 +763,12 @@ export class Acp implements Adapter { ).unref(); return; } - this.reportReactiveEnd("completed"); + // agy also emits usage during a pass, including just before announcing + // another tool. Wait for a quiet interval and invalidate it on work. + this.reactiveIdle = setTimeout( + () => this.reportReactiveEnd("completed"), + REACTIVE_SETTLE_MS, + ).unref(); } private timeoutReactiveTurn(detail: string) { this.reportReactiveEnd("interrupted", detail); @@ -1336,32 +1344,59 @@ export class Acp implements Adapter { if (this.waitsForReactiveTurns && !this.loading) { const input = u.rawInput; const title = u.title ?? this.toolItems.get(u.toolCallId)?.title; + const command = + input && + typeof input === "object" && + "CommandLine" in input && + typeof input.CommandLine === "string"; const daemon = - (title === "run_command" || title === "schedule") && + (command || title === "run_command" || title === "schedule") && input && typeof input === "object" && "IsDaemon" in input && input.IsDaemon === true; - if ( - !daemon && - (u.sessionUpdate === "tool_call" || - this.reactiveTools.has(u.toolCallId)) && - ((title === "run_command" && + const knownTool = + u.sessionUpdate === "tool_call" || + this.reactiveTools.has(u.toolCallId); + if (knownTool && !daemon) { + if (u.status === "pending") this.toolStartedAt.delete(u.toolCallId); + if ( + u.status === "in_progress" && + !this.toolStartedAt.has(u.toolCallId) + ) + this.toolStartedAt.set(u.toolCallId, performance.now()); + if ( + (command || title === "run_command") && input && typeof input === "object" && "WaitMsBeforeAsync" in input && typeof input.WaitMsBeforeAsync === "number" && - input.WaitMsBeforeAsync >= 0) || + Number.isFinite(input.WaitMsBeforeAsync) && + input.WaitMsBeforeAsync >= 0 + ) + this.backgroundTools.set(u.toolCallId, input.WaitMsBeforeAsync); + else if ( title === "invoke_subagent" || title === "schedule" || - title === "run_workflow") - ) - this.backgroundTools.add(u.toolCallId); + title === "run_workflow" + ) + this.backgroundTools.set(u.toolCallId, 0); + } if (daemon || u.status === "completed" || u.status === "failed") { reactiveWorkChanged = this.reactiveTools.delete(u.toolCallId); // A background-capable call can settle just before the response // that yielded to it. Keep watching until the model answers again. - if (this.backgroundTools.delete(u.toolCallId) && !daemon) + const delay = this.backgroundTools.get(u.toolCallId); + const startedAt = this.toolStartedAt.get(u.toolCallId); + this.backgroundTools.delete(u.toolCallId); + this.toolStartedAt.delete(u.toolCallId); + if ( + !daemon && + delay !== undefined && + (delay === 0 || + (startedAt !== undefined && + performance.now() - startedAt >= delay)) + ) this.pendingWakeup = true; } else if (u.sessionUpdate === "tool_call") { this.reactiveTools.add(u.toolCallId); diff --git a/test/antigravity-steering-native.test.ts b/test/antigravity-steering-native.test.ts index 18adb562..4aa4345d 100644 --- a/test/antigravity-steering-native.test.ts +++ b/test/antigravity-steering-native.test.ts @@ -442,7 +442,7 @@ it("publishes the result only after Antigravity's reactive work and approval fin await sessions.interrupt(run.id); await execution; } -}); +}, 10_000); it("replaces an idle ACP session after refreshing workspace-tool support while retaining native context", async () => { const { run } = task("agy-acp-upgrade"); diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index 417e0023..1b28b292 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -116,13 +116,26 @@ for (const mode of ["reactive-before-end", "reactive-sync-answer"]) t.after(() => adapter.dispose()); await adapter.start(); await adapter.prompt("Run background work"); - await until(() => complete(events).length === 1, 3000); + await until(() => complete(events).length === 1, 8000); assert.deepEqual( events.flatMap((e) => (e.type === "delta" ? [e.text] : [])), ["Waiting.", "Done."], ); }); +test("Antigravity completes a synchronous tool-only turn at end_turn", async (t) => { + fixture(t); + process.env.LOOP_TEST_AGY_MODE = "reactive-tool-only"; + const events: AdapterEvent[] = []; + const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => + events.push(e), + ); + t.after(() => adapter.dispose()); + await adapter.start(); + await adapter.prompt("Run the tool"); + await until(() => complete(events).length === 1, 2000); +}); + test("Antigravity retires the live session when a steering limit interrupts reactive work", async (t) => { fixture(t); process.env.LOOP_TEST_AGY_MODE = "reactive-steer-limit"; @@ -150,7 +163,7 @@ test("Antigravity keeps accepting reactive output after echoing and acknowledgin await adapter.start(); await adapter.prompt("Run background work"); await adapter.steer!("Keep going"); - await until(() => complete(events).length === 1, 3000); + await until(() => complete(events).length === 1, 8000); assert.deepEqual(statuses(events), ["ready", "completed"]); assert.deepEqual( events.flatMap((e) => (e.type === "delta" ? [e.text] : [])), diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index 2b70e761..911d3eb4 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -153,7 +153,7 @@ function reactiveTurn(sessionId, mode) { const reportUsage = () => update(sessionId, { sessionUpdate: "usage_update", used: 20, size: 100 }); - tool("daemon", { IsDaemon: true }, "run_command"); + tool("daemon", { CommandLine: "sleep 90", IsDaemon: true }, "sleep 90"); if (mode !== "daemon-only") tool( "background", @@ -168,10 +168,19 @@ function reactiveTurn(sessionId, mode) { ); message(mode === "daemon-only" ? "Daemon started." : "Waiting."); reportUsage(); - if (mode === "reactive-before-end" || mode === "reactive-sync-answer") { - complete("background", "completed", { WaitMsBeforeAsync: 500 }); - if (mode === "reactive-sync-answer") { - message("Done."); + if ( + [ + "reactive-before-end", + "reactive-sync-answer", + "reactive-tool-only", + ].includes(mode) + ) { + complete("background", "completed", { + CommandLine: "sleep 5", + WaitMsBeforeAsync: mode === "reactive-before-end" ? 0 : 500, + }); + if (mode !== "reactive-before-end") { + if (mode === "reactive-sync-answer") message("Done."); finish(sessionId); } else { finish(sessionId); @@ -203,6 +212,7 @@ function reactiveTurn(sessionId, mode) { reportUsage(); // This usage precedes the still-open steering response. } reply(request.id, { stopReason: "end_turn" }); + if (mode === "reactive-steer-ack") reportUsage(); setTimeout(() => { message("Done."); reportUsage(); From ef0f68b13d53abdcdb7199609515ab5bcb2d4071 Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 10:29:28 +0000 Subject: [PATCH 10/31] Preserve unconfirmed Antigravity reactive output as partial --- src/adapters/acp.ts | 59 ++++------- test/antigravity-steering-native.test.ts | 20 +++- test/antigravity-steering.node.test.ts | 109 ++++++++++++-------- test/fixtures/fake-antigravity-steering.mjs | 5 +- 4 files changed, 100 insertions(+), 93 deletions(-) diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index 42cbd3d5..9358be78 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -75,7 +75,6 @@ function matchEcho(echo: Echo, chunk: string) { const ECHO_WAIT = 5000; const REACTIVE_IDLE_MS = 60_000; const REACTIVE_WATCHDOG_MS = 60 * 60_000; -const REACTIVE_SETTLE_MS = 5_000; const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms).unref()); const text = (value: unknown) => @@ -672,7 +671,10 @@ export class Acp implements Adapter { result.stopReason, ); const interrupted = - this.cancelling || limited || result.stopReason === "cancelled"; + this.cancelling || + this.reactiveEnd || + limited || + result.stopReason === "cancelled"; if ( interrupted && (this.reactiveEnd || this.pendingWakeup || this.reactiveTools.size) @@ -729,11 +731,11 @@ export class Acp implements Adapter { }); return request; } - private finishReactiveTurn(confirmed = false) { + private finishReactiveTurn() { clearTimeout(this.reactiveIdle); if (this.closed || this.terminalReported || !this.reactiveEnd) return; if (this.cancelling) { - this.reportReactiveEnd("interrupted"); + this.interruptReactiveTurn(); return; } if (this.permissions.size) return; @@ -743,51 +745,35 @@ export class Acp implements Adapter { this.reactiveWatchdogStarted = Date.now(); this.reactiveWatchdog = setTimeout( () => - this.timeoutReactiveTurn( + this.interruptReactiveTurn( "Antigravity did not finish its reactive turn within an hour.", ), this.reactiveBudget, ).unref(); } if (this.openPrompts || this.reactiveTools.size) return; - if (!confirmed) { - // Usage sent while work is still open can mark a yield to another - // wakeup. Give agy time to acknowledge the settled pass before - // retiring it with partial output. - this.reactiveIdle = setTimeout( - () => - this.timeoutReactiveTurn( - "Antigravity did not confirm the end of its reactive turn.", - ), - REACTIVE_IDLE_MS, - ).unref(); - return; - } - // agy also emits usage during a pass, including just before announcing - // another tool. Wait for a quiet interval and invalidate it on work. + // ACP usage updates also occur mid-pass. A quiet reactive wait can + // preserve partial output, but cannot certify a completed Result. this.reactiveIdle = setTimeout( - () => this.reportReactiveEnd("completed"), - REACTIVE_SETTLE_MS, + () => + this.interruptReactiveTurn( + "Antigravity did not confirm the end of its reactive turn.", + ), + REACTIVE_IDLE_MS, ).unref(); } - private timeoutReactiveTurn(detail: string) { - this.reportReactiveEnd("interrupted", detail); - } - private reportReactiveEnd( - status: "interrupted" | "completed", - detail?: string, - ) { + private interruptReactiveTurn(detail?: string) { clearTimeout(this.reactiveIdle); clearTimeout(this.reactiveWatchdog); this.reactiveWatchdog = undefined; - if (status === "interrupted") this.retireReactiveSession = true; + this.retireReactiveSession = true; this.terminalReported = true; this.active = false; this.emit({ type: "status", - status, + status: "interrupted", detail, - recoverable: status === "completed", + recoverable: false, }); } private addUsage(result: unknown) { @@ -1327,15 +1313,6 @@ export class Acp implements Adapter { this.finishReactiveTurn(); return; } - if (u.sessionUpdate === "usage_update" && this.reactiveEnd) { - // agy 1.5.14 sends this after a reactive pass but sends no second - // prompt response. A pass that leaves more work open can wake again. - // A usage update that arrived during an open request cannot certify a - // later steering response. Evaluate it at arrival and never latch it. - if (!this.cancelling && !this.pendingWakeup) - this.finishReactiveTurn(true); - return; - } if ( u.sessionUpdate === "tool_call" || u.sessionUpdate === "tool_call_update" diff --git a/test/antigravity-steering-native.test.ts b/test/antigravity-steering-native.test.ts index 4aa4345d..6a326cb7 100644 --- a/test/antigravity-steering-native.test.ts +++ b/test/antigravity-steering-native.test.ts @@ -404,7 +404,7 @@ it("steers a running turn through agy acp without a restart or replaying the tas ]); }); -it("publishes the result only after Antigravity's reactive work and approval finish", async () => { +it("preserves unconfirmed Antigravity reactive output without publishing a Result", async () => { process.env.LOOP_TEST_AGY_MODE = "reactive"; const { run } = task("agy-reactive"); const before = prompts().length; @@ -429,11 +429,21 @@ it("publishes the result only after Antigravity's reactive work and approval fin await sessions.decisions.answer(decision()!.id, "reactive-approval", { choice: "allow", }); - expect(await execution).toMatchObject({ kind: "finished" }); - expect(checkpoint()).toMatchObject({ - stage: "done", - output: expect.stringContaining("Done."), + const reactiveOutput = () => + db + .prepare("SELECT item FROM native_items WHERE run_id=?") + .all(run.id) + .some((row) => + JSON.parse((row as { item: string }).item).text?.includes("Done."), + ); + await until(reactiveOutput, 5000); + await sessions.interrupt(run.id); + expect(await execution).toMatchObject({ + kind: "already-moved", + reason: "native-interrupted", }); + expect(checkpoint()).toMatchObject({ stage: "native", output: "" }); + expect(reactiveOutput()).toBe(true); expect(prompts().slice(before)).toEqual([ "Saved fixture instructions\n\nExplicit task", ]); diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index 1b28b292..9c81b61a 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -60,15 +60,16 @@ test("Antigravity waits through successive reactive passes and approvals", async ["Waiting.", "Waiting again."], ); await adapter.answer(approval.request.id, { choice: "allow" }); - await until(() => complete(events).length === 1); - assert.deepEqual(statuses(events), ["ready", "completed"]); + await until(() => + events.some((e) => e.type === "delta" && e.text === "Done."), + ); + assert.deepEqual(statuses(events), ["ready"]); assert.deepEqual( events.flatMap((e) => (e.type === "delta" ? [e.text] : [])), ["Waiting.", "Waiting again.", "Done."], ); assert.deepEqual(prompts(requests), ["Run background work"]); - await adapter.prompt("Next turn"); - await until(() => complete(events).length === 2); + await assert.rejects(adapter.prompt("Next turn"), /busy/); }); test("Antigravity completes normally with only a daemon still running", async (t) => { @@ -97,7 +98,10 @@ test("Antigravity keeps accepting reactive output after overlapping prompts end" await adapter.prompt("Run background work"); await until(() => events.some((e) => e.type === "delta")); await adapter.steer!("Keep going"); - await until(() => complete(events).length === 1); + await until(() => + events.some((e) => e.type === "delta" && e.text === "Done."), + ); + assert.deepEqual(statuses(events), ["ready"]); assert.deepEqual( events.flatMap((e) => (e.type === "delta" ? [e.text] : [])), ["Waiting.", "Done."], @@ -116,7 +120,12 @@ for (const mode of ["reactive-before-end", "reactive-sync-answer"]) t.after(() => adapter.dispose()); await adapter.start(); await adapter.prompt("Run background work"); - await until(() => complete(events).length === 1, 8000); + await until(() => + events.some((e) => e.type === "delta" && e.text === "Done."), + ); + if (mode === "reactive-sync-answer") + await until(() => complete(events).length === 1); + else assert.deepEqual(statuses(events), ["ready"]); assert.deepEqual( events.flatMap((e) => (e.type === "delta" ? [e.text] : [])), ["Waiting.", "Done."], @@ -163,8 +172,10 @@ test("Antigravity keeps accepting reactive output after echoing and acknowledgin await adapter.start(); await adapter.prompt("Run background work"); await adapter.steer!("Keep going"); - await until(() => complete(events).length === 1, 8000); - assert.deepEqual(statuses(events), ["ready", "completed"]); + await until(() => + events.some((e) => e.type === "delta" && e.text === "Done."), + ); + assert.deepEqual(statuses(events), ["ready"]); assert.deepEqual( events.flatMap((e) => (e.type === "delta" ? [e.text] : [])), ["Waiting.", "Acknowledged.", "Done."], @@ -289,51 +300,59 @@ test( t.mock.timers.tick(60 * 60_000); assert.deepEqual(statuses(events), ["ready"]); await adapter.answer(decisionId, { choice: "allow" }); - t.mock.timers.tick(60_000); - assert.deepEqual(statuses(events), ["ready", "interrupted"]); - } finally { - t.mock.timers.reset(); - } - }, -); - -test( - "Antigravity interrupts a settled reactive pass without a final usage update", - { timeout: 5000 }, - async (t) => { - fixture(t); - process.env.LOOP_TEST_AGY_MODE = "reactive-reordered"; - const events: AdapterEvent[] = []; - let settle!: () => void; - const settled = new Promise((resolve) => { - settle = resolve; - }); - const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => { - events.push(e); - if ( - e.type === "activity" && - e.activity.kind === "tool" && - e.activity.id === "background" && - e.activity.patch.status === "completed" - ) - settle(); - }); - t.after(() => adapter.dispose()); - await adapter.start(); - t.mock.timers.enable({ apis: ["setTimeout"] }); - try { - await adapter.prompt("Run background work"); - await settled; + t.mock.timers.tick(5_000); assert.deepEqual(statuses(events), ["ready"]); - t.mock.timers.tick(60_000); + t.mock.timers.tick(55_000); assert.deepEqual(statuses(events), ["ready", "interrupted"]); - assert.equal(adapter.reusable, false); } finally { t.mock.timers.reset(); } }, ); +for (const mode of ["reactive-reordered", "reactive-final-usage"]) + test( + `Antigravity preserves partial output and interrupts in ${mode}`, + { timeout: 5000 }, + async (t) => { + fixture(t); + process.env.LOOP_TEST_AGY_MODE = mode; + const events: AdapterEvent[] = []; + let settle!: () => void; + const settled = new Promise((resolve) => { + settle = resolve; + }); + const adapter = new Antigravity( + { ...options, version: "1.5.14" }, + (e) => { + events.push(e); + if ( + e.type === "activity" && + e.activity.kind === "tool" && + e.activity.id === "background" && + e.activity.patch.status === "completed" + ) + settle(); + }, + ); + t.after(() => adapter.dispose()); + await adapter.start(); + t.mock.timers.enable({ apis: ["setTimeout"] }); + try { + await adapter.prompt("Run background work"); + await settled; + assert.deepEqual(statuses(events), ["ready"]); + t.mock.timers.tick(5_000); + assert.deepEqual(statuses(events), ["ready"]); + t.mock.timers.tick(55_000); + assert.deepEqual(statuses(events), ["ready", "interrupted"]); + assert.equal(adapter.reusable, false); + } finally { + t.mock.timers.reset(); + } + }, + ); + for (const stop of ["cancel", "dispose"] as const) test(`Antigravity ${stop} can stop a turn waiting for a reactive wakeup`, async (t) => { const requests = fixture(t); diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index 911d3eb4..ef74ea5a 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -221,11 +221,12 @@ function reactiveTurn(sessionId, mode) { return; } finish(sessionId); - if (mode === "reactive-reordered") { + if (mode === "reactive-reordered" || mode === "reactive-final-usage") { setTimeout(() => { message("Done."); - reportUsage(); + if (mode === "reactive-reordered") reportUsage(); complete("background"); + if (mode === "reactive-final-usage") reportUsage(); }, 30); return; } From e3242abd56fe281f5791b39141d046c121117a22 Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 10:33:21 +0000 Subject: [PATCH 11/31] Fence trailing progress and recognize late daemon metadata --- docs/harnesses.md | 2 + src/adapters/acp.ts | 42 +++++++++++++++++---- src/adapters/antigravity.ts | 1 + test/antigravity-steering.node.test.ts | 32 +++++++++------- test/fixtures/fake-antigravity-steering.mjs | 13 +++++++ 5 files changed, 69 insertions(+), 21 deletions(-) diff --git a/docs/harnesses.md b/docs/harnesses.md index 15d53470..5741fd23 100644 --- a/docs/harnesses.md +++ b/docs/harnesses.md @@ -94,6 +94,8 @@ Install [Antigravity CLI](https://antigravity.google/docs/getting-started?tab=cl With **Antigravity CLI 1.5.9 or newer**, Loop uses the documented [ACP interface](https://antigravity.google/docs/ide/extensions/acp), launched with `agy acp --process-per-session`. Each native session receives its own authenticated Loop MCP connection through ACP session creation or resuming. This enables Agent mail, team delegation and Loop tool integrations without editing global or project MCP configuration. ACP must advertise HTTP MCP support; setup fails before sending a prompt if it does not. Enable Antigravity again after upgrading the CLI so Loop refreshes its saved runtime version and capabilities. Existing streaming sessions switch to ACP on their next turn; refreshing does not interrupt a running turn. See [session reuse](state-machines.md#companion_sessionsstate). +When Antigravity returns `end_turn` while background work is still pending, Loop keeps receiving output and approvals. Antigravity can send usage updates both during the continuation and after its final text. Until ACP supplies a definitive completion signal, Loop bounds that wait and interrupts the run with its partial output preserved in the conversation trace. This can leave a successful background continuation without a published Result. Explicit daemons can outlive ordinary completed turns. See the [upstream ACP discussion](https://github.com/google-antigravity/antigravity-cli/issues/1461). + Model discovery and session initialization send no model prompt. Saved instructions accompany explicit prompts, and interrupted tasks are never automatically replayed. Existing native conversation IDs and workspace bindings are retained when a newer runtime resumes a conversation created by the streaming adapter. Commands and skills come from the session’s ACP catalog. Catalog probes and slash-leading prompts or live replies wait up to five seconds for that catalog. A discovered command stays at the start of an explicit prompt, followed by saved instructions; other slash-leading text stays literal, including when discovery times out. Saved instructions starting with `/` also stay literal. The model catalog comes from ACP; if the account no longer offers a previously selected model through that interface, select an available model explicitly. Loop does not choose a replacement model after failure. Antigravity requires `--billing existing`. Its native sign-in, billing and permission rules apply; Loop does not verify a subscription entitlement. ACP permission requests appear in Loop's approval flow. CLI 1.5.2–1.5.8 uses `agy acp` with approvals and live steering, while Agent mail and team delegation require 1.5.9 or newer. A reply during a running ACP turn uses another `session/prompt`; Loop waits for the original prompt echo, then confirms delivery from an exact reply echo or normal request completion. Replies wait while an approval is open. Unconfirmed replies are not automatically resent. Older streaming runtimes queue follow-ups for the next turn. Antigravity is not bundled in the Docker images. diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index 9358be78..64bb25ed 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -150,6 +150,7 @@ export class Acp implements Adapter { private toolStartedAt = new Map(); private pendingWakeup = false; private reactiveEnd = false; + private canResolveAsDaemonOnly = false; private reactiveIdle?: NodeJS.Timeout; private reactiveWatchdog?: NodeJS.Timeout; private reactiveWatchdogStarted = 0; @@ -619,6 +620,7 @@ export class Acp implements Adapter { this.toolStartedAt.clear(); this.pendingWakeup = false; this.reactiveEnd = false; + this.canResolveAsDaemonOnly = false; this.reactiveBudget = REACTIVE_WATCHDOG_MS; const expected = this.echoOf(value).trim(); this.promptEcho = undefined; @@ -650,8 +652,9 @@ export class Acp implements Adapter { if (this.closed || this.terminalReported) return; if (result.stopReason === "end_turn") { if (!last) this.earlierEnd = true; - // An echoed steer and its text can be an interim update. Once - // a reactive wait begins, require the reactive usage boundary. + // Antigravity gives reactive passes no definitive end signal. + // Preserve their output as partial instead of publishing it + // based on usage, steering replies, or elapsed time. if ( !this.cancelling && this.waitsForReactiveTurns && @@ -660,6 +663,9 @@ export class Acp implements Adapter { this.reactiveTools.size || this.permissions.size) ) { + if (!this.reactiveEnd) + this.canResolveAsDaemonOnly = + last && !this.pendingWakeup && !this.permissions.size; this.reactiveEnd = true; this.finishReactiveTurn(); return; @@ -776,6 +782,25 @@ export class Acp implements Adapter { recoverable: false, }); } + private reactiveToolChanged() { + if (!this.reactiveEnd || this.cancelling) return; + if ( + this.canResolveAsDaemonOnly && + !this.openPrompts && + !this.reactiveTools.size + ) { + // The original end_turn is authoritative when every tool that + // blocked it was subsequently identified as a daemon. + clearTimeout(this.reactiveIdle); + clearTimeout(this.reactiveWatchdog); + this.reactiveWatchdog = undefined; + this.terminalReported = true; + this.active = false; + this.emit({ type: "status", status: "completed", recoverable: true }); + return; + } + this.finishReactiveTurn(); + } private addUsage(result: unknown) { if (!this.reportsUsage) return; const usage = z @@ -1217,6 +1242,7 @@ export class Acp implements Adapter { if (!choices.length) return Promise.resolve({ outcome: { outcome: "cancelled" } }); const id = randomUUID(); + this.canResolveAsDaemonOnly = false; clearTimeout(this.reactiveIdle); if (this.reactiveWatchdog) this.reactiveBudget = Math.max( @@ -1295,7 +1321,7 @@ export class Acp implements Adapter { } if (u.sessionUpdate === "agent_message_chunk") { if (!this.loading && u.content.type === "text") { - if (u.content.text.trim()) this.pendingWakeup = false; + this.canResolveAsDaemonOnly = false; this.emit({ type: "delta", id: this.messageId, @@ -1310,6 +1336,7 @@ export class Acp implements Adapter { this.reactiveEnd && !this.cancelling ) { + this.canResolveAsDaemonOnly = false; this.finishReactiveTurn(); return; } @@ -1361,6 +1388,8 @@ export class Acp implements Adapter { } if (daemon || u.status === "completed" || u.status === "failed") { reactiveWorkChanged = this.reactiveTools.delete(u.toolCallId); + if (reactiveWorkChanged && !daemon) + this.canResolveAsDaemonOnly = false; // A background-capable call can settle just before the response // that yielded to it. Keep watching until the model answers again. const delay = this.backgroundTools.get(u.toolCallId); @@ -1376,6 +1405,7 @@ export class Acp implements Adapter { ) this.pendingWakeup = true; } else if (u.sessionUpdate === "tool_call") { + this.canResolveAsDaemonOnly = false; this.reactiveTools.add(u.toolCallId); reactiveWorkChanged = true; } @@ -1394,8 +1424,7 @@ export class Acp implements Adapter { }; this.toolItems.set(u.toolCallId, item); this.emit({ type: "item", item }); - if (reactiveWorkChanged && this.reactiveEnd && !this.cancelling) - this.finishReactiveTurn(); + if (reactiveWorkChanged) this.reactiveToolChanged(); return; } const kind = u.kind ?? this.toolKinds.get(u.toolCallId); @@ -1614,8 +1643,7 @@ export class Acp implements Adapter { }, this.loading, ); - if (reactiveWorkChanged && this.reactiveEnd && !this.cancelling) - this.finishReactiveTurn(); + if (reactiveWorkChanged) this.reactiveToolChanged(); return; } if (u.sessionUpdate === "plan") { diff --git a/src/adapters/antigravity.ts b/src/adapters/antigravity.ts index 88da91e7..2fca7243 100644 --- a/src/adapters/antigravity.ts +++ b/src/adapters/antigravity.ts @@ -208,6 +208,7 @@ export class Antigravity implements Adapter { } canReuse(registration: Options) { return ( + this.reusable !== false && meetsMinimum(registration.version, ANTIGRAVITY_ACP_MINIMUM_VERSION) === this.adapter instanceof Acp && meetsMinimum( diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index 9c81b61a..eb635b59 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -72,19 +72,20 @@ test("Antigravity waits through successive reactive passes and approvals", async await assert.rejects(adapter.prompt("Next turn"), /busy/); }); -test("Antigravity completes normally with only a daemon still running", async (t) => { - fixture(t); - process.env.LOOP_TEST_AGY_MODE = "daemon-only"; - const events: AdapterEvent[] = []; - const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => - events.push(e), - ); - t.after(() => adapter.dispose()); - await adapter.start(); - await adapter.prompt("Start a daemon"); - await until(() => complete(events).length === 1); - assert.deepEqual(statuses(events), ["ready", "completed"]); -}); +for (const mode of ["daemon-only", "reactive-late-daemon"]) + test(`Antigravity completes normally with only a daemon still running in ${mode}`, async (t) => { + fixture(t); + process.env.LOOP_TEST_AGY_MODE = mode; + const events: AdapterEvent[] = []; + const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => + events.push(e), + ); + t.after(() => adapter.dispose()); + await adapter.start(); + await adapter.prompt("Start a daemon"); + await until(() => complete(events).length === 1); + assert.deepEqual(statuses(events), ["ready", "completed"]); + }); test("Antigravity keeps accepting reactive output after overlapping prompts end", async (t) => { const requests = fixture(t); @@ -128,7 +129,9 @@ for (const mode of ["reactive-before-end", "reactive-sync-answer"]) else assert.deepEqual(statuses(events), ["ready"]); assert.deepEqual( events.flatMap((e) => (e.type === "delta" ? [e.text] : [])), - ["Waiting.", "Done."], + mode === "reactive-before-end" + ? ["Waiting.", "Waiting for the wakeup.", "Done."] + : ["Waiting.", "Done."], ); }); @@ -158,6 +161,7 @@ test("Antigravity retires the live session when a steering limit interrupts reac await assert.rejects(adapter.steer!("Keep going"), /max_tokens/); assert.deepEqual(statuses(events), ["ready", "interrupted"]); assert.equal(adapter.reusable, false); + assert.equal(adapter.canReuse({ ...options, version: "1.5.14" }), false); await assert.rejects(adapter.prompt("Next turn"), /unavailable/); }); diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index ef74ea5a..a983496d 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -153,6 +153,18 @@ function reactiveTurn(sessionId, mode) { const reportUsage = () => update(sessionId, { sessionUpdate: "usage_update", used: 20, size: 100 }); + if (mode === "reactive-late-daemon") { + tool("daemon", undefined, "sleep 90"); + message("Daemon started."); + finish(sessionId); + update(sessionId, { + sessionUpdate: "tool_call_update", + toolCallId: "daemon", + status: "in_progress", + rawInput: { CommandLine: "sleep 90", IsDaemon: true }, + }); + return; + } tool("daemon", { CommandLine: "sleep 90", IsDaemon: true }, "sleep 90"); if (mode !== "daemon-only") tool( @@ -183,6 +195,7 @@ function reactiveTurn(sessionId, mode) { if (mode === "reactive-sync-answer") message("Done."); finish(sessionId); } else { + message("Waiting for the wakeup."); finish(sessionId); reportUsage(); // A settled tool still has a pending wakeup. setTimeout(() => { From 1d566cd1c3db6c2b5b3500cde0b21cca2b055afe Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 10:36:15 +0000 Subject: [PATCH 12/31] Handle synchronous tools and daemon-only steers --- src/adapters/acp.ts | 18 ++++++------- test/antigravity-steering.node.test.ts | 20 +++++++++++--- test/fixtures/fake-antigravity-steering.mjs | 29 ++++++++++++++++----- 3 files changed, 47 insertions(+), 20 deletions(-) diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index 64bb25ed..e55798ac 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -652,6 +652,12 @@ export class Acp implements Adapter { if (this.closed || this.terminalReported) return; if (result.stopReason === "end_turn") { if (!last) this.earlierEnd = true; + if ( + this.canResolveAsDaemonOnly && + !this.reactiveTools.size && + !this.permissions.size + ) + this.reactiveEnd = false; // Antigravity gives reactive passes no definitive end signal. // Preserve their output as partial instead of publishing it // based on usage, steering replies, or elapsed time. @@ -665,7 +671,7 @@ export class Acp implements Adapter { ) { if (!this.reactiveEnd) this.canResolveAsDaemonOnly = - last && !this.pendingWakeup && !this.permissions.size; + !this.pendingWakeup && !this.permissions.size; this.reactiveEnd = true; this.finishReactiveTurn(); return; @@ -748,7 +754,7 @@ export class Acp implements Adapter { // The reactive wait stays bounded even if a concurrent steer never // answers. Human approval time does not count against the watchdog. if (!this.reactiveWatchdog) { - this.reactiveWatchdogStarted = Date.now(); + this.reactiveWatchdogStarted = performance.now(); this.reactiveWatchdog = setTimeout( () => this.interruptReactiveTurn( @@ -1248,7 +1254,7 @@ export class Acp implements Adapter { this.reactiveBudget = Math.max( 0, this.reactiveBudget - - Math.max(0, Date.now() - this.reactiveWatchdogStarted), + (performance.now() - this.reactiveWatchdogStarted), ); clearTimeout(this.reactiveWatchdog); this.reactiveWatchdog = undefined; @@ -1379,12 +1385,6 @@ export class Acp implements Adapter { input.WaitMsBeforeAsync >= 0 ) this.backgroundTools.set(u.toolCallId, input.WaitMsBeforeAsync); - else if ( - title === "invoke_subagent" || - title === "schedule" || - title === "run_workflow" - ) - this.backgroundTools.set(u.toolCallId, 0); } if (daemon || u.status === "completed" || u.status === "failed") { reactiveWorkChanged = this.reactiveTools.delete(u.toolCallId); diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index eb635b59..6446af7e 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -72,7 +72,11 @@ test("Antigravity waits through successive reactive passes and approvals", async await assert.rejects(adapter.prompt("Next turn"), /busy/); }); -for (const mode of ["daemon-only", "reactive-late-daemon"]) +for (const mode of [ + "daemon-only", + "reactive-late-daemon", + "reactive-steer-daemon", +]) test(`Antigravity completes normally with only a daemon still running in ${mode}`, async (t) => { fixture(t); process.env.LOOP_TEST_AGY_MODE = mode; @@ -83,6 +87,7 @@ for (const mode of ["daemon-only", "reactive-late-daemon"]) t.after(() => adapter.dispose()); await adapter.start(); await adapter.prompt("Start a daemon"); + if (mode === "reactive-steer-daemon") await adapter.steer!("Keep going"); await until(() => complete(events).length === 1); assert.deepEqual(statuses(events), ["ready", "completed"]); }); @@ -110,7 +115,11 @@ test("Antigravity keeps accepting reactive output after overlapping prompts end" assert.deepEqual(prompts(requests), ["Run background work", "Keep going"]); }); -for (const mode of ["reactive-before-end", "reactive-sync-answer"]) +for (const mode of [ + "reactive-before-end", + "reactive-sync-answer", + "reactive-sync-subagent", +]) test(`Antigravity handles an async-capable tool that settles before end_turn in ${mode}`, async (t) => { fixture(t); process.env.LOOP_TEST_AGY_MODE = mode; @@ -124,14 +133,16 @@ for (const mode of ["reactive-before-end", "reactive-sync-answer"]) await until(() => events.some((e) => e.type === "delta" && e.text === "Done."), ); - if (mode === "reactive-sync-answer") + if (mode !== "reactive-before-end") await until(() => complete(events).length === 1); else assert.deepEqual(statuses(events), ["ready"]); assert.deepEqual( events.flatMap((e) => (e.type === "delta" ? [e.text] : [])), mode === "reactive-before-end" ? ["Waiting.", "Waiting for the wakeup.", "Done."] - : ["Waiting.", "Done."], + : mode === "reactive-sync-subagent" + ? ["Done."] + : ["Waiting.", "Done."], ); }); @@ -295,6 +306,7 @@ test( t.after(() => adapter.dispose()); await adapter.start(); t.mock.timers.enable({ apis: ["setTimeout", "Date"] }); + t.mock.method(performance, "now", () => Date.now()); try { await adapter.prompt("Run background work"); await promptEnded; diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index a983496d..b321efe5 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -153,16 +153,31 @@ function reactiveTurn(sessionId, mode) { const reportUsage = () => update(sessionId, { sessionUpdate: "usage_update", used: 20, size: 100 }); - if (mode === "reactive-late-daemon") { + if (["reactive-late-daemon", "reactive-steer-daemon"].includes(mode)) { tool("daemon", undefined, "sleep 90"); message("Daemon started."); + const identifyDaemon = () => { + finish(sessionId); + update(sessionId, { + sessionUpdate: "tool_call_update", + toolCallId: "daemon", + status: "in_progress", + rawInput: { CommandLine: "sleep 90", IsDaemon: true }, + }); + }; + if (mode === "reactive-steer-daemon") + endReactiveSteer = (request) => { + identifyDaemon(); + reply(request.id, { stopReason: "end_turn" }); + }; + else identifyDaemon(); + return; + } + if (mode === "reactive-sync-subagent") { + tool("subagent", {}, "invoke_subagent"); + complete("subagent"); + message("Done."); finish(sessionId); - update(sessionId, { - sessionUpdate: "tool_call_update", - toolCallId: "daemon", - status: "in_progress", - rawInput: { CommandLine: "sleep 90", IsDaemon: true }, - }); return; } tool("daemon", { CommandLine: "sleep 90", IsDaemon: true }, "sleep 90"); From f6db254892a5406e39d470bf1344b92c6111b95c Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 10:39:05 +0000 Subject: [PATCH 13/31] Keep daemon-only completion when a steer is rejected --- src/adapters/acp.ts | 47 +++++++++------------ test/antigravity-steering.node.test.ts | 3 ++ test/fixtures/fake-antigravity-steering.mjs | 17 ++++++-- 3 files changed, 37 insertions(+), 30 deletions(-) diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index e55798ac..261e8e23 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -652,12 +652,6 @@ export class Acp implements Adapter { if (this.closed || this.terminalReported) return; if (result.stopReason === "end_turn") { if (!last) this.earlierEnd = true; - if ( - this.canResolveAsDaemonOnly && - !this.reactiveTools.size && - !this.permissions.size - ) - this.reactiveEnd = false; // Antigravity gives reactive passes no definitive end signal. // Preserve their output as partial instead of publishing it // based on usage, steering replies, or elapsed time. @@ -751,6 +745,22 @@ export class Acp implements Adapter { return; } if (this.permissions.size) return; + if ( + this.canResolveAsDaemonOnly && + !this.pendingWakeup && + !this.openPrompts && + !this.reactiveTools.size + ) { + // The original end_turn is authoritative when every tool that + // blocked it was subsequently identified as a daemon. + clearTimeout(this.reactiveIdle); + clearTimeout(this.reactiveWatchdog); + this.reactiveWatchdog = undefined; + this.terminalReported = true; + this.active = false; + this.emit({ type: "status", status: "completed", recoverable: true }); + return; + } // The reactive wait stays bounded even if a concurrent steer never // answers. Human approval time does not count against the watchdog. if (!this.reactiveWatchdog) { @@ -788,25 +798,6 @@ export class Acp implements Adapter { recoverable: false, }); } - private reactiveToolChanged() { - if (!this.reactiveEnd || this.cancelling) return; - if ( - this.canResolveAsDaemonOnly && - !this.openPrompts && - !this.reactiveTools.size - ) { - // The original end_turn is authoritative when every tool that - // blocked it was subsequently identified as a daemon. - clearTimeout(this.reactiveIdle); - clearTimeout(this.reactiveWatchdog); - this.reactiveWatchdog = undefined; - this.terminalReported = true; - this.active = false; - this.emit({ type: "status", status: "completed", recoverable: true }); - return; - } - this.finishReactiveTurn(); - } private addUsage(result: unknown) { if (!this.reportsUsage) return; const usage = z @@ -1424,7 +1415,8 @@ export class Acp implements Adapter { }; this.toolItems.set(u.toolCallId, item); this.emit({ type: "item", item }); - if (reactiveWorkChanged) this.reactiveToolChanged(); + if (reactiveWorkChanged && this.reactiveEnd && !this.cancelling) + this.finishReactiveTurn(); return; } const kind = u.kind ?? this.toolKinds.get(u.toolCallId); @@ -1643,7 +1635,8 @@ export class Acp implements Adapter { }, this.loading, ); - if (reactiveWorkChanged) this.reactiveToolChanged(); + if (reactiveWorkChanged && this.reactiveEnd && !this.cancelling) + this.finishReactiveTurn(); return; } if (u.sessionUpdate === "plan") { diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index 6446af7e..7ea76153 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -76,6 +76,7 @@ for (const mode of [ "daemon-only", "reactive-late-daemon", "reactive-steer-daemon", + "reactive-rejected-steer-daemon", ]) test(`Antigravity completes normally with only a daemon still running in ${mode}`, async (t) => { fixture(t); @@ -88,6 +89,8 @@ for (const mode of [ await adapter.start(); await adapter.prompt("Start a daemon"); if (mode === "reactive-steer-daemon") await adapter.steer!("Keep going"); + if (mode === "reactive-rejected-steer-daemon") + await assert.rejects(adapter.steer!("Keep going"), /Steer rejected/); await until(() => complete(events).length === 1); assert.deepEqual(statuses(events), ["ready", "completed"]); }); diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index b321efe5..cdb89db0 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -153,7 +153,13 @@ function reactiveTurn(sessionId, mode) { const reportUsage = () => update(sessionId, { sessionUpdate: "usage_update", used: 20, size: 100 }); - if (["reactive-late-daemon", "reactive-steer-daemon"].includes(mode)) { + if ( + [ + "reactive-late-daemon", + "reactive-steer-daemon", + "reactive-rejected-steer-daemon", + ].includes(mode) + ) { tool("daemon", undefined, "sleep 90"); message("Daemon started."); const identifyDaemon = () => { @@ -165,10 +171,15 @@ function reactiveTurn(sessionId, mode) { rawInput: { CommandLine: "sleep 90", IsDaemon: true }, }); }; - if (mode === "reactive-steer-daemon") + if (mode !== "reactive-late-daemon") endReactiveSteer = (request) => { identifyDaemon(); - reply(request.id, { stopReason: "end_turn" }); + if (mode === "reactive-rejected-steer-daemon") + send({ + id: request.id, + error: { code: -32603, message: "Steer rejected" }, + }); + else reply(request.id, { stopReason: "end_turn" }); }; else identifyDaemon(); return; From 2a715f2a57bde8a6ee23a49c42c38c761e5125e8 Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 10:42:03 +0000 Subject: [PATCH 14/31] Recheck reactive work before completing a rejected steer --- src/adapters/acp.ts | 47 ++++++++++++--------- test/antigravity-steering.node.test.ts | 47 +++++++++++---------- test/fixtures/fake-antigravity-steering.mjs | 17 ++++++++ 3 files changed, 70 insertions(+), 41 deletions(-) diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index 261e8e23..64789b49 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -655,21 +655,7 @@ export class Acp implements Adapter { // Antigravity gives reactive passes no definitive end signal. // Preserve their output as partial instead of publishing it // based on usage, steering replies, or elapsed time. - if ( - !this.cancelling && - this.waitsForReactiveTurns && - (this.reactiveEnd || - this.pendingWakeup || - this.reactiveTools.size || - this.permissions.size) - ) { - if (!this.reactiveEnd) - this.canResolveAsDaemonOnly = - !this.pendingWakeup && !this.permissions.size; - this.reactiveEnd = true; - this.finishReactiveTurn(); - return; - } + if (this.waitForReactiveTurn()) return; } if (!last) return; this.terminalReported = true; @@ -700,13 +686,17 @@ export class Acp implements Adapter { if (!last || this.closed || this.terminalReported) return; // A rejected steering input that never joined the turn does not // undo the turn's own normal end. - if ( - this.reactiveEnd && - (this.cancelling || (steer && !this.steerJoined)) - ) { + if (this.reactiveEnd && this.cancelling) { this.finishReactiveTurn(); return; } + if ( + steer && + !this.steerJoined && + (this.earlierEnd || this.reactiveEnd) && + this.waitForReactiveTurn() + ) + return; this.terminalReported = true; if (steer && !this.steerJoined && this.earlierEnd) { this.emit({ @@ -737,6 +727,25 @@ export class Acp implements Adapter { }); return request; } + private waitForReactiveTurn() { + if ( + this.cancelling || + !this.waitsForReactiveTurns || + !( + this.reactiveEnd || + this.pendingWakeup || + this.reactiveTools.size || + this.permissions.size + ) + ) + return false; + if (!this.reactiveEnd) + this.canResolveAsDaemonOnly = + !this.pendingWakeup && !this.permissions.size; + this.reactiveEnd = true; + this.finishReactiveTurn(); + return true; + } private finishReactiveTurn() { clearTimeout(this.reactiveIdle); if (this.closed || this.terminalReported || !this.reactiveEnd) return; diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index 7ea76153..232a4cff 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -95,28 +95,31 @@ for (const mode of [ assert.deepEqual(statuses(events), ["ready", "completed"]); }); -test("Antigravity keeps accepting reactive output after overlapping prompts end", async (t) => { - const requests = fixture(t); - process.env.LOOP_TEST_AGY_MODE = "reactive-steering"; - const events: AdapterEvent[] = []; - const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => - events.push(e), - ); - t.after(() => adapter.dispose()); - await adapter.start(); - await adapter.prompt("Run background work"); - await until(() => events.some((e) => e.type === "delta")); - await adapter.steer!("Keep going"); - await until(() => - events.some((e) => e.type === "delta" && e.text === "Done."), - ); - assert.deepEqual(statuses(events), ["ready"]); - assert.deepEqual( - events.flatMap((e) => (e.type === "delta" ? [e.text] : [])), - ["Waiting.", "Done."], - ); - assert.deepEqual(prompts(requests), ["Run background work", "Keep going"]); -}); +for (const mode of ["reactive-steering", "reactive-rejected-steer-late-tool"]) + test(`Antigravity keeps accepting output after overlapping prompts in ${mode}`, async (t) => { + const requests = fixture(t); + process.env.LOOP_TEST_AGY_MODE = mode; + const events: AdapterEvent[] = []; + const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => + events.push(e), + ); + t.after(() => adapter.dispose()); + await adapter.start(); + await adapter.prompt("Run background work"); + await until(() => events.some((e) => e.type === "delta")); + if (mode === "reactive-rejected-steer-late-tool") + await assert.rejects(adapter.steer!("Keep going"), /Steer rejected/); + else await adapter.steer!("Keep going"); + await until(() => + events.some((e) => e.type === "delta" && e.text === "Done."), + ); + assert.deepEqual(statuses(events), ["ready"]); + assert.deepEqual( + events.flatMap((e) => (e.type === "delta" ? [e.text] : [])), + ["Waiting.", "Done."], + ); + assert.deepEqual(prompts(requests), ["Run background work", "Keep going"]); + }); for (const mode of [ "reactive-before-end", diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index cdb89db0..89e227e0 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -153,6 +153,23 @@ function reactiveTurn(sessionId, mode) { const reportUsage = () => update(sessionId, { sessionUpdate: "usage_update", used: 20, size: 100 }); + if (mode === "reactive-rejected-steer-late-tool") { + message("Waiting."); + endReactiveSteer = (request) => { + finish(sessionId); + tool("late-background", { CommandLine: "sleep 5" }, "sleep 5"); + send({ + id: request.id, + error: { code: -32603, message: "Steer rejected" }, + }); + setTimeout(() => { + complete("late-background"); + message("Done."); + reportUsage(); + }, 30); + }; + return; + } if ( [ "reactive-late-daemon", From 54dbc0570a9c29c8773f204f3c36afd96183cd03 Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 10:46:22 +0000 Subject: [PATCH 15/31] Limit reactive waiting to outstanding work --- docs/harnesses.md | 2 +- src/adapters/acp.ts | 62 ++------------------- test/antigravity-steering.node.test.ts | 18 ++---- test/fixtures/fake-antigravity-steering.mjs | 41 +++++--------- 4 files changed, 24 insertions(+), 99 deletions(-) diff --git a/docs/harnesses.md b/docs/harnesses.md index 5741fd23..d6425940 100644 --- a/docs/harnesses.md +++ b/docs/harnesses.md @@ -94,7 +94,7 @@ Install [Antigravity CLI](https://antigravity.google/docs/getting-started?tab=cl With **Antigravity CLI 1.5.9 or newer**, Loop uses the documented [ACP interface](https://antigravity.google/docs/ide/extensions/acp), launched with `agy acp --process-per-session`. Each native session receives its own authenticated Loop MCP connection through ACP session creation or resuming. This enables Agent mail, team delegation and Loop tool integrations without editing global or project MCP configuration. ACP must advertise HTTP MCP support; setup fails before sending a prompt if it does not. Enable Antigravity again after upgrading the CLI so Loop refreshes its saved runtime version and capabilities. Existing streaming sessions switch to ACP on their next turn; refreshing does not interrupt a running turn. See [session reuse](state-machines.md#companion_sessionsstate). -When Antigravity returns `end_turn` while background work is still pending, Loop keeps receiving output and approvals. Antigravity can send usage updates both during the continuation and after its final text. Until ACP supplies a definitive completion signal, Loop bounds that wait and interrupts the run with its partial output preserved in the conversation trace. This can leave a successful background continuation without a published Result. Explicit daemons can outlive ordinary completed turns. See the [upstream ACP discussion](https://github.com/google-antigravity/antigravity-cli/issues/1461). +When Antigravity returns `end_turn` while a tool call or approval is still open, Loop keeps receiving output and approvals. A tool that has already reported a terminal status cannot establish that another wakeup is pending. Antigravity can send usage updates both during a continuation and after its final text. Until ACP supplies a definitive completion signal, Loop bounds the wait and interrupts the run with its partial output preserved in the conversation trace. This can leave a successful background continuation without a published Result. Explicit daemons can outlive ordinary completed turns. See the [upstream ACP discussion](https://github.com/google-antigravity/antigravity-cli/issues/1461). Model discovery and session initialization send no model prompt. Saved instructions accompany explicit prompts, and interrupted tasks are never automatically replayed. Existing native conversation IDs and workspace bindings are retained when a newer runtime resumes a conversation created by the streaming adapter. Commands and skills come from the session’s ACP catalog. Catalog probes and slash-leading prompts or live replies wait up to five seconds for that catalog. A discovered command stays at the start of an explicit prompt, followed by saved instructions; other slash-leading text stays literal, including when discovery times out. Saved instructions starting with `/` also stay literal. The model catalog comes from ACP; if the account no longer offers a previously selected model through that interface, select an available model explicitly. Loop does not choose a replacement model after failure. diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index 64789b49..a0c0b7f6 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -146,9 +146,6 @@ export class Acp implements Adapter { /** agy can return end_turn before its background work wakes the model. */ protected waitsForReactiveTurns = false; private reactiveTools = new Set(); - private backgroundTools = new Map(); - private toolStartedAt = new Map(); - private pendingWakeup = false; private reactiveEnd = false; private canResolveAsDaemonOnly = false; private reactiveIdle?: NodeJS.Timeout; @@ -616,9 +613,6 @@ export class Acp implements Adapter { this.turnUsage = undefined; this.earlierEnd = false; this.reactiveTools.clear(); - this.backgroundTools.clear(); - this.toolStartedAt.clear(); - this.pendingWakeup = false; this.reactiveEnd = false; this.canResolveAsDaemonOnly = false; this.reactiveBudget = REACTIVE_WATCHDOG_MS; @@ -667,10 +661,7 @@ export class Acp implements Adapter { this.reactiveEnd || limited || result.stopReason === "cancelled"; - if ( - interrupted && - (this.reactiveEnd || this.pendingWakeup || this.reactiveTools.size) - ) + if (interrupted && (this.reactiveEnd || this.reactiveTools.size)) this.retireReactiveSession = true; this.emit({ type: "status", @@ -731,17 +722,10 @@ export class Acp implements Adapter { if ( this.cancelling || !this.waitsForReactiveTurns || - !( - this.reactiveEnd || - this.pendingWakeup || - this.reactiveTools.size || - this.permissions.size - ) + !(this.reactiveEnd || this.reactiveTools.size || this.permissions.size) ) return false; - if (!this.reactiveEnd) - this.canResolveAsDaemonOnly = - !this.pendingWakeup && !this.permissions.size; + if (!this.reactiveEnd) this.canResolveAsDaemonOnly = !this.permissions.size; this.reactiveEnd = true; this.finishReactiveTurn(); return true; @@ -756,7 +740,6 @@ export class Acp implements Adapter { if (this.permissions.size) return; if ( this.canResolveAsDaemonOnly && - !this.pendingWakeup && !this.openPrompts && !this.reactiveTools.size ) { @@ -1327,7 +1310,7 @@ export class Acp implements Adapter { } if (u.sessionUpdate === "agent_message_chunk") { if (!this.loading && u.content.type === "text") { - this.canResolveAsDaemonOnly = false; + if (!this.openPrompts) this.canResolveAsDaemonOnly = false; this.emit({ type: "delta", id: this.messageId, @@ -1342,7 +1325,7 @@ export class Acp implements Adapter { this.reactiveEnd && !this.cancelling ) { - this.canResolveAsDaemonOnly = false; + if (!this.openPrompts) this.canResolveAsDaemonOnly = false; this.finishReactiveTurn(); return; } @@ -1365,45 +1348,10 @@ export class Acp implements Adapter { typeof input === "object" && "IsDaemon" in input && input.IsDaemon === true; - const knownTool = - u.sessionUpdate === "tool_call" || - this.reactiveTools.has(u.toolCallId); - if (knownTool && !daemon) { - if (u.status === "pending") this.toolStartedAt.delete(u.toolCallId); - if ( - u.status === "in_progress" && - !this.toolStartedAt.has(u.toolCallId) - ) - this.toolStartedAt.set(u.toolCallId, performance.now()); - if ( - (command || title === "run_command") && - input && - typeof input === "object" && - "WaitMsBeforeAsync" in input && - typeof input.WaitMsBeforeAsync === "number" && - Number.isFinite(input.WaitMsBeforeAsync) && - input.WaitMsBeforeAsync >= 0 - ) - this.backgroundTools.set(u.toolCallId, input.WaitMsBeforeAsync); - } if (daemon || u.status === "completed" || u.status === "failed") { reactiveWorkChanged = this.reactiveTools.delete(u.toolCallId); if (reactiveWorkChanged && !daemon) this.canResolveAsDaemonOnly = false; - // A background-capable call can settle just before the response - // that yielded to it. Keep watching until the model answers again. - const delay = this.backgroundTools.get(u.toolCallId); - const startedAt = this.toolStartedAt.get(u.toolCallId); - this.backgroundTools.delete(u.toolCallId); - this.toolStartedAt.delete(u.toolCallId); - if ( - !daemon && - delay !== undefined && - (delay === 0 || - (startedAt !== undefined && - performance.now() - startedAt >= delay)) - ) - this.pendingWakeup = true; } else if (u.sessionUpdate === "tool_call") { this.canResolveAsDaemonOnly = false; this.reactiveTools.add(u.toolCallId); diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index 232a4cff..bb99bedb 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -93,6 +93,8 @@ for (const mode of [ await assert.rejects(adapter.steer!("Keep going"), /Steer rejected/); await until(() => complete(events).length === 1); assert.deepEqual(statuses(events), ["ready", "completed"]); + if (mode === "reactive-steer-daemon") + assert(events.some((e) => e.type === "delta" && e.text === "Done.")); }); for (const mode of ["reactive-steering", "reactive-rejected-steer-late-tool"]) @@ -121,11 +123,7 @@ for (const mode of ["reactive-steering", "reactive-rejected-steer-late-tool"]) assert.deepEqual(prompts(requests), ["Run background work", "Keep going"]); }); -for (const mode of [ - "reactive-before-end", - "reactive-sync-answer", - "reactive-sync-subagent", -]) +for (const mode of ["reactive-sync-answer", "reactive-sync-subagent"]) test(`Antigravity handles an async-capable tool that settles before end_turn in ${mode}`, async (t) => { fixture(t); process.env.LOOP_TEST_AGY_MODE = mode; @@ -139,16 +137,10 @@ for (const mode of [ await until(() => events.some((e) => e.type === "delta" && e.text === "Done."), ); - if (mode !== "reactive-before-end") - await until(() => complete(events).length === 1); - else assert.deepEqual(statuses(events), ["ready"]); + await until(() => complete(events).length === 1); assert.deepEqual( events.flatMap((e) => (e.type === "delta" ? [e.text] : [])), - mode === "reactive-before-end" - ? ["Waiting.", "Waiting for the wakeup.", "Done."] - : mode === "reactive-sync-subagent" - ? ["Done."] - : ["Waiting.", "Done."], + mode === "reactive-sync-subagent" ? ["Done."] : ["Waiting.", "Done."], ); }); diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index 89e227e0..f36962d2 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -196,7 +196,10 @@ function reactiveTurn(sessionId, mode) { id: request.id, error: { code: -32603, message: "Steer rejected" }, }); - else reply(request.id, { stopReason: "end_turn" }); + else { + message("Done."); + reply(request.id, { stopReason: "end_turn" }); + } }; else identifyDaemon(); return; @@ -212,40 +215,22 @@ function reactiveTurn(sessionId, mode) { if (mode !== "daemon-only") tool( "background", - mode === "reactive-before-end" - ? undefined - : { - CommandLine: "sleep 5", - IsDaemon: false, - WaitMsBeforeAsync: 500, - }, + { + CommandLine: "sleep 5", + IsDaemon: false, + WaitMsBeforeAsync: 500, + }, "run_command", ); message(mode === "daemon-only" ? "Daemon started." : "Waiting."); reportUsage(); - if ( - [ - "reactive-before-end", - "reactive-sync-answer", - "reactive-tool-only", - ].includes(mode) - ) { + if (["reactive-sync-answer", "reactive-tool-only"].includes(mode)) { complete("background", "completed", { CommandLine: "sleep 5", - WaitMsBeforeAsync: mode === "reactive-before-end" ? 0 : 500, + WaitMsBeforeAsync: 500, }); - if (mode !== "reactive-before-end") { - if (mode === "reactive-sync-answer") message("Done."); - finish(sessionId); - } else { - message("Waiting for the wakeup."); - finish(sessionId); - reportUsage(); // A settled tool still has a pending wakeup. - setTimeout(() => { - message("Done."); - reportUsage(); - }, 30); - } + if (mode === "reactive-sync-answer") message("Done."); + finish(sessionId); return; } if (mode === "reactive-steer-limit") { From f74f1764fb5a35a95e3ed1af53f6fe4ab24dc325 Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 10:49:19 +0000 Subject: [PATCH 16/31] Keep reactive work observed during unjoined steering --- src/adapters/acp.ts | 12 ++++++++++-- test/antigravity-steering.node.test.ts | 13 ++++++++++--- test/fixtures/fake-antigravity-steering.mjs | 21 ++++++++++++++++++--- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index a0c0b7f6..d1b4f810 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -1246,6 +1246,8 @@ export class Acp implements Adapter { choices: new Set(choices.map((choice) => choice.optionId)), resolve, }); + if (this.earlierEnd && !this.reactiveEnd && !this.steerJoined) + this.waitForReactiveTurn(); this.emit({ type: "request", request: { @@ -1310,7 +1312,8 @@ export class Acp implements Adapter { } if (u.sessionUpdate === "agent_message_chunk") { if (!this.loading && u.content.type === "text") { - if (!this.openPrompts) this.canResolveAsDaemonOnly = false; + if (!this.openPrompts || !this.steerJoined) + this.canResolveAsDaemonOnly = false; this.emit({ type: "delta", id: this.messageId, @@ -1325,7 +1328,8 @@ export class Acp implements Adapter { this.reactiveEnd && !this.cancelling ) { - if (!this.openPrompts) this.canResolveAsDaemonOnly = false; + if (!this.openPrompts || !this.steerJoined) + this.canResolveAsDaemonOnly = false; this.finishReactiveTurn(); return; } @@ -1355,6 +1359,10 @@ export class Acp implements Adapter { } else if (u.sessionUpdate === "tool_call") { this.canResolveAsDaemonOnly = false; this.reactiveTools.add(u.toolCallId); + if (this.earlierEnd && !this.reactiveEnd && !this.steerJoined) { + this.waitForReactiveTurn(); + this.canResolveAsDaemonOnly = false; + } reactiveWorkChanged = true; } } diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index bb99bedb..673b1549 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -97,7 +97,12 @@ for (const mode of [ assert(events.some((e) => e.type === "delta" && e.text === "Done.")); }); -for (const mode of ["reactive-steering", "reactive-rejected-steer-late-tool"]) +for (const mode of [ + "reactive-steering", + "reactive-rejected-steer-late-tool", + "reactive-rejected-steer-settled-tool", + "reactive-daemon-unechoed-steer-output", +]) test(`Antigravity keeps accepting output after overlapping prompts in ${mode}`, async (t) => { const requests = fixture(t); process.env.LOOP_TEST_AGY_MODE = mode; @@ -109,7 +114,7 @@ for (const mode of ["reactive-steering", "reactive-rejected-steer-late-tool"]) await adapter.start(); await adapter.prompt("Run background work"); await until(() => events.some((e) => e.type === "delta")); - if (mode === "reactive-rejected-steer-late-tool") + if (mode !== "reactive-steering") await assert.rejects(adapter.steer!("Keep going"), /Steer rejected/); else await adapter.steer!("Keep going"); await until(() => @@ -118,7 +123,9 @@ for (const mode of ["reactive-steering", "reactive-rejected-steer-late-tool"]) assert.deepEqual(statuses(events), ["ready"]); assert.deepEqual( events.flatMap((e) => (e.type === "delta" ? [e.text] : [])), - ["Waiting.", "Done."], + mode === "reactive-daemon-unechoed-steer-output" + ? ["Daemon started.", "Waiting.", "Done."] + : ["Waiting.", "Done."], ); assert.deepEqual(prompts(requests), ["Run background work", "Keep going"]); }); diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index f36962d2..1d1de334 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -153,17 +153,23 @@ function reactiveTurn(sessionId, mode) { const reportUsage = () => update(sessionId, { sessionUpdate: "usage_update", used: 20, size: 100 }); - if (mode === "reactive-rejected-steer-late-tool") { + if ( + mode === "reactive-rejected-steer-late-tool" || + mode === "reactive-rejected-steer-settled-tool" + ) { message("Waiting."); endReactiveSteer = (request) => { finish(sessionId); tool("late-background", { CommandLine: "sleep 5" }, "sleep 5"); + if (mode === "reactive-rejected-steer-settled-tool") + complete("late-background"); send({ id: request.id, error: { code: -32603, message: "Steer rejected" }, }); setTimeout(() => { - complete("late-background"); + if (mode === "reactive-rejected-steer-late-tool") + complete("late-background"); message("Done."); reportUsage(); }, 30); @@ -175,6 +181,7 @@ function reactiveTurn(sessionId, mode) { "reactive-late-daemon", "reactive-steer-daemon", "reactive-rejected-steer-daemon", + "reactive-daemon-unechoed-steer-output", ].includes(mode) ) { tool("daemon", undefined, "sleep 90"); @@ -191,12 +198,20 @@ function reactiveTurn(sessionId, mode) { if (mode !== "reactive-late-daemon") endReactiveSteer = (request) => { identifyDaemon(); - if (mode === "reactive-rejected-steer-daemon") + if (mode === "reactive-daemon-unechoed-steer-output") { + message("Waiting."); + setTimeout(() => message("Done."), 30); + } + if (mode !== "reactive-steer-daemon") send({ id: request.id, error: { code: -32603, message: "Steer rejected" }, }); else { + update(sessionId, { + sessionUpdate: "user_message_chunk", + content: { type: "text", text: request.params.prompt[0].text }, + }); message("Done."); reply(request.id, { stopReason: "end_turn" }); } From 652a78909e9bdcc55cd0e4ea7fa74e78914dc41d Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 10:53:04 +0000 Subject: [PATCH 17/31] Keep echoed steering inside the reactive boundary --- src/adapters/acp.ts | 11 ++++----- test/antigravity-steering.node.test.ts | 14 ++++++------ test/fixtures/fake-antigravity-steering.mjs | 25 +++++++++++++++------ 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index d1b4f810..78e785fd 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -1246,8 +1246,7 @@ export class Acp implements Adapter { choices: new Set(choices.map((choice) => choice.optionId)), resolve, }); - if (this.earlierEnd && !this.reactiveEnd && !this.steerJoined) - this.waitForReactiveTurn(); + if (this.earlierEnd && !this.reactiveEnd) this.waitForReactiveTurn(); this.emit({ type: "request", request: { @@ -1312,8 +1311,7 @@ export class Acp implements Adapter { } if (u.sessionUpdate === "agent_message_chunk") { if (!this.loading && u.content.type === "text") { - if (!this.openPrompts || !this.steerJoined) - this.canResolveAsDaemonOnly = false; + this.canResolveAsDaemonOnly = false; this.emit({ type: "delta", id: this.messageId, @@ -1328,8 +1326,7 @@ export class Acp implements Adapter { this.reactiveEnd && !this.cancelling ) { - if (!this.openPrompts || !this.steerJoined) - this.canResolveAsDaemonOnly = false; + this.canResolveAsDaemonOnly = false; this.finishReactiveTurn(); return; } @@ -1359,7 +1356,7 @@ export class Acp implements Adapter { } else if (u.sessionUpdate === "tool_call") { this.canResolveAsDaemonOnly = false; this.reactiveTools.add(u.toolCallId); - if (this.earlierEnd && !this.reactiveEnd && !this.steerJoined) { + if (this.earlierEnd && !this.reactiveEnd) { this.waitForReactiveTurn(); this.canResolveAsDaemonOnly = false; } diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index 673b1549..0d6d8952 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -23,7 +23,7 @@ function fixture(t: { after(fn: () => void): void }) { t.after(() => { delete process.env.LOOP_TEST_AGY_LOG; delete process.env.LOOP_TEST_AGY_MODE; - rmSync(dir, { recursive: true, force: true }); + rmSync(dir, { recursive: true, force: true, maxRetries: 3 }); }); return () => existsSync(path) @@ -75,7 +75,6 @@ test("Antigravity waits through successive reactive passes and approvals", async for (const mode of [ "daemon-only", "reactive-late-daemon", - "reactive-steer-daemon", "reactive-rejected-steer-daemon", ]) test(`Antigravity completes normally with only a daemon still running in ${mode}`, async (t) => { @@ -88,20 +87,19 @@ for (const mode of [ t.after(() => adapter.dispose()); await adapter.start(); await adapter.prompt("Start a daemon"); - if (mode === "reactive-steer-daemon") await adapter.steer!("Keep going"); if (mode === "reactive-rejected-steer-daemon") await assert.rejects(adapter.steer!("Keep going"), /Steer rejected/); await until(() => complete(events).length === 1); assert.deepEqual(statuses(events), ["ready", "completed"]); - if (mode === "reactive-steer-daemon") - assert(events.some((e) => e.type === "delta" && e.text === "Done.")); }); for (const mode of [ "reactive-steering", "reactive-rejected-steer-late-tool", "reactive-rejected-steer-settled-tool", + "reactive-echoed-steer-settled-tool", "reactive-daemon-unechoed-steer-output", + "reactive-steer-daemon", ]) test(`Antigravity keeps accepting output after overlapping prompts in ${mode}`, async (t) => { const requests = fixture(t); @@ -114,7 +112,7 @@ for (const mode of [ await adapter.start(); await adapter.prompt("Run background work"); await until(() => events.some((e) => e.type === "delta")); - if (mode !== "reactive-steering") + if (mode.includes("rejected") || mode.includes("unechoed")) await assert.rejects(adapter.steer!("Keep going"), /Steer rejected/); else await adapter.steer!("Keep going"); await until(() => @@ -125,7 +123,9 @@ for (const mode of [ events.flatMap((e) => (e.type === "delta" ? [e.text] : [])), mode === "reactive-daemon-unechoed-steer-output" ? ["Daemon started.", "Waiting.", "Done."] - : ["Waiting.", "Done."], + : mode === "reactive-steer-daemon" + ? ["Daemon started.", "Done."] + : ["Waiting.", "Done."], ); assert.deepEqual(prompts(requests), ["Run background work", "Keep going"]); }); diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index 1d1de334..43298dd3 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -154,19 +154,30 @@ function reactiveTurn(sessionId, mode) { update(sessionId, { sessionUpdate: "usage_update", used: 20, size: 100 }); if ( - mode === "reactive-rejected-steer-late-tool" || - mode === "reactive-rejected-steer-settled-tool" + [ + "reactive-rejected-steer-late-tool", + "reactive-rejected-steer-settled-tool", + "reactive-echoed-steer-settled-tool", + ].includes(mode) ) { message("Waiting."); endReactiveSteer = (request) => { + const joined = mode === "reactive-echoed-steer-settled-tool"; + if (joined) + update(sessionId, { + sessionUpdate: "user_message_chunk", + content: { type: "text", text: request.params.prompt[0].text }, + }); finish(sessionId); tool("late-background", { CommandLine: "sleep 5" }, "sleep 5"); - if (mode === "reactive-rejected-steer-settled-tool") + if (mode !== "reactive-rejected-steer-late-tool") complete("late-background"); - send({ - id: request.id, - error: { code: -32603, message: "Steer rejected" }, - }); + if (joined) reply(request.id, { stopReason: "end_turn" }); + else + send({ + id: request.id, + error: { code: -32603, message: "Steer rejected" }, + }); setTimeout(() => { if (mode === "reactive-rejected-steer-late-tool") complete("late-background"); From 42d6d3ba7edd683a0f66743fed45ca884c46aa1f Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 10:55:53 +0000 Subject: [PATCH 18/31] Handle daemon identification and launch failures during reactive waiting --- src/adapters/acp.ts | 7 ++----- test/antigravity-steering.node.test.ts | 19 +++++++++++++++++++ test/fixtures/fake-antigravity-steering.mjs | 18 ++++++++++++++---- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index 78e785fd..41219861 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -1351,15 +1351,12 @@ export class Acp implements Adapter { input.IsDaemon === true; if (daemon || u.status === "completed" || u.status === "failed") { reactiveWorkChanged = this.reactiveTools.delete(u.toolCallId); - if (reactiveWorkChanged && !daemon) + if (reactiveWorkChanged && (!daemon || u.status === "failed")) this.canResolveAsDaemonOnly = false; } else if (u.sessionUpdate === "tool_call") { this.canResolveAsDaemonOnly = false; this.reactiveTools.add(u.toolCallId); - if (this.earlierEnd && !this.reactiveEnd) { - this.waitForReactiveTurn(); - this.canResolveAsDaemonOnly = false; - } + if (this.earlierEnd && !this.reactiveEnd) this.waitForReactiveTurn(); reactiveWorkChanged = true; } } diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index 0d6d8952..86540725 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -76,6 +76,7 @@ for (const mode of [ "daemon-only", "reactive-late-daemon", "reactive-rejected-steer-daemon", + "reactive-late-tool-steer-daemon", ]) test(`Antigravity completes normally with only a daemon still running in ${mode}`, async (t) => { fixture(t); @@ -87,12 +88,30 @@ for (const mode of [ t.after(() => adapter.dispose()); await adapter.start(); await adapter.prompt("Start a daemon"); + if (mode === "reactive-late-tool-steer-daemon") + await adapter.steer!("Keep going"); if (mode === "reactive-rejected-steer-daemon") await assert.rejects(adapter.steer!("Keep going"), /Steer rejected/); await until(() => complete(events).length === 1); assert.deepEqual(statuses(events), ["ready", "completed"]); }); +test("Antigravity keeps a failed daemon launch open for recovery output", async (t) => { + fixture(t); + process.env.LOOP_TEST_AGY_MODE = "reactive-daemon-failed"; + const events: AdapterEvent[] = []; + const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => + events.push(e), + ); + t.after(() => adapter.dispose()); + await adapter.start(); + await adapter.prompt("Start a daemon"); + await until(() => + events.some((e) => e.type === "delta" && e.text === "Daemon failed."), + ); + assert.deepEqual(statuses(events), ["ready"]); +}); + for (const mode of [ "reactive-steering", "reactive-rejected-steer-late-tool", diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index 43298dd3..8c3fb93c 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -193,27 +193,37 @@ function reactiveTurn(sessionId, mode) { "reactive-steer-daemon", "reactive-rejected-steer-daemon", "reactive-daemon-unechoed-steer-output", + "reactive-late-tool-steer-daemon", + "reactive-daemon-failed", ].includes(mode) ) { - tool("daemon", undefined, "sleep 90"); + if (mode !== "reactive-late-tool-steer-daemon") + tool("daemon", undefined, "sleep 90"); message("Daemon started."); const identifyDaemon = () => { finish(sessionId); + if (mode === "reactive-late-tool-steer-daemon") + tool("daemon", undefined, "sleep 90"); update(sessionId, { sessionUpdate: "tool_call_update", toolCallId: "daemon", - status: "in_progress", + status: mode === "reactive-daemon-failed" ? "failed" : "in_progress", rawInput: { CommandLine: "sleep 90", IsDaemon: true }, }); }; - if (mode !== "reactive-late-daemon") + if (mode === "reactive-daemon-failed") { + identifyDaemon(); + setTimeout(() => message("Daemon failed."), 30); + } else if (mode !== "reactive-late-daemon") endReactiveSteer = (request) => { identifyDaemon(); if (mode === "reactive-daemon-unechoed-steer-output") { message("Waiting."); setTimeout(() => message("Done."), 30); } - if (mode !== "reactive-steer-daemon") + if (mode === "reactive-late-tool-steer-daemon") + reply(request.id, { stopReason: "end_turn" }); + else if (mode !== "reactive-steer-daemon") send({ id: request.id, error: { code: -32603, message: "Steer rejected" }, From 6bdf9e276e7396c4d3fbac0999af635d74d6b155 Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 10:59:23 +0000 Subject: [PATCH 19/31] Latch continuation evidence and cancel on reactive timeout --- src/adapters/acp.ts | 41 +++++++++++++++------ test/antigravity-steering.node.test.ts | 24 +++++++++--- test/fixtures/fake-antigravity-steering.mjs | 40 ++++++++++++++++++-- 3 files changed, 86 insertions(+), 19 deletions(-) diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index 41219861..7f6efb5d 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -147,7 +147,8 @@ export class Acp implements Adapter { protected waitsForReactiveTurns = false; private reactiveTools = new Set(); private reactiveEnd = false; - private canResolveAsDaemonOnly = false; + private reclassifiedDaemons = new Set(); + private reactiveContinuationObserved = false; private reactiveIdle?: NodeJS.Timeout; private reactiveWatchdog?: NodeJS.Timeout; private reactiveWatchdogStarted = 0; @@ -614,7 +615,8 @@ export class Acp implements Adapter { this.earlierEnd = false; this.reactiveTools.clear(); this.reactiveEnd = false; - this.canResolveAsDaemonOnly = false; + this.reclassifiedDaemons.clear(); + this.reactiveContinuationObserved = false; this.reactiveBudget = REACTIVE_WATCHDOG_MS; const expected = this.echoOf(value).trim(); this.promptEcho = undefined; @@ -725,7 +727,7 @@ export class Acp implements Adapter { !(this.reactiveEnd || this.reactiveTools.size || this.permissions.size) ) return false; - if (!this.reactiveEnd) this.canResolveAsDaemonOnly = !this.permissions.size; + if (this.permissions.size) this.reactiveContinuationObserved = true; this.reactiveEnd = true; this.finishReactiveTurn(); return true; @@ -739,7 +741,8 @@ export class Acp implements Adapter { } if (this.permissions.size) return; if ( - this.canResolveAsDaemonOnly && + this.reclassifiedDaemons.size && + !this.reactiveContinuationObserved && !this.openPrompts && !this.reactiveTools.size ) { @@ -777,6 +780,12 @@ export class Acp implements Adapter { ).unref(); } private interruptReactiveTurn(detail?: string) { + if (!this.cancelling && this.session && this.connection) { + this.cancelling = true; + // The supervisor also retires the process when it sees this adapter + // is no longer reusable. A blocked cancel write cannot delay that. + void this.connection.cancel({ sessionId: this.session }).catch(() => {}); + } clearTimeout(this.reactiveIdle); clearTimeout(this.reactiveWatchdog); this.reactiveWatchdog = undefined; @@ -1231,7 +1240,8 @@ export class Acp implements Adapter { if (!choices.length) return Promise.resolve({ outcome: { outcome: "cancelled" } }); const id = randomUUID(); - this.canResolveAsDaemonOnly = false; + if (this.earlierEnd || this.reactiveEnd) + this.reactiveContinuationObserved = true; clearTimeout(this.reactiveIdle); if (this.reactiveWatchdog) this.reactiveBudget = Math.max( @@ -1311,7 +1321,8 @@ export class Acp implements Adapter { } if (u.sessionUpdate === "agent_message_chunk") { if (!this.loading && u.content.type === "text") { - this.canResolveAsDaemonOnly = false; + if (this.earlierEnd || this.reactiveEnd) + this.reactiveContinuationObserved = true; this.emit({ type: "delta", id: this.messageId, @@ -1323,10 +1334,10 @@ export class Acp implements Adapter { } if ( u.sessionUpdate === "agent_thought_chunk" && - this.reactiveEnd && + (this.earlierEnd || this.reactiveEnd) && !this.cancelling ) { - this.canResolveAsDaemonOnly = false; + this.reactiveContinuationObserved = true; this.finishReactiveTurn(); return; } @@ -1351,10 +1362,18 @@ export class Acp implements Adapter { input.IsDaemon === true; if (daemon || u.status === "completed" || u.status === "failed") { reactiveWorkChanged = this.reactiveTools.delete(u.toolCallId); - if (reactiveWorkChanged && (!daemon || u.status === "failed")) - this.canResolveAsDaemonOnly = false; + const knownDaemon = this.reclassifiedDaemons.has(u.toolCallId); + if (reactiveWorkChanged && daemon && u.status !== "failed") + this.reclassifiedDaemons.add(u.toolCallId); + if ( + (this.earlierEnd || this.reactiveEnd) && + ((reactiveWorkChanged && !daemon) || + (u.status === "failed" && (reactiveWorkChanged || knownDaemon))) + ) { + this.reactiveContinuationObserved = true; + reactiveWorkChanged = true; + } } else if (u.sessionUpdate === "tool_call") { - this.canResolveAsDaemonOnly = false; this.reactiveTools.add(u.toolCallId); if (this.earlierEnd && !this.reactiveEnd) this.waitForReactiveTurn(); reactiveWorkChanged = true; diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index 86540725..67d2dc5d 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -77,6 +77,7 @@ for (const mode of [ "reactive-late-daemon", "reactive-rejected-steer-daemon", "reactive-late-tool-steer-daemon", + "reactive-multiple-steer-daemons", ]) test(`Antigravity completes normally with only a daemon still running in ${mode}`, async (t) => { fixture(t); @@ -88,7 +89,10 @@ for (const mode of [ t.after(() => adapter.dispose()); await adapter.start(); await adapter.prompt("Start a daemon"); - if (mode === "reactive-late-tool-steer-daemon") + if ( + mode === "reactive-late-tool-steer-daemon" || + mode === "reactive-multiple-steer-daemons" + ) await adapter.steer!("Keep going"); if (mode === "reactive-rejected-steer-daemon") await assert.rejects(adapter.steer!("Keep going"), /Steer rejected/); @@ -119,6 +123,8 @@ for (const mode of [ "reactive-echoed-steer-settled-tool", "reactive-daemon-unechoed-steer-output", "reactive-steer-daemon", + "reactive-daemon-failed-after-identification", + "reactive-daemon-output-before-tool", ]) test(`Antigravity keeps accepting output after overlapping prompts in ${mode}`, async (t) => { const requests = fixture(t); @@ -131,7 +137,12 @@ for (const mode of [ await adapter.start(); await adapter.prompt("Run background work"); await until(() => events.some((e) => e.type === "delta")); - if (mode.includes("rejected") || mode.includes("unechoed")) + if ( + mode.includes("rejected") || + mode.includes("unechoed") || + mode === "reactive-daemon-failed-after-identification" || + mode === "reactive-daemon-output-before-tool" + ) await assert.rejects(adapter.steer!("Keep going"), /Steer rejected/); else await adapter.steer!("Keep going"); await until(() => @@ -140,9 +151,11 @@ for (const mode of [ assert.deepEqual(statuses(events), ["ready"]); assert.deepEqual( events.flatMap((e) => (e.type === "delta" ? [e.text] : [])), - mode === "reactive-daemon-unechoed-steer-output" + mode === "reactive-daemon-unechoed-steer-output" || + mode === "reactive-daemon-output-before-tool" ? ["Daemon started.", "Waiting.", "Done."] - : mode === "reactive-steer-daemon" + : mode === "reactive-steer-daemon" || + mode === "reactive-daemon-failed-after-identification" ? ["Daemon started.", "Done."] : ["Waiting.", "Done."], ); @@ -355,7 +368,7 @@ for (const mode of ["reactive-reordered", "reactive-final-usage"]) `Antigravity preserves partial output and interrupts in ${mode}`, { timeout: 5000 }, async (t) => { - fixture(t); + const requests = fixture(t); process.env.LOOP_TEST_AGY_MODE = mode; const events: AdapterEvent[] = []; let settle!: () => void; @@ -390,6 +403,7 @@ for (const mode of ["reactive-reordered", "reactive-final-usage"]) } finally { t.mock.timers.reset(); } + await until(() => requests().some((r) => r.acp === "session/cancel")); }, ); diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index 8c3fb93c..2e548859 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -195,21 +195,44 @@ function reactiveTurn(sessionId, mode) { "reactive-daemon-unechoed-steer-output", "reactive-late-tool-steer-daemon", "reactive-daemon-failed", + "reactive-daemon-failed-after-identification", + "reactive-daemon-output-before-tool", + "reactive-multiple-steer-daemons", ].includes(mode) ) { - if (mode !== "reactive-late-tool-steer-daemon") + if ( + ![ + "reactive-late-tool-steer-daemon", + "reactive-daemon-output-before-tool", + ].includes(mode) + ) tool("daemon", undefined, "sleep 90"); message("Daemon started."); const identifyDaemon = () => { finish(sessionId); - if (mode === "reactive-late-tool-steer-daemon") + if (mode === "reactive-daemon-output-before-tool") message("Waiting."); + if ( + [ + "reactive-late-tool-steer-daemon", + "reactive-daemon-output-before-tool", + ].includes(mode) + ) tool("daemon", undefined, "sleep 90"); + if (mode === "reactive-multiple-steer-daemons") + tool("second-daemon", undefined, "sleep 91"); update(sessionId, { sessionUpdate: "tool_call_update", toolCallId: "daemon", status: mode === "reactive-daemon-failed" ? "failed" : "in_progress", rawInput: { CommandLine: "sleep 90", IsDaemon: true }, }); + if (mode === "reactive-multiple-steer-daemons") + update(sessionId, { + sessionUpdate: "tool_call_update", + toolCallId: "second-daemon", + status: "in_progress", + rawInput: { CommandLine: "sleep 91", IsDaemon: true }, + }); }; if (mode === "reactive-daemon-failed") { identifyDaemon(); @@ -217,11 +240,22 @@ function reactiveTurn(sessionId, mode) { } else if (mode !== "reactive-late-daemon") endReactiveSteer = (request) => { identifyDaemon(); + if (mode === "reactive-daemon-failed-after-identification") { + complete("daemon", "failed"); + setTimeout(() => message("Done."), 30); + } + if (mode === "reactive-daemon-output-before-tool") + setTimeout(() => message("Done."), 30); if (mode === "reactive-daemon-unechoed-steer-output") { message("Waiting."); setTimeout(() => message("Done."), 30); } - if (mode === "reactive-late-tool-steer-daemon") + if ( + [ + "reactive-late-tool-steer-daemon", + "reactive-multiple-steer-daemons", + ].includes(mode) + ) reply(request.id, { stopReason: "end_turn" }); else if (mode !== "reactive-steer-daemon") send({ From d8f00dfb55bd1972526f14523138bd341d41df11 Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 11:02:31 +0000 Subject: [PATCH 20/31] Keep late daemon classification inside the reactive wait --- docs/harnesses.md | 2 +- src/adapters/acp.ts | 37 --------------- test/antigravity-steering.node.test.ts | 52 +++++++++------------ test/fixtures/fake-antigravity-steering.mjs | 51 ++++++-------------- 4 files changed, 36 insertions(+), 106 deletions(-) diff --git a/docs/harnesses.md b/docs/harnesses.md index d6425940..2ee9e059 100644 --- a/docs/harnesses.md +++ b/docs/harnesses.md @@ -94,7 +94,7 @@ Install [Antigravity CLI](https://antigravity.google/docs/getting-started?tab=cl With **Antigravity CLI 1.5.9 or newer**, Loop uses the documented [ACP interface](https://antigravity.google/docs/ide/extensions/acp), launched with `agy acp --process-per-session`. Each native session receives its own authenticated Loop MCP connection through ACP session creation or resuming. This enables Agent mail, team delegation and Loop tool integrations without editing global or project MCP configuration. ACP must advertise HTTP MCP support; setup fails before sending a prompt if it does not. Enable Antigravity again after upgrading the CLI so Loop refreshes its saved runtime version and capabilities. Existing streaming sessions switch to ACP on their next turn; refreshing does not interrupt a running turn. See [session reuse](state-machines.md#companion_sessionsstate). -When Antigravity returns `end_turn` while a tool call or approval is still open, Loop keeps receiving output and approvals. A tool that has already reported a terminal status cannot establish that another wakeup is pending. Antigravity can send usage updates both during a continuation and after its final text. Until ACP supplies a definitive completion signal, Loop bounds the wait and interrupts the run with its partial output preserved in the conversation trace. This can leave a successful background continuation without a published Result. Explicit daemons can outlive ordinary completed turns. See the [upstream ACP discussion](https://github.com/google-antigravity/antigravity-cli/issues/1461). +When Antigravity returns `end_turn` while a tool call or approval is still open, Loop keeps receiving output and approvals. A tool that has already reported a terminal status cannot establish that another wakeup is pending. Antigravity can send usage updates both during a continuation and after its final text. Until ACP supplies a definitive completion signal, Loop bounds the wait and interrupts the run with its partial output preserved in the conversation trace. This can leave a successful background continuation without a published Result. Daemons identified before the prompt returns can outlive ordinary completed turns. A late daemon update can clear an open tool but does not certify completion after reactive waiting has begun. See the [upstream ACP discussion](https://github.com/google-antigravity/antigravity-cli/issues/1461). Model discovery and session initialization send no model prompt. Saved instructions accompany explicit prompts, and interrupted tasks are never automatically replayed. Existing native conversation IDs and workspace bindings are retained when a newer runtime resumes a conversation created by the streaming adapter. Commands and skills come from the session’s ACP catalog. Catalog probes and slash-leading prompts or live replies wait up to five seconds for that catalog. A discovered command stays at the start of an explicit prompt, followed by saved instructions; other slash-leading text stays literal, including when discovery times out. Saved instructions starting with `/` also stay literal. The model catalog comes from ACP; if the account no longer offers a previously selected model through that interface, select an available model explicitly. Loop does not choose a replacement model after failure. diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index 7f6efb5d..0e0ba57d 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -147,8 +147,6 @@ export class Acp implements Adapter { protected waitsForReactiveTurns = false; private reactiveTools = new Set(); private reactiveEnd = false; - private reclassifiedDaemons = new Set(); - private reactiveContinuationObserved = false; private reactiveIdle?: NodeJS.Timeout; private reactiveWatchdog?: NodeJS.Timeout; private reactiveWatchdogStarted = 0; @@ -615,8 +613,6 @@ export class Acp implements Adapter { this.earlierEnd = false; this.reactiveTools.clear(); this.reactiveEnd = false; - this.reclassifiedDaemons.clear(); - this.reactiveContinuationObserved = false; this.reactiveBudget = REACTIVE_WATCHDOG_MS; const expected = this.echoOf(value).trim(); this.promptEcho = undefined; @@ -727,7 +723,6 @@ export class Acp implements Adapter { !(this.reactiveEnd || this.reactiveTools.size || this.permissions.size) ) return false; - if (this.permissions.size) this.reactiveContinuationObserved = true; this.reactiveEnd = true; this.finishReactiveTurn(); return true; @@ -740,22 +735,6 @@ export class Acp implements Adapter { return; } if (this.permissions.size) return; - if ( - this.reclassifiedDaemons.size && - !this.reactiveContinuationObserved && - !this.openPrompts && - !this.reactiveTools.size - ) { - // The original end_turn is authoritative when every tool that - // blocked it was subsequently identified as a daemon. - clearTimeout(this.reactiveIdle); - clearTimeout(this.reactiveWatchdog); - this.reactiveWatchdog = undefined; - this.terminalReported = true; - this.active = false; - this.emit({ type: "status", status: "completed", recoverable: true }); - return; - } // The reactive wait stays bounded even if a concurrent steer never // answers. Human approval time does not count against the watchdog. if (!this.reactiveWatchdog) { @@ -1240,8 +1219,6 @@ export class Acp implements Adapter { if (!choices.length) return Promise.resolve({ outcome: { outcome: "cancelled" } }); const id = randomUUID(); - if (this.earlierEnd || this.reactiveEnd) - this.reactiveContinuationObserved = true; clearTimeout(this.reactiveIdle); if (this.reactiveWatchdog) this.reactiveBudget = Math.max( @@ -1321,8 +1298,6 @@ export class Acp implements Adapter { } if (u.sessionUpdate === "agent_message_chunk") { if (!this.loading && u.content.type === "text") { - if (this.earlierEnd || this.reactiveEnd) - this.reactiveContinuationObserved = true; this.emit({ type: "delta", id: this.messageId, @@ -1337,7 +1312,6 @@ export class Acp implements Adapter { (this.earlierEnd || this.reactiveEnd) && !this.cancelling ) { - this.reactiveContinuationObserved = true; this.finishReactiveTurn(); return; } @@ -1362,17 +1336,6 @@ export class Acp implements Adapter { input.IsDaemon === true; if (daemon || u.status === "completed" || u.status === "failed") { reactiveWorkChanged = this.reactiveTools.delete(u.toolCallId); - const knownDaemon = this.reclassifiedDaemons.has(u.toolCallId); - if (reactiveWorkChanged && daemon && u.status !== "failed") - this.reclassifiedDaemons.add(u.toolCallId); - if ( - (this.earlierEnd || this.reactiveEnd) && - ((reactiveWorkChanged && !daemon) || - (u.status === "failed" && (reactiveWorkChanged || knownDaemon))) - ) { - this.reactiveContinuationObserved = true; - reactiveWorkChanged = true; - } } else if (u.sessionUpdate === "tool_call") { this.reactiveTools.add(u.toolCallId); if (this.earlierEnd && !this.reactiveEnd) this.waitForReactiveTurn(); diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index 67d2dc5d..34d9de8c 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -72,14 +72,25 @@ test("Antigravity waits through successive reactive passes and approvals", async await assert.rejects(adapter.prompt("Next turn"), /busy/); }); +test("Antigravity completes normally with only a known daemon still running", async (t) => { + fixture(t); + process.env.LOOP_TEST_AGY_MODE = "daemon-only"; + const events: AdapterEvent[] = []; + const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => + events.push(e), + ); + t.after(() => adapter.dispose()); + await adapter.start(); + await adapter.prompt("Start a daemon"); + await until(() => complete(events).length === 1); + assert.deepEqual(statuses(events), ["ready", "completed"]); +}); + for (const mode of [ - "daemon-only", - "reactive-late-daemon", - "reactive-rejected-steer-daemon", - "reactive-late-tool-steer-daemon", - "reactive-multiple-steer-daemons", + "reactive-daemon-failed", + "reactive-daemon-failed-unsteered", ]) - test(`Antigravity completes normally with only a daemon still running in ${mode}`, async (t) => { + test(`Antigravity keeps a failed daemon launch open in ${mode}`, async (t) => { fixture(t); process.env.LOOP_TEST_AGY_MODE = mode; const events: AdapterEvent[] = []; @@ -89,33 +100,12 @@ for (const mode of [ t.after(() => adapter.dispose()); await adapter.start(); await adapter.prompt("Start a daemon"); - if ( - mode === "reactive-late-tool-steer-daemon" || - mode === "reactive-multiple-steer-daemons" - ) - await adapter.steer!("Keep going"); - if (mode === "reactive-rejected-steer-daemon") - await assert.rejects(adapter.steer!("Keep going"), /Steer rejected/); - await until(() => complete(events).length === 1); - assert.deepEqual(statuses(events), ["ready", "completed"]); + await until(() => + events.some((e) => e.type === "delta" && e.text === "Daemon failed."), + ); + assert.deepEqual(statuses(events), ["ready"]); }); -test("Antigravity keeps a failed daemon launch open for recovery output", async (t) => { - fixture(t); - process.env.LOOP_TEST_AGY_MODE = "reactive-daemon-failed"; - const events: AdapterEvent[] = []; - const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => - events.push(e), - ); - t.after(() => adapter.dispose()); - await adapter.start(); - await adapter.prompt("Start a daemon"); - await until(() => - events.some((e) => e.type === "delta" && e.text === "Daemon failed."), - ); - assert.deepEqual(statuses(events), ["ready"]); -}); - for (const mode of [ "reactive-steering", "reactive-rejected-steer-late-tool", diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index 2e548859..4491cff0 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -189,55 +189,40 @@ function reactiveTurn(sessionId, mode) { } if ( [ - "reactive-late-daemon", "reactive-steer-daemon", - "reactive-rejected-steer-daemon", "reactive-daemon-unechoed-steer-output", - "reactive-late-tool-steer-daemon", "reactive-daemon-failed", + "reactive-daemon-failed-unsteered", "reactive-daemon-failed-after-identification", "reactive-daemon-output-before-tool", - "reactive-multiple-steer-daemons", ].includes(mode) ) { - if ( - ![ - "reactive-late-tool-steer-daemon", - "reactive-daemon-output-before-tool", - ].includes(mode) - ) + if (mode !== "reactive-daemon-output-before-tool") tool("daemon", undefined, "sleep 90"); message("Daemon started."); const identifyDaemon = () => { finish(sessionId); if (mode === "reactive-daemon-output-before-tool") message("Waiting."); - if ( - [ - "reactive-late-tool-steer-daemon", - "reactive-daemon-output-before-tool", - ].includes(mode) - ) + if (mode === "reactive-daemon-output-before-tool") tool("daemon", undefined, "sleep 90"); - if (mode === "reactive-multiple-steer-daemons") - tool("second-daemon", undefined, "sleep 91"); update(sessionId, { sessionUpdate: "tool_call_update", toolCallId: "daemon", status: mode === "reactive-daemon-failed" ? "failed" : "in_progress", rawInput: { CommandLine: "sleep 90", IsDaemon: true }, }); - if (mode === "reactive-multiple-steer-daemons") - update(sessionId, { - sessionUpdate: "tool_call_update", - toolCallId: "second-daemon", - status: "in_progress", - rawInput: { CommandLine: "sleep 91", IsDaemon: true }, - }); }; - if (mode === "reactive-daemon-failed") { + if ( + mode === "reactive-daemon-failed" || + mode === "reactive-daemon-failed-unsteered" + ) { identifyDaemon(); - setTimeout(() => message("Daemon failed."), 30); - } else if (mode !== "reactive-late-daemon") + setTimeout(() => { + if (mode === "reactive-daemon-failed-unsteered") + complete("daemon", "failed"); + message("Daemon failed."); + }, 30); + } else endReactiveSteer = (request) => { identifyDaemon(); if (mode === "reactive-daemon-failed-after-identification") { @@ -250,14 +235,7 @@ function reactiveTurn(sessionId, mode) { message("Waiting."); setTimeout(() => message("Done."), 30); } - if ( - [ - "reactive-late-tool-steer-daemon", - "reactive-multiple-steer-daemons", - ].includes(mode) - ) - reply(request.id, { stopReason: "end_turn" }); - else if (mode !== "reactive-steer-daemon") + if (mode !== "reactive-steer-daemon") send({ id: request.id, error: { code: -32603, message: "Steer rejected" }, @@ -271,7 +249,6 @@ function reactiveTurn(sessionId, mode) { reply(request.id, { stopReason: "end_turn" }); } }; - else identifyDaemon(); return; } if (mode === "reactive-sync-subagent") { From e26a9067beecaf3d97374883c1cdc7e0d3058003 Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 11:05:29 +0000 Subject: [PATCH 21/31] Preserve normal completion for acknowledged synchronous steers --- docs/harnesses.md | 2 +- src/adapters/acp.ts | 8 ++++++-- test/antigravity-steering.node.test.ts | 10 ++++++++-- test/fixtures/fake-antigravity-steering.mjs | 12 ++++++++---- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/docs/harnesses.md b/docs/harnesses.md index 2ee9e059..3157d808 100644 --- a/docs/harnesses.md +++ b/docs/harnesses.md @@ -94,7 +94,7 @@ Install [Antigravity CLI](https://antigravity.google/docs/getting-started?tab=cl With **Antigravity CLI 1.5.9 or newer**, Loop uses the documented [ACP interface](https://antigravity.google/docs/ide/extensions/acp), launched with `agy acp --process-per-session`. Each native session receives its own authenticated Loop MCP connection through ACP session creation or resuming. This enables Agent mail, team delegation and Loop tool integrations without editing global or project MCP configuration. ACP must advertise HTTP MCP support; setup fails before sending a prompt if it does not. Enable Antigravity again after upgrading the CLI so Loop refreshes its saved runtime version and capabilities. Existing streaming sessions switch to ACP on their next turn; refreshing does not interrupt a running turn. See [session reuse](state-machines.md#companion_sessionsstate). -When Antigravity returns `end_turn` while a tool call or approval is still open, Loop keeps receiving output and approvals. A tool that has already reported a terminal status cannot establish that another wakeup is pending. Antigravity can send usage updates both during a continuation and after its final text. Until ACP supplies a definitive completion signal, Loop bounds the wait and interrupts the run with its partial output preserved in the conversation trace. This can leave a successful background continuation without a published Result. Daemons identified before the prompt returns can outlive ordinary completed turns. A late daemon update can clear an open tool but does not certify completion after reactive waiting has begun. See the [upstream ACP discussion](https://github.com/google-antigravity/antigravity-cli/issues/1461). +When Antigravity returns `end_turn` while a tool call or approval is still open, Loop keeps receiving output and approvals. For an acknowledged steer that runs a tool and receives its terminal status before the final prompt response, Loop follows that response unless reactive waiting already began. A tool that has already reported a terminal status cannot establish that another wakeup is pending. Antigravity can send usage updates both during a continuation and after its final text. Until ACP supplies a definitive completion signal, Loop bounds the wait and interrupts the run with its partial output preserved in the conversation trace. This can leave a successful background continuation without a published Result. Daemons identified before the prompt returns can outlive ordinary completed turns. A late daemon update can clear an open tool but does not certify completion after reactive waiting has begun. See the [upstream ACP discussion](https://github.com/google-antigravity/antigravity-cli/issues/1461). Model discovery and session initialization send no model prompt. Saved instructions accompany explicit prompts, and interrupted tasks are never automatically replayed. Existing native conversation IDs and workspace bindings are retained when a newer runtime resumes a conversation created by the streaming adapter. Commands and skills come from the session’s ACP catalog. Catalog probes and slash-leading prompts or live replies wait up to five seconds for that catalog. A discovered command stays at the start of an explicit prompt, followed by saved instructions; other slash-leading text stays literal, including when discovery times out. Saved instructions starting with `/` also stay literal. The model catalog comes from ACP; if the account no longer offers a previously selected model through that interface, select an available model explicitly. Loop does not choose a replacement model after failure. diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index 0e0ba57d..41c0d938 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -1233,7 +1233,8 @@ export class Acp implements Adapter { choices: new Set(choices.map((choice) => choice.optionId)), resolve, }); - if (this.earlierEnd && !this.reactiveEnd) this.waitForReactiveTurn(); + if (this.earlierEnd && !this.reactiveEnd && !this.steerJoined) + this.waitForReactiveTurn(); this.emit({ type: "request", request: { @@ -1338,7 +1339,10 @@ export class Acp implements Adapter { reactiveWorkChanged = this.reactiveTools.delete(u.toolCallId); } else if (u.sessionUpdate === "tool_call") { this.reactiveTools.add(u.toolCallId); - if (this.earlierEnd && !this.reactiveEnd) this.waitForReactiveTurn(); + // After the steer is echoed, its normal tool calls belong to an + // open prompt. Check for outstanding work when that prompt ends. + if (this.earlierEnd && !this.reactiveEnd && !this.steerJoined) + this.waitForReactiveTurn(); reactiveWorkChanged = true; } } diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index 34d9de8c..7cdcdc9a 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -110,7 +110,7 @@ for (const mode of [ "reactive-steering", "reactive-rejected-steer-late-tool", "reactive-rejected-steer-settled-tool", - "reactive-echoed-steer-settled-tool", + "reactive-echoed-steer-open-tool", "reactive-daemon-unechoed-steer-output", "reactive-steer-daemon", "reactive-daemon-failed-after-identification", @@ -152,7 +152,11 @@ for (const mode of [ assert.deepEqual(prompts(requests), ["Run background work", "Keep going"]); }); -for (const mode of ["reactive-sync-answer", "reactive-sync-subagent"]) +for (const mode of [ + "reactive-sync-answer", + "reactive-sync-subagent", + "reactive-steered-sync-tool", +]) test(`Antigravity handles an async-capable tool that settles before end_turn in ${mode}`, async (t) => { fixture(t); process.env.LOOP_TEST_AGY_MODE = mode; @@ -163,6 +167,8 @@ for (const mode of ["reactive-sync-answer", "reactive-sync-subagent"]) t.after(() => adapter.dispose()); await adapter.start(); await adapter.prompt("Run background work"); + if (mode === "reactive-steered-sync-tool") + await adapter.steer!("Keep going"); await until(() => events.some((e) => e.type === "delta" && e.text === "Done."), ); diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index 4491cff0..c1f6d890 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -157,12 +157,14 @@ function reactiveTurn(sessionId, mode) { [ "reactive-rejected-steer-late-tool", "reactive-rejected-steer-settled-tool", - "reactive-echoed-steer-settled-tool", + "reactive-echoed-steer-open-tool", + "reactive-steered-sync-tool", ].includes(mode) ) { message("Waiting."); endReactiveSteer = (request) => { - const joined = mode === "reactive-echoed-steer-settled-tool"; + const synchronous = mode === "reactive-steered-sync-tool"; + const joined = synchronous || mode === "reactive-echoed-steer-open-tool"; if (joined) update(sessionId, { sessionUpdate: "user_message_chunk", @@ -170,8 +172,9 @@ function reactiveTurn(sessionId, mode) { }); finish(sessionId); tool("late-background", { CommandLine: "sleep 5" }, "sleep 5"); - if (mode !== "reactive-rejected-steer-late-tool") + if (synchronous || mode === "reactive-rejected-steer-settled-tool") complete("late-background"); + if (synchronous) message("Done."); if (joined) reply(request.id, { stopReason: "end_turn" }); else send({ @@ -179,7 +182,8 @@ function reactiveTurn(sessionId, mode) { error: { code: -32603, message: "Steer rejected" }, }); setTimeout(() => { - if (mode === "reactive-rejected-steer-late-tool") + if (synchronous) return; + if (mode !== "reactive-rejected-steer-settled-tool") complete("late-background"); message("Done."); reportUsage(); From c91ed9f6005c64da26371b4882913bba2399f600 Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 11:08:46 +0000 Subject: [PATCH 22/31] Follow acknowledged steers and preserve unjoined continuation text --- src/adapters/acp.ts | 18 ++++++++++++++---- test/antigravity-steering.node.test.ts | 8 ++++++-- test/fixtures/fake-antigravity-steering.mjs | 12 ++++++++++-- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index 41c0d938..505e6947 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -647,7 +647,8 @@ export class Acp implements Adapter { // Antigravity gives reactive passes no definitive end signal. // Preserve their output as partial instead of publishing it // based on usage, steering replies, or elapsed time. - if (this.waitForReactiveTurn()) return; + if ((last || !this.steerJoined) && this.waitForReactiveTurn()) + return; } if (!last) return; this.terminalReported = true; @@ -716,11 +717,16 @@ export class Acp implements Adapter { }); return request; } - private waitForReactiveTurn() { + private waitForReactiveTurn(observedContinuation = false) { if ( this.cancelling || !this.waitsForReactiveTurns || - !(this.reactiveEnd || this.reactiveTools.size || this.permissions.size) + !( + observedContinuation || + this.reactiveEnd || + this.reactiveTools.size || + this.permissions.size + ) ) return false; this.reactiveEnd = true; @@ -1305,6 +1311,8 @@ export class Acp implements Adapter { text: text(u.content.text), }); } + if (this.earlierEnd && !this.reactiveEnd && !this.steerJoined) + this.waitForReactiveTurn(true); if (this.reactiveEnd && !this.cancelling) this.finishReactiveTurn(); return; } @@ -1313,7 +1321,9 @@ export class Acp implements Adapter { (this.earlierEnd || this.reactiveEnd) && !this.cancelling ) { - this.finishReactiveTurn(); + if (this.earlierEnd && !this.reactiveEnd && !this.steerJoined) + this.waitForReactiveTurn(true); + else this.finishReactiveTurn(); return; } if ( diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index 7cdcdc9a..69aacb8b 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -110,6 +110,7 @@ for (const mode of [ "reactive-steering", "reactive-rejected-steer-late-tool", "reactive-rejected-steer-settled-tool", + "reactive-rejected-steer-text-before-tool", "reactive-echoed-steer-open-tool", "reactive-daemon-unechoed-steer-output", "reactive-steer-daemon", @@ -147,7 +148,9 @@ for (const mode of [ : mode === "reactive-steer-daemon" || mode === "reactive-daemon-failed-after-identification" ? ["Daemon started.", "Done."] - : ["Waiting.", "Done."], + : mode === "reactive-rejected-steer-text-before-tool" + ? ["Waiting.", "Still waiting.", "Done."] + : ["Waiting.", "Done."], ); assert.deepEqual(prompts(requests), ["Run background work", "Keep going"]); }); @@ -156,6 +159,7 @@ for (const mode of [ "reactive-sync-answer", "reactive-sync-subagent", "reactive-steered-sync-tool", + "reactive-steered-sync-open-at-first-end", ]) test(`Antigravity handles an async-capable tool that settles before end_turn in ${mode}`, async (t) => { fixture(t); @@ -167,7 +171,7 @@ for (const mode of [ t.after(() => adapter.dispose()); await adapter.start(); await adapter.prompt("Run background work"); - if (mode === "reactive-steered-sync-tool") + if (mode.startsWith("reactive-steered-sync")) await adapter.steer!("Keep going"); await until(() => events.some((e) => e.type === "delta" && e.text === "Done."), diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index c1f6d890..0ec3b510 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -159,19 +159,26 @@ function reactiveTurn(sessionId, mode) { "reactive-rejected-steer-settled-tool", "reactive-echoed-steer-open-tool", "reactive-steered-sync-tool", + "reactive-steered-sync-open-at-first-end", + "reactive-rejected-steer-text-before-tool", ].includes(mode) ) { message("Waiting."); endReactiveSteer = (request) => { - const synchronous = mode === "reactive-steered-sync-tool"; + const synchronous = mode.startsWith("reactive-steered-sync"); const joined = synchronous || mode === "reactive-echoed-steer-open-tool"; if (joined) update(sessionId, { sessionUpdate: "user_message_chunk", content: { type: "text", text: request.params.prompt[0].text }, }); + const startTool = () => + tool("late-background", { CommandLine: "sleep 5" }, "sleep 5"); + if (mode === "reactive-steered-sync-open-at-first-end") startTool(); finish(sessionId); - tool("late-background", { CommandLine: "sleep 5" }, "sleep 5"); + if (mode === "reactive-rejected-steer-text-before-tool") + message("Still waiting."); + else if (mode !== "reactive-steered-sync-open-at-first-end") startTool(); if (synchronous || mode === "reactive-rejected-steer-settled-tool") complete("late-background"); if (synchronous) message("Done."); @@ -183,6 +190,7 @@ function reactiveTurn(sessionId, mode) { }); setTimeout(() => { if (synchronous) return; + if (mode === "reactive-rejected-steer-text-before-tool") startTool(); if (mode !== "reactive-rejected-steer-settled-tool") complete("late-background"); message("Done."); From 92f27af4168c08ab8c03afd91faa71a478f78d7e Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 11:10:23 +0000 Subject: [PATCH 23/31] Preserve response-based confirmation for bare steered commands --- src/adapters/acp.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index 505e6947..63b80c1f 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -1239,7 +1239,7 @@ export class Acp implements Adapter { choices: new Set(choices.map((choice) => choice.optionId)), resolve, }); - if (this.earlierEnd && !this.reactiveEnd && !this.steerJoined) + if (this.earlierEnd && !this.reactiveEnd && this.echo) this.waitForReactiveTurn(); this.emit({ type: "request", @@ -1311,7 +1311,7 @@ export class Acp implements Adapter { text: text(u.content.text), }); } - if (this.earlierEnd && !this.reactiveEnd && !this.steerJoined) + if (this.earlierEnd && !this.reactiveEnd && this.echo) this.waitForReactiveTurn(true); if (this.reactiveEnd && !this.cancelling) this.finishReactiveTurn(); return; @@ -1321,7 +1321,7 @@ export class Acp implements Adapter { (this.earlierEnd || this.reactiveEnd) && !this.cancelling ) { - if (this.earlierEnd && !this.reactiveEnd && !this.steerJoined) + if (this.earlierEnd && !this.reactiveEnd && this.echo) this.waitForReactiveTurn(true); else this.finishReactiveTurn(); return; @@ -1351,7 +1351,7 @@ export class Acp implements Adapter { this.reactiveTools.add(u.toolCallId); // After the steer is echoed, its normal tool calls belong to an // open prompt. Check for outstanding work when that prompt ends. - if (this.earlierEnd && !this.reactiveEnd && !this.steerJoined) + if (this.earlierEnd && !this.reactiveEnd && this.echo) this.waitForReactiveTurn(); reactiveWorkChanged = true; } From c06ebe593e6a2c2d4288f5df4cf985c291076fad Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 11:12:48 +0000 Subject: [PATCH 24/31] Bound acknowledged steering and distinguish a rejected response --- src/adapters/acp.ts | 42 ++++++++++++--------- test/antigravity-steering.node.test.ts | 9 ++++- test/fixtures/fake-antigravity-steering.mjs | 19 ++++++++++ 3 files changed, 52 insertions(+), 18 deletions(-) diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index 63b80c1f..35fecf5b 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -168,6 +168,7 @@ export class Acp implements Adapter { private steering = false; /** The steering input's echo arrived, so it joined the running turn. */ private steerJoined = false; + private outputWhileSteerUnconfirmed = false; /** An earlier request of this turn ended it normally. */ private earlierEnd = false; private end!: () => void; @@ -649,6 +650,7 @@ export class Acp implements Adapter { // based on usage, steering replies, or elapsed time. if ((last || !this.steerJoined) && this.waitForReactiveTurn()) return; + if (!last && this.waitsForReactiveTurns) this.refreshReactiveWait(); } if (!last) return; this.terminalReported = true; @@ -677,14 +679,14 @@ export class Acp implements Adapter { // A rejected steering input that never joined the turn does not // undo the turn's own normal end. if (this.reactiveEnd && this.cancelling) { - this.finishReactiveTurn(); + this.refreshReactiveWait(); return; } if ( steer && !this.steerJoined && (this.earlierEnd || this.reactiveEnd) && - this.waitForReactiveTurn() + this.waitForReactiveTurn(this.outputWhileSteerUnconfirmed) ) return; this.terminalReported = true; @@ -730,14 +732,19 @@ export class Acp implements Adapter { ) return false; this.reactiveEnd = true; - this.finishReactiveTurn(); + this.refreshReactiveWait(); return true; } - private finishReactiveTurn() { + private refreshReactiveWait() { clearTimeout(this.reactiveIdle); - if (this.closed || this.terminalReported || !this.reactiveEnd) return; + if ( + this.closed || + this.terminalReported || + !(this.reactiveEnd || (this.earlierEnd && this.openPrompts)) + ) + return; if (this.cancelling) { - this.interruptReactiveTurn(); + if (this.reactiveEnd) this.interruptReactiveTurn(); return; } if (this.permissions.size) return; @@ -753,7 +760,8 @@ export class Acp implements Adapter { this.reactiveBudget, ).unref(); } - if (this.openPrompts || this.reactiveTools.size) return; + if (!this.reactiveEnd || this.openPrompts || this.reactiveTools.size) + return; // ACP usage updates also occur mid-pass. A quiet reactive wait can // preserve partial output, but cannot certify a completed Result. this.reactiveIdle = setTimeout( @@ -863,6 +871,7 @@ export class Acp implements Adapter { throw new NotDelivered("ACP session is busy."); beforeDispatch?.(); this.steerJoined = false; + this.outputWhileSteerUnconfirmed = false; const echoed = new Promise((resolve) => { if (expected) this.echo = { @@ -904,7 +913,7 @@ export class Acp implements Adapter { !this.closed && this.session && this.connection && this.active ? this.connection.cancel({ sessionId: this.session }) : undefined; - this.finishReactiveTurn(); + this.refreshReactiveWait(); await notification; } async answer( @@ -925,7 +934,8 @@ export class Acp implements Adapter { outcome: { outcome: "selected", optionId: answer.choice }, }); this.emit({ type: "resolved", id }); - if (this.reactiveEnd && !this.cancelling) this.finishReactiveTurn(); + if (this.waitsForReactiveTurns && !this.cancelling) + this.refreshReactiveWait(); } async dispose() { this.closed = true; @@ -1311,9 +1321,8 @@ export class Acp implements Adapter { text: text(u.content.text), }); } - if (this.earlierEnd && !this.reactiveEnd && this.echo) - this.waitForReactiveTurn(true); - if (this.reactiveEnd && !this.cancelling) this.finishReactiveTurn(); + if (this.earlierEnd && this.echo) this.outputWhileSteerUnconfirmed = true; + if (this.reactiveEnd && !this.cancelling) this.refreshReactiveWait(); return; } if ( @@ -1321,9 +1330,8 @@ export class Acp implements Adapter { (this.earlierEnd || this.reactiveEnd) && !this.cancelling ) { - if (this.earlierEnd && !this.reactiveEnd && this.echo) - this.waitForReactiveTurn(true); - else this.finishReactiveTurn(); + if (this.earlierEnd && this.echo) this.outputWhileSteerUnconfirmed = true; + this.refreshReactiveWait(); return; } if ( @@ -1371,7 +1379,7 @@ export class Acp implements Adapter { this.toolItems.set(u.toolCallId, item); this.emit({ type: "item", item }); if (reactiveWorkChanged && this.reactiveEnd && !this.cancelling) - this.finishReactiveTurn(); + this.refreshReactiveWait(); return; } const kind = u.kind ?? this.toolKinds.get(u.toolCallId); @@ -1591,7 +1599,7 @@ export class Acp implements Adapter { this.loading, ); if (reactiveWorkChanged && this.reactiveEnd && !this.cancelling) - this.finishReactiveTurn(); + this.refreshReactiveWait(); return; } if (u.sessionUpdate === "plan") { diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index 69aacb8b..36942226 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -160,6 +160,7 @@ for (const mode of [ "reactive-sync-subagent", "reactive-steered-sync-tool", "reactive-steered-sync-open-at-first-end", + "reactive-steered-sync-without-echo", ]) test(`Antigravity handles an async-capable tool that settles before end_turn in ${mode}`, async (t) => { fixture(t); @@ -234,7 +235,11 @@ test("Antigravity keeps accepting reactive output after echoing and acknowledgin ); }); -for (const mode of ["reactive-stalled", "reactive-stalled-steer"]) +for (const mode of [ + "reactive-stalled", + "reactive-stalled-steer", + "reactive-stalled-joined-steer", +]) test( `Antigravity bounds the wait for ${mode}`, { timeout: 5000 }, @@ -258,6 +263,8 @@ for (const mode of ["reactive-stalled", "reactive-stalled-steer"]) t.mock.timers.enable({ apis: ["setTimeout"] }); try { await adapter.prompt("Run background work"); + if (mode === "reactive-stalled-joined-steer") + await adapter.steer!("Keep going"); await promptEnded; if (mode === "reactive-stalled-steer") await adapter.steer!("Keep going"); diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index 0ec3b510..0963cb55 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -153,6 +153,15 @@ function reactiveTurn(sessionId, mode) { const reportUsage = () => update(sessionId, { sessionUpdate: "usage_update", used: 20, size: 100 }); + if (mode === "reactive-steered-sync-without-echo") { + message("Waiting."); + endReactiveSteer = (request) => { + finish(sessionId); + message("Done."); + reply(request.id, { stopReason: "end_turn" }); + }; + return; + } if ( [ "reactive-rejected-steer-late-tool", @@ -299,6 +308,16 @@ function reactiveTurn(sessionId, mode) { }; return; } + if (mode === "reactive-stalled-joined-steer") { + endReactiveSteer = (request) => { + update(sessionId, { + sessionUpdate: "user_message_chunk", + content: { type: "text", text: request.params.prompt[0].text }, + }); + finish(sessionId); + }; + return; + } if (mode === "reactive-steering" || mode === "reactive-steer-ack") { endReactiveSteer = (request) => { finish(sessionId); From c53f480296287224c9b9f12b7d7231d5e007b7d3 Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 11:15:58 +0000 Subject: [PATCH 25/31] Track inherited tools and observed steering progress --- src/adapters/acp.ts | 39 +++++++++++++++++---- test/antigravity-steering.node.test.ts | 1 + test/fixtures/fake-antigravity-steering.mjs | 24 +++++++++---- 3 files changed, 50 insertions(+), 14 deletions(-) diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index 35fecf5b..6752973a 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -168,6 +168,7 @@ export class Acp implements Adapter { private steering = false; /** The steering input's echo arrived, so it joined the running turn. */ private steerJoined = false; + private toolsAtSteerEcho = new Set(); private outputWhileSteerUnconfirmed = false; /** An earlier request of this turn ended it normally. */ private earlierEnd = false; @@ -648,7 +649,13 @@ export class Acp implements Adapter { // Antigravity gives reactive passes no definitive end signal. // Preserve their output as partial instead of publishing it // based on usage, steering replies, or elapsed time. - if ((last || !this.steerJoined) && this.waitForReactiveTurn()) + const inheritedWork = [...this.toolsAtSteerEcho].some((id) => + this.reactiveTools.has(id), + ); + if ( + (last || !this.steerJoined || inheritedWork) && + this.waitForReactiveTurn() + ) return; if (!last && this.waitsForReactiveTurns) this.refreshReactiveWait(); } @@ -772,6 +779,22 @@ export class Acp implements Adapter { REACTIVE_IDLE_MS, ).unref(); } + private noteReactiveActivity() { + if (!this.waitsForReactiveTurns || this.cancelling) return; + if ( + !this.reactiveEnd && + this.earlierEnd && + this.openPrompts && + !this.permissions.size + ) { + // An ordinary steer can keep making progress after the original + // request ends. Only the latched reactive wait has a total budget. + clearTimeout(this.reactiveWatchdog); + this.reactiveWatchdog = undefined; + this.reactiveBudget = REACTIVE_WATCHDOG_MS; + } + this.refreshReactiveWait(); + } private interruptReactiveTurn(detail?: string) { if (!this.cancelling && this.session && this.connection) { this.cancelling = true; @@ -871,6 +894,7 @@ export class Acp implements Adapter { throw new NotDelivered("ACP session is busy."); beforeDispatch?.(); this.steerJoined = false; + this.toolsAtSteerEcho.clear(); this.outputWhileSteerUnconfirmed = false; const echoed = new Promise((resolve) => { if (expected) @@ -879,6 +903,7 @@ export class Acp implements Adapter { seen: "", resolve: () => { this.steerJoined = true; + this.toolsAtSteerEcho = new Set(this.reactiveTools); resolve(); }, }; @@ -1322,7 +1347,7 @@ export class Acp implements Adapter { }); } if (this.earlierEnd && this.echo) this.outputWhileSteerUnconfirmed = true; - if (this.reactiveEnd && !this.cancelling) this.refreshReactiveWait(); + this.noteReactiveActivity(); return; } if ( @@ -1331,7 +1356,7 @@ export class Acp implements Adapter { !this.cancelling ) { if (this.earlierEnd && this.echo) this.outputWhileSteerUnconfirmed = true; - this.refreshReactiveWait(); + this.noteReactiveActivity(); return; } if ( @@ -1378,8 +1403,8 @@ export class Acp implements Adapter { }; this.toolItems.set(u.toolCallId, item); this.emit({ type: "item", item }); - if (reactiveWorkChanged && this.reactiveEnd && !this.cancelling) - this.refreshReactiveWait(); + if (reactiveWorkChanged || this.reactiveTools.has(u.toolCallId)) + this.noteReactiveActivity(); return; } const kind = u.kind ?? this.toolKinds.get(u.toolCallId); @@ -1598,8 +1623,8 @@ export class Acp implements Adapter { }, this.loading, ); - if (reactiveWorkChanged && this.reactiveEnd && !this.cancelling) - this.refreshReactiveWait(); + if (reactiveWorkChanged || this.reactiveTools.has(u.toolCallId)) + this.noteReactiveActivity(); return; } if (u.sessionUpdate === "plan") { diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index 36942226..411887e7 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -112,6 +112,7 @@ for (const mode of [ "reactive-rejected-steer-settled-tool", "reactive-rejected-steer-text-before-tool", "reactive-echoed-steer-open-tool", + "reactive-inherited-steer-settled-tool", "reactive-daemon-unechoed-steer-output", "reactive-steer-daemon", "reactive-daemon-failed-after-identification", diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index 0963cb55..a6e0f15c 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -169,26 +169,35 @@ function reactiveTurn(sessionId, mode) { "reactive-echoed-steer-open-tool", "reactive-steered-sync-tool", "reactive-steered-sync-open-at-first-end", + "reactive-inherited-steer-settled-tool", "reactive-rejected-steer-text-before-tool", ].includes(mode) ) { message("Waiting."); endReactiveSteer = (request) => { const synchronous = mode.startsWith("reactive-steered-sync"); - const joined = synchronous || mode === "reactive-echoed-steer-open-tool"; + const inherited = mode === "reactive-inherited-steer-settled-tool"; + const joined = + synchronous || inherited || mode === "reactive-echoed-steer-open-tool"; + const startTool = () => + tool("late-background", { CommandLine: "sleep 5" }, "sleep 5"); + if (inherited) startTool(); if (joined) update(sessionId, { sessionUpdate: "user_message_chunk", content: { type: "text", text: request.params.prompt[0].text }, }); - const startTool = () => - tool("late-background", { CommandLine: "sleep 5" }, "sleep 5"); if (mode === "reactive-steered-sync-open-at-first-end") startTool(); finish(sessionId); if (mode === "reactive-rejected-steer-text-before-tool") message("Still waiting."); - else if (mode !== "reactive-steered-sync-open-at-first-end") startTool(); - if (synchronous || mode === "reactive-rejected-steer-settled-tool") + else if (!inherited && mode !== "reactive-steered-sync-open-at-first-end") + startTool(); + if ( + synchronous || + inherited || + mode === "reactive-rejected-steer-settled-tool" + ) complete("late-background"); if (synchronous) message("Done."); if (joined) reply(request.id, { stopReason: "end_turn" }); @@ -200,7 +209,7 @@ function reactiveTurn(sessionId, mode) { setTimeout(() => { if (synchronous) return; if (mode === "reactive-rejected-steer-text-before-tool") startTool(); - if (mode !== "reactive-rejected-steer-settled-tool") + if (!inherited && mode !== "reactive-rejected-steer-settled-tool") complete("late-background"); message("Done."); reportUsage(); @@ -280,7 +289,7 @@ function reactiveTurn(sessionId, mode) { return; } tool("daemon", { CommandLine: "sleep 90", IsDaemon: true }, "sleep 90"); - if (mode !== "daemon-only") + if (mode !== "daemon-only" && mode !== "reactive-stalled-joined-steer") tool( "background", { @@ -314,6 +323,7 @@ function reactiveTurn(sessionId, mode) { sessionUpdate: "user_message_chunk", content: { type: "text", text: request.params.prompt[0].text }, }); + tool("background", { CommandLine: "sleep 5" }, "sleep 5"); finish(sessionId); }; return; From affed231984488ac8454aec0c1f4279c26d6942a Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 11:19:51 +0000 Subject: [PATCH 26/31] Separate inherited tools from pending steering work --- docs/harnesses.md | 2 +- src/adapters/acp.ts | 67 ++++++++------------- test/antigravity-steering.node.test.ts | 4 ++ test/fixtures/fake-antigravity-steering.mjs | 22 +++++-- 4 files changed, 47 insertions(+), 48 deletions(-) diff --git a/docs/harnesses.md b/docs/harnesses.md index 3157d808..53c59223 100644 --- a/docs/harnesses.md +++ b/docs/harnesses.md @@ -94,7 +94,7 @@ Install [Antigravity CLI](https://antigravity.google/docs/getting-started?tab=cl With **Antigravity CLI 1.5.9 or newer**, Loop uses the documented [ACP interface](https://antigravity.google/docs/ide/extensions/acp), launched with `agy acp --process-per-session`. Each native session receives its own authenticated Loop MCP connection through ACP session creation or resuming. This enables Agent mail, team delegation and Loop tool integrations without editing global or project MCP configuration. ACP must advertise HTTP MCP support; setup fails before sending a prompt if it does not. Enable Antigravity again after upgrading the CLI so Loop refreshes its saved runtime version and capabilities. Existing streaming sessions switch to ACP on their next turn; refreshing does not interrupt a running turn. See [session reuse](state-machines.md#companion_sessionsstate). -When Antigravity returns `end_turn` while a tool call or approval is still open, Loop keeps receiving output and approvals. For an acknowledged steer that runs a tool and receives its terminal status before the final prompt response, Loop follows that response unless reactive waiting already began. A tool that has already reported a terminal status cannot establish that another wakeup is pending. Antigravity can send usage updates both during a continuation and after its final text. Until ACP supplies a definitive completion signal, Loop bounds the wait and interrupts the run with its partial output preserved in the conversation trace. This can leave a successful background continuation without a published Result. Daemons identified before the prompt returns can outlive ordinary completed turns. A late daemon update can clear an open tool but does not certify completion after reactive waiting has begun. See the [upstream ACP discussion](https://github.com/google-antigravity/antigravity-cli/issues/1461). +When Antigravity returns `end_turn` while a tool call or approval is still open, Loop keeps receiving output and approvals. For overlapping steering requests, Loop keeps waiting for inherited work that was open before steering. Otherwise, the final prompt response remains authoritative if all work has settled and reactive waiting has not started. An overlapping request that never resolves is subject to the one-hour watchdog. A tool that has already reported a terminal status cannot establish that another wakeup is pending. Antigravity can send usage updates both during a continuation and after its final text. Until ACP supplies a definitive completion signal, Loop bounds the wait and interrupts the run with its partial output preserved in the conversation trace. This can leave a successful background continuation without a published Result. Daemons identified before the prompt returns can outlive ordinary completed turns. A late daemon update can clear an open tool but does not certify completion after reactive waiting has begun. See the [upstream ACP discussion](https://github.com/google-antigravity/antigravity-cli/issues/1461). Model discovery and session initialization send no model prompt. Saved instructions accompany explicit prompts, and interrupted tasks are never automatically replayed. Existing native conversation IDs and workspace bindings are retained when a newer runtime resumes a conversation created by the streaming adapter. Commands and skills come from the session’s ACP catalog. Catalog probes and slash-leading prompts or live replies wait up to five seconds for that catalog. A discovered command stays at the start of an explicit prompt, followed by saved instructions; other slash-leading text stays literal, including when discovery times out. Saved instructions starting with `/` also stay literal. The model catalog comes from ACP; if the account no longer offers a previously selected model through that interface, select an available model explicitly. Loop does not choose a replacement model after failure. diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index 6752973a..2d7268cc 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -168,8 +168,8 @@ export class Acp implements Adapter { private steering = false; /** The steering input's echo arrived, so it joined the running turn. */ private steerJoined = false; - private toolsAtSteerEcho = new Set(); - private outputWhileSteerUnconfirmed = false; + private toolsAtSteerDispatch = new Set(); + private workWhileSteerUnconfirmed = false; /** An earlier request of this turn ended it normally. */ private earlierEnd = false; private end!: () => void; @@ -649,15 +649,18 @@ export class Acp implements Adapter { // Antigravity gives reactive passes no definitive end signal. // Preserve their output as partial instead of publishing it // based on usage, steering replies, or elapsed time. - const inheritedWork = [...this.toolsAtSteerEcho].some((id) => + const inheritedWork = [...this.toolsAtSteerDispatch].some((id) => this.reactiveTools.has(id), ); - if ( - (last || !this.steerJoined || inheritedWork) && - this.waitForReactiveTurn() - ) - return; - if (!last && this.waitsForReactiveTurns) this.refreshReactiveWait(); + if ((last || inheritedWork) && this.waitForReactiveTurn()) return; + if (!last && this.waitsForReactiveTurns) { + if ( + this.echo && + (this.reactiveTools.size || this.permissions.size) + ) + this.workWhileSteerUnconfirmed = true; + this.refreshReactiveWait(); + } } if (!last) return; this.terminalReported = true; @@ -693,7 +696,7 @@ export class Acp implements Adapter { steer && !this.steerJoined && (this.earlierEnd || this.reactiveEnd) && - this.waitForReactiveTurn(this.outputWhileSteerUnconfirmed) + this.waitForReactiveTurn(this.workWhileSteerUnconfirmed) ) return; this.terminalReported = true; @@ -779,22 +782,6 @@ export class Acp implements Adapter { REACTIVE_IDLE_MS, ).unref(); } - private noteReactiveActivity() { - if (!this.waitsForReactiveTurns || this.cancelling) return; - if ( - !this.reactiveEnd && - this.earlierEnd && - this.openPrompts && - !this.permissions.size - ) { - // An ordinary steer can keep making progress after the original - // request ends. Only the latched reactive wait has a total budget. - clearTimeout(this.reactiveWatchdog); - this.reactiveWatchdog = undefined; - this.reactiveBudget = REACTIVE_WATCHDOG_MS; - } - this.refreshReactiveWait(); - } private interruptReactiveTurn(detail?: string) { if (!this.cancelling && this.session && this.connection) { this.cancelling = true; @@ -894,8 +881,8 @@ export class Acp implements Adapter { throw new NotDelivered("ACP session is busy."); beforeDispatch?.(); this.steerJoined = false; - this.toolsAtSteerEcho.clear(); - this.outputWhileSteerUnconfirmed = false; + this.toolsAtSteerDispatch = new Set(this.reactiveTools); + this.workWhileSteerUnconfirmed = false; const echoed = new Promise((resolve) => { if (expected) this.echo = { @@ -903,7 +890,6 @@ export class Acp implements Adapter { seen: "", resolve: () => { this.steerJoined = true; - this.toolsAtSteerEcho = new Set(this.reactiveTools); resolve(); }, }; @@ -1274,8 +1260,7 @@ export class Acp implements Adapter { choices: new Set(choices.map((choice) => choice.optionId)), resolve, }); - if (this.earlierEnd && !this.reactiveEnd && this.echo) - this.waitForReactiveTurn(); + if (this.earlierEnd && this.echo) this.workWhileSteerUnconfirmed = true; this.emit({ type: "request", request: { @@ -1346,8 +1331,8 @@ export class Acp implements Adapter { text: text(u.content.text), }); } - if (this.earlierEnd && this.echo) this.outputWhileSteerUnconfirmed = true; - this.noteReactiveActivity(); + if (this.earlierEnd && this.echo) this.workWhileSteerUnconfirmed = true; + this.refreshReactiveWait(); return; } if ( @@ -1355,8 +1340,8 @@ export class Acp implements Adapter { (this.earlierEnd || this.reactiveEnd) && !this.cancelling ) { - if (this.earlierEnd && this.echo) this.outputWhileSteerUnconfirmed = true; - this.noteReactiveActivity(); + if (this.earlierEnd && this.echo) this.workWhileSteerUnconfirmed = true; + this.refreshReactiveWait(); return; } if ( @@ -1382,10 +1367,10 @@ export class Acp implements Adapter { reactiveWorkChanged = this.reactiveTools.delete(u.toolCallId); } else if (u.sessionUpdate === "tool_call") { this.reactiveTools.add(u.toolCallId); - // After the steer is echoed, its normal tool calls belong to an - // open prompt. Check for outstanding work when that prompt ends. - if (this.earlierEnd && !this.reactiveEnd && this.echo) - this.waitForReactiveTurn(); + // A pending steer might own this tool. Its successful response + // decides whether work remains; a rejection retains the evidence. + if (this.earlierEnd && this.echo) + this.workWhileSteerUnconfirmed = true; reactiveWorkChanged = true; } } @@ -1404,7 +1389,7 @@ export class Acp implements Adapter { this.toolItems.set(u.toolCallId, item); this.emit({ type: "item", item }); if (reactiveWorkChanged || this.reactiveTools.has(u.toolCallId)) - this.noteReactiveActivity(); + this.refreshReactiveWait(); return; } const kind = u.kind ?? this.toolKinds.get(u.toolCallId); @@ -1624,7 +1609,7 @@ export class Acp implements Adapter { this.loading, ); if (reactiveWorkChanged || this.reactiveTools.has(u.toolCallId)) - this.noteReactiveActivity(); + this.refreshReactiveWait(); return; } if (u.sessionUpdate === "plan") { diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index 411887e7..b12704d0 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -161,6 +161,7 @@ for (const mode of [ "reactive-sync-subagent", "reactive-steered-sync-tool", "reactive-steered-sync-open-at-first-end", + "reactive-steered-sync-before-echo", "reactive-steered-sync-without-echo", ]) test(`Antigravity handles an async-capable tool that settles before end_turn in ${mode}`, async (t) => { @@ -225,6 +226,9 @@ test("Antigravity keeps accepting reactive output after echoing and acknowledgin t.after(() => adapter.dispose()); await adapter.start(); await adapter.prompt("Run background work"); + await until(() => + events.some((e) => e.type === "delta" && e.text === "Waiting."), + ); await adapter.steer!("Keep going"); await until(() => events.some((e) => e.type === "delta" && e.text === "Done."), diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index a6e0f15c..f134f277 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -169,29 +169,39 @@ function reactiveTurn(sessionId, mode) { "reactive-echoed-steer-open-tool", "reactive-steered-sync-tool", "reactive-steered-sync-open-at-first-end", + "reactive-steered-sync-before-echo", "reactive-inherited-steer-settled-tool", "reactive-rejected-steer-text-before-tool", ].includes(mode) ) { + const inherited = mode === "reactive-inherited-steer-settled-tool"; + const beforeEcho = mode === "reactive-steered-sync-before-echo"; + const startTool = () => + tool("late-background", { CommandLine: "sleep 5" }, "sleep 5"); + if (inherited) startTool(); message("Waiting."); endReactiveSteer = (request) => { const synchronous = mode.startsWith("reactive-steered-sync"); - const inherited = mode === "reactive-inherited-steer-settled-tool"; const joined = synchronous || inherited || mode === "reactive-echoed-steer-open-tool"; - const startTool = () => - tool("late-background", { CommandLine: "sleep 5" }, "sleep 5"); - if (inherited) startTool(); + if (beforeEcho) { + finish(sessionId); + startTool(); + } if (joined) update(sessionId, { sessionUpdate: "user_message_chunk", content: { type: "text", text: request.params.prompt[0].text }, }); if (mode === "reactive-steered-sync-open-at-first-end") startTool(); - finish(sessionId); + if (!beforeEcho) finish(sessionId); if (mode === "reactive-rejected-steer-text-before-tool") message("Still waiting."); - else if (!inherited && mode !== "reactive-steered-sync-open-at-first-end") + else if ( + !beforeEcho && + !inherited && + mode !== "reactive-steered-sync-open-at-first-end" + ) startTool(); if ( synchronous || From 11f24620bdd3fa6fdea3190b5f4445a4b952901a Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 11:22:58 +0000 Subject: [PATCH 27/31] Preserve cancellation and approval across overlapping prompts --- src/adapters/acp.ts | 14 +++++-- test/antigravity-steering.node.test.ts | 41 +++++++++++++++++++++ test/fixtures/fake-antigravity-steering.mjs | 41 +++++++++++++++++++++ 3 files changed, 93 insertions(+), 3 deletions(-) diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index 2d7268cc..36beefa3 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -652,7 +652,11 @@ export class Acp implements Adapter { const inheritedWork = [...this.toolsAtSteerDispatch].some((id) => this.reactiveTools.has(id), ); - if ((last || inheritedWork) && this.waitForReactiveTurn()) return; + if ( + (last || inheritedWork || this.permissions.size) && + this.waitForReactiveTurn() + ) + return; if (!last && this.waitsForReactiveTurns) { if ( this.echo && @@ -688,8 +692,12 @@ export class Acp implements Adapter { if (!last || this.closed || this.terminalReported) return; // A rejected steering input that never joined the turn does not // undo the turn's own normal end. - if (this.reactiveEnd && this.cancelling) { - this.refreshReactiveWait(); + if ( + this.cancelling && + (this.reactiveEnd || + (this.waitsForReactiveTurns && this.earlierEnd)) + ) { + this.interruptReactiveTurn(); return; } if ( diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index b12704d0..313b98a5 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -302,6 +302,47 @@ test("Antigravity cancels a reactive turn with an outstanding steering request", assert.equal(adapter.reusable, false); }); +test("Antigravity interrupts when cancellation rejects an unjoined steer after end_turn", async (t) => { + fixture(t); + process.env.LOOP_TEST_AGY_MODE = "reactive-cancel-unjoined-steer"; + const events: AdapterEvent[] = []; + const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => + events.push(e), + ); + t.after(() => adapter.dispose()); + await adapter.start(); + await adapter.prompt("Start work"); + const rejected = assert.rejects( + adapter.steer!("Keep going"), + /Steer rejected/, + ); + await until(() => events.some((e) => e.type === "usage")); + await adapter.cancel(); + await rejected; + assert.deepEqual(statuses(events), ["ready", "interrupted"]); +}); + +test("Antigravity keeps an approval spanning the original end_turn in the reactive wait", async (t) => { + fixture(t); + process.env.LOOP_TEST_AGY_MODE = "reactive-approval-at-first-end"; + const events: AdapterEvent[] = []; + const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => + events.push(e), + ); + t.after(() => adapter.dispose()); + await adapter.start(); + await adapter.prompt("Start work"); + const steer = adapter.steer!("Keep going"); + await until(() => events.some((e) => e.type === "usage")); + const approval = events.find((e) => e.type === "request")!; + await adapter.answer(approval.request.id, { choice: "allow" }); + await steer; + await until(() => + events.some((e) => e.type === "delta" && e.text === "Done."), + ); + assert.deepEqual(statuses(events), ["ready"]); +}); + test("Antigravity reports interruption before a blocked cancel notification settles", async (t) => { fixture(t); process.env.LOOP_TEST_AGY_MODE = "reactive-stalled"; diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index f134f277..5c944920 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -128,6 +128,7 @@ const finish = (sessionId, stopReason = "end_turn") => { let permission = 0; const permissions = new Map(); let endReactiveSteer; +let rejectSteerOnCancel; function reactiveTurn(sessionId, mode) { const tool = (toolCallId, rawInput, title = toolCallId) => @@ -153,6 +154,41 @@ function reactiveTurn(sessionId, mode) { const reportUsage = () => update(sessionId, { sessionUpdate: "usage_update", used: 20, size: 100 }); + if ( + mode === "reactive-cancel-unjoined-steer" || + mode === "reactive-approval-at-first-end" + ) { + message("Waiting."); + endReactiveSteer = (request) => { + if (mode === "reactive-cancel-unjoined-steer") { + finish(sessionId); + rejectSteerOnCancel = () => + send({ + id: request.id, + error: { code: -32603, message: "Steer rejected" }, + }); + return; + } + const id = `perm-${++permission}`; + permissions.set(id, () => { + reply(request.id, { stopReason: "end_turn" }); + setTimeout(() => message("Done."), 30); + }); + send({ + id, + method: "session/request_permission", + params: { + sessionId, + toolCall: { toolCallId: "approval-only", title: "Reactive approval" }, + options: [ + { optionId: "allow", name: "Allow once", kind: "allow_once" }, + ], + }, + }); + finish(sessionId); + }; + return; + } if (mode === "reactive-steered-sync-without-echo") { message("Waiting."); endReactiveSteer = (request) => { @@ -454,6 +490,11 @@ createInterface({ input: process.stdin }).on("line", (line) => { case "session/close": return reply(req.id, {}); case "session/cancel": + if (rejectSteerOnCancel) { + const reject = rejectSteerOnCancel; + rejectSteerOnCancel = undefined; + return reject(); + } return finish(sessionId, "cancelled"); case "session/prompt": { const text = req.params.prompt[0].text; From 07a85f2af307d72de8a8365938d234064c913c9a Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 11:25:51 +0000 Subject: [PATCH 28/31] Preserve the original tool baseline across overlapping steers --- src/adapters/acp.ts | 11 ++++++----- test/antigravity-steering.node.test.ts | 19 +++++++++++++++++++ test/fixtures/fake-antigravity-steering.mjs | 21 +++++++++++++++++++++ 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index 36beefa3..f41c4ade 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -168,7 +168,7 @@ export class Acp implements Adapter { private steering = false; /** The steering input's echo arrived, so it joined the running turn. */ private steerJoined = false; - private toolsAtSteerDispatch = new Set(); + private toolsAtFirstSteerDispatch?: Set; private workWhileSteerUnconfirmed = false; /** An earlier request of this turn ended it normally. */ private earlierEnd = false; @@ -613,6 +613,7 @@ export class Acp implements Adapter { this.messageId = randomUUID(); this.turnUsage = undefined; this.earlierEnd = false; + this.toolsAtFirstSteerDispatch = undefined; this.reactiveTools.clear(); this.reactiveEnd = false; this.reactiveBudget = REACTIVE_WATCHDOG_MS; @@ -649,9 +650,9 @@ export class Acp implements Adapter { // Antigravity gives reactive passes no definitive end signal. // Preserve their output as partial instead of publishing it // based on usage, steering replies, or elapsed time. - const inheritedWork = [...this.toolsAtSteerDispatch].some((id) => - this.reactiveTools.has(id), - ); + const inheritedWork = [ + ...(this.toolsAtFirstSteerDispatch ?? []), + ].some((id) => this.reactiveTools.has(id)); if ( (last || inheritedWork || this.permissions.size) && this.waitForReactiveTurn() @@ -889,7 +890,7 @@ export class Acp implements Adapter { throw new NotDelivered("ACP session is busy."); beforeDispatch?.(); this.steerJoined = false; - this.toolsAtSteerDispatch = new Set(this.reactiveTools); + this.toolsAtFirstSteerDispatch ??= new Set(this.reactiveTools); this.workWhileSteerUnconfirmed = false; const echoed = new Promise((resolve) => { if (expected) diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index 313b98a5..2337df2a 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -199,6 +199,25 @@ test("Antigravity completes a synchronous tool-only turn at end_turn", async (t) await until(() => complete(events).length === 1, 2000); }); +test("Antigravity keeps the first steer baseline across a second overlapping steer", async (t) => { + fixture(t); + process.env.LOOP_TEST_AGY_MODE = "reactive-overlapping-steers"; + const events: AdapterEvent[] = []; + const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => + events.push(e), + ); + t.after(() => adapter.dispose()); + await adapter.start(); + await adapter.prompt("Start work"); + await adapter.steer!("First steer"); + await until(() => + events.some((e) => e.type === "activity" && e.activity.id === "steer-tool"), + ); + await adapter.steer!("Second steer"); + await until(() => complete(events).length === 1, 2000); + assert.deepEqual(statuses(events), ["ready", "completed"]); +}); + test("Antigravity retires the live session when a steering limit interrupts reactive work", async (t) => { fixture(t); process.env.LOOP_TEST_AGY_MODE = "reactive-steer-limit"; diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index 5c944920..00030ce2 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -154,6 +154,27 @@ function reactiveTurn(sessionId, mode) { const reportUsage = () => update(sessionId, { sessionUpdate: "usage_update", used: 20, size: 100 }); + if (mode === "reactive-overlapping-steers") { + const echoSteer = (request) => + update(sessionId, { + sessionUpdate: "user_message_chunk", + content: { type: "text", text: request.params.prompt[0].text }, + }); + message("Waiting."); + endReactiveSteer = (first) => { + echoSteer(first); + tool("steer-tool", {}, "Synchronous tool"); + endReactiveSteer = (second) => { + echoSteer(second); + finish(sessionId); + complete("steer-tool"); + reply(first.id, { stopReason: "end_turn" }); + message("Done."); + reply(second.id, { stopReason: "end_turn" }); + }; + }; + return; + } if ( mode === "reactive-cancel-unjoined-steer" || mode === "reactive-approval-at-first-end" From 6714ab083b91057b74f667233dc09b2a2d852bab Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 11:28:32 +0000 Subject: [PATCH 29/31] Interrupt an unanswered overlapping prompt on cancellation --- src/adapters/acp.ts | 2 +- test/antigravity-steering.node.test.ts | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index f41c4ade..302c205a 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -763,7 +763,7 @@ export class Acp implements Adapter { ) return; if (this.cancelling) { - if (this.reactiveEnd) this.interruptReactiveTurn(); + this.interruptReactiveTurn(); return; } if (this.permissions.size) return; diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index 2337df2a..f1d380a9 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -341,6 +341,23 @@ test("Antigravity interrupts when cancellation rejects an unjoined steer after e assert.deepEqual(statuses(events), ["ready", "interrupted"]); }); +test("Antigravity interrupts an unanswered acknowledged steer on cancellation", async (t) => { + fixture(t); + process.env.LOOP_TEST_AGY_MODE = "reactive-stalled-joined-steer"; + const events: AdapterEvent[] = []; + const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => + events.push(e), + ); + t.after(() => adapter.dispose()); + await adapter.start(); + await adapter.prompt("Start work"); + await adapter.steer!("Keep going"); + await until(() => events.some((e) => e.type === "usage")); + await adapter.cancel(); + assert.deepEqual(statuses(events), ["ready", "interrupted"]); + assert.equal(adapter.reusable, false); +}); + test("Antigravity keeps an approval spanning the original end_turn in the reactive wait", async (t) => { fixture(t); process.env.LOOP_TEST_AGY_MODE = "reactive-approval-at-first-end"; From afffcf41a64f5637d2a90c092638ff2fda7599fb Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 11:32:16 +0000 Subject: [PATCH 30/31] Retain reactive work after late steering errors and usage --- src/adapters/acp.ts | 11 ++++++++-- test/antigravity-steering.node.test.ts | 18 ++++++++++++++++ test/fixtures/fake-antigravity-steering.mjs | 23 ++++++++++++++++++++- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index 302c205a..996dfc09 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -703,8 +703,7 @@ export class Acp implements Adapter { } if ( steer && - !this.steerJoined && - (this.earlierEnd || this.reactiveEnd) && + (this.reactiveEnd || (!this.steerJoined && this.earlierEnd)) && this.waitForReactiveTurn(this.workWhileSteerUnconfirmed) ) return; @@ -1353,6 +1352,14 @@ export class Acp implements Adapter { this.refreshReactiveWait(); return; } + if ( + u.sessionUpdate === "usage_update" && + this.reactiveEnd && + !this.cancelling + ) { + this.refreshReactiveWait(); + return; + } if ( u.sessionUpdate === "tool_call" || u.sessionUpdate === "tool_call_update" diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index f1d380a9..cccdf01f 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -321,6 +321,24 @@ test("Antigravity cancels a reactive turn with an outstanding steering request", assert.equal(adapter.reusable, false); }); +test("Antigravity preserves a reactive continuation when an echoed steer later rejects", async (t) => { + fixture(t); + process.env.LOOP_TEST_AGY_MODE = "reactive-reject-joined"; + const events: AdapterEvent[] = []; + const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => + events.push(e), + ); + t.after(() => adapter.dispose()); + await adapter.start(); + await adapter.prompt("Start work"); + await until(() => events.some((e) => e.type === "usage")); + await adapter.steer!("Keep going"); + await until(() => + events.some((e) => e.type === "delta" && e.text === "Done."), + ); + assert.deepEqual(statuses(events), ["ready"]); +}); + test("Antigravity interrupts when cancellation rejects an unjoined steer after end_turn", async (t) => { fixture(t); process.env.LOOP_TEST_AGY_MODE = "reactive-cancel-unjoined-steer"; diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index 00030ce2..afc017ef 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -521,12 +521,33 @@ createInterface({ input: process.stdin }).on("line", (line) => { const text = req.params.prompt[0].text; if ( turn === 1 && - ["reactive-stalled-steer", "reactive-budget"].includes(mode) + [ + "reactive-stalled-steer", + "reactive-budget", + "reactive-reject-joined", + ].includes(mode) ) { update(sessionId, { sessionUpdate: "user_message_chunk", content: { type: "text", text }, }); + if (mode === "reactive-reject-joined") { + send({ + id: req.id, + error: { code: -32603, message: "Steer rejected" }, + }); + setTimeout(() => { + update(sessionId, { + sessionUpdate: "tool_call_update", + toolCallId: "background", + status: "completed", + }); + update(sessionId, { + sessionUpdate: "agent_message_chunk", + content: { type: "text", text: "Done." }, + }); + }, 30); + } if (mode === "reactive-budget") send({ id: `perm-${++permission}`, From 261d4ac318346f7293ff937a1d5410c905fa0af0 Mon Sep 17 00:00:00 2001 From: Jamie Asefa <13409617+j-asefa@users.noreply.github.com> Date: Sat, 21 Nov 2026 11:36:11 +0000 Subject: [PATCH 31/31] Respect approvals from an acknowledged steering prompt --- src/adapters/acp.ts | 10 +++- test/antigravity-steering.node.test.ts | 51 +++++++++++++-------- test/fixtures/fake-antigravity-steering.mjs | 13 +++++- 3 files changed, 51 insertions(+), 23 deletions(-) diff --git a/src/adapters/acp.ts b/src/adapters/acp.ts index 996dfc09..31bdbc81 100644 --- a/src/adapters/acp.ts +++ b/src/adapters/acp.ts @@ -654,7 +654,9 @@ export class Acp implements Adapter { ...(this.toolsAtFirstSteerDispatch ?? []), ].some((id) => this.reactiveTools.has(id)); if ( - (last || inheritedWork || this.permissions.size) && + (last || + inheritedWork || + (!this.steerJoined && this.permissions.size)) && this.waitForReactiveTurn() ) return; @@ -703,7 +705,11 @@ export class Acp implements Adapter { } if ( steer && - (this.reactiveEnd || (!this.steerJoined && this.earlierEnd)) && + (this.reactiveEnd || + (this.earlierEnd && + (!this.steerJoined || + this.reactiveTools.size || + this.permissions.size))) && this.waitForReactiveTurn(this.workWhileSteerUnconfirmed) ) return; diff --git a/test/antigravity-steering.node.test.ts b/test/antigravity-steering.node.test.ts index cccdf01f..586d1e04 100644 --- a/test/antigravity-steering.node.test.ts +++ b/test/antigravity-steering.node.test.ts @@ -376,26 +376,37 @@ test("Antigravity interrupts an unanswered acknowledged steer on cancellation", assert.equal(adapter.reusable, false); }); -test("Antigravity keeps an approval spanning the original end_turn in the reactive wait", async (t) => { - fixture(t); - process.env.LOOP_TEST_AGY_MODE = "reactive-approval-at-first-end"; - const events: AdapterEvent[] = []; - const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => - events.push(e), - ); - t.after(() => adapter.dispose()); - await adapter.start(); - await adapter.prompt("Start work"); - const steer = adapter.steer!("Keep going"); - await until(() => events.some((e) => e.type === "usage")); - const approval = events.find((e) => e.type === "request")!; - await adapter.answer(approval.request.id, { choice: "allow" }); - await steer; - await until(() => - events.some((e) => e.type === "delta" && e.text === "Done."), - ); - assert.deepEqual(statuses(events), ["ready"]); -}); +for (const mode of [ + "reactive-approval-at-first-end", + "reactive-steer-owned-approval", +]) + test(`Antigravity handles an approval spanning the original end_turn in ${mode}`, async (t) => { + fixture(t); + process.env.LOOP_TEST_AGY_MODE = mode; + const events: AdapterEvent[] = []; + const adapter = new Antigravity({ ...options, version: "1.5.14" }, (e) => + events.push(e), + ); + t.after(() => adapter.dispose()); + await adapter.start(); + await adapter.prompt("Start work"); + const steer = adapter.steer!("Keep going"); + await until(() => events.some((e) => e.type === "usage")); + const approval = events.find((e) => e.type === "request")!; + await adapter.answer(approval.request.id, { choice: "allow" }); + await steer; + await until(() => + events.some((e) => e.type === "delta" && e.text === "Done."), + ); + if (mode === "reactive-steer-owned-approval") + await until(() => complete(events).length === 1, 2000); + assert.deepEqual( + statuses(events), + mode === "reactive-steer-owned-approval" + ? ["ready", "completed"] + : ["ready"], + ); + }); test("Antigravity reports interruption before a blocked cancel notification settles", async (t) => { fixture(t); diff --git a/test/fixtures/fake-antigravity-steering.mjs b/test/fixtures/fake-antigravity-steering.mjs index afc017ef..8cd343e6 100755 --- a/test/fixtures/fake-antigravity-steering.mjs +++ b/test/fixtures/fake-antigravity-steering.mjs @@ -177,7 +177,8 @@ function reactiveTurn(sessionId, mode) { } if ( mode === "reactive-cancel-unjoined-steer" || - mode === "reactive-approval-at-first-end" + mode === "reactive-approval-at-first-end" || + mode === "reactive-steer-owned-approval" ) { message("Waiting."); endReactiveSteer = (request) => { @@ -192,9 +193,19 @@ function reactiveTurn(sessionId, mode) { } const id = `perm-${++permission}`; permissions.set(id, () => { + if (mode === "reactive-steer-owned-approval") { + message("Done."); + reply(request.id, { stopReason: "end_turn" }); + return; + } reply(request.id, { stopReason: "end_turn" }); setTimeout(() => message("Done."), 30); }); + if (mode === "reactive-steer-owned-approval") + update(sessionId, { + sessionUpdate: "user_message_chunk", + content: { type: "text", text: request.params.prompt[0].text }, + }); send({ id, method: "session/request_permission",