fix(doctor): add --fix batch pruning for oversized sessions#174
fix(doctor): add --fix batch pruning for oversized sessions#174carlkibler wants to merge 1 commit into
Conversation
check_oversized_sessions had no fix function, so `cozempic doctor --fix` skipped it — the operator had to run each treat command by hand. This wires fix_oversized_sessions into ALL_CHECKS so `--fix` handles it: - `cozempic doctor --fix` now applies the aggressive prescription to every session over 50MB in one pass, writing a .bak per session first. - The check's fix_description points at `doctor --fix` for the batch path while still listing the individual treat commands. No change to the check's pass/fail status or to any other check. Co-Authored-By: Claude <noreply@anthropic.com>
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a290332eb3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| messages = load_messages(sess["path"]) | ||
| pruned, _ = run_prescription(messages, PRESCRIPTIONS["aggressive"], {}) | ||
| save_messages(sess["path"], pruned, create_backup=True) |
There was a problem hiding this comment.
Preserve concurrent appends during batch pruning
When doctor --fix is run while Claude is still appending to an oversized live transcript, this path reads with load_messages and then calls save_messages(..., snapshot=None) without the _PruneLock/load_messages_and_snapshot protection used by treat --execute. Any lines appended between the read and the final os.replace are therefore silently lost instead of being merged or deferred, so the batch fix can corrupt an active session.
Useful? React with 👍 / 👎.
| ("oversized-sessions", check_oversized_sessions, fix_oversized_sessions), | ||
| ("stale-backups", check_stale_backups, fix_stale_backups), |
There was a problem hiding this comment.
Keep fresh prune backups from same-run cleanup
In run_doctor(fix=True), checks execute in this list order. Since oversized-sessions now creates .jsonl.bak files and stale-backups immediately follows, any newly-created backup(s) totaling over 100MB, such as one 200MB session backup, are classified as stale and deleted in the same command, leaving the user without the rollback that the prune just promised. Consider skipping stale-backups after batch pruning or ignoring backups created during the current run.
Useful? React with 👍 / 👎.




What
check_oversized_sessionshasNoneas its fix function inALL_CHECKS, socozempic doctor --fixsilently skips it — the operator has to run eachtreatcommand by hand. This wiresfix_oversized_sessionsin so--fixhandles it.cozempic doctor --fixnow applies the aggressive prescription to every session over 50MB in one pass, writing a.bakper session first.fix_descriptionpoints atdoctor --fixfor the batch path while still listing the individualtreatcommands.Why
On main (1.8.39) both
oversized-sessionsanddisk-usageare the only checks still registered with aNonefix function, so--fixis a no-op for exactly the two checks most likely to matter on a bloated machine.Tests
tests/test_doctor.py— 43 passed (adds coverage for the batch fix path).https://claude.ai/code/session_01UFpNbexgthmPFAcyHuVepn