fix: avoid direct transcript stat fallback · openclaw/openclaw@e397636
steipete
·
2026-05-28
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -489,13 +489,7 @@ async function readSessionLogSnapshot(params: {
|
489 | 489 | snapshot.byteSize = Math.floor(scannedSize); |
490 | 490 | return snapshot; |
491 | 491 | } |
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); |
499 | 493 | } |
500 | 494 | |
501 | 495 | return snapshot; |
@@ -507,6 +501,20 @@ type SessionLogUsageScan = {
|
507 | 501 | byteSize: number; |
508 | 502 | }; |
509 | 503 | |
| 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 | + |
510 | 518 | async function readLastNonzeroUsageFromSessionLog(logPath: string): Promise<SessionLogUsageScan> { |
511 | 519 | const handle = await fs.promises.open(logPath, "r"); |
512 | 520 | try { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。