xonecas.io
64875
Mc

mini-coder / commit 913e461

fix: prevent subagent log file truncation causing null-byte corruption

Subagent processes called initApiLog()/initErrorLog() which truncated
the shared log files to zero bytes. When the parent process resumed
writing at its old file offset, the OS filled the gap with null bytes
(POSIX sparse file behavior), corrupting ~124KB of the api.log.

Skip log initialization in subagent processes (MC_SUBAGENT_DEPTH > 0)
since they share the same log files as the parent.

xonecas2026-03-17 913e461023bb9e564dfff00bc904abceaae1600b parent ed0231b

2 files changed

src/cli/error-log.ts+4−0
@@ -6,6 +6,10 @@ let writer: ReturnType<ReturnType<typeof Bun.file>["writer"]> | null = null;
66
77 export function initErrorLog(): void {
88 if (writer) return;
9+ // Subagent processes must not truncate/write the shared log file (same
10+ // sparse-hole issue as api-log.ts — see comment there for details).
11+ if (process.env.MC_SUBAGENT_DEPTH && process.env.MC_SUBAGENT_DEPTH !== "0")
12+ return;
913
1014 const dirPath = join(homedir(), ".config", "mini-coder");
1115 const logPath = join(dirPath, "errors.log");
src/llm-api/api-log.ts+5−0
@@ -10,6 +10,11 @@ const MAX_ENTRY_BYTES = 8 * 1024;
1010
1111 export function initApiLog(): void {
1212 if (writer) return;
13+ // Subagent processes must not truncate/write the shared log file — the parent
14+ // process already owns the writer and a second truncation creates a sparse
15+ // null-byte hole when the parent resumes writing at its old file offset.
16+ if (process.env.MC_SUBAGENT_DEPTH && process.env.MC_SUBAGENT_DEPTH !== "0")
17+ return;
1318
1419 const dirPath = join(homedir(), ".config", "mini-coder");
1520 const logPath = join(dirPath, "api.log");