swaglog: delete oldest logs on rollover, not newest#38322
Open
PeterPhuTran wants to merge 1 commit into
Open
Conversation
SwaglogRotatingFileHandler maintains its file list newest-first: _open() prepends each new file with insert(0, ...) and doRollover() prunes past backup_count with pop() from the tail. But get_existing_logfiles() seeded the list oldest-first, so after a process restart at the backup_count cap the tail held the newest pre-existing file - every rollover then deleted the most recently written logs, marching backwards through them, while the oldest logs survived indefinitely. Observed on a comma three: each boot destroyed the newest ~100+ swaglog files from before the reboot - exactly the files needed to debug whatever caused the reboot. Fix: seed the list newest-first to match the insert(0)/pop() convention. The new test fails on master and passes with the fix; it covers the restart prune, repeated rollovers, and a second restart. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
Process replay diff reportReplays driving segments through this PR and compares the behavior to master. ✅ 0 changed, 66 passed, 0 errors |
Author
|
Note on the failing checks: this PR's CI jobs ran on a GitHub-hosted |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
SwaglogRotatingFileHandlermaintains its file list newest-first —_open()prepends each new file with
insert(0, ...)anddoRollover()prunes pastbackup_countwithpop()from the tail — butget_existing_logfiles()seeds thelist oldest-first. After a process restart at the
backup_countcap, the tail holdsthe newest pre-existing file, so every rollover deletes the most recently written
logs (marching backwards through them) while the oldest logs survive indefinitely —
the opposite of the intended retention.
Observed on a comma three: each boot destroyed the newest ~100+ swaglog files from
before the reboot — exactly the files needed to debug whatever caused the reboot.
Fix: seed the list newest-first (
sorted(log_files, reverse=True)) to match theinsert(0)/pop()convention. One line.Verification
New
openpilot/common/tests/test_swaglog.py: fails on master, passes with the fix.Covers the restart prune, repeated rollovers, and a second restart over the
survivors. Pure file I/O, no hardware; warning-clean under
-Werror.🤖 Generated with Claude Code