Skip to content

swaglog: delete oldest (not newest) logs on rotation after restart - #310

Closed
PeterPhuTran wants to merge 10000 commits into
FrogAi:MAKE-PRS-HEREfrom
PeterPhuTran:swaglog-delete-oldest-first
Closed

swaglog: delete oldest (not newest) logs on rotation after restart#310
PeterPhuTran wants to merge 10000 commits into
FrogAi:MAKE-PRS-HEREfrom
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() seeded the list
oldest-first. After any process restart at the 2500-file cap, the tail therefore
held the newest pre-existing file, and every rollover deleted the most recently
written logs, marching backwards through them, while months-old files survived.

Field evidence: on a real comma three, every boot destroyed the newest ~100+ swaglog
files from before the reboot — exactly the files needed to debug whatever caused the
reboot. This bug erased weeks of crash forensics during the #309 investigation
(logs from the failing boots kept vanishing days after being written).

Fix: one word — seed the list newest-first (sorted(log_files, reverse=True))
to match the insert(0)/pop() convention.

Verification

New common/tests/test_swaglog.py:

  • fails on the unpatched base (restart prune deletes the wrong files), passes with the fix
  • covers the restart prune, repeated rollovers, and a second restart over survivors
  • verified on-device (comma three, red-on-bug → green-on-fix)

The same bug exists in upstream commaai/openpilot; submitted there separately.

🤖 Generated with Claude Code

Loading
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.