Skip to content

fix(maintenance): make the catalog own replay execution semantics - #3244

Merged
Sinity merged 1 commit into
masterfrom
fix/maintenance/catalog-owns-replay
Jul 21, 2026
Merged

Sinity merged 1 commit into
masterfrom
fix/maintenance/catalog-owns-replay

Conversation

@Sinity

@Sinity Sinity commented Jul 21, 2026

Copy link
Copy Markdown
Owner

Summary

The canonical maintenance target catalog owns target identity, default
selection, and (now) replay capability. _REPLAY_DISPATCH -- a private,
independently-maintained handler table in polylogue/maintenance/replay.py
-- is deleted; replay dispatch now looks up
polylogue.storage.repair.REPAIR_HANDLERS directly, gated by
MaintenanceTargetSpec.replayable. Targetless maintenance run/preview/
execute now expands to the documented run-all set on all three real
adapters (CLI, HTTP, MCP), and a failed maintenance envelope is a typed
failure everywhere (non-zero CLI exit, HTTP 422, MCP typed error) instead
of a 200/exit-0 body that merely says "status": "failed".

Problem

Two concrete bugs (polylogue-71ey):

  1. The catalog (polylogue/maintenance/targets.py) advertised seven
    targets. polylogue/maintenance/replay.py kept a private six-target
    _REPLAY_DISPATCH dict that omitted superseded_raw_snapshots. The CLI
    accepted the target (click.Choice is built from the catalog) and then
    execute_replay recorded UnsupportedReplayTargetError -- even though
    repair_superseded_raw_snapshots was already fully implemented and
    already present in storage/repair.py's own (separate) handler dict.
  2. polylogue ops maintenance run with no --target -- the documented
    "no scope, full inventory" path -- resolved to zero targets and
    returned status=failed, silently, with exit code 0. The same bug
    existed independently in execute_backfill/preview_backfill
    (HTTP/MCP), which resolve targets through a separate, non-resumable
    code path from the CLI's execute_replay.

Solution

  • MaintenanceTargetSpec gains replayable: bool = True and
    non_replayable_reason: str = "". MaintenanceTargetCatalog gains
    resolve_or_default(names) (empty selection expands to every catalog
    target in declared order; an explicit-but-unresolvable name still fails
    closed to ()) and replayable_names().
  • polylogue/storage/repair.py's _REPAIR_HANDLERS/_PREVIEW_HANDLERS
    are renamed public (REPAIR_HANDLERS/PREVIEW_HANDLERS) -- they were
    already the complete, catalog-aligned handler dict; the bug was that
    replay.py kept its own incomplete copy instead of using them.
    _REPLAY_DISPATCH is deleted entirely; _run_one_target and
    supported_replay_targets() look up REPAIR_HANDLERS directly, gated
    by spec.replayable.
  • execute_replay (CLI, resumable), execute_backfill, and
    preview_backfill (HTTP/MCP, one-shot) all resolve targets through the
    new shared resolve_or_default(), so all three surfaces agree on what
    "no --target" means. execute_replay's offline-guard repair/
    cleanup flags are also corrected to reflect each resolved target's
    real SAFE_REPAIR_TARGETS/CLEANUP_TARGETS membership instead of
    piggybacking on dispatch-table presence.
  • Failure surfacing: CLI maintenance run raises SystemExit(1) when the
    envelope status is failed (both plain and --output-format json
    paths); the daemon HTTP POST /api/maintenance/run returns
    422 Unprocessable Entity instead of 200; the MCP maintenance tool
    returns a typed error payload (code=maintenance_execute_failed) instead
    of a plain envelope.

Alternatives rejected

Unifying execute_backfill (HTTP/MCP) into a thin wrapper over
execute_replay (CLI) was considered for full orchestrator convergence,
but execute_backfill reuses the preview-count fast path in
run_selected_maintenance and is exercised by its own contract tests
(tests/unit/maintenance/test_planner_contract.py); merging it risked
destabilizing that surface for a decomposition-only benefit. Instead, the
two orchestrators now share target resolution (resolve_or_default) and
target dispatch (REPAIR_HANDLERS), and a new real-adapter test
(TestRealAdapterTargetlessRunAll.test_three_adapters_agree_on_targetless_target_set)
proves they agree on the resolved target set, offline guard, and failure
routing end to end. Resumption remains CLI-only by design (HTTP/MCP are
stateless request/response; execute_backfill never calls the
.maintenance-state cursor machinery) -- this is now documented in
execute_replay's docstring and covered by dedicated CLI-only resume
tests in test_resume.py, rather than asserted as a full-code-path merge.

Verification

devtools test tests/unit/maintenance/ tests/unit/cli/test_archive_maintenance_cli.py \
  tests/unit/cli/test_maintenance_registration.py \
  tests/unit/cli/test_maintenance_verify_archive_cli.py \
  tests/unit/daemon/test_http_write_coordination.py tests/unit/mcp/ \
  tests/integration/test_blob_lifecycle_e2e.py
# 628 passed, 4 failed -- all 4 reproduce identically on unmodified master
# (TestRepairOrphanedBlobsHandler blob-GC age-floor flake,
# test_should_use_plain_contract, "mark candidates --help"); none touch
# the changed surface (confirmed via git stash + rerun).

mypy --strict polylogue/maintenance/ polylogue/storage/repair.py \
  polylogue/daemon/http.py polylogue/mcp/server_cutover.py \
  polylogue/cli/commands/maintenance/_run.py tests/unit/maintenance/ \
  tests/integration/test_blob_lifecycle_e2e.py
# Success: no issues found in 35 source files

devtools render all --check   # no drift
devtools verify --quick       # 16/16 steps ok

AC matrix (polylogue-71ey)

  1. Catalog equality proves every advertised target is executable or
    explicitly non-replayable with a surface-visible reason;
    superseded_raw_snapshots succeeds through the real explicit-target CLI
    route.
    Satisfied. TestCatalogReplayEquality in
    tests/unit/maintenance/test_targets.py derives expected replayability
    from the live catalog + REPAIR_HANDLERS (no hardcoded target list);
    TestExplicitSupersededRawSnapshotsRoute.test_cli_run_explicit_target_succeeds
    drives the real CLI route. All seven current targets are replayable
    with real handlers; the non-replayable path exists in the type and is
    tested structurally but has no live instance today (nothing in the
    catalog currently needs it).
  2. Targetless polylogue ops maintenance run --dry-run executes the
    documented run-all set and returns success; deleting default expansion
    makes the real-route test fail.
    Satisfied. resolve_or_default() is
    the single default-expansion implementation used by all three
    surfaces; TestRealAdapterTargetlessRunAll exercises the real CLI,
    MCP, and HTTP routes.
  3. CLI, MCP, and HTTP real adapters invoke the same target
    resolver/orchestrator and agree on target set, resumption, failure
    routing, and offline guards, or a typed capability matrix proves each
    intentional difference.
    Partially satisfied by design, not full
    orchestrator merge -- see "Alternatives rejected" above. Target
    resolution (resolve_or_default) and dispatch (REPAIR_HANDLERS) are
    shared; test_three_adapters_agree_on_targetless_target_set proves
    real-route agreement on the resolved target set. Resumption is
    intentionally CLI-only (stateless HTTP/MCP vs. cursor-persisting CLI
    replay) and documented as such rather than merged.
  4. Any failed maintenance envelope yields non-zero CLI exit and typed
    HTTP/MCP failure behavior.
    Satisfied.
    TestFailedEnvelopeSurfaces drives a real handler failure through all
    three adapters and asserts exit code / HTTP 422 / MCP typed error.
  5. Focused maintenance CLI/replay/envelope tests and devtools verify --quick pass. Satisfied -- see Verification above.

Ref polylogue-71ey

Problem: the canonical maintenance target catalog advertised seven
targets, but polylogue.maintenance.replay kept a private, hand-copied
six-target _REPLAY_DISPATCH that silently omitted
superseded_raw_snapshots -- the generated CLI accepted the target
(click.Choice is built from the catalog) and then recorded
UnsupportedReplayTargetError. Separately, the documented targetless
`polylogue ops maintenance run` path (CLI, HTTP, and MCP) resolved to
zero targets and returned status=failed with a zero exit code, because
an empty --target selection was never expanded to the run-all set.

What changed:

- MaintenanceTargetSpec gains `replayable`/`non_replayable_reason`
  fields; MaintenanceTargetCatalog gains `resolve_or_default()` (empty
  target selection expands to every catalog target, an explicit-but-
  unknown name still fails closed) and `replayable_names()`.
- Deleted the independent _REPLAY_DISPATCH dict. Replay dispatch now
  looks up polylogue.storage.repair.REPAIR_HANDLERS (renamed public
  from _REPAIR_HANDLERS/_PREVIEW_HANDLERS) directly, gated by
  spec.replayable -- the same dict run_selected_maintenance already
  used, so there is one handler vocabulary instead of two. This fixes
  superseded_raw_snapshots for free: it was already fully implemented
  in repair.py, just missing from the old private copy.
- execute_replay, execute_backfill, and preview_backfill all resolve
  targets through the shared resolve_or_default(), so CLI (resumable
  replay), and HTTP/MCP (one-shot backfill) agree on what "no
  --target" means.
- A failed maintenance envelope is now a typed failure on every
  surface: CLI raises SystemExit(1), HTTP returns 422, MCP returns a
  typed error payload (code=maintenance_execute_failed) -- previously
  all three returned a 200/exit-0 body that merely said "failed".

Verification:
- devtools test tests/unit/maintenance/ tests/unit/cli/test_archive_maintenance_cli.py
  tests/unit/cli/test_maintenance_registration.py
  tests/unit/cli/test_maintenance_verify_archive_cli.py
  tests/unit/daemon/test_http_write_coordination.py tests/unit/mcp/
  tests/integration/test_blob_lifecycle_e2e.py -> 628 passed, 4 failed;
  all 4 failures reproduce identically on unmodified master
  (TestRepairOrphanedBlobsHandler blob-GC age-floor flake,
  test_should_use_plain_contract, "mark candidates --help") -- none
  touch the changed surface.
- mypy --strict on every touched module and test file: no issues.
- devtools render all --check: no drift.

Ref polylogue-71ey
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 37 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: e7e1ecce-3f83-4c53-ab63-bc011a2fbb34

📥 Commits

Reviewing files that changed from the base of the PR and between 2cf432c and 15f54c1.

📒 Files selected for processing (13)
  • polylogue/cli/commands/maintenance/_run.py
  • polylogue/daemon/http.py
  • polylogue/maintenance/planner.py
  • polylogue/maintenance/replay.py
  • polylogue/maintenance/targets.py
  • polylogue/mcp/server_cutover.py
  • polylogue/storage/repair.py
  • tests/integration/test_blob_lifecycle_e2e.py
  • tests/unit/maintenance/test_failure_routing.py
  • tests/unit/maintenance/test_idempotency.py
  • tests/unit/maintenance/test_registry.py
  • tests/unit/maintenance/test_resume.py
  • tests/unit/maintenance/test_targets.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/maintenance/catalog-owns-replay

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.

@Sinity

Sinity commented Jul 21, 2026

Copy link
Copy Markdown
Owner Author

Coordinator stand-in review (CodeRabbit rate-limited): read the diff structure + full lane receipts. Catalog-derived dispatch (deleting _REPLAY_DISPATCH), declared replayability with anti-vacuity pins both directions, resolve_or_default for the targetless run-all path on all three surfaces, and the bonus failed-envelope surfacing (CLI exit 1 / HTTP 422 / MCP typed error) fixes a real silent-failure class. The execute_backfill-vs-execute_replay non-merge is a documented partial-by-design, acceptable. 628 tests green, 4 pre-existing stash-verified. Merging.

@Sinity
Sinity merged commit db11def into master Jul 21, 2026
2 of 3 checks passed
@Sinity
Sinity deleted the fix/maintenance/catalog-owns-replay branch July 21, 2026 15:37
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