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

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

fix(server): truncated Claude task output no longer starts with a replacement character (#28643)

Abhishek B R committed Nov 4, 2026 at 04:35 UTC eee9525fe4a8add18d6a5dedf11e8e73de3a0547
2 files changed +31 -2
apps/server/src/orchestration-v2/Adapters/ClaudeTaskOutputTail.test.ts
+27 -1
@@ -20,7 +20,7 @@ const makeTaskFile = Effect.gen(function* () {
20 return { root, tasks, file: path.join(tasks, `${TASK_ID}.output`) };
21 });
22
23 -// TestClock cannot interleave with real filesystem I/O; use the live clock.
23 +// TestClock cannot interleave with real filesystem I/O; tests that wait on a poll use the live clock.
24 describe("tailClaudeTaskOutput", () => {
25 it.live("follows a file that appears after the task starts, across split characters", () =>
26 Effect.scoped(
@@ -48,6 +48,32 @@ describe("tailClaudeTaskOutput", () => {
48 ).pipe(Effect.provide(NodeServices.layer)),
49 );
50
51 + it.effect("drops a split character when the file is truncated and rewritten", () =>
52 + Effect.scoped(
53 + Effect.gen(function* () {
54 + const fileSystem = yield* FileSystem.FileSystem;
55 + const { root, tasks, file } = yield* makeTaskFile;
56 + yield* fileSystem.makeDirectory(tasks, { recursive: true });
57 + // End the first read inside the two-byte é.
58 + yield* fileSystem.writeFile(file, new TextEncoder().encode("café").subarray(0, 4));
59 + const chunks = yield* Queue.unbounded<string>();
60 + const stop = yield* Deferred.make<void>();
61 + yield* tailClaudeTaskOutput({
62 + root,
63 + sessionId: SESSION_ID,
64 + taskId: TASK_ID,
65 + stop,
66 + onChunk: (chunk) => Queue.offer(chunks, chunk),
67 + }).pipe(Effect.forkScoped);
68 + assert.equal(yield* Queue.take(chunks), "caf");
69 +
70 + yield* fileSystem.writeFileString(file, "ok\n");
71 + yield* Deferred.succeed(stop, undefined);
72 + assert.equal(yield* Queue.take(chunks), "ok\n");
73 + }),
74 + ).pipe(Effect.provide(NodeServices.layer)),
75 + );
76 +
77 it.live("skips ahead when the command writes faster than it is read", () =>
78 Effect.scoped(
79 Effect.gen(function* () {
apps/server/src/orchestration-v2/Adapters/ClaudeTaskOutputTail.ts
+4 -1
@@ -88,7 +88,10 @@ export const tailClaudeTaskOutput = Effect.fn("ClaudeTaskOutputTail.tail")(funct
88 Effect.map((info) => Number(info.size)),
89 Effect.orElseSucceed(() => offset),
90 );
91 - if (size < offset) offset = 0;
91 + if (size < offset) {
92 + offset = 0;
93 + decoder = new TextDecoder("utf-8", { fatal: false });
94 + }
95 if (size > offset) {
96 const start = size - offset > MAX_READ_BYTES ? size - MAX_READ_BYTES : offset;
97 const bytes = yield* Effect.scoped(