Skip to content

Commit cefab49

Browse files
fix(antigravity): let Stop end commands that outlived their turn
Antigravity keeps a backgrounded command (a watcher, a dev server) open after end_turn, and T3 shows it as Monitoring. The Stop button on that banner sends a turn interrupt, which the adapter turned into session/cancel. With no prompt running that did nothing, so Monitoring stayed up until the command exited on its own or the server restarted (#12325). The agent only kills its background commands when its session closes, so when nothing but promoted commands is running, interruptTurn now stops the session, as Claude's adapter does. That completes each command as stopped; the next turn resumes the conversation. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent e67abcf commit cefab49

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

‎apps/server/src/provider/Layers/AntigravityAdapter.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,44 @@ it.layer(layer)("AntigravityAdapter", (it) => {
775775
}),
776776
);
777777

778+
it.effect("stops commands left running after a turn when the idle turn is stopped", () =>
779+
Effect.gen(function* () {
780+
const h = yield* makeHarness();
781+
yield* h.adapter.startSession({
782+
threadId,
783+
cwd: process.cwd(),
784+
runtimeMode: "approval-required",
785+
});
786+
const sending = yield* h.adapter
787+
.sendTurn({ threadId, input: "Start a watcher" })
788+
.pipe(Effect.forkChild);
789+
const prompt = yield* h.nextPrompt;
790+
yield* h.emitNative({
791+
_tag: "ToolCallUpdated",
792+
toolCall: {
793+
toolCallId: "watcher-1",
794+
kind: "execute",
795+
status: "inProgress",
796+
command: "tail -f log",
797+
data: {},
798+
},
799+
rawPayload: {},
800+
});
801+
yield* Deferred.succeed(prompt.result, { stopReason: "end_turn" });
802+
yield* Fiber.join(sending);
803+
const started = yield* h.waitForEvent((event) => event.type === "task.started");
804+
805+
// Monitoring's Stop reaches the adapter as a turn interrupt. With no
806+
// prompt to cancel, it has to end the session to stop the command.
807+
yield* h.adapter.interruptTurn(threadId);
808+
const stopped = yield* h.waitForEvent((event) => event.type === "task.completed");
809+
expect(stopped.payload).toMatchObject({ taskId: started.payload.taskId, status: "stopped" });
810+
yield* h.waitForEvent((event) => event.type === "session.exited");
811+
expect(yield* h.adapter.hasSession(threadId)).toBe(false);
812+
expect(h.controls.closed).toBe(1);
813+
}),
814+
);
815+
778816
it.effect("keeps a launched batch active while child tools continue", () =>
779817
Effect.gen(function* () {
780818
const h = yield* makeHarness();

‎apps/server/src/provider/Layers/AntigravityAdapter.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,13 @@ export const makeAntigravityAdapter = Effect.fn("makeAntigravityAdapter")(functi
11651165
const interruptTurn: Adapter["interruptTurn"] = (threadId) =>
11661166
Effect.gen(function* () {
11671167
const context = yield* requireSession(threadId);
1168+
// A command that outlived its turn keeps running in the agent, and
1169+
// session/cancel only stops a prompt. The agent kills its background
1170+
// commands when its session closes, so Stop with nothing else running
1171+
// ends the session, as Claude's does. The next turn resumes it.
1172+
if (!context.promptFiber && [...context.commands.values()].some((c) => c.promoted)) {
1173+
return yield* withThreadLock(threadId, stopContext(context));
1174+
}
11681175
yield* context.promptLock
11691176
.withPermit(
11701177
Effect.gen(function* () {

0 commit comments

Comments
 (0)