Skip to content

swaglog: delete oldest logs on rollover, not newest#38322

Open
PeterPhuTran wants to merge 1 commit into
commaai:masterfrom
PeterPhuTran:swaglog-delete-oldest-first
Open

swaglog: delete oldest logs on rollover, not newest#38322
PeterPhuTran wants to merge 1 commit into
commaai:masterfrom
PeterPhuTran:swaglog-delete-oldest-first

Conversation

@PeterPhuTran

Copy link
Copy Markdown

Description

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() seeds the
list oldest-first. After a process restart at the backup_count cap, the tail holds
the 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 the
insert(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

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>
@github-actions

Copy link
Copy Markdown
Contributor

Process replay diff report

Replays driving segments through this PR and compares the behavior to master.
Please review any changes carefully to ensure they are expected.

✅ 0 changed, 66 passed, 0 errors

@PeterPhuTran

Copy link
Copy Markdown
Author

Note on the failing checks: this PR's CI jobs ran on a GitHub-hosted ubuntu-24.04 fallback runner (runner: GitHub Actions) rather than the namespace-profile-amd64-8x16 runners that passing PRs use — the fallback lacks libGLESv2, so test_raylib_ui and the two manager tests that import the UI stack fail on library load. The tests added by this PR run and pass in the same job. Happy to rebase/re-run whenever routing allows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant