fix(run-log-store): close fd leak in log append that caused spawn EBADF
The append method created a new WriteStream for every log chunk and resolved the promise on the end callback (data flushed) rather than the close event (fd released). Over many agent runs the leaked fds corrupted the fd table, causing child_process.spawn to fail with EBADF. Replace with fs.appendFile which properly opens, writes, and closes the fd before resolving. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { createReadStream, createWriteStream, promises as fs } from "node:fs";
|
||||
import { createReadStream, promises as fs } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { createHash } from "node:crypto";
|
||||
import { notFound } from "../errors.js";
|
||||
@@ -113,11 +113,7 @@ function createLocalFileRunLogStore(basePath: string): RunLogStore {
|
||||
stream: event.stream,
|
||||
chunk: event.chunk,
|
||||
});
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const stream = createWriteStream(absPath, { flags: "a", encoding: "utf8" });
|
||||
stream.on("error", reject);
|
||||
stream.end(`${line}\n`, () => resolve());
|
||||
});
|
||||
await fs.appendFile(absPath, `${line}\n`, "utf8");
|
||||
},
|
||||
|
||||
async finalize(handle) {
|
||||
|
||||
Reference in New Issue
Block a user