fix(daemon): honor max_rotated_files == 0 in rotate_log_files - #3081
fix(daemon): honor max_rotated_files == 0 in rotate_log_files#3081phil-opp wants to merge 1 commit into
Conversation
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
`rotate_log_files` deletes the oldest rotated file (`log_<node>.<max>.jsonl`), shifts `.N -> .N+1` for `1..max`, then renames the current file to `.1`. When `max_files == 0` the shift range `(1..0)` is empty and the delete-oldest step targets `log_<node>.0.jsonl` (never created), yet the current file is still renamed to `log_<node>.1.jsonl`. That rotated file is then never pruned, so a node configured with `max_rotated_files: 0` keeps a rotated log forever instead of retaining none. `max_rotated_files` is user-configurable via the dataflow descriptor and reaches this function directly (`spawn/prepared.rs`), so `0` is a reachable input to this public library function. Fix by special-casing `max_files == 0`: discard the current log and prune any rotated files a previous (non-zero) configuration may have left behind, so the "retain no rotated copies" contract holds regardless of history. Adds regression tests for a single/repeated rotation and for pruning pre-existing rotated files. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SD4dBVimzepwKSh2b9F8aG
653dcb6 to
df99cd1
Compare
|
🤖 Automated review by Claude — this is a fully automated review with no human in the loop. I reviewed this diff and found no issues. The One minor, non-blocking observation: the prune loop stops at the first missing index, so it assumes rotated files are contiguous. That holds for files produced by this rotation scheme, so it's fine in practice. Generated by Claude Code |
|
I found one issue with the premise of this change: Descriptor validation rejects
That leaves two things worth resolving:
If the intent is for 🤖 Automated review by Claude (Claude Code). This review was generated fully automatically with no human in the loop and has not been vetted by a maintainer — treat it as advisory. Generated by Claude Code |
Issue
rotate_log_files(binaries/daemon/src/log.rs) rotates node logs by:log_<node>.<max_files>.jsonl,.N -> .N+1fori in (1..max_files),log_<node>.1.jsonl.When
max_files == 0:log_<node>.0.jsonl, which is never created,(1..0)is empty,log_<node>.1.jsonl.That
.1file is never pruned on subsequent rotations either, so a node configured withmax_rotated_files: 0keeps a rotated log forever instead of retaining zero — directly contradicting the requested value.max_rotated_filesis user-configurable through the dataflow descriptor (libraries/message/src/descriptor.rs) and reaches this public library function viabinaries/daemon/src/spawn/prepared.rs(.unwrap_or(DEFAULT_MAX_ROTATED_FILES)only substitutes the default when the option isNone, not when it isSome(0)), so0is a reachable input.Fix
Special-case
max_files == 0: discard the current log and prune any rotated files a previous (non-zero) configuration may have left behind, so the "retain no rotated copies" contract holds regardless of history. All other values keep their existing behavior.Validation
rotate_with_zero_max_files_discards_current— the current file is gone, no.1is left, and a repeated rotation does not accumulate files.rotate_with_zero_max_files_prunes_preexisting_rotated_files— pre-existing.1/.2rotated files are removed too.cargo test -p dora-daemon --lib log::— 12 passed (existing rotation tests unchanged).cargo fmt --all -- --checkandcargo clippy -p dora-daemon -- -D warningsclean.The pre-existing-rotated-file pruning was added after an automated
/reviewpass noted the original fix only removed the current file.🤖 This is a machine-generated pull request opened by Claude Code as part of an automated code-review pass. Please review carefully before merging.
🤖 Generated with Claude Code