Skip to content

fix(doctor): add --fix batch pruning for oversized sessions#174

Open
carlkibler wants to merge 1 commit into
Ruya-AI:mainfrom
carlkibler:pr/doctor-fix-oversized-sessions
Open

fix(doctor): add --fix batch pruning for oversized sessions#174
carlkibler wants to merge 1 commit into
Ruya-AI:mainfrom
carlkibler:pr/doctor-fix-oversized-sessions

Conversation

@carlkibler

Copy link
Copy Markdown
Contributor

What

check_oversized_sessions has None as its fix function in ALL_CHECKS, so cozempic doctor --fix silently skips it — the operator has to run each treat command by hand. This wires fix_oversized_sessions in 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.

Why

On main (1.8.39) both oversized-sessions and disk-usage are the only checks still registered with a None fix function, so --fix is 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

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>
@sonarqubecloud

sonarqubecloud Bot commented Jul 8, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
D Security Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread src/cozempic/doctor.py
Comment on lines +173 to +175
messages = load_messages(sess["path"])
pruned, _ = run_prescription(messages, PRESCRIPTIONS["aggressive"], {})
save_messages(sess["path"], pruned, create_backup=True)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment thread src/cozempic/doctor.py
Comment on lines +1516 to 1517
("oversized-sessions", check_oversized_sessions, fix_oversized_sessions),
("stale-backups", check_stale_backups, fix_stale_backups),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

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