ClawWork icon indicating copy to clipboard operation
ClawWork copied to clipboard

[Bug] debug logger has no size rotation or retention policy

Open samzong opened this issue 7 months ago • 3 comments

Problem

logger.ts writes all events to a daily-rotated file debug-YYYY-MM-DD.ndjson, but there is no size cap within a single day and no retention policy for old days. Two concrete problems:

  1. Unbounded daily file size — during a high-volume day (reconnect storms, development sessions), a single day's log file can grow to hundreds of MB or more. There is no rotation once it gets large.
  2. No retention — once the date rolls over, the previous day's file is left on disk untouched forever. Over a year of daily use, the user accumulates 365+ ndjson files under app.getPath('logs'), silently consuming disk.

Location

File: packages/desktop/src/main/debug/logger.ts:95-98

function currentFilePath(): string {
  const day = new Date().toISOString().slice(0, 10);
  return join(options.debugDir, `debug-${day}.ndjson`);
}

Fix Approach

Add two bounds:

  1. Size-based rotation within a day: track the current file size; when it exceeds a threshold (e.g. 50 MB), rotate to debug-YYYY-MM-DD.1.ndjson, .2.ndjson, etc.
  2. Age-based cleanup: on logger init, scan options.debugDir for files matching debug-*.ndjson, parse the date from the filename, and delete files older than N days (e.g. 14 days). Keep it simple — no need for a full retention library.

Both should be configurable via CreateDebugLoggerOptions so tests can disable them.

Verification

  1. Run pnpm check — must pass.
  2. Unit test for the filename parser + age filter logic.
  3. Manual: set a low rotation threshold (e.g. 10 KB), write enough events to trigger rotation, confirm a new file is created.

Context

  • WG: Observability & DX
  • Priority: Low (disk hygiene)
  • Estimated effort: 1-2 hours

samzong avatar Apr 15 '26 09:04 samzong

Hi @samzong, Thanks for opening an issue! We will look into it as soon as possible.

Details

Instructions for interacting with me using comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the gh-ci-bot repository.

github-actions[bot] avatar Apr 15 '26 09:04 github-actions[bot]

The debug log's unbounded daily file size and lack of retention will silently consume disk. I'd handle this by adding configurable size rotation and age-based cleanup directly in logger.ts. I can have a PR with tests up in a few hours—I've implemented similar file rotation in production Node.js apps.

snakefood3232 avatar Apr 15 '26 10:04 snakefood3232

The unbounded daily file size and missing retention policy are clear issues. I'd handle this by adding configurable size rotation and age-based cleanup directly in logger.ts, as outlined. Can have a PR up in a few hours—I've implemented similar file-based logging with rotation in production TypeScript apps.

snakefood3232 avatar Apr 15 '26 10:04 snakefood3232