Skip to content

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

Open
PeterPhuTran wants to merge 1 commit into
FrogAi:MAKE-PRS-HEREfrom
PeterPhuTran:fp-swaglog-delete-oldest-first
Open

swaglog: delete oldest (not newest) logs on rotation after restart#313
PeterPhuTran wants to merge 1 commit into
FrogAi:MAKE-PRS-HEREfrom
PeterPhuTran:fp-swaglog-delete-oldest-first

Conversation

@PeterPhuTran

Copy link
Copy Markdown

Replaces #310, which was auto-closed by an accidental force-push to its head branch (a fork-tooling mishap — the fork is shared with upstream openpilot PR branches). Content unchanged.

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

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 any process restart at the backup_count
cap, the tail was the *newest* pre-existing file - every rollover then
deleted the most recently written logs, marching backwards through them,
while months-old files survived.

Observed on a real device: each 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 while
investigating FrogAi#309).

Fix: seed the list newest-first to match the insert(0)/pop() convention.
Adds a unit test covering the restart prune, repeated rollovers, and a
second restart.

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

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Thanks for contributing! A maintainer will review your pull request soon.

@FrogAi

FrogAi commented Jul 31, 2026

Copy link
Copy Markdown
Owner

Ignore this — posted in error while I was testing some workflow automation. Your PR is targeted at the right branch, nothing is wrong with it, and I've reopened it. Sorry for the noise!

@FrogAi FrogAi closed this Jul 31, 2026
@FrogAi FrogAi reopened this Jul 31, 2026
@FrogAi

FrogAi commented Jul 31, 2026

Copy link
Copy Markdown
Owner

Sorry, testing new workflows lol

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.

2 participants