@devries-cameron20 / t3code-1 / commits / 90c028c6fc
Fork 0

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

fix(server): a slow disk no longer freezes the service while it writes a log line (#39857)

Julius Marminge committed Nov 20, 2026 at 12:06 UTC 90c028c6fc4a9ecd3af048cb52432e819af6487c
1 file changed +41 -1
apps/server/src/serviceLauncher.ts
+41 -1
@@ -88,6 +88,42 @@ const runtimeSpawnArguments = (paths: ReturnType<typeof runtimePaths>) => ({
88 args: ["serve"],
89 });
90
91 +function isRegularFile(fd: number): boolean {
92 + try {
93 + return NodeFS.fstatSync(fd).isFile();
94 + } catch {
95 + return false;
96 + }
97 +}
98 +
99 +const MAX_PENDING_OUTPUT_BYTES = 8 * 1024 * 1024;
100 +
101 +/**
102 + * Node writes to a regular file synchronously, so a server whose output is the log file freezes
103 + * while the filesystem stalls one append. It gets a pipe instead, drained here without backpressure;
104 + * output beyond the cap is dropped while a write is stuck.
105 + */
106 +function appendOutput(source: NodeJS.ReadableStream, fd: number): void {
107 + let pending: Array<Buffer> = [];
108 + let pendingBytes = 0;
109 + let writing = false;
110 + const flush = (): void => {
111 + writing = pending.length > 0;
112 + if (!writing) return;
113 + const chunk = Buffer.concat(pending, pendingBytes);
114 + pending = [];
115 + pendingBytes = 0;
116 + // Best effort, like the launcher's own diagnostics: a failed append drops that output.
117 + NodeFS.write(fd, chunk, flush);
118 + };
119 + source.on("data", (chunk: Buffer) => {
120 + if (pendingBytes + chunk.length > MAX_PENDING_OUTPUT_BYTES) return;
121 + pending.push(chunk);
122 + pendingBytes += chunk.length;
123 + if (!writing) flush();
124 + });
125 +}
126 +
127 /**
128 * The unit or launch agent that `t3 service install` wrote. Its program names
129 * the runtime that ran the install, and a remote update never replaces it, so
@@ -1179,13 +1215,17 @@ export class Launcher {
1215 ...(update === undefined ? {} : { update }),
1216 };
1217 const spawnArguments = runtimeSpawnArguments(paths);
1218 + const appendStdout = this.#output === undefined && isRegularFile(1);
1219 + const appendStderr = this.#output === undefined && isRegularFile(2);
1220 const child = NodeChildProcess.spawn(spawnArguments.command, spawnArguments.args, {
1221 env: { ...this.#environment, [SERVICE_LAUNCHER_CONTEXT_ENV]: JSON.stringify(context) },
1222 stdio:
1223 this.#output === undefined
1186 - ? ["inherit", "inherit", "inherit", "ipc"]
1224 + ? ["inherit", appendStdout ? "pipe" : "inherit", appendStderr ? "pipe" : "inherit", "ipc"]
1225 : ["ignore", this.#output, this.#output, "ipc"],
1226 });
1227 + if (child.stdout !== null) appendOutput(child.stdout, 1);
1228 + if (child.stderr !== null) appendOutput(child.stderr, 2);
1229 await new Promise<void>((resolve, reject) => {
1230 const onError = (error: Error) => reject(error);
1231 child.once("error", onError);