Skip to content

Commit e397636

Browse files
committed
fix: avoid direct transcript stat fallback
1 parent 23f494c commit e397636

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

src/auto-reply/reply/agent-runner-memory.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -489,13 +489,7 @@ async function readSessionLogSnapshot(params: {
489489
snapshot.byteSize = Math.floor(scannedSize);
490490
return snapshot;
491491
}
492-
try {
493-
const stat = await fs.promises.stat(logPath);
494-
const size = Math.floor(stat.size);
495-
snapshot.byteSize = Number.isFinite(size) && size >= 0 ? size : undefined;
496-
} catch {
497-
snapshot.byteSize = undefined;
498-
}
492+
snapshot.byteSize = await readSessionLogByteSize(logPath);
499493
}
500494

501495
return snapshot;
@@ -507,6 +501,20 @@ type SessionLogUsageScan = {
507501
byteSize: number;
508502
};
509503

504+
async function readSessionLogByteSize(logPath: string): Promise<number | undefined> {
505+
let handle: fs.promises.FileHandle | undefined;
506+
try {
507+
handle = await fs.promises.open(logPath, "r");
508+
const stat = await handle.stat();
509+
const size = Math.floor(stat.size);
510+
return Number.isFinite(size) && size >= 0 ? size : undefined;
511+
} catch {
512+
return undefined;
513+
} finally {
514+
await handle?.close();
515+
}
516+
}
517+
510518
async function readLastNonzeroUsageFromSessionLog(logPath: string): Promise<SessionLogUsageScan> {
511519
const handle = await fs.promises.open(logPath, "r");
512520
try {

0 commit comments

Comments
 (0)