The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 07:15 UTC
fix(server): Antigravity invoke_subagent calls show as running subagents again (#38966)
Julius Marminge committed
Nov 18, 2026 at 22:54 UTC
43b37b6d3c0aff0025331226fc91a2affcf4ac08
5 files changed
+281
-6
apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts
+122
-1
@@ -99,6 +99,20 @@ describe("AntigravityAdapterV2 flavor", () => {
99
});
100
assert.equal(launch?.title, "Readme Reader");
101
assert.equal(launch?.prompt, "Read README.md");
102
+
103
+ // agy 1.5.x auto-approves one subagent per call with a flat input.
104
+ const single = flavor.extractSubagentUpdate?.({
105
+ toolCallId: "call_16976942396429577770",
106
+ title: "Run invoke_subagent",
107
+ kind: "other",
108
+ status: "completed",
109
+ data: {
110
+ rawInput: { TypeName: "research", Role: "Codebase Researcher", Prompt: "Read README.md" },
111
+ },
112
+ });
113
+ assert.equal(single?.status, "running");
114
+ assert.equal(single?.title, "Codebase Researcher");
115
+ assert.equal(single?.prompt, "Read README.md");
116
});
117
118
it("routes interaction_* permission requests to the question card", () => {
@@ -1066,6 +1080,8 @@ describe("AntigravityAdapterV2 html_render pages", () => {
1080
*/
1081
const openSessionWithRunningCommand = Effect.fn("openSessionWithRunningCommand")(function* (
1082
commandInput: Record<string, unknown>,
1083
+ /** The prompt launches one agy 1.5 subagent instead; its records live below this profile. */
1084
+ detachedChildProfile?: string,
1085
) {
1086
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
1087
const path = yield* Path.Path;
@@ -1124,7 +1140,18 @@ const openSessionWithRunningCommand = Effect.fn("openSessionWithRunningCommand")
1140
}).pipe(Effect.andThen(runtime.handleRequestPermission(handler))),
1141
prompt: () =>
1142
Effect.gen(function* () {
1127
- yield* send({ sessionUpdate: "tool_call", ...command, status: "in_progress" });
1143
+ yield* send(
1144
+ detachedChildProfile === undefined
1145
+ ? { sessionUpdate: "tool_call", ...command, status: "in_progress" }
1146
+ : {
1147
+ sessionUpdate: "tool_call",
1148
+ toolCallId: "call_research",
1149
+ kind: "other",
1150
+ title: "Run invoke_subagent",
1151
+ status: "completed",
1152
+ rawInput: { TypeName: "research", Role: "Researcher", Prompt: "Read it" },
1153
+ },
1154
+ );
1155
yield* send({
1156
sessionUpdate: "agent_message_chunk",
1157
content: { type: "text", text: "I'll render once the fetch finishes." },
@@ -1137,6 +1164,7 @@ const openSessionWithRunningCommand = Effect.fn("openSessionWithRunningCommand")
1164
},
1165
withProcess: (_stop, task) => task,
1166
defaultModel: Effect.undefined,
1167
+ ...(detachedChildProfile === undefined ? {} : { profileDirectory: detachedChildProfile }),
1168
});
1169
const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
1170
runtimeMode: "full-access",
@@ -1347,6 +1375,99 @@ describe("AntigravityAdapterV2 work after the prompt ends", () => {
1375
}).pipe(Effect.provide(layerSession)),
1376
);
1377
1378
+ // Files as agy 1.5.12 wrote them: the launch sits in the child's inbox, and the child's report
1379
+ // lands in the parent's inbox with no session update. Only the agent's own reply follows.
1380
+ it.effect.each([
1381
+ { reports: "after the prompt ends", duringPrompt: false },
1382
+ { reports: "while the prompt runs", duringPrompt: true },
1383
+ ])("keeps a detached subagent running until it reports $reports", ({ duringPrompt }) =>
1384
+ Effect.gen(function* () {
1385
+ const fileSystem = yield* FileSystem.FileSystem;
1386
+ const path = yield* Path.Path;
1387
+ const profile = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-antigravity-kids-" });
1388
+ const records = (conversationId: string, kind: string) =>
1389
+ path.join(profile, "antigravity-acp", "brain", conversationId, ".system_generated", kind);
1390
+ const write = (directory: string, name: string, value: unknown) =>
1391
+ fileSystem
1392
+ .makeDirectory(directory, { recursive: true })
1393
+ .pipe(
1394
+ Effect.andThen(
1395
+ fileSystem.writeFileString(path.join(directory, name), JSON.stringify(value)),
1396
+ ),
1397
+ );
1398
+ yield* write(records("mock-session-1", "subagents"), "child-1.json", {});
1399
+ yield* write(records("child-1", "messages"), "launch.json", {
1400
+ sender: "mock-session-1",
1401
+ sourceMetadata: { tool: { toolCall: { id: "call_research", name: "invoke_subagent" } } },
1402
+ });
1403
+ const report = write(records("mock-session-1", "messages"), "report.json", {
1404
+ sender: "child-1",
1405
+ });
1406
+ if (duringPrompt) yield* report;
1407
+
1408
+ const { usage, offers, send, startTurn, until, throughPromptSettled } =
1409
+ yield* openSessionWithRunningCommand({}, profile);
1410
+ yield* startTurn(1, false);
1411
+ const statuses = (events: ReadonlyArray<ProviderAdapter.ProviderAdapterV2Event>) =>
1412
+ events.flatMap((event) =>
1413
+ event.type === "subagent.updated" ? [event.subagent.status] : [],
1414
+ );
1415
+ const prompt = yield* throughPromptSettled;
1416
+ assert.equal(statuses(prompt).at(-1), duringPrompt ? "idle" : "running");
1417
+ if (!duringPrompt) {
1418
+ yield* TestClock.adjust("10 minutes");
1419
+ yield* report;
1420
+ yield* send({
1421
+ sessionUpdate: "agent_message_chunk",
1422
+ content: { type: "text", text: "The researcher found it." },
1423
+ });
1424
+ yield* send(usage);
1425
+ yield* TestClock.adjust("3 seconds");
1426
+ }
1427
+ const run = yield* until((event) => event.type === "turn.terminal");
1428
+ const terminal = run.at(-1);
1429
+ assert.equal(terminal?.type === "turn.terminal" && terminal.status, "completed");
1430
+ assert.equal(statuses([...prompt, ...run]).at(-1), "idle");
1431
+ assert.equal(
1432
+ JSON.stringify(run).includes("The researcher found it."),
1433
+ !duringPrompt,
1434
+ "the reply about the report is part of the run",
1435
+ );
1436
+ assert.lengthOf(offers, 0, "the open run needs no continuation");
1437
+ }).pipe(Effect.provide(layerSession)),
1438
+ );
1439
+
1440
+ it.effect("ends a continuation run whose replayed reply launched a subagent", () =>
1441
+ Effect.gen(function* () {
1442
+ const fileSystem = yield* FileSystem.FileSystem;
1443
+ // No records: nothing proves a child is at work, so none may hold a run open.
1444
+ const profile = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-antigravity-kids-" });
1445
+ const { usage, offers, send, startTurn, throughTerminal } =
1446
+ yield* openSessionWithRunningCommand({}, profile);
1447
+ yield* startTurn(1, false);
1448
+ yield* throughTerminal;
1449
+ yield* send({
1450
+ sessionUpdate: "tool_call",
1451
+ toolCallId: "call_follow_up",
1452
+ kind: "other",
1453
+ title: "Run invoke_subagent",
1454
+ status: "completed",
1455
+ rawInput: { TypeName: "research", Role: "Checker", Prompt: "Check it" },
1456
+ });
1457
+ yield* send({
1458
+ sessionUpdate: "agent_message_chunk",
1459
+ content: { type: "text", text: "Started a checker." },
1460
+ });
1461
+ yield* send(usage);
1462
+ assert.lengthOf(offers, 1, "the agent's own reply must wake the thread");
1463
+ yield* offers[0]!.dispatchIfCurrent!(Effect.void);
1464
+ yield* startTurn(2, true);
1465
+ yield* TestClock.adjust("3 seconds");
1466
+ const terminal = (yield* throughTerminal).at(-1);
1467
+ assert.equal(terminal?.type === "turn.terminal" && terminal.status, "completed");
1468
+ }).pipe(Effect.provide(layerSession)),
1469
+ );
1470
+
1471
it.effect.each([
1472
// session/cancel ends the agent's commands, so only Stop may send it.
1473
{ ending: "Stop", cancels: 1, status: "interrupted" },
apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.ts
+7
@@ -31,6 +31,7 @@ import {
31
ANTIGRAVITY_SUBAGENT_BATCH_TITLE,
32
antigravitySubagentLaunches,
33
describeAntigravitySubagentLaunches,
34
+ readAntigravityChildrenAtWork,
35
} from "../../provider/acp/AntigravityChildWork.ts";
36
import { readAntigravityClientTextFile } from "../../provider/acp/AntigravityClientFiles.ts";
37
import { watchAntigravityPromptOutcome } from "../../provider/acp/AntigravityTurnOutcome.ts";
@@ -303,6 +304,12 @@ export function makeAntigravityAcpAdapterFlavor(
304
: {
305
watchPromptOutcome: (sessionId: string) =>
306
watchAntigravityPromptOutcome(profileDirectory, sessionId),
307
+ subagentsOutlivingPrompt: ({ sessionId, nativeTaskIds }) =>
308
+ readAntigravityChildrenAtWork({
309
+ profileDirectory,
310
+ rootSessionId: sessionId,
311
+ toolCallIds: nativeTaskIds,
312
+ }),
313
}),
314
};
315
}
apps/server/src/provider/acp/AntigravityChildWork.ts
+98
-4
@@ -35,6 +35,8 @@ const TRANSCRIPT_BYTE_CAP = 256 * 1024;
35
const BATCH_TRANSCRIPT_BYTES = 512 * 1024;
36
const STEP_TEXT_CAP = 4_000;
37
const TOOL_INPUT_CAP = 1_000;
38
+const MAX_MESSAGE_FILES = 256;
39
+const MAX_DETACHED_CHILDREN = 64;
40
41
/** T3's title for a batch whose launch text it never saw. */
42
export const ANTIGRAVITY_SUBAGENT_BATCH_TITLE = "Antigravity subagent batch";
@@ -44,10 +46,10 @@ interface AntigravityChildLaunch {
46
readonly prompt: string;
47
}
48
49
+const LaunchInput = Schema.Struct({ Role: Schema.String, Prompt: Schema.String });
50
+// agy 1.5 launches one child per call with a flat input; earlier releases send a batch.
51
const decodeLaunchInput = Schema.decodeUnknownOption(
48
- Schema.Struct({
49
- Subagents: Schema.NonEmptyArray(Schema.Struct({ Role: Schema.String, Prompt: Schema.String })),
50
- }),
52
+ Schema.Union([Schema.Struct({ Subagents: Schema.NonEmptyArray(LaunchInput) }), LaunchInput]),
53
);
54
55
/** `invoke_subagent` arguments, from the permission prompt or the persisted record. */
@@ -56,7 +58,10 @@ export function antigravitySubagentLaunches(
58
): ReadonlyArray<AntigravityChildLaunch> | undefined {
59
return Option.getOrUndefined(
60
Option.map(decodeLaunchInput(input), (decoded) =>
59
- decoded.Subagents.map((entry) => ({ role: entry.Role, prompt: entry.Prompt })),
61
+ ("Subagents" in decoded ? decoded.Subagents : [decoded]).map((entry) => ({
62
+ role: entry.Role,
63
+ prompt: entry.Prompt,
64
+ })),
65
),
66
);
67
}
@@ -476,3 +481,92 @@ export const readAntigravityChildWork = Effect.fn("readAntigravityChildWork")(fu
481
catch: (cause) => new AntigravityChildWorkReadError({ cause }),
482
});
483
});
484
+
485
+const decodeChildMessage = Schema.decodeUnknownOption(
486
+ Schema.fromJsonString(
487
+ Schema.Struct({
488
+ sender: Schema.String,
489
+ sourceMetadata: Schema.optional(
490
+ Schema.Struct({
491
+ tool: Schema.optional(
492
+ Schema.Struct({
493
+ toolCall: Schema.optional(Schema.Struct({ id: Schema.String, name: Schema.String })),
494
+ }),
495
+ ),
496
+ }),
497
+ ),
498
+ }),
499
+ ),
500
+);
501
+
502
+/** A conversation's inbox. Throws past a bound or on a file it cannot read, so nothing is proven. */
503
+async function readInbox(profileRoot: string, conversationId: string) {
504
+ const directory = ["antigravity-acp", "brain", conversationId, ".system_generated", "messages"];
505
+ const inbox = await antigravityManagedPath(profileRoot, directory, "directory");
506
+ if (inbox === undefined) return [];
507
+ // `read.json` is the runtime's read receipts, not a message.
508
+ const names = (await NodeFSP.readdir(inbox.path)).filter(
509
+ (name) => name.endsWith(".json") && name !== "read.json",
510
+ );
511
+ if (names.length > MAX_MESSAGE_FILES) throw new Error("Too many messages");
512
+ return Promise.all(
513
+ names.map(async (name) => {
514
+ const file = await antigravityManagedPath(profileRoot, [...directory, name], "file");
515
+ if (file === undefined || file.info.size > MAX_STEP_BYTES) throw new Error("Unreadable");
516
+ return Option.getOrThrow(decodeChildMessage(await NodeFSP.readFile(file.path, "utf8")));
517
+ }),
518
+ );
519
+}
520
+
521
+/**
522
+ * agy 1.5 children outlive their `invoke_subagent` call and the agent reports no end for them:
523
+ * a child is done, or waits for guidance, once its message is in the parent's inbox. Returns the
524
+ * launching tool call ids of children with no message yet; none when the records prove nothing.
525
+ */
526
+export const readAntigravityChildrenAtWork = Effect.fn("readAntigravityChildrenAtWork")(
527
+ function* (input: {
528
+ readonly profileDirectory: string;
529
+ readonly rootSessionId: string;
530
+ readonly toolCallIds: ReadonlyArray<string>;
531
+ }) {
532
+ if (!NATIVE_ID.test(input.rootSessionId)) return [];
533
+ const read = async (): Promise<ReadonlyArray<string>> => {
534
+ const profileRoot = await antigravityProfileRoot(input.profileDirectory);
535
+ const children =
536
+ profileRoot === undefined
537
+ ? undefined
538
+ : await antigravityManagedPath(
539
+ profileRoot,
540
+ ["antigravity-acp", "brain", input.rootSessionId, ".system_generated", "subagents"],
541
+ "directory",
542
+ );
543
+ if (profileRoot === undefined || children === undefined) return [];
544
+ const childIds = (await NodeFSP.readdir(children.path)).flatMap((name) =>
545
+ name.endsWith(".json") && NATIVE_ID.test(name.slice(0, -5)) ? [name.slice(0, -5)] : [],
546
+ );
547
+ if (childIds.length > MAX_DETACHED_CHILDREN) return [];
548
+ const reported = new Set(
549
+ (await readInbox(profileRoot, input.rootSessionId)).map((message) => message.sender),
550
+ );
551
+ const atWork: Array<string> = [];
552
+ for (const childId of childIds) {
553
+ if (reported.has(childId)) continue;
554
+ for (const message of await readInbox(profileRoot, childId)) {
555
+ const launch = message.sourceMetadata?.tool?.toolCall;
556
+ if (
557
+ message.sender === input.rootSessionId &&
558
+ launch?.name === "invoke_subagent" &&
559
+ input.toolCallIds.includes(launch.id)
560
+ ) {
561
+ atWork.push(launch.id);
562
+ }
563
+ }
564
+ }
565
+ return atWork;
566
+ };
567
+ return yield* Effect.tryPromise({
568
+ try: read,
569
+ catch: (cause) => new AntigravityChildWorkReadError({ cause }),
570
+ }).pipe(Effect.orElseSucceed((): ReadonlyArray<string> => []));
571
+ },
572
+);
apps/server/src/provider/acp/AntigravityProtocol.ts
+2
@@ -516,6 +516,8 @@ const ANTIGRAVITY_SUBAGENT_TITLES = new Set([
516
"Run start_subagent?",
517
"Running invoke_subagent",
518
"Run invoke_subagent?",
519
+ // agy 1.5 auto-approved calls.
520
+ "Run invoke_subagent",
521
]);
522
523
/** The ACP agent reports subagent calls as ordinary tools without child IDs or models. */
packages/provider-acp/src/server/adapter.ts
+52
-1
@@ -503,6 +503,15 @@ export interface AcpAdapterV2Flavor {
503
cwd: string,
504
) => Effect.Effect<void>;
505
readonly subagentsIdleOnTurnCompletion?: boolean;
506
+ /**
507
+ * Subagents the agent goes on running after its prompt, with no update when one ends. Asked
508
+ * when the prompt ends and when a reply the agent started by itself ends; the native task ids
509
+ * it returns hold the turn open and the rest become idle.
510
+ */
511
+ readonly subagentsOutlivingPrompt?: (input: {
512
+ readonly sessionId: string;
513
+ readonly nativeTaskIds: ReadonlyArray<string>;
514
+ }) => Effect.Effect<ReadonlyArray<string>>;
515
readonly supportsCompaction?: boolean;
516
/** Sends `/compact` as a prompt, only to sessions whose advertised commands include `compact`. */
517
readonly compactViaAdvertisedCommand?: boolean;
@@ -4156,7 +4165,11 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
4165
if (status === "pending" || status === "running") return true;
4166
}
4167
// finalizeTurn idles these subagents, so waiting on them would never settle.
4159
- if (flavor.subagentsIdleOnTurnCompletion === true) return false;
4168
+ if (
4169
+ flavor.subagentsIdleOnTurnCompletion === true &&
4170
+ flavor.subagentsOutlivingPrompt === undefined
4171
+ )
4172
+ return false;
4173
for (const subagent of context.subagents.values()) {
4174
if (acpSubagentStatusBlocksTurnSettlement(subagent.task.status)) {
4175
return true;
@@ -4165,6 +4178,39 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
4178
return false;
4179
};
4180
4181
+ const idleReportedSubagents = Effect.fn("AcpAdapterV2.idleReportedSubagents")(function* (
4182
+ context: ActiveAcpTurn,
4183
+ ) {
4184
+ if (flavor.subagentsOutlivingPrompt === undefined) return;
4185
+ const nativeTaskId = (subagent: ActiveAcpSubagent) =>
4186
+ subagent.task.nativeTaskRef?.nativeId ?? String(subagent.task.id);
4187
+ const running = [...context.subagents.values()].filter((subagent) =>
4188
+ acpSubagentStatusBlocksTurnSettlement(subagent.task.status),
4189
+ );
4190
+ if (running.length === 0) return;
4191
+ const atWork = yield* flavor.subagentsOutlivingPrompt({
4192
+ sessionId: context.nativeThreadId,
4193
+ nativeTaskIds: running.map(nativeTaskId),
4194
+ });
4195
+ if (context.finalized) return;
4196
+ for (const subagent of running) {
4197
+ if (
4198
+ atWork.includes(nativeTaskId(subagent)) ||
4199
+ !acpSubagentStatusBlocksTurnSettlement(subagent.task.status)
4200
+ )
4201
+ continue;
4202
+ yield* emitSubagent(context, {
4203
+ nativeTaskId: nativeTaskId(subagent),
4204
+ prompt: subagent.task.prompt,
4205
+ title: subagent.task.title,
4206
+ model: subagent.task.model,
4207
+ status: "idle",
4208
+ childSessionId: subagent.childSessionId,
4209
+ result: null,
4210
+ });
4211
+ }
4212
+ });
4213
+
4214
const hasSurvivingBackgroundWork = (context: ActiveAcpTurn): boolean =>
4215
[...context.toolCallIdsByBackgroundTaskId.values()].some((toolCallId) => {
4216
const tool = context.tools.get(toolCallId);
@@ -5515,6 +5561,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
5561
} else if (context.nativeThreadId === notification.sessionId) {
5562
if (update.sessionUpdate === "usage_update") {
5563
context.replyOpen = false;
5564
+ if (context.promptSettled) yield* idleReportedSubagents(context);
5565
yield* rearmDeferredFinalize(context);
5566
} else if (acpRootSessionUpdateIngestsOutput(notification)) {
5567
context.replyOpen = true;
@@ -9050,6 +9097,8 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
9097
}
9098
context.promptSettled = true;
9099
context.promptSettledStatus = "completed";
9100
+ // The replayed reply ended before the prompt counted as settled.
9101
+ yield* idleReportedSubagents(context);
9102
if (drainedWakeCount === 0) {
9103
if (continuationWasRequested && defersFinalizeForBackgroundWork) {
9104
if (hasDeferredBackgroundWork(context)) {
@@ -9200,6 +9249,8 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
9249
});
9250
return;
9251
}
9252
+ yield* idleReportedSubagents(context);
9253
+ if (context.finalized) return;
9254
if (
9255
defersFinalizeForBackgroundWork &&
9256
!context.interrupted &&