feat(7642): bin/compactStalePads — staleness-gated bulk compaction#7708
feat(7642): bin/compactStalePads — staleness-gated bulk compaction#7708SamTV12345 merged 2 commits intoether:developfrom
Conversation
Adds bin/compactStalePads with --older-than / --keep / --dry-run. Composes listAllPads → getLastEdited → compactPad so hot pads in active timeslider use are left alone and only the cold tail is compacted. Targeting stays a CLI concern; compactPad's API surface is unchanged. Per-pad failures (including a getLastEdited fault) don't stop the run — same error-tolerance shape as compactAllPads. End-to-end test plumbs through the real /api/1.3.1/getLastEdited + compactPad endpoints to lock the adapter contract. Daily-cron variant (cleanup.compactOlderThanDays setting) deferred to a follow-up so this PR stays focused on the on-demand operator tool from the issue's primary acceptance bullet. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one. |
Review Summary by QodoAdd bin/compactStalePads for staleness-gated bulk compaction
WalkthroughsDescription• Adds bin/compactStalePads.ts CLI tool for staleness-gated bulk pad compaction • Filters pads by edit recency using --older-than <days> before compacting • Supports --keep N and --dry-run flags matching compactAllPads interface • Implements per-pad error tolerance; failures don't abort the run • Comprehensive test coverage with 30 passing tests including end-to-end validation Diagramflowchart LR
listAllPads["listAllPads()"]
getLastEdited["getLastEdited(padId)"]
filter["Filter by cutoff<br/>olderThanDays"]
getRevCount["getRevisionsCount(padId)"]
compactPad["compactPad(padId,<br/>keepRevisions)"]
report["CompactStaleReport<br/>ok/failed/skipped"]
listAllPads -->|all pads| getLastEdited
getLastEdited -->|lastEdited ts| filter
filter -->|stale pads| getRevCount
getRevCount -->|before count| compactPad
compactPad -->|success/failure| report
File Changes1. bin/compactStalePads.ts
|
Code Review by Qodo
1. No docs for compactStalePads
|
|
/review |
ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one. |
Code Review by Qodo
Context used 1. No docs for compactStalePads
|
| 'use strict'; | ||
|
|
||
| /* | ||
| * Compact every pad on the instance that has not been edited recently. | ||
| * | ||
| * Usage: | ||
| * node bin/compactStalePads.js --older-than 90 # collapse history on pads not edited in 90 days | ||
| * node bin/compactStalePads.js --older-than 90 --keep 50 # keep last 50 revisions | ||
| * node bin/compactStalePads.js --older-than 90 --dry-run # list, don't write | ||
| * | ||
| * Composes `listAllPads` → `getLastEdited` → `compactPad`. Same shape as | ||
| * `bin/compactAllPads` (per-pad error tolerance, dry-run, tally), but | ||
| * filters by edit-recency before touching anything. Targeting which pads | ||
| * to compact is deliberately a CLI concern and not a `compactPad` API | ||
| * param — staleness changes from one run to the next, the compaction | ||
| * primitive does not. |
There was a problem hiding this comment.
1. No docs for compactstalepads 📎 Requirement gap ⚙ Maintainability
This PR adds a new operator-facing CLI (bin/compactStalePads) but does not update the admin/CLI documentation under doc/ to describe its usage and flags. This makes the feature undiscoverable and violates the documentation update requirement.
Agent Prompt
## Issue description
A new CLI tool (`bin/compactStalePads`) was introduced, but the admin/CLI documentation was not updated to describe how to use it (flags `--older-than`, `--keep`, `--dry-run`, and behavior).
## Issue Context
Compliance requires that operator-facing CLI functionality be documented in the appropriate `doc/` admin/CLI documentation so administrators can discover and safely use it.
## Fix Focus Areas
- doc/cli.md[1-200]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Qodo flagged two real issues: 1. Race window between staleness selection and compaction. On a long bulk run a pad could become active between first-pass filtering and compactPad, which would then kick those sessions. Added a getLastEdited recheck right before each compact call; if the pad is now fresh it's reclassified as skippedFresh rather than failed (the user did the right thing — edited it — and we bow out). 2. doc/cli.md had nothing on pad compaction at all (gap predates this PR; ether#6194 landed without doc updates). Added a Pad compaction section covering all three CLIs — compactPad, compactAllPads, compactStalePads — so the toolset is discoverable as a unit. Tests cover both the recheck-skip path and a recheck-failure path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Addressed Qodo's findings in d19dc0e:
/review |
Closes #7642.
Summary
bin/compactStalePads.tswith--older-than <days>,--keep N, and--dry-run. ComposeslistAllPads→getLastEdited→compactPad, mirroring the per-pad error tolerance / dry-run / tally shape ofbin/compactAllPads.getLastEditedfault on one pad is counted as a failure but doesn't stop the run — same posture as agetRevisionsCountfault incompactAllPads.Design decisions
compactPadendpoint is unchanged. Keeps both surfaces simple and lets non-time staleness signals (rev count, byte size — issue calls these out as follow-ons) layer on later without further API churn.cleanup.compactOlderThanDaysships in the same PR. I've kept this PR scoped to the on-demand operator tool (the primary acceptance bullet) and split the cron variant out as a follow-up — easier to review, and the cron variant has its own settings/lifecycle questions (timer registration, log shape, interaction withcleanup.enabled) that deserve their own diff. Happy to fold it in here if reviewers prefer.Test plan
pnpm ts-checkcleanmocha tests/backend/specs/compactPad.ts— 30 passing, including:parseArgsaccepts--older-than/--keep/--dry-run, rejects missing/negative/unknownnow--keep Nis plumbed through tocompactPad--dry-rundoes not callcompactPadgetLastEditedfailure on one pad is counted as failure but doesn't stop iterationlistAllPadsfailure aborts cleanly withfailed=1--older-than 0edge cases/api/1.3.1/getLastEdited+compactPadSemver
patch (CLI addition; no API surface change)
🤖 Generated with Claude Code