Skip to content

Commit 7cc1f5e

Browse files
fix(pipeline): improve log file handling by using file descriptors for offset tracking
1 parent f66d683 commit 7cc1f5e

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/pipeline/pipeline.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -424,17 +424,22 @@ export async function runPipeline(
424424
const opencodeLogPath = path.join(toolDataDir, 'opencode', 'log', 'opencode.log');
425425
let opencodeLogOffset = 0;
426426
try {
427-
if (fs.existsSync(opencodeLogPath)) opencodeLogOffset = fs.statSync(opencodeLogPath).size;
427+
const fd = fs.openSync(opencodeLogPath, 'r');
428+
try {
429+
opencodeLogOffset = fs.fstatSync(fd).size;
430+
} finally {
431+
fs.closeSync(fd);
432+
}
428433
} catch (_) {}
429434
const readFreshOpencodeLog = () => {
430435
try {
431-
const stat = fs.statSync(opencodeLogPath);
432-
// log rotate/truncate: restart from the new beginning
433-
if (stat.size < opencodeLogOffset) opencodeLogOffset = 0;
434-
const bytes = stat.size - opencodeLogOffset;
435-
if (bytes <= 0) return '';
436436
const fd = fs.openSync(opencodeLogPath, 'r');
437437
try {
438+
const stat = fs.fstatSync(fd);
439+
// log rotate/truncate: restart from the new beginning
440+
if (stat.size < opencodeLogOffset) opencodeLogOffset = 0;
441+
const bytes = stat.size - opencodeLogOffset;
442+
if (bytes <= 0) return '';
438443
const buf = Buffer.allocUnsafe(bytes);
439444
const read = fs.readSync(fd, buf, 0, bytes, opencodeLogOffset);
440445
opencodeLogOffset += read;

0 commit comments

Comments
 (0)