@devries-cameron20 / t3code-1 / commits / c4dc9ed55b
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(antigravity): keep truncated command output valid Unicode (#38837)

Co-authored-by: Simone <185146821+Lucenx9@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Simone committed Nov 19, 2026 at 07:04 UTC c4dc9ed55b35267a40857aa27525c520bf913342
4 files changed +86 -20
apps/server/src/provider/acp/AntigravityChildWork.test.ts
+8 -1
@@ -96,7 +96,7 @@ it.layer(NodeServices.layer)("readAntigravityChildWork", (it) => {
96 it.effect("matches a permission-prompt call by its launch text, only when unique", () =>
97 Effect.gen(function* () {
98 const other = { role: "Test Runner", prompt: "Run the tests" };
99 - const long = { role: "Long Reader", prompt: `Read this:\n${"x".repeat(9_000)}` };
99 + const long = { role: "Long Reader", prompt: `Read this:\n🚀${"x".repeat(7_999)}` };
100 // A role's leading byte order mark is part of its text.
101 const marked = { role: "\uFEFFMarked", prompt: "Check the mark" };
102 const { profile } = yield* makeProfile({
@@ -142,6 +142,13 @@ it.layer(NodeServices.layer)("readAntigravityChildWork", (it) => {
142 );
143 const longMatch = yield* read(profile, opaque, describeAntigravitySubagentLaunches(stored!));
144 expect(longMatch.map((child) => child.prompt)).toEqual([long.prompt]);
145 + const savedLaunch = {
146 + title: long.role,
147 + prompt: `[Earlier output truncated]\n\n\uDE80${"x".repeat(7_999)}`,
148 + };
149 + expect((yield* read(profile, opaque, savedLaunch)).map((child) => child.prompt)).toEqual([
150 + long.prompt,
151 + ]);
152 expect(
153 yield* read(profile, opaque, describeAntigravitySubagentLaunches([marked])),
154 ).toHaveLength(1);
apps/server/src/provider/acp/AntigravityProtocol.test.ts
+34 -6
@@ -460,29 +460,57 @@ describe("Antigravity tool results", () => {
460 });
461 });
462
463 - it("bounds both canonical output and retained raw output", () => {
464 - const output = `${"output line\n".repeat(20_000)}last line\n`;
463 + it.each([
464 + { name: "ASCII", boundary: "x", kept: "x", field: "combinedOutput" },
465 + { name: "split emoji", boundary: "🚀", kept: "", field: "combinedOutput" },
466 + { name: "split emoji (snake case)", boundary: "🚀", kept: "", field: "combined_output" },
467 + ])("bounds both canonical and retained raw output at $name", ({ boundary, kept, field }) => {
468 + const tail = `${"x".repeat(7_989)}last line\n`;
469 + const output = `${"output line\n".repeat(20_000)}${boundary}${tail}`;
470 + const expected = `[Earlier output truncated]\n\n${kept}${tail}`;
471 + const { combinedOutput: _combinedOutput, ...rawOutput } = commandCompleted.update.rawOutput;
472 const event = parseToolUpdate({
473 ...commandCompleted,
474 update: {
475 ...commandCompleted.update,
476 rawOutput: {
470 - ...commandCompleted.update.rawOutput,
471 - combinedOutput: output,
477 + ...rawOutput,
478 + [field]: output,
479 formatted_output: output,
480 },
481 },
482 });
483 const toolCall = normalizeAntigravityToolCall(event.toolCall);
484 expect(toolCall.data).toMatchObject({
478 - item: { aggregatedOutput: expect.stringContaining("last line\n") },
479 - rawOutput: { combinedOutput: expect.stringContaining("last line\n") },
485 + item: { aggregatedOutput: expected },
486 + rawOutput: { [field]: expected },
487 });
488 + expect(event.toolCall.data.rawOutput).toMatchObject({ [field]: expected });
489 expect(JSON.stringify(toolCall).length).toBeLessThan(20_000);
490 expect(JSON.stringify(event.rawPayload).length).toBeLessThan(10_000);
491 expect(JSON.stringify(event.rawPayload)).not.toContain("formatted_output");
492 });
493
494 + it("keeps 1.5 command output and its content text valid Unicode when cut", () => {
495 + const tail = `${"x".repeat(7_982)}build completed\r\n`;
496 + const output = `Command output:\nprefix\r\n🚀${tail}`;
497 + const expected = `[Earlier output truncated]\n\n${tail}`;
498 + const toolCall = normalizeAntigravityToolCall(
499 + parseToolUpdate({
500 + ...commandCompleted,
501 + update: {
502 + ...commandCompleted.update,
503 + rawOutput: { output, exit_code: 0 },
504 + content: [{ type: "content", content: { type: "text", text: output } }],
505 + },
506 + }).toolCall,
507 + );
508 + expect(toolCall.data).toMatchObject({
509 + rawOutput: { output: expected },
510 + content: [{ content: { text: expected.trimEnd() } }],
511 + });
512 + });
513 +
514 it("removes inline images while preserving valid tool content and the local image path", () => {
515 const inlineImage = "inline-image-bytes".repeat(50_000);
516 const notification = {
apps/server/src/provider/acp/AntigravityProtocol.ts
+26 -4
@@ -179,6 +179,20 @@ function boundText(text: string, limit = TOOL_TEXT_LIMIT): string {
179 : copyBoundedText(`${TOOL_TEXT_TRUNCATED}${text.slice(-limit)}`);
180 }
181
182 +function boundCommandOutput(text: string, limit = TOOL_TEXT_LIMIT): string {
183 + if (
184 + text.length <= limit ||
185 + (text.length <= limit + TOOL_TEXT_TRUNCATED.length && text.startsWith(TOOL_TEXT_TRUNCATED))
186 + ) {
187 + return text;
188 + }
189 + const tail = text.slice(-limit).replace(/^[\uDC00-\uDFFF]/u, "");
190 + return copyBoundedText(`${TOOL_TEXT_TRUNCATED}${tail}`);
191 +}
192 +
193 +// 1.5 runtimes report command output as `output` and repeat it as content `text`.
194 +const OUTPUT_TEXT_FIELDS = new Set(["combinedOutput", "combined_output", "output", "text"]);
195 +
196 /** Keeps the tail of long tool text, as every bounded tool payload does. */
197 export { boundText as boundAntigravityToolText };
198
@@ -190,7 +204,12 @@ interface ToolPayloadBudget {
204 text: number;
205 }
206
193 -function sanitizeToolValue(value: unknown, budget: ToolPayloadBudget, depth: number): unknown {
207 +function sanitizeToolValue(
208 + value: unknown,
209 + budget: ToolPayloadBudget,
210 + depth: number,
211 + field?: string,
212 +): unknown {
213 if (depth > 12 || budget.nodes-- <= 0) {
214 return undefined;
215 }
@@ -198,7 +217,9 @@ function sanitizeToolValue(value: unknown, budget: ToolPayloadBudget, depth: num
217 if (/^data:image\//i.test(value) || budget.text <= 0) {
218 return undefined;
219 }
201 - const text = boundText(value, Math.min(TOOL_TEXT_LIMIT, budget.text));
220 + const bound =
221 + field !== undefined && OUTPUT_TEXT_FIELDS.has(field) ? boundCommandOutput : boundText;
222 + const text = bound(value, Math.min(TOOL_TEXT_LIMIT, budget.text));
223 budget.text -= text.length;
224 return text;
225 }
@@ -227,7 +248,7 @@ function sanitizeToolValue(value: unknown, budget: ToolPayloadBudget, depth: num
248 ) {
249 continue;
250 }
230 - const sanitized = sanitizeToolValue(entry, budget, depth + 1);
251 + const sanitized = sanitizeToolValue(entry, budget, depth + 1, key);
252 if (sanitized !== undefined) entries.push([key, sanitized]);
253 }
254 return Object.fromEntries(entries);
@@ -445,7 +466,8 @@ export function normalizeAntigravityToolCall(
466 output?.working_dir;
467 const cwd = nativeCwd?.trim() ? boundText(nativeCwd.trim()) : undefined;
468 const nativeOutput = output?.combinedOutput ?? output?.combined_output;
448 - const aggregatedOutput = nativeOutput === undefined ? undefined : boundText(nativeOutput);
469 + const aggregatedOutput =
470 + nativeOutput === undefined ? undefined : boundCommandOutput(nativeOutput);
471 const exitCode = output?.exitCode ?? output?.exit_code;
472 const imagePath = localImagePath(output?.imagePath);
473 const sanitizedData = sanitizeAntigravityToolPayload(toolCall.data);
packages/provider-acp/src/server/runtimeModel.ts
+18 -9
@@ -648,12 +648,22 @@ function locationsFromToolCallInput(input: {
648 const TOOL_CALL_CONTENT_MAX_CHARS = 8_000;
649 const TOOL_CALL_CONTENT_TRUNCATION_MARKER = "[Earlier output truncated]\n\n";
650
651 -function boundToolCallOutputText(text: string): string {
652 - if (text.length <= TOOL_CALL_CONTENT_MAX_CHARS) {
653 - return text;
651 +/** The tail to keep, or undefined when the text fits or an adapter already bounded it. */
652 +function retainedToolCallOutputTail(text: string): string | undefined {
653 + if (
654 + text.length <= TOOL_CALL_CONTENT_MAX_CHARS ||
655 + (text.startsWith(TOOL_CALL_CONTENT_TRUNCATION_MARKER) &&
656 + text.length <= TOOL_CALL_CONTENT_MAX_CHARS + TOOL_CALL_CONTENT_TRUNCATION_MARKER.length)
657 + ) {
658 + return undefined;
659 }
655 - const tail = text.slice(text.length - TOOL_CALL_CONTENT_MAX_CHARS);
656 - return `${TOOL_CALL_CONTENT_TRUNCATION_MARKER}${tail}`;
660 + // A tail starting inside a surrogate pair is invalid Unicode.
661 + return text.slice(-TOOL_CALL_CONTENT_MAX_CHARS).replace(/^[\uDC00-\uDFFF]/u, "");
662 +}
663 +
664 +function boundToolCallOutputText(text: string): string {
665 + const tail = retainedToolCallOutputTail(text);
666 + return tail === undefined ? text : `${TOOL_CALL_CONTENT_TRUNCATION_MARKER}${tail}`;
667 }
668
669 const RAW_OUTPUT_TEXT_FIELDS = ["content", "stdout", "stderr", "output"] as const;
@@ -726,13 +736,12 @@ function extractTextContentFromToolCallContent(
736 return { text: undefined, content: boundToolCallContentEntries(content) };
737 }
738 const joined = chunks.join("\n");
729 - if (joined.length <= TOOL_CALL_CONTENT_MAX_CHARS) {
739 + const tail = retainedToolCallOutputTail(joined);
740 + if (tail === undefined) {
741 return { text: joined, content: boundToolCallContentEntries(content) };
742 }
732 - const bounded = boundToolCallOutputText(joined);
733 - const tail = joined.slice(joined.length - TOOL_CALL_CONTENT_MAX_CHARS);
743 return {
735 - text: bounded,
744 + text: `${TOOL_CALL_CONTENT_TRUNCATION_MARKER}${tail}`,
745 content: distributeRetainedTailAcrossContent(content, tail),
746 };
747 }