mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 08:01:23 +00:00
fix(tools): improve session_status cache-aware usage reporting
Co-authored-by: Lucian Feraru <1ucian@users.noreply.github.com>
This commit is contained in:
@@ -243,7 +243,20 @@ const readUsageFromSessionLog = (
|
||||
}
|
||||
|
||||
try {
|
||||
const lines = fs.readFileSync(logPath, "utf-8").split(/\n+/);
|
||||
// Read the tail only; we only need the most recent usage entries.
|
||||
const TAIL_BYTES = 8192;
|
||||
const stat = fs.statSync(logPath);
|
||||
const offset = Math.max(0, stat.size - TAIL_BYTES);
|
||||
const buf = Buffer.alloc(Math.min(TAIL_BYTES, stat.size));
|
||||
const fd = fs.openSync(logPath, "r");
|
||||
try {
|
||||
fs.readSync(fd, buf, 0, buf.length, offset);
|
||||
} finally {
|
||||
fs.closeSync(fd);
|
||||
}
|
||||
const tail = buf.toString("utf-8");
|
||||
const lines = (offset > 0 ? tail.slice(tail.indexOf("\n") + 1) : tail).split(/\n+/);
|
||||
|
||||
let input = 0;
|
||||
let output = 0;
|
||||
let promptTokens = 0;
|
||||
@@ -270,7 +283,7 @@ const readUsageFromSessionLog = (
|
||||
}
|
||||
model = parsed.message?.model ?? parsed.model ?? model;
|
||||
} catch {
|
||||
// ignore bad lines
|
||||
// ignore bad lines (including a truncated first tail line)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user