The best way to control Claude Code, Codex and more from any computer or phone
fix(server): read detached Antigravity 1.5 subagent transcripts (#39004)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
zhangyc committed
Nov 19, 2026 at 16:03 UTC
066be300053f47889e1f076c363297832633e760
2 files changed
+310
-42
apps/server/src/provider/acp/AntigravityChildWork.test.ts
+154
@@ -318,6 +318,160 @@ it.layer(NodeServices.layer)("readAntigravityChildWork", (it) => {
318
}),
319
);
320
321
+ it.effect("follows a detached 1.5 launch id through the child's inbox to its transcript", () =>
322
+ Effect.gen(function* () {
323
+ const fs = yield* FileSystem.FileSystem;
324
+ const path = yield* Path.Path;
325
+ const profile = yield* fs.makeTempDirectoryScoped({ prefix: "t3-agy-detached-" });
326
+ const sibling = "b468c0e1-d2f3-4a5b-6c7d-8e9f0a1b2c3d";
327
+ const writeJson = (segments: ReadonlyArray<string>, value: unknown) => {
328
+ const file = path.join(profile, "antigravity-acp", "brain", ...segments);
329
+ return fs
330
+ .makeDirectory(path.dirname(file), { recursive: true })
331
+ .pipe(Effect.andThen(fs.writeFileString(file, JSON.stringify(value))));
332
+ };
333
+ const writeTranscript = (
334
+ conversationId: string,
335
+ lines: ReadonlyArray<Record<string, unknown>>,
336
+ ) => {
337
+ const file = path.join(
338
+ profile,
339
+ "antigravity-acp",
340
+ "brain",
341
+ conversationId,
342
+ ".system_generated",
343
+ "logs",
344
+ "transcript.jsonl",
345
+ );
346
+ return fs
347
+ .makeDirectory(path.dirname(file), { recursive: true })
348
+ .pipe(
349
+ Effect.andThen(
350
+ fs.writeFileString(file, lines.map((line) => JSON.stringify(line)).join("\n") + "\n"),
351
+ ),
352
+ );
353
+ };
354
+
355
+ // Matches real agy 1.5.12 records (no legacy step_type=127 database row).
356
+ yield* writeJson([ROOT, ".system_generated", "subagents", `${CHILD}.json`], {
357
+ conversationId: CHILD,
358
+ subagentDescriptor: { typeName: "research", role: LAUNCH.role },
359
+ state: "SUBAGENT_STATE_ALIVE",
360
+ });
361
+ yield* writeJson([CHILD, ".system_generated", "messages", "launch.json"], {
362
+ sender: ROOT,
363
+ content: LAUNCH.prompt,
364
+ sourceMetadata: {
365
+ tool: {
366
+ conversationId: ROOT,
367
+ stepIndex: 2,
368
+ toolCall: {
369
+ id: "call_11340266277043349041",
370
+ name: "invoke_subagent",
371
+ argumentsJson: JSON.stringify({
372
+ TypeName: "research",
373
+ Role: LAUNCH.role,
374
+ Prompt: LAUNCH.prompt,
375
+ }),
376
+ },
377
+ },
378
+ },
379
+ });
380
+ yield* writeJson([CHILD, ".system_generated", "messages", "read.json"], { launch: true });
381
+ yield* writeTranscript(CHILD, [
382
+ {
383
+ step_index: 0,
384
+ type: "SYSTEM_MESSAGE",
385
+ status: "DONE",
386
+ content: `<SYSTEM_MESSAGE>\n[Message] sender=${ROOT} content=${LAUNCH.prompt}\n</SYSTEM_MESSAGE>`,
387
+ },
388
+ {
389
+ step_index: 1,
390
+ type: "PLANNER_RESPONSE",
391
+ status: "DONE",
392
+ tool_calls: [{ name: "read_file", args: { Path: '"/project/README.md"' } }],
393
+ },
394
+ {
395
+ step_index: 2,
396
+ type: "GENERIC",
397
+ status: "DONE",
398
+ content: "2: MAGIC_TOKEN=probe-38478-ok",
399
+ },
400
+ ]);
401
+
402
+ // A second detached child without argumentsJson falls back to descriptor role + message content.
403
+ yield* writeJson([ROOT, ".system_generated", "subagents", `${sibling}.json`], {
404
+ conversationId: sibling,
405
+ subagentDescriptor: { typeName: "research", role: "Line Counter" },
406
+ });
407
+ yield* writeJson([sibling, ".system_generated", "messages", "launch.json"], {
408
+ sender: ROOT,
409
+ content: "Count lines in README.md",
410
+ sourceMetadata: {
411
+ tool: {
412
+ toolCall: { id: "call_22340266277043349042", name: "invoke_subagent" },
413
+ },
414
+ },
415
+ });
416
+ // A follow-up send_message must not be treated as a launch.
417
+ yield* writeJson([sibling, ".system_generated", "messages", "followup.json"], {
418
+ sender: ROOT,
419
+ content: "Also check LICENSE",
420
+ sourceMetadata: {
421
+ tool: {
422
+ toolCall: { id: "call_followup", name: "send_message" },
423
+ },
424
+ },
425
+ });
426
+
427
+ const [first, ...firstRest] = yield* read(profile, "call_11340266277043349041", {
428
+ title: LAUNCH.role,
429
+ prompt: LAUNCH.prompt,
430
+ });
431
+ expect(firstRest).toEqual([]);
432
+ expect(first).toMatchObject({
433
+ conversationId: CHILD,
434
+ role: LAUNCH.role,
435
+ prompt: LAUNCH.prompt,
436
+ truncated: false,
437
+ });
438
+ expect(first?.steps?.map((step) => step.text ?? step.toolCalls[0]?.name)).toEqual([
439
+ "read_file",
440
+ "2: MAGIC_TOKEN=probe-38478-ok",
441
+ ]);
442
+ expect(first?.steps?.[0]?.toolCalls[0]?.input).toBe('{"Path":"/project/README.md"}');
443
+
444
+ // Missing transcript still returns the proven child with steps: null.
445
+ const [second] = yield* read(profile, "call_22340266277043349042", {
446
+ title: "Line Counter",
447
+ prompt: "Count lines in README.md",
448
+ });
449
+ expect(second).toEqual({
450
+ conversationId: sibling,
451
+ role: "Line Counter",
452
+ prompt: "Count lines in README.md",
453
+ steps: null,
454
+ truncated: false,
455
+ });
456
+
457
+ // Unknown id and send_message id return nothing.
458
+ expect(yield* read(profile, "call_unknown")).toEqual([]);
459
+ expect(yield* read(profile, "call_followup")).toEqual([]);
460
+
461
+ // Another child claiming the same toolCall id makes ownership ambiguous.
462
+ yield* writeJson([sibling, ".system_generated", "messages", "dup.json"], {
463
+ sender: ROOT,
464
+ content: LAUNCH.prompt,
465
+ sourceMetadata: {
466
+ tool: {
467
+ toolCall: { id: "call_11340266277043349041", name: "invoke_subagent" },
468
+ },
469
+ },
470
+ });
471
+ expect(yield* read(profile, "call_11340266277043349041")).toEqual([]);
472
+ }),
473
+ );
474
+
475
it.effect("shares one transcript budget across the batch", () =>
476
Effect.gen(function* () {
477
const filler = JSON.stringify({
apps/server/src/provider/acp/AntigravityChildWork.ts
+156
-42
@@ -125,7 +125,10 @@ const text = (bytes: Uint8Array | undefined, field: number) => {
125
interface InvokeRecord {
126
readonly toolCallId: string | undefined;
127
readonly launches: ReadonlyArray<AntigravityChildLaunch>;
128
- readonly children: ReadonlyArray<{ readonly conversationId: string; readonly logUri: string }>;
128
+ readonly children: ReadonlyArray<{
129
+ readonly conversationId: string;
130
+ readonly logUri?: string | undefined;
131
+ }>;
132
}
133
134
const NATIVE_ID = /^[A-Za-z0-9-]{1,64}$/;
@@ -386,13 +389,15 @@ async function readChildTranscript(
389
)
390
)?.path;
391
if (expected === undefined) return undefined;
389
- let named: string;
390
- try {
391
- named = NodeURL.fileURLToPath(child.logUri);
392
- } catch {
393
- return undefined;
392
+ if (child.logUri !== undefined) {
393
+ let named: string;
394
+ try {
395
+ named = NodeURL.fileURLToPath(child.logUri);
396
+ } catch {
397
+ return undefined;
398
+ }
399
+ if ((await NodeFSP.realpath(named).catch(() => undefined)) !== expected) return undefined;
400
}
395
- if ((await NodeFSP.realpath(named).catch(() => undefined)) !== expected) return undefined;
401
const handle = await NodeFSP.open(
402
expected,
403
NodeFS.constants.O_RDONLY | (NodeFS.constants.O_NOFOLLOW ?? 0),
@@ -435,23 +440,27 @@ export const readAntigravityChildWork = Effect.fn("readAntigravityChildWork")(fu
440
return yield* Effect.tryPromise({
441
try: async (): Promise<ReadonlyArray<OrchestrationV2NativeChildWork>> => {
442
const profileRoot = await antigravityProfileRoot(input.profileDirectory);
438
- const databasePath =
439
- profileRoot === undefined
440
- ? undefined
441
- : (
442
- await antigravityManagedPath(
443
- profileRoot,
444
- ["antigravity-acp", "conversations", `${input.rootSessionId}.db`],
445
- "file",
446
- )
447
- )?.path;
448
- if (profileRoot === undefined || databasePath === undefined) return [];
449
- const database = new NodeSqlite.DatabaseSync(databasePath, { readOnly: true });
450
- let record: InvokeRecord | undefined;
451
- try {
452
- record = findInvokeRecord(database, input);
453
- } finally {
454
- database.close();
443
+ if (profileRoot === undefined) return [];
444
+ let record = await findDetachedInvokeRecord(
445
+ profileRoot,
446
+ input.rootSessionId,
447
+ input.nativeTaskId,
448
+ );
449
+ if (record === undefined) {
450
+ const databasePath = (
451
+ await antigravityManagedPath(
452
+ profileRoot,
453
+ ["antigravity-acp", "conversations", `${input.rootSessionId}.db`],
454
+ "file",
455
+ )
456
+ )?.path;
457
+ if (databasePath === undefined) return [];
458
+ const database = new NodeSqlite.DatabaseSync(databasePath, { readOnly: true });
459
+ try {
460
+ record = findInvokeRecord(database, input);
461
+ } finally {
462
+ database.close();
463
+ }
464
}
465
if (record === undefined) return [];
466
const { launches, children } = record;
@@ -486,11 +495,19 @@ const decodeChildMessage = Schema.decodeUnknownOption(
495
Schema.fromJsonString(
496
Schema.Struct({
497
sender: Schema.String,
498
+ content: Schema.optional(Schema.String),
499
sourceMetadata: Schema.optional(
500
Schema.Struct({
501
tool: Schema.optional(
502
Schema.Struct({
493
- toolCall: Schema.optional(Schema.Struct({ id: Schema.String, name: Schema.String })),
503
+ conversationId: Schema.optional(Schema.String),
504
+ toolCall: Schema.optional(
505
+ Schema.Struct({
506
+ id: Schema.String,
507
+ name: Schema.String,
508
+ argumentsJson: Schema.optional(Schema.String),
509
+ }),
510
+ ),
511
}),
512
),
513
}),
@@ -499,6 +516,19 @@ const decodeChildMessage = Schema.decodeUnknownOption(
516
),
517
);
518
519
+const decodeDetachedSubagent = Schema.decodeUnknownOption(
520
+ Schema.fromJsonString(
521
+ Schema.Struct({
522
+ conversationId: Schema.optional(Schema.String),
523
+ subagentDescriptor: Schema.optional(
524
+ Schema.Struct({
525
+ role: Schema.optional(Schema.String),
526
+ }),
527
+ ),
528
+ }),
529
+ ),
530
+);
531
+
532
/** A conversation's inbox. Throws past a bound or on a file it cannot read, so nothing is proven. */
533
async function readInbox(profileRoot: string, conversationId: string) {
534
const directory = ["antigravity-acp", "brain", conversationId, ".system_generated", "messages"];
@@ -518,6 +548,102 @@ async function readInbox(profileRoot: string, conversationId: string) {
548
);
549
}
550
551
+type ChildMessage = Awaited<ReturnType<typeof readInbox>>[number];
552
+
553
+async function listDetachedChildIds(
554
+ profileRoot: string,
555
+ rootSessionId: string,
556
+): Promise<ReadonlyArray<string> | undefined> {
557
+ const children = await antigravityManagedPath(
558
+ profileRoot,
559
+ ["antigravity-acp", "brain", rootSessionId, ".system_generated", "subagents"],
560
+ "directory",
561
+ );
562
+ if (children === undefined) return undefined;
563
+ const entries = await NodeFSP.readdir(children.path).catch(() => undefined);
564
+ if (entries === undefined) return undefined;
565
+ const childIds = entries.flatMap((name) =>
566
+ name.endsWith(".json") && NATIVE_ID.test(name.slice(0, -5)) ? [name.slice(0, -5)] : [],
567
+ );
568
+ return childIds.length > MAX_DETACHED_CHILDREN ? undefined : childIds;
569
+}
570
+
571
+function detachedLaunchCall(message: ChildMessage, rootSessionId: string) {
572
+ const tool = message.sourceMetadata?.tool;
573
+ const call = tool?.toolCall;
574
+ return message.sender === rootSessionId &&
575
+ (tool?.conversationId === undefined || tool.conversationId === rootSessionId) &&
576
+ call?.name === "invoke_subagent"
577
+ ? call
578
+ : undefined;
579
+}
580
+
581
+async function readDetachedSubagent(profileRoot: string, rootSessionId: string, childId: string) {
582
+ const file = await antigravityManagedPath(
583
+ profileRoot,
584
+ [
585
+ "antigravity-acp",
586
+ "brain",
587
+ rootSessionId,
588
+ ".system_generated",
589
+ "subagents",
590
+ `${childId}.json`,
591
+ ],
592
+ "file",
593
+ );
594
+ if (file === undefined || file.info.size > MAX_STEP_BYTES) return undefined;
595
+ const contents = await NodeFSP.readFile(file.path, "utf8").catch(() => undefined);
596
+ if (contents === undefined) return undefined;
597
+ const record = Option.getOrUndefined(decodeDetachedSubagent(contents));
598
+ return record !== undefined &&
599
+ (record.conversationId === undefined || record.conversationId === childId)
600
+ ? record
601
+ : undefined;
602
+}
603
+
604
+/**
605
+ * agy 1.5 records detached children under `subagents/` instead of a SQLite `INVOKE_SUBAGENT` step;
606
+ * the child's own inbox carries the parent's launching `invoke_subagent` tool call id.
607
+ */
608
+async function findDetachedInvokeRecord(
609
+ profileRoot: string,
610
+ rootSessionId: string,
611
+ nativeTaskId: string,
612
+): Promise<InvokeRecord | undefined> {
613
+ const childIds = await listDetachedChildIds(profileRoot, rootSessionId);
614
+ if (childIds === undefined || childIds.length === 0) return undefined;
615
+ const matches: Array<InvokeRecord> = [];
616
+ for (const childId of childIds) {
617
+ const messages = await readInbox(profileRoot, childId).catch(() => undefined);
618
+ // An unreadable or oversized sibling inbox could also claim this id, so uniqueness is unproven.
619
+ if (messages === undefined) return undefined;
620
+ const launchMessage = messages.find(
621
+ (message) => detachedLaunchCall(message, rootSessionId)?.id === nativeTaskId,
622
+ );
623
+ if (launchMessage === undefined) continue;
624
+ const subagent = await readDetachedSubagent(profileRoot, rootSessionId, childId);
625
+ if (subagent === undefined) return undefined;
626
+ const argumentsJson = launchMessage.sourceMetadata?.tool?.toolCall?.argumentsJson;
627
+ const parsedArgs =
628
+ argumentsJson === undefined
629
+ ? undefined
630
+ : Option.getOrUndefined(decodeArgument(argumentsJson));
631
+ const [fromArgs] = antigravitySubagentLaunches(parsedArgs) ?? [];
632
+ matches.push({
633
+ toolCallId: nativeTaskId,
634
+ launches: [
635
+ fromArgs ?? {
636
+ role: subagent.subagentDescriptor?.role ?? "",
637
+ prompt: launchMessage.content ?? "",
638
+ },
639
+ ],
640
+ children: [{ conversationId: childId }],
641
+ });
642
+ }
643
+ const [match] = matches;
644
+ return matches.length === 1 ? match : undefined;
645
+}
646
+
647
/**
648
* agy 1.5 children outlive their `invoke_subagent` call and the agent reports no end for them:
649
* a child is done, or waits for guidance, once its message is in the parent's inbox. Returns the
@@ -532,19 +658,11 @@ export const readAntigravityChildrenAtWork = Effect.fn("readAntigravityChildrenA
658
if (!NATIVE_ID.test(input.rootSessionId)) return [];
659
const read = async (): Promise<ReadonlyArray<string>> => {
660
const profileRoot = await antigravityProfileRoot(input.profileDirectory);
535
- const children =
661
+ const childIds =
662
profileRoot === undefined
663
? 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 [];
664
+ : await listDetachedChildIds(profileRoot, input.rootSessionId);
665
+ if (profileRoot === undefined || childIds === undefined) return [];
666
const reported = new Set(
667
(await readInbox(profileRoot, input.rootSessionId)).map((message) => message.sender),
668
);
@@ -552,12 +670,8 @@ export const readAntigravityChildrenAtWork = Effect.fn("readAntigravityChildrenA
670
for (const childId of childIds) {
671
if (reported.has(childId)) continue;
672
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
- ) {
673
+ const launch = detachedLaunchCall(message, input.rootSessionId);
674
+ if (launch !== undefined && input.toolCallIds.includes(launch.id)) {
675
atWork.push(launch.id);
676
}
677
}