Skip to content

Commit af6fb53

Browse files
shivamhwpjuliusmarmingeclaude
committed
fix(server): keep Antigravity commands active and show wakeups
Keep running execute tools attached to the turn after end_turn, and clear tracking when their terminal update omits kind. Enable provider continuations and preserve wake replies while a follow-up command is running. Refs #28415 Co-authored-by: Julius Marminge <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 575579d commit af6fb53

3 files changed

Lines changed: 274 additions & 1 deletion

File tree

‎apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts‎

Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@ import { htmlRenderFromToolItem } from "@t3tools/shared/toolOutput";
1616
import * as Crypto from "effect/Crypto";
1717
import * as DateTime from "effect/DateTime";
1818
import * as Deferred from "effect/Deferred";
19+
import type * as Duration from "effect/Duration";
1920
import * as Effect from "effect/Effect";
2021
import * as Exit from "effect/Exit";
2122
import * as FileSystem from "effect/FileSystem";
2223
import * as Layer from "effect/Layer";
2324
import * as Path from "effect/Path";
25+
import * as Queue from "effect/Queue";
2426
import * as Stream from "effect/Stream";
27+
import * as TestClock from "effect/testing/TestClock";
2528
import { ChildProcessSpawner } from "effect/process";
2629
import type * as EffectAcpSchema from "effect-acp/compat";
2730
import * as EffectAcpErrors from "effect-acp/errors";
@@ -36,10 +39,12 @@ import { normalizeAntigravitySessionUpdate } from "../../provider/acp/Antigravit
3639
import { ANTIGRAVITY_SIGN_IN_REQUIRED_MESSAGE } from "../../provider/antigravityAuthSupport.ts";
3740
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
3841
import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
42+
import type * as ProviderContinuationRequests from "@t3tools/provider-core/server/ProviderContinuationRequests";
3943
import {
4044
makeAntigravityAcpAdapterFlavor,
4145
makeAntigravityAdapterV2,
4246
} from "./AntigravityAdapterV2.ts";
47+
import { makeTurnInput } from "./AcpAdapterV2.testkit.ts";
4348

4449
const flavor = makeAntigravityAcpAdapterFlavor({
4550
instanceId: ProviderInstanceId.make("antigravity-test"),
@@ -1037,3 +1042,251 @@ describe("AntigravityAdapterV2 subagent reads", () => {
10371042
}).pipe(Effect.provide(layerSession), Effect.scoped),
10381043
);
10391044
});
1045+
1046+
describe("AntigravityAdapterV2 commands running past the reply", () => {
1047+
it.effect("holds the turn for a running command and offers a continuation for its wake", () =>
1048+
Effect.gen(function* () {
1049+
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
1050+
const path = yield* Path.Path;
1051+
const crypto = yield* Crypto.Crypto;
1052+
const mockAgentPath = yield* path.fromFileUrl(
1053+
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
1054+
);
1055+
type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"];
1056+
let sessionUpdate: Parameters<RuntimeService["handleSessionUpdate"]>[0] | undefined;
1057+
const promptStarted = yield* Deferred.make<void>();
1058+
const promptGate = yield* Deferred.make<EffectAcpSchema.PromptResponse>();
1059+
const promptHeld = yield* Deferred.make<void>();
1060+
const finalizeScheduled = yield* Queue.unbounded<Duration.Input>();
1061+
const continuationRequests: Array<ProviderContinuationRequests.ProviderContinuationRequest> =
1062+
[];
1063+
const instanceId = ProviderInstanceId.make("antigravity-running-command-test");
1064+
const threadId = ThreadId.make("thread-antigravity-running-command");
1065+
const adapter = yield* makeAntigravityAdapterV2({
1066+
instanceId,
1067+
selfInvocation: yield* resolveSelfInvocation(),
1068+
makeRuntime: (input) =>
1069+
makeAntigravityAcpRuntime({
1070+
...input,
1071+
childProcessSpawner,
1072+
spawn: {
1073+
command: process.execPath,
1074+
args: [mockAgentPath],
1075+
cwd: input.cwd,
1076+
env: { T3_ACP_ANTIGRAVITY: "1" },
1077+
},
1078+
}).pipe(
1079+
Effect.provideService(Crypto.Crypto, crypto),
1080+
Effect.map((runtime): RuntimeService => ({
1081+
...runtime,
1082+
handleSessionUpdate: (handler) =>
1083+
Effect.sync(() => {
1084+
sessionUpdate = handler;
1085+
}).pipe(Effect.andThen(runtime.handleSessionUpdate(handler))),
1086+
prompt: () =>
1087+
Deferred.succeed(promptStarted, undefined).pipe(
1088+
Effect.andThen(Deferred.await(promptGate)),
1089+
),
1090+
})),
1091+
),
1092+
withProcess: (_stop, task) => task,
1093+
defaultModel: Effect.undefined,
1094+
continuationRequests: {
1095+
offer: (request) => Effect.sync(() => void continuationRequests.push(request)),
1096+
},
1097+
testHooks: {
1098+
afterPromptSettledWithBackgroundWork: () =>
1099+
Deferred.succeed(promptHeld, undefined).pipe(Effect.asVoid),
1100+
onDeferredFinalizeScheduled: (debounce) =>
1101+
Queue.offer(finalizeScheduled, debounce).pipe(Effect.asVoid),
1102+
},
1103+
});
1104+
const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
1105+
runtimeMode: "full-access",
1106+
interactionMode: "default",
1107+
cwd: process.cwd(),
1108+
});
1109+
const modelSelection = { instanceId, model: "gemini-test-low" } as const;
1110+
const session = yield* adapter.openSession({
1111+
threadId,
1112+
providerSessionId: ProviderSessionId.make("provider-session-antigravity-running-command"),
1113+
modelSelection,
1114+
runtimePolicy,
1115+
});
1116+
const events = yield* Queue.unbounded<ProviderAdapter.ProviderAdapterV2Event>();
1117+
yield* session.events.pipe(
1118+
Stream.runForEach((event) => Queue.offer(events, event)),
1119+
Effect.forkScoped,
1120+
);
1121+
const providerThread = yield* session.ensureThread({
1122+
threadId,
1123+
modelSelection,
1124+
runtimePolicy,
1125+
});
1126+
const now = yield* DateTime.now;
1127+
const turnInput = (ordinal: number, continuation: boolean) =>
1128+
makeTurnInput({
1129+
threadId,
1130+
providerThread,
1131+
instanceId,
1132+
runtimePolicy,
1133+
now,
1134+
ordinal,
1135+
modelSelection,
1136+
...(continuation
1137+
? { messageCreatedBy: "agent" as const, messageCreationSource: "provider" as const }
1138+
: {}),
1139+
});
1140+
const seen: Array<ProviderAdapter.ProviderAdapterV2Event> = [];
1141+
const takeUntil = (done: (event: ProviderAdapter.ProviderAdapterV2Event) => boolean) =>
1142+
Effect.gen(function* () {
1143+
while (true) {
1144+
const event = yield* Queue.take(events);
1145+
seen.push(event);
1146+
if (done(event)) return event;
1147+
}
1148+
});
1149+
const toolStatuses = (runId: RunId, nativeId: string) =>
1150+
seen.flatMap((event) =>
1151+
event.type === "turn_item.updated" &&
1152+
event.turnItem.runId === runId &&
1153+
event.turnItem.nativeItemRef?.nativeId === nativeId
1154+
? [event.turnItem.status]
1155+
: [],
1156+
);
1157+
const send = (update: EffectAcpSchema.SessionUpdate) =>
1158+
sessionUpdate === undefined
1159+
? Effect.die("the adapter must handle session updates")
1160+
: sessionUpdate(
1161+
normalizeAntigravitySessionUpdate({ sessionId: "mock-session-1", update }),
1162+
);
1163+
const say = (text: string) =>
1164+
send({ sessionUpdate: "agent_message_chunk", content: { type: "text", text } });
1165+
1166+
const first = turnInput(1, false);
1167+
yield* session.startTurn(first).pipe(Effect.forkScoped);
1168+
yield* Deferred.await(promptStarted);
1169+
// A command that finishes inside the prompt is ordinary foreground work.
1170+
yield* send({
1171+
sessionUpdate: "tool_call",
1172+
toolCallId: "list",
1173+
title: "Terminal",
1174+
kind: "execute",
1175+
status: "in_progress",
1176+
rawInput: { CommandLine: "ls" },
1177+
});
1178+
yield* send({ sessionUpdate: "tool_call_update", toolCallId: "list", status: "completed" });
1179+
yield* send({
1180+
sessionUpdate: "tool_call",
1181+
toolCallId: "build",
1182+
title: "Terminal",
1183+
kind: "execute",
1184+
status: "in_progress",
1185+
rawInput: { CommandLine: "npm run build" },
1186+
});
1187+
// Neither a command awaiting approval nor a subagent batch may hold the turn.
1188+
yield* send({
1189+
sessionUpdate: "tool_call",
1190+
toolCallId: "approval",
1191+
title: "Terminal",
1192+
kind: "execute",
1193+
status: "pending",
1194+
rawInput: { CommandLine: "npm run dev" },
1195+
});
1196+
yield* send({
1197+
sessionUpdate: "tool_call",
1198+
toolCallId: "trajectory:4",
1199+
title: "Running start_subagent",
1200+
kind: "other",
1201+
status: "completed",
1202+
rawOutput: "Started two agents.",
1203+
});
1204+
yield* say("Waiting for the build to finish.");
1205+
yield* Deferred.succeed(promptGate, { stopReason: "end_turn" });
1206+
const held = yield* Deferred.await(promptHeld).pipe(
1207+
Effect.as(true),
1208+
Effect.raceFirst(
1209+
takeUntil((event) => event.type === "turn.terminal").pipe(Effect.as(false)),
1210+
),
1211+
);
1212+
assert.isTrue(held, "the running command holds the turn past end_turn");
1213+
1214+
// Antigravity reports the command's end after the prompt returned, without its kind.
1215+
yield* send({ sessionUpdate: "tool_call_update", toolCallId: "build", status: "completed" });
1216+
yield* takeUntil(
1217+
(event) =>
1218+
event.type === "turn_item.updated" &&
1219+
event.turnItem.nativeItemRef?.nativeId === "build" &&
1220+
event.turnItem.status === "completed",
1221+
);
1222+
assert.isFalse(seen.some((event) => event.type === "turn.terminal"));
1223+
yield* TestClock.adjust(yield* Queue.take(finalizeScheduled));
1224+
const firstTerminal = yield* takeUntil((event) => event.type === "turn.terminal");
1225+
assert.equal(
1226+
firstTerminal.type === "turn.terminal" ? firstTerminal.status : null,
1227+
"completed",
1228+
);
1229+
assert.deepEqual(toolStatuses(first.runId, "build").slice(-1), ["completed"]);
1230+
assert.deepEqual(toolStatuses(first.runId, "approval").slice(-1), ["completed"]);
1231+
const batch = seen.findLast((event) => event.type === "subagent.updated");
1232+
assert.equal(batch?.type === "subagent.updated" ? batch.subagent.status : null, "idle");
1233+
assert.lengthOf(continuationRequests, 0);
1234+
yield* Queue.clear(finalizeScheduled);
1235+
1236+
// The command's completion wakes the agent, which starts another command before speaking.
1237+
yield* send({
1238+
sessionUpdate: "tool_call",
1239+
toolCallId: "test",
1240+
title: "Terminal",
1241+
kind: "execute",
1242+
status: "in_progress",
1243+
rawInput: { CommandLine: "npm test" },
1244+
});
1245+
yield* say("The build passed. Running the tests.");
1246+
assert.lengthOf(continuationRequests, 1, "the reply opens a continuation while tests run");
1247+
assert.equal(continuationRequests[0]?.threadId, threadId);
1248+
yield* send({
1249+
sessionUpdate: "tool_call_update",
1250+
toolCallId: "test",
1251+
status: "in_progress",
1252+
content: [{ type: "content", content: { type: "text", text: "3 of 6 suites passed" } }],
1253+
});
1254+
yield* say("Halfway through the tests.");
1255+
1256+
const continuation = turnInput(2, true);
1257+
yield* session.startTurn(continuation).pipe(Effect.forkScoped);
1258+
yield* takeUntil(
1259+
(event) =>
1260+
event.type === "message.updated" &&
1261+
event.message.runId === continuation.runId &&
1262+
event.message.text.includes("Halfway through the tests."),
1263+
);
1264+
assert.equal(yield* Queue.size(finalizeScheduled), 0, "the running command holds the turn");
1265+
yield* send({ sessionUpdate: "tool_call_update", toolCallId: "test", status: "completed" });
1266+
yield* say("All tests passed.");
1267+
yield* TestClock.adjust(yield* Queue.take(finalizeScheduled));
1268+
const continuationTerminal = yield* takeUntil(
1269+
(event) => event.type === "turn.terminal" && event.runOrdinal === continuation.runOrdinal,
1270+
);
1271+
assert.equal(
1272+
continuationTerminal.type === "turn.terminal" ? continuationTerminal.status : null,
1273+
"completed",
1274+
);
1275+
const continuationText = seen.flatMap((event) =>
1276+
event.type === "message.updated" &&
1277+
event.message.role === "assistant" &&
1278+
event.message.runId === continuation.runId
1279+
? [event.message.text]
1280+
: [],
1281+
);
1282+
assert.isTrue(
1283+
["The build passed.", "Halfway through the tests.", "All tests passed."].every((reply) =>
1284+
continuationText.some((text) => text.includes(reply)),
1285+
),
1286+
"the wake's replies stream into the continuation",
1287+
);
1288+
assert.deepEqual(toolStatuses(continuation.runId, "test").slice(-1), ["completed"]);
1289+
assert.lengthOf(continuationRequests, 1);
1290+
}).pipe(Effect.provide(layerSession), Effect.scoped),
1291+
);
1292+
});

‎apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export interface AntigravityAdapterV2Options {
8080
readonly onSessionEvent?: AcpAdapterV2Flavor["onSessionEvent"];
8181
readonly nativeLogging?: Parameters<typeof makeAcpAdapterV2>[0]["nativeLogging"];
8282
readonly continuationRequests?: Parameters<typeof makeAcpAdapterV2>[0]["continuationRequests"];
83+
readonly testHooks?: Parameters<typeof makeAcpAdapterV2>[0]["testHooks"];
8384
}
8485

8586
/** Native subagent tools report no child session ids. */
@@ -202,6 +203,17 @@ export function makeAntigravityAcpAdapterFlavor(
202203
),
203204
// Loading history replays tool calls; resume avoids replay.
204205
subagentsIdleOnTurnCompletion: true,
206+
// Antigravity answers end_turn while commands it started keep running.
207+
// Their terminal updates can omit the kind, so any terminal id clears tracking.
208+
extractBackgroundTaskId: (toolCall) =>
209+
(toolCall.kind === "execute" && toolCall.status === "inProgress") ||
210+
toolCall.status === "completed" ||
211+
toolCall.status === "failed"
212+
? toolCall.toolCallId
213+
: undefined,
214+
backgroundTasksIncludeForegroundTools: true,
215+
deferFinalizeForBackgroundWork: true,
216+
enablePostSettleContinuation: true,
205217
...(options.onSessionEvent === undefined ? {} : { onSessionEvent: options.onSessionEvent }),
206218
applyModelSelection: Effect.fn("AntigravityAdapterV2.applyModelSelection")(function* ({
207219
runtime,
@@ -261,5 +273,6 @@ export const makeAntigravityAdapterV2 = Effect.fn("makeAntigravityAdapterV2")(fu
261273
...(options.continuationRequests === undefined
262274
? {}
263275
: { continuationRequests: options.continuationRequests }),
276+
...(options.testHooks === undefined ? {} : { testHooks: options.testHooks }),
264277
});
265278
});

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,8 @@ export interface AcpAdapterV2Flavor {
374374
readonly normalizeToolCall?: (toolCall: AcpToolCallState) => AcpToolCallState;
375375
readonly extractProposedPlanMarkdown?: (toolCall: AcpToolCallState) => string | undefined;
376376
readonly extractBackgroundTaskId?: (toolCall: AcpToolCallState) => string | undefined;
377+
/** Tracked tools include ordinary foreground tools, so agent output around them is not ack chatter. */
378+
readonly backgroundTasksIncludeForegroundTools?: boolean;
377379
/** Distinguishes commands from monitors when lifecycle notifications omit their kind. */
378380
readonly isBackgroundCommandTool?: (toolCall: AcpToolCallState) => boolean;
379381
readonly extractBackgroundToolMutation?: (text: string) => ReadonlyArray<{
@@ -3397,6 +3399,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
33973399
const status = toolStatus(tool.status);
33983400
if (status === "pending" || status === "running") return true;
33993401
}
3402+
if (flavor.subagentsIdleOnTurnCompletion === true) return false;
34003403
for (const subagent of context.subagents.values()) {
34013404
if (acpSubagentStatusBlocksTurnSettlement(subagent.task.status)) {
34023405
return true;
@@ -3540,6 +3543,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
35403543
backgroundStatus === "pending" || backgroundStatus === "running",
35413544
);
35423545
if (
3546+
flavor.backgroundTasksIncludeForegroundTools !== true &&
35433547
!context.promptSettled &&
35443548
backgroundStatus !== "pending" &&
35453549
backgroundStatus !== "running"
@@ -4397,7 +4401,10 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
43974401
}
43984402
}
43994403
}
4400-
const backgroundWorkRunning = (yield* Ref.get(runningBackgroundTaskIds)).size > 0;
4404+
// A woken agent's own running tool is its work, not a monitor it acknowledges.
4405+
const backgroundWorkRunning =
4406+
flavor.backgroundTasksIncludeForegroundTools !== true &&
4407+
(yield* Ref.get(runningBackgroundTaskIds)).size > 0;
44014408
const handledInTurnCount = (yield* Ref.get(handledBackgroundTaskIdsInActiveTurn)).size;
44024409
const isInTurnHandledAgentChatter =
44034410
handledInTurnCount > 0 &&

0 commit comments

Comments
 (0)