Skip to content

feat(maintenance): staleness inventory preview (#1145) - #1154

Merged
Sinity merged 1 commit into
masterfrom
feature/feat/maintenance-preview-staleness
May 17, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/feat/maintenance-preview-staleness

Conversation

@Sinity

@Sinity Sinity commented May 17, 2026

Copy link
Copy Markdown
Owner

Summary

Adds the preview half of the maintenance backfill planner: a typed, read-only
staleness inventory exposed as a Python API (staleness_inventory()) and as
the polylogue maintenance preview CLI subcommand. Operators can now answer
"what will be rebuilt and why" before triggering any mutating maintenance.

Problem

Before this PR, polylogue maintenance plan returned an aggregate
affected_rows count and a per-target debt dict, but operators had no way to
see why a row was considered stale — every "needs work" item rolled up into
one bucket. Issue #1145 specifies a per-model, per-scope inventory tagged with
typed invalidation reasons so operators (and downstream automation) can
distinguish "never built", "older than its source", "version mismatch", and
"orphaned" without grepping debt strings.

Solution

  • polylogue/maintenance/preview.py (new): staleness_inventory(db_path, scopes=..., verify_full=...) returns a StalenessInventory of
    StalenessItem(model, scope, reason, count, source_total, materialized_total, detail, sample_ids, truncated) rows. InvalidationReason
    is a 6-variant enum (MISSING, STALE, ORPHAN, MISSING_PROVENANCE,
    VERSION_MISMATCH, ORPHAN_ARCHIVE_ROW). Sources counts from the existing
    collect_derived_model_statuses_sync() and the four orphan-row counters in
    storage/repair.py.
  • Models inventoried across four scopes:
    • derived — 12 read models (FTS, action events, session insights,
      threads, tag rollups, day/week summaries).
    • retrieval — 4 retrieval-layer models (embeddings + RRF lanes).
    • archive_cleanup — 4 orphan-row scopes (orphaned_messages,
      orphaned_content_blocks, empty_conversations,
      orphaned_attachments).
    • backfill — message_type_backfill.
  • polylogue/cli/commands/maintenance.py: new preview subcommand with
    --scope, --output-format {plain,json}, --shallow.
  • Zero-row models still emit explicit rows for the three baseline reasons so
    consumers don't have to distinguish "absent" from "zero".
  • docs/plans/topology-target.yaml updated to declare the new module.

Non-goals deferred to the planner contract (#1144 / #996): mapping the
per-model inventory back to MaintenanceTargetSpec groupings, surfacing
sample ids beyond truncated plumbing, and execution (covered by the
resume/idempotency child).

Verification

  • nix develop -c pytest tests/unit/maintenance/test_preview.py — 11 tests
    pass in 10s, including a row-count-snapshot assertion that no table row
    count changes across a staleness_inventory() call (read-only invariant).
  • nix develop -c pytest tests/unit/maintenance/ tests/unit/core/test_maintenance_targets.py tests/unit/storage/test_derived_status.py tests/unit/cli/test_maintenance_registration.py tests/unit/daemon/test_maintenance_endpoints.py — 33 passed, 0 failed.
  • nix develop -c devtools verify --quick — exit 0.
  • Smoke: polylogue maintenance preview --output-format json against an empty
    archive emits 51 zero-count items across all 4 scopes; JSON validates and
    contains captured_at, db_path, total_stale, per-item fraction.

Ref #1145

@coderabbitai

coderabbitai Bot commented May 17, 2026 •

Copy link
Copy Markdown

Warning

Rate limit exceeded

@Sinity has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 54 minutes and 47 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 8e6755f5-14f0-47c7-b656-1518c74fa2a4

📥 Commits

Reviewing files that changed from the base of the PR and between b6e3a27 and 3dd7d84.

📒 Files selected for processing (8)
  • docs/plans/topology-target.yaml
  • docs/test-quality-workflows.md
  • docs/topology-status.md
  • docs/verification-catalog.md
  • polylogue/cli/commands/maintenance.py
  • polylogue/maintenance/preview.py
  • tests/unit/maintenance/__init__.py
  • tests/unit/maintenance/test_preview.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/feat/maintenance-preview-staleness

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Add `polylogue/maintenance/preview.py` exposing `staleness_inventory()`
which enumerates stale/missing/orphan derived artifacts per model with
typed `InvalidationReason` tags (MISSING, STALE, ORPHAN,
MISSING_PROVENANCE, VERSION_MISMATCH, ORPHAN_ARCHIVE_ROW). Wire the
inventory through a new `polylogue maintenance preview` subcommand
that renders plain and JSON output, with `--scope` filtering across
derived/retrieval/archive_cleanup/backfill.

Models with nothing stale emit explicit zero rows (not absence) so
consumers can render a complete inventory without distinguishing
"absent" from "zero". The preview is read-only: tests assert no row
counts change across the call and the new subcommand never opens a
write connection.

Ref #1145

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@Sinity
Sinity force-pushed the feature/feat/maintenance-preview-staleness branch from 5a816e8 to 3dd7d84 Compare May 17, 2026 04:39
@Sinity
Sinity merged commit 3d464f6 into master May 17, 2026
2 of 3 checks passed
@Sinity
Sinity deleted the feature/feat/maintenance-preview-staleness branch May 17, 2026 04:39

@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: 5a816e8bf0

ℹ️ 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 polylogue/maintenance/preview.py Resolved
@Sinity

Sinity commented Sep 30, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

Only the rows listed above are dispositioned. Held findings remain open.

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