Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions apps/server/src/provider/acp/AntigravityChildWork.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,31 @@ it.layer(NodeServices.layer)("readAntigravityChildWork", (it) => {
expect(child?.steps?.length).toBeLessThan(40);
expect(child?.steps?.at(-1)?.text).toBe("marker 4242 found");
expect(child?.steps?.[0]?.text?.length).toBeLessThanOrEqual(4_001);

const lastLine = JSON.stringify(transcriptLines[3]) + "\n";
const step = { step_index: 2, type: "VIEW_FILE", content: "" };
const remaining = 256 * 1024 - Buffer.byteLength(JSON.stringify(step) + "\n" + lastLine);
const firstLine = JSON.stringify({
...step,
content: "é".repeat(Math.floor(remaining / 2)) + "x".repeat(remaining % 2),
});
const aligned = yield* makeProfile({
steps: autoApproved,
transcript: `${filler}\n${firstLine}\n${lastLine}`,
});
const [alignedChild] = yield* read(aligned.profile, `${ROOT}:1`);
expect(alignedChild).toMatchObject({
truncated: true,
steps: [{ index: 2 }, { index: 3 }],
});

const paddedLine = firstLine.padEnd(firstLine.length + Buffer.byteLength(lastLine) + 1);
const undelimited = yield* makeProfile({
steps: autoApproved,
transcript: filler + paddedLine,
});
const [undelimitedChild] = yield* read(undelimited.profile, `${ROOT}:1`);
expect(undelimitedChild).toMatchObject({ truncated: true, steps: [] });
}),
);

Expand Down
22 changes: 14 additions & 8 deletions apps/server/src/provider/acp/AntigravityChildWork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,20 @@ async function readChildTranscript(
try {
const stat = await handle.stat();
if (!stat.isFile()) return undefined;
const length = Math.min(stat.size, byteCap);
const buffer = Buffer.alloc(length);
const { bytesRead } = await handle.read(buffer, 0, length, stat.size - length);
const truncated = stat.size > length;
let contents = buffer.subarray(0, bytesRead).toString("utf8");
// A tail read starts mid-line.
if (truncated) contents = contents.slice(contents.indexOf("\n") + 1);
return { steps: transcriptSteps(contents, prompt), truncated };
const tailStart = Math.max(0, stat.size - byteCap);
// One extra byte tells whether the retained tail starts on a line boundary.
const readStart = Math.max(0, tailStart - 1);
const buffer = Buffer.alloc(stat.size - readStart);
const { bytesRead } = await handle.read(buffer, 0, buffer.length, readStart);
const bytes = buffer.subarray(0, bytesRead);
let lineStart = 0;
if (tailStart > 0) {
const newline = bytes.indexOf(0x0a);
if (newline === -1) return { steps: [], truncated: true };
lineStart = newline + 1;
}
const contents = bytes.toString("utf8", lineStart);
return { steps: transcriptSteps(contents, prompt), truncated: tailStart > 0 };
} finally {
await handle.close();
}
Expand Down
Loading