@devries-cameron20 / t3code-1 / commits / 5e0d0fd74c
Fork 0

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

fix(server): truncated file previews no longer end in a replacement character (#24255)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

MarcoDotIO committed Oct 31, 2026 at 04:34 UTC 5e0d0fd74c4ae50361152ecd49989a2d26acb59f
2 files changed +24 -2
apps/server/src/workspace/WorkspaceFileSystem.test.ts
+20
@@ -361,6 +361,26 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i
361 }),
362 );
363
364 + it.effect("drops a multibyte character split by the read limit", () =>
365 + Effect.gen(function* () {
366 + const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
367 + const fileSystem = yield* FileSystem.FileSystem;
368 + const path = yield* Path.Path;
369 + const cwd = yield* makeTempDir;
370 + const limit = 1024 * 1024;
371 + const euro = new TextEncoder().encode("€");
372 + const bytes = new Uint8Array(limit - 1 + euro.length).fill(0x61);
373 + bytes.set(euro, limit - 1);
374 + yield* fileSystem.writeFile(path.join(cwd, "large.txt"), bytes);
375 +
376 + const result = yield* workspaceFileSystem.readFile({ cwd, relativePath: "large.txt" });
377 +
378 + expect(result.truncated).toBe(true);
379 + expect(result.byteLength).toBe(bytes.length);
380 + expect(result.contents).toBe("a".repeat(limit - 1));
381 + }),
382 + );
383 +
384 it.effect("rejects binary files without leaking their contents into the error", () =>
385 Effect.gen(function* () {
386 const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
apps/server/src/workspace/WorkspaceFileSystem.ts
+4 -2
@@ -426,11 +426,13 @@ export const make = Effect.gen(function* () {
426 });
427 }
428
429 + const truncated = stat.size > PROJECT_READ_FILE_MAX_BYTES;
430 return {
431 relativePath: target.relativePath,
431 - contents: new TextDecoder("utf-8").decode(fileBytes),
432 + // Streaming decode drops a character the byte limit split, instead of ending in U+FFFD.
433 + contents: new TextDecoder("utf-8").decode(fileBytes, { stream: truncated }),
434 byteLength: stat.size,
433 - truncated: stat.size > PROJECT_READ_FILE_MAX_BYTES,
435 + truncated,
436 };
437 }),
438 (handle) =>