Skip to content

fix(doctor): add --fix pruning for disk-usage, skipping recent sessions#175

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

fix(doctor): add --fix pruning for disk-usage, skipping recent sessions#175
carlkibler wants to merge 1 commit into
Ruya-AI:mainfrom
carlkibler:pr/doctor-fix-disk-usage

Conversation

@carlkibler

Copy link
Copy Markdown
Contributor

What

check_disk_usage has None as its fix function in ALL_CHECKS, so cozempic doctor --fix skips it and leaves only a generic treat <session> hint. This wires fix_disk_usage in with a conservative, age-gated selection:

  • cozempic doctor --fix now applies the gentle prescription to sessions that are both larger than 5MB and untouched for more than 7 days, writing a .bak per session first.
  • Recent sessions (modified within 7 days) are skipped so an active or in-flight session is never rewritten; the fix reports treated-vs-skipped counts.
  • The check's fix_description shows the candidate count and threshold instead of the generic placeholder.
  • No change to the check's pass/fail status or to any other check.

Why

On main (1.8.39) disk-usage and oversized-sessions are the only two checks still registered with a None fix function. This one is deliberately conservative (age + size gated, .bak first) because disk-usage sweeps a broad set of sessions, some of which may be live.

Tests

tests/test_doctor.py — 43 passed (adds coverage for the age-gate and skip-recent behavior).

Companion to #174 (oversized-sessions --fix). The two touch adjacent ALL_CHECKS entries; happy to rebase whichever merges second.

https://claude.ai/code/session_01UFpNbexgthmPFAcyHuVepn

check_disk_usage had no fix function, so `cozempic doctor --fix` skipped
it and left only a generic "treat <session>" hint. This wires
fix_disk_usage into ALL_CHECKS with a conservative, age-gated selection:

- `cozempic doctor --fix` now applies the gentle prescription to sessions
  that are both larger than 5MB and untouched for more than 7 days,
  writing a .bak per session first.
- Recent sessions (modified within 7 days) are skipped so an active or
  in-flight session is never rewritten; the fix reports treated vs
  skipped counts.
- The check's fix_description now shows the candidate count and threshold
  instead of the generic placeholder.

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: b832d43928

ℹ️ 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 +269 to +271
messages = load_messages(sess["path"])
pruned, _ = run_prescription(messages, PRESCRIPTIONS["gentle"], {})
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 append-safety when pruning disk-usage candidates

In the doctor --fix disk-usage path, this rewrites session JSONL files using a plain load_messages()/save_messages() round trip without the _PruneLock and snapshot that the existing treat/guard/orphaned-fix write paths use. For an eligible old session that is resumed, appended to, or pruned by another process after the mtime candidate check but before this save_messages() call, the replace can discard those concurrent lines because save_messages() only performs append-conflict detection when a snapshot is passed. Please use load_messages_and_snapshot() plus _PruneLock and pass snapshot= here so automatic doctor --fix cannot clobber live transcript updates.

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