@devries-cameron20 / t3code Mirror · read-only / commits / 851328784f
Fork 0

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 22, 07:00 UTC

fix(server): truncated text stays the same when projected again (#28418)

Victor Vogel committed Nov 1, 2026 at 16:07 UTC 851328784fc320645caf7eccce0b12f111423ae7
3 files changed +17 -7
apps/server/src/orchestration-v2/WireProjection.test.ts
+9 -3
@@ -175,7 +175,9 @@ describe("orchestration V2 wire projection", () => {
175 });
176
177 it("truncates detail at a UTF-8 boundary without changing the source", () => {
178 - const progress = "a".repeat(32_767) + "😀" + "x".repeat(100_000);
178 + const marker = "\n… output truncated for transport";
179 + const prefixBytes = 32_768 - Buffer.byteLength(marker);
180 + const progress = "a".repeat(prefixBytes - 1) + "😀" + "x".repeat(100_000);
181 const item = {
182 ...base,
183 type: "subagent" as const,
@@ -184,13 +186,17 @@ describe("orchestration V2 wire projection", () => {
186 driver: ProviderDriverKind.make("codex"),
187 providerInstanceId: ProviderInstanceId.make("codex"),
188 childThreadId: null,
187 - prompt: "Inspect code",
189 + prompt: "漢".repeat(12_000),
190 result: null,
191 progress,
192 };
193 const projected = projectTurnItemForWire(item);
194 + expect(projectTurnItemForWire(projected)).toEqual(projected);
195 + expect(
196 + Buffer.byteLength(projected.type === "subagent" ? projected.prompt : ""),
197 + ).toBeLessThanOrEqual(32_768);
198 expect(projected.type === "subagent" ? projected.progress : null).toBe(
193 - "a".repeat(32_767) + "\n… output truncated for transport",
199 + "a".repeat(prefixBytes - 1) + marker,
200 );
201 expect(item.progress).toBe(progress);
202 });
apps/server/src/orchestration-v2/WireProjection.ts
+7 -3
@@ -26,6 +26,8 @@ const MAX_WIRE_CHECKPOINT_FILES = 200;
26 const MAX_DETAIL_STRING_BYTES = 32_768;
27 const MAX_DYNAMIC_VALUE_BYTES = 16_384;
28 const MAX_ON_DEMAND_BYTES = 256 * 1024;
29 +const TRUNCATION_MARKER = "\n… output truncated for transport";
30 +const TRUNCATION_MARKER_BYTES = Buffer.byteLength(TRUNCATION_MARKER, "utf8");
31
32 function truncateDetail(
33 value: string | undefined,
@@ -37,12 +39,14 @@ function truncateDetail(
39 ) {
40 return value;
41 }
42 + // The marker counts toward the cap, so projecting truncated text again leaves it unchanged.
43 + const budget = maxBytes - TRUNCATION_MARKER_BYTES;
44 // UTF-8 needs at least one byte per UTF-16 unit; encode only a potentially fitting prefix.
41 - const prefix = Buffer.from(value.slice(0, maxBytes), "utf8")
42 - .subarray(0, maxBytes)
45 + const prefix = Buffer.from(value.slice(0, budget), "utf8")
46 + .subarray(0, budget)
47 .toString("utf8")
48 .replace(/\uFFFD$/u, "");
45 - return `${prefix}\n… output truncated for transport`;
49 + return `${prefix}${TRUNCATION_MARKER}`;
50 }
51
52 /** Bound stored diffs to the client wire limit to avoid retaining invisible data in SQLite and heap. */
apps/server/src/ws.ts
+1 -1
@@ -852,7 +852,7 @@ export const subscribeOrchestrationV2Thread = Effect.fn("ws.orchestrationV2.subs
852 Stream.map((stored) => ({
853 kind: "event" as const,
854 sequence: stored.sequence,
855 - event: projectDomainEventForWire(stored.event),
855 + event: stored.event,
856 })),
857 coalesceThreadLiveStream,
858 Stream.mapError(