From 02cddf694e65a4535f999d288de40aebf2fbdbb5 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 5 Nov 2026 05:46:01 +0000 Subject: [PATCH 1/3] test(server): auto-approved Antigravity launch ids name the step that ran them (reproduces #31297) The runtime numbers auto-approved tool call ids by the executing step, skipping planner steps that carry neither text nor thinking. The reader treats the suffix as the planner's steps.idx, so a later launch in a session resolves to no children. Co-Authored-By: Claude Opus 5.5 --- .../provider/acp/AntigravityChildWork.test.ts | 58 +++++++++++++++++++ .../acp/AntigravityChildWork.testkit.ts | 18 +++++- 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/apps/server/src/provider/acp/AntigravityChildWork.test.ts b/apps/server/src/provider/acp/AntigravityChildWork.test.ts index 78927b09d74e3..d1c17bd878971 100644 --- a/apps/server/src/provider/acp/AntigravityChildWork.test.ts +++ b/apps/server/src/provider/acp/AntigravityChildWork.test.ts @@ -20,6 +20,7 @@ import { invokeStep, LAUNCH, makeProfile, + plannerResponse, plannerStep, ROOT, transcriptLines, @@ -68,6 +69,63 @@ it.layer(NodeServices.layer)("readAntigravityChildWork", (it) => { }), ); + it.effect("follows each auto-approved launch id to the step that ran it", () => + Effect.gen(function* () { + const tester = { role: "Test Runner", prompt: "Run the tests" }; + const empty = new Uint8Array(); + // A 1.4.5 session: USER_INPUT 14, VIEW_FILE 8, SYSTEM_MESSAGE 101, PLANNER_RESPONSE 15. + // Ids number the executing steps, skipping planners with neither text nor thinking: + // the invoke records at idx 8 and 12 arrive as `:6` and `:9`. + const { profile } = yield* makeProfile({ + steps: (logUri) => [ + [0, 14, empty], + [ + 1, + 15, + plannerResponse({ + calls: [ + ["v1", "view_file"], + ["v2", "view_file"], + ], + }), + ], + [2, 8, empty], + [3, 8, empty], + [4, 15, plannerResponse({ text: "Reading more", calls: [["v3", "view_file"]] })], + [5, 8, empty], + [ + 6, + 15, + plannerResponse({ + calls: [ + ["v4", "view_file"], + ["call-a", "invoke_subagent"], + ], + }), + ], + [7, 8, empty], + [ + 8, + 127, + invokeStep({ callId: "call-a", launches: [LAUNCH], children: [{ id: CHILD, logUri }] }), + ], + [9, 15, plannerResponse({ text: "The reader is done", calls: [] })], + [10, 101, empty], + [11, 15, plannerResponse({ calls: [["call-b", "invoke_subagent"]] })], + [ + 12, + 127, + invokeStep({ callId: "call-b", launches: [tester], children: [{ id: CHILD, logUri }] }), + ], + ], + }); + const first = yield* read(profile, `${ROOT}:6`); + expect(first.map((child) => child.role)).toEqual([LAUNCH.role]); + const second = yield* read(profile, `${ROOT}:9`); + expect(second.map((child) => child.role)).toEqual([tester.role]); + }), + ); + it.effect("needs proof that the call id belongs to the parent's record", () => Effect.gen(function* () { const { profile } = yield* makeProfile({ diff --git a/apps/server/src/provider/acp/AntigravityChildWork.testkit.ts b/apps/server/src/provider/acp/AntigravityChildWork.testkit.ts index 82a2befbf6698..2a815149a84ca 100644 --- a/apps/server/src/provider/acp/AntigravityChildWork.testkit.ts +++ b/apps/server/src/provider/acp/AntigravityChildWork.testkit.ts @@ -25,7 +25,7 @@ const field = (number: number, value: string | Uint8Array) => { return [...varint(number * 8 + 2), ...varint(bytes.length), ...bytes]; }; const proto = (...parts: number[][]) => Uint8Array.from(parts.flat()); -const toolCall = (id: string) => proto(field(1, id), field(2, "invoke_subagent")); +const toolCall = (id: string, name = "invoke_subagent") => proto(field(1, id), field(2, name)); export const invokeStep = (input: { readonly callId: string; @@ -49,6 +49,22 @@ export const invokeStep = (input: { ); export const plannerStep = (callIds: ReadonlyArray) => proto(field(20, proto(...callIds.map((id) => field(7, toolCall(id)))))); +/** A planner message with response text (field 1) or thinking (field 3) besides its calls. */ +export const plannerResponse = (input: { + readonly text?: string; + readonly thinking?: string; + readonly calls: ReadonlyArray; +}) => + proto( + field( + 20, + proto( + input.text === undefined ? [] : field(1, input.text), + input.thinking === undefined ? [] : field(3, input.thinking), + ...input.calls.map(([id, name]) => field(7, toolCall(id, name))), + ), + ), + ); export const transcriptLines = [ // Trimmed from 1.4.5: the launch envelope around the prompt the parent record already holds. From 3e9603a91defe4966994f522e4444d466ff36243 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 5 Nov 2026 05:52:00 +0000 Subject: [PATCH 2/3] fix(server): Antigravity subagent view finds auto-approved launches An auto-approved launch id `:` numbers the step that ran invoke_subagent, counting every step except planner responses with neither text nor thinking. The reader took n as the planner's row idx, so later launches in a session showed no children. It now walks the planner and invoke rows in order and resolves n to the invoke record at that position, for the launch and for sibling claims alike, and declines when a planner below is unreadable or a scan bound is hit. Co-Authored-By: Claude Opus 5.5 --- .../provider/acp/AntigravityChildWork.test.ts | 57 +++++-- .../src/provider/acp/AntigravityChildWork.ts | 142 +++++++++++------- 2 files changed, 134 insertions(+), 65 deletions(-) diff --git a/apps/server/src/provider/acp/AntigravityChildWork.test.ts b/apps/server/src/provider/acp/AntigravityChildWork.test.ts index d1c17bd878971..8d198a6c572e5 100644 --- a/apps/server/src/provider/acp/AntigravityChildWork.test.ts +++ b/apps/server/src/provider/acp/AntigravityChildWork.test.ts @@ -128,26 +128,65 @@ it.layer(NodeServices.layer)("readAntigravityChildWork", (it) => { it.effect("needs proof that the call id belongs to the parent's record", () => Effect.gen(function* () { + const empty = new Uint8Array(); + // Planners with thinking take an index too: steps 0-2, 4-7 number 0-6. const { profile } = yield* makeProfile({ steps: (logUri) => [ - ...autoApproved(logUri), - [5, 15, plannerStep(["call-b", "call-c"])], + [0, 14, empty], + [1, 15, plannerResponse({ thinking: "Look first", calls: [["v1", "view_file"]] })], + [2, 8, empty], + [3, 15, plannerResponse({ calls: [["v2", "view_file"]] })], + [4, 8, empty], [ - 6, - 127, - invokeStep({ callId: "call-b", launches: [LAUNCH], children: [{ id: CHILD, logUri }] }), + 5, + 15, + plannerResponse({ + thinking: "Delegate", + calls: [ + ["v3", "view_file"], + ["call-a", "invoke_subagent"], + ], + }), ], + [6, 8, empty], [ 7, 127, - invokeStep({ callId: "call-c", launches: [LAUNCH], children: [{ id: CHILD, logUri }] }), + invokeStep({ callId: "call-a", launches: [LAUNCH], children: [{ id: CHILD, logUri }] }), ], ], }); - // Another session's id, a step that is not the planner call, and parallel calls that share one id. - expect(yield* read(profile, `00000000-0000-4000-8000-000000000000:1`)).toEqual([]); - expect(yield* read(profile, `${ROOT}:2`)).toEqual([]); + expect(yield* read(profile, `${ROOT}:6`)).toHaveLength(1); + // Another session's id, a step that ran another tool, and a step past the end. + expect(yield* read(profile, `00000000-0000-4000-8000-000000000000:6`)).toEqual([]); expect(yield* read(profile, `${ROOT}:5`)).toEqual([]); + expect(yield* read(profile, `${ROOT}:7`)).toEqual([]); + }), + ); + + it.effect("declines an auto-approved id when a planner below it is unreadable", () => + Effect.gen(function* () { + // That planner may or may not take an index, so the record is at `:1` or `:2`. + for (const planner of [Uint8Array.from([0xff, 0xff]), new Uint8Array(1024 * 1024 + 1)]) { + const { profile } = yield* makeProfile({ + steps: (logUri) => [ + [0, 14, new Uint8Array()], + [1, 15, planner], + [2, 15, plannerStep(["call-a"])], + [ + 3, + 127, + invokeStep({ + callId: "call-a", + launches: [LAUNCH], + children: [{ id: CHILD, logUri }], + }), + ], + ], + }); + expect(yield* read(profile, `${ROOT}:1`)).toEqual([]); + expect(yield* read(profile, `${ROOT}:2`)).toEqual([]); + } }), ); diff --git a/apps/server/src/provider/acp/AntigravityChildWork.ts b/apps/server/src/provider/acp/AntigravityChildWork.ts index ea12e0e2b20de..eb43217dd864a 100644 --- a/apps/server/src/provider/acp/AntigravityChildWork.ts +++ b/apps/server/src/provider/acp/AntigravityChildWork.ts @@ -17,19 +17,22 @@ import { antigravityManagedPath, antigravityProfileRoot } from "./AntigravityPro import { boundAntigravityToolText, isCutAntigravityToolText } from "./AntigravityProtocol.ts"; // Field numbers from the runtime's trajectory protos (exa.cortex_pb). -const STEP_METADATA = 5; -const METADATA_TOOL_CALL = 4; const STEP_PLANNER_RESPONSE = 20; -const PLANNER_TOOL_CALLS = 7; +const PLANNER_TEXT = 1; +const PLANNER_THINKING = 3; const STEP_INVOKE_SUBAGENT = 143; const INVOKE_SPECS = 9; const INVOKE_RESULTS = 10; const INVOKE_SUBAGENT_STEP_TYPE = 127; +const PLANNER_RESPONSE_STEP_TYPE = 15; // One open reads at most this much; past any bound the batch view stays as it was. const MAX_STEP_BYTES = 1024 * 1024; const MAX_INVOKE_ROWS = 200; const MAX_SCAN_BYTES = 8 * 1024 * 1024; +// Numbering an auto-approved id reads the planner steps below its record. +const MAX_PLANNER_ROWS = 2_000; +const MAX_PLANNER_BYTES = 32 * 1024 * 1024; const MAX_CHILDREN = 16; const TRANSCRIPT_BYTE_CAP = 256 * 1024; const BATCH_TRANSCRIPT_BYTES = 512 * 1024; @@ -118,7 +121,6 @@ const text = (bytes: Uint8Array | undefined, field: number) => { }; interface InvokeRecord { - readonly toolCallId: string | undefined; readonly launches: ReadonlyArray; readonly children: ReadonlyArray<{ readonly conversationId: string; readonly logUri: string }>; } @@ -145,7 +147,6 @@ const decodeInvokeRecord = safely((payload): InvokeRecord | undefined => { })); if (!children.every((child) => NATIVE_ID.test(child.conversationId))) return undefined; return { - toolCallId: text(message(message(payload, STEP_METADATA), METADATA_TOOL_CALL), 1), launches: messages(invoke, INVOKE_SPECS).map((spec) => ({ role: text(spec, 2) ?? "", prompt: text(spec, 3) ?? "", @@ -154,13 +155,13 @@ const decodeInvokeRecord = safely((payload): InvokeRecord | undefined => { }; }); -const plannerInvokeCallIds = safely((payload): ReadonlyArray => { +/** The runtime gives no step index to a planner response with neither text nor thinking. */ +const plannerTakesIndex = safely((payload): boolean | undefined => { const planner = message(payload, STEP_PLANNER_RESPONSE); - if (planner === undefined) return []; - return messages(planner, PLANNER_TOOL_CALLS).flatMap((call) => { - const id = text(call, 1); - return text(call, 2) === "invoke_subagent" && id !== undefined ? [id] : []; - }); + if (planner === undefined) return undefined; + return [PLANNER_TEXT, PLANNER_THINKING].some( + (field) => (message(planner, field)?.length ?? 0) > 0, + ); }); const payloadOf = (row: unknown) => @@ -176,21 +177,66 @@ interface BatchLaunch { readonly prompt: string; } -const plannerCallIdsAt = (database: NodeSqlite.DatabaseSync, plannerIdx: number) => { - const planner = payloadOf( +/** + * Maps runtime step indexes to the idx of the invoke record that ran there. Steps take indexes in + * idx order, except planner responses with neither text nor thinking; an unreadable planner below + * leaves the numbering unproven, so the result is undefined. + */ +function invokeIdxAtStepIndex( + database: NodeSqlite.DatabaseSync, + stepIndexes: ReadonlySet, +): ReadonlyMap | undefined { + const found = new Map(); + const last = Math.max(...stepIndexes); + let skipped = 0; + let invokes = 0; + let planners = 0; + let plannerBytes = 0; + for (const row of database + .prepare( + // SQLite returns only in-bound planner payloads, so an oversized row never reaches this process. + "SELECT idx, step_type, step_format, length(step_payload) AS size, CASE WHEN step_type = ? AND length(step_payload) <= ? THEN step_payload END AS step_payload FROM steps WHERE step_type IN (?, ?) ORDER BY idx", + ) + .iterate( + PLANNER_RESPONSE_STEP_TYPE, + MAX_STEP_BYTES, + PLANNER_RESPONSE_STEP_TYPE, + INVOKE_SUBAGENT_STEP_TYPE, + )) { + const idx = Number(row.idx); + if (row.step_type === INVOKE_SUBAGENT_STEP_TYPE) { + if (++invokes > MAX_INVOKE_ROWS) return undefined; + const stepIndex = idx - skipped; + if (stepIndexes.has(stepIndex)) found.set(stepIndex, idx); + if (stepIndex >= last) break; + continue; + } + planners += 1; + plannerBytes += Number(row.size ?? 0); + if (planners > MAX_PLANNER_ROWS || plannerBytes > MAX_PLANNER_BYTES) return undefined; + const payload = row.step_format === 0 ? payloadOf(row) : undefined; + const takesIndex = payload === undefined ? undefined : plannerTakesIndex(payload); + if (takesIndex === undefined) return undefined; + if (!takesIndex) skipped += 1; + } + return found; +} + +const invokeRecordAt = (database: NodeSqlite.DatabaseSync, idx: number) => { + const payload = payloadOf( database .prepare( - "SELECT step_payload FROM steps WHERE idx = ? AND step_format = 0 AND length(step_payload) <= ?", + "SELECT step_payload FROM steps WHERE idx = ? AND step_type = ? AND step_format = 0 AND length(step_payload) <= ?", ) - .get(plannerIdx, MAX_STEP_BYTES), + .get(idx, INVOKE_SUBAGENT_STEP_TYPE, MAX_STEP_BYTES), ); - return planner === undefined ? undefined : plannerInvokeCallIds(planner); + return payload === undefined ? undefined : decodeInvokeRecord(payload); }; /** - * Auto-approved calls carry `:`; the record with that planner call's id - * is the proof. Permission prompts carry a random id, so the launch text must match one record - * no auto-approved sibling claims, and no sibling may share the text. + * Auto-approved calls carry `:`, the runtime's index of the step that ran the call, + * so the record at that index is the proof. Permission prompts carry a random id, so the launch + * text must match one record no auto-approved sibling claims, and no sibling may share the text. */ function findInvokeRecord( database: NodeSqlite.DatabaseSync, @@ -201,35 +247,16 @@ function findInvokeRecord( readonly siblings: ReadonlyArray; }, ): InvokeRecord | undefined { - const plannerIdxOf = (nativeTaskId: string) => { + const stepIndexOf = (nativeTaskId: string) => { const stepId = /^(.+):(\d+)$/.exec(nativeTaskId); return stepId === null ? undefined : stepId[1] === input.rootSessionId ? Number(stepId[2]) : -1; }; - const plannerIdx = plannerIdxOf(input.nativeTaskId); - if (plannerIdx !== undefined) { - if (plannerIdx < 0) return undefined; - const callIds = plannerCallIdsAt(database, plannerIdx) ?? []; - const [callId] = callIds; - if (callIds.length !== 1) return undefined; - // The record follows the planner step that issued the call. - let rows = 0; - let bytes = 0; - for (const row of database - .prepare( - // SQLite returns only in-bound payloads, so an oversized row never reaches this process. - "SELECT length(step_payload) AS size, CASE WHEN length(step_payload) <= ? THEN step_payload END AS step_payload FROM steps WHERE step_type = ? AND step_format = 0 AND idx > ? ORDER BY idx", - ) - .iterate(MAX_STEP_BYTES, INVOKE_SUBAGENT_STEP_TYPE, plannerIdx)) { - const size = row !== null && typeof row === "object" && "size" in row ? Number(row.size) : 0; - rows += 1; - bytes += size; - if (rows > MAX_INVOKE_ROWS || size > MAX_STEP_BYTES || bytes > MAX_SCAN_BYTES) - return undefined; - const payload = payloadOf(row); - const record = payload === undefined ? undefined : decodeInvokeRecord(payload); - if (record !== undefined && record.toolCallId === callId) return complete(record); - } - return undefined; + const stepIndex = stepIndexOf(input.nativeTaskId); + if (stepIndex !== undefined) { + if (stepIndex < 0) return undefined; + const idx = invokeIdxAtStepIndex(database, new Set([stepIndex]))?.get(stepIndex); + const record = idx === undefined ? undefined : invokeRecordAt(database, idx); + return record === undefined ? undefined : complete(record); } const totals = database .prepare( @@ -249,12 +276,12 @@ function findInvokeRecord( ) { return undefined; } - const claimed = new Set(); + const siblingStepIndexes = new Set(); for (const sibling of input.siblings) { - const idx = plannerIdxOf(sibling.nativeTaskId); - // A sibling whose launch text is missing, or cut under the same roles, or whose planner step - // is unreadable, cannot be ruled out. - if (idx === undefined) { + const siblingStepIndex = stepIndexOf(sibling.nativeTaskId); + // A sibling whose launch text is missing, or cut under the same roles, or whose step does not + // resolve to a record, cannot be ruled out. + if (siblingStepIndex === undefined) { if ( sibling.title === ANTIGRAVITY_SUBAGENT_BATCH_TITLE || (sibling.title !== null && isCutAntigravityToolText(sibling.title)) || @@ -264,20 +291,23 @@ function findInvokeRecord( return undefined; continue; } - if (idx < 0) continue; - const callIds = plannerCallIdsAt(database, idx); - if (callIds === undefined || callIds.length === 0) return undefined; - for (const callId of callIds) claimed.add(callId); + if (siblingStepIndex >= 0) siblingStepIndexes.add(siblingStepIndex); } + const claimedIdx = + siblingStepIndexes.size === 0 + ? new Map() + : invokeIdxAtStepIndex(database, siblingStepIndexes); + if (claimedIdx === undefined || claimedIdx.size !== siblingStepIndexes.size) return undefined; + const claimed = new Set(claimedIdx.values()); const matches: Array = []; for (const row of database - .prepare("SELECT step_payload FROM steps WHERE step_type = ? ORDER BY idx") + .prepare("SELECT idx, step_payload FROM steps WHERE step_type = ? ORDER BY idx") .iterate(INVOKE_SUBAGENT_STEP_TYPE)) { const payload = payloadOf(row); const record = payload === undefined ? undefined : decodeInvokeRecord(payload); // An unreadable record could be an identical launch, so uniqueness is unproven. if (record === undefined) return undefined; - if (record.toolCallId !== undefined && claimed.has(record.toolCallId)) continue; + if (claimed.has(Number(row.idx))) continue; // T3 stored the launch from the bounded tool payload, so bound the record the same way. const described = describeAntigravitySubagentLaunches( record.launches.map((launch) => ({ From aa83aa7ce628982a618aaed21da19397817ca20f Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 5 Nov 2026 06:04:06 +0000 Subject: [PATCH 3/3] fix(server): earlier subagent launches no longer hide a later one The step-index scan capped every invoke record below the target, so the 201st launch in a long session showed no children. Those rows carry no payload in the scan; the planner bounds still limit the work. Co-Authored-By: Claude Opus 5.5 --- .../provider/acp/AntigravityChildWork.test.ts | 34 +++++++++++++++++-- .../src/provider/acp/AntigravityChildWork.ts | 2 -- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/apps/server/src/provider/acp/AntigravityChildWork.test.ts b/apps/server/src/provider/acp/AntigravityChildWork.test.ts index 8d198a6c572e5..1edce5e373899 100644 --- a/apps/server/src/provider/acp/AntigravityChildWork.test.ts +++ b/apps/server/src/provider/acp/AntigravityChildWork.test.ts @@ -48,7 +48,7 @@ const read = ( }); it.layer(NodeServices.layer)("readAntigravityChildWork", (it) => { - it.effect("follows an auto-approved call id through its planner step to the record", () => + it.effect("follows an auto-approved call id to the record that ran it", () => Effect.gen(function* () { const { profile } = yield* makeProfile({ steps: autoApproved }); const [child, ...rest] = yield* read(profile, `${ROOT}:1`); @@ -126,6 +126,34 @@ it.layer(NodeServices.layer)("readAntigravityChildWork", (it) => { }), ); + it.effect("follows a launch id past many earlier launches", () => + Effect.gen(function* () { + const launches = Array.from({ length: 201 }, (_, index) => ({ + role: `Reader ${index + 1}`, + prompt: LAUNCH.prompt, + })); + const { profile } = yield* makeProfile({ + steps: (logUri) => [ + [0, 14, new Uint8Array()], + ...launches.flatMap((launch, index) => [ + [1 + index * 2, 15, plannerStep([`call-${index}`])] as const, + [ + 2 + index * 2, + 127, + invokeStep({ + callId: `call-${index}`, + launches: [launch], + children: [{ id: CHILD, logUri }], + }), + ] as const, + ]), + ], + }); + const children = yield* read(profile, `${ROOT}:201`); + expect(children.map((child) => child.role)).toEqual(["Reader 201"]); + }), + ); + it.effect("needs proof that the call id belongs to the parent's record", () => Effect.gen(function* () { const empty = new Uint8Array(); @@ -256,14 +284,14 @@ it.layer(NodeServices.layer)("readAntigravityChildWork", (it) => { const launch = describeAntigravitySubagentLaunches([LAUNCH]); const opaque = "35bea692fa95447fbdae6333fec5515f"; expect(yield* read(profile, opaque, launch)).toHaveLength(1); - // An earlier auto-approved batch stored no launch text, but its planner step claims the record. + // An earlier auto-approved batch stored no launch text, but its call id claims the record. const auto = { nativeTaskId: `${ROOT}:1`, title: ANTIGRAVITY_SUBAGENT_BATCH_TITLE, prompt: "", }; expect(yield* read(profile, opaque, launch, [auto])).toEqual([]); - // A sibling that cannot be ruled out refuses the match: its planner step is unreadable, + // A sibling that cannot be ruled out refuses the match: its call id resolves to no record, // or it is a permission batch whose launch text is missing or cut. for (const sibling of [ { ...auto, nativeTaskId: `${ROOT}:99` }, diff --git a/apps/server/src/provider/acp/AntigravityChildWork.ts b/apps/server/src/provider/acp/AntigravityChildWork.ts index eb43217dd864a..1d59b64156de5 100644 --- a/apps/server/src/provider/acp/AntigravityChildWork.ts +++ b/apps/server/src/provider/acp/AntigravityChildWork.ts @@ -189,7 +189,6 @@ function invokeIdxAtStepIndex( const found = new Map(); const last = Math.max(...stepIndexes); let skipped = 0; - let invokes = 0; let planners = 0; let plannerBytes = 0; for (const row of database @@ -205,7 +204,6 @@ function invokeIdxAtStepIndex( )) { const idx = Number(row.idx); if (row.step_type === INVOKE_SUBAGENT_STEP_TYPE) { - if (++invokes > MAX_INVOKE_ROWS) return undefined; const stepIndex = idx - skipped; if (stepIndexes.has(stepIndex)) found.set(stepIndex, idx); if (stepIndex >= last) break;