Repository navigation
fix(maintenance): make the catalog own replay execution semantics - #3244
Conversation
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
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reached
Next review available in: 37 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (13)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
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. |
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_HANDLERSdirectly, gated byMaintenanceTargetSpec.replayable. Targetlessmaintenance run/preview/executenow expands to the documented run-all set on all three realadapters (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):
polylogue/maintenance/targets.py) advertised seventargets.
polylogue/maintenance/replay.pykept a private six-target_REPLAY_DISPATCHdict that omittedsuperseded_raw_snapshots. The CLIaccepted the target (
click.Choiceis built from the catalog) and thenexecute_replayrecordedUnsupportedReplayTargetError-- even thoughrepair_superseded_raw_snapshotswas already fully implemented andalready present in
storage/repair.py's own (separate) handler dict.polylogue ops maintenance runwith no--target-- the documented"no scope, full inventory" path -- resolved to zero targets and
returned
status=failed, silently, with exit code 0. The same bugexisted 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
MaintenanceTargetSpecgainsreplayable: bool = Trueandnon_replayable_reason: str = "".MaintenanceTargetCataloggainsresolve_or_default(names)(empty selection expands to every catalogtarget in declared order; an explicit-but-unresolvable name still fails
closed to
()) andreplayable_names().polylogue/storage/repair.py's_REPAIR_HANDLERS/_PREVIEW_HANDLERSare renamed public (
REPAIR_HANDLERS/PREVIEW_HANDLERS) -- they werealready the complete, catalog-aligned handler dict; the bug was that
replay.pykept its own incomplete copy instead of using them._REPLAY_DISPATCHis deleted entirely;_run_one_targetandsupported_replay_targets()look upREPAIR_HANDLERSdirectly, gatedby
spec.replayable.execute_replay(CLI, resumable),execute_backfill, andpreview_backfill(HTTP/MCP, one-shot) all resolve targets through thenew shared
resolve_or_default(), so all three surfaces agree on what"no
--target" means.execute_replay's offline-guardrepair/cleanupflags are also corrected to reflect each resolved target'sreal
SAFE_REPAIR_TARGETS/CLEANUP_TARGETSmembership instead ofpiggybacking on dispatch-table presence.
maintenance runraisesSystemExit(1)when theenvelope status is
failed(both plain and--output-format jsonpaths); the daemon HTTP
POST /api/maintenance/runreturns422 Unprocessable Entityinstead of200; the MCPmaintenancetoolreturns a typed error payload (
code=maintenance_execute_failed) insteadof a plain envelope.
Alternatives rejected
Unifying
execute_backfill(HTTP/MCP) into a thin wrapper overexecute_replay(CLI) was considered for full orchestrator convergence,but
execute_backfillreuses the preview-count fast path inrun_selected_maintenanceand is exercised by its own contract tests(
tests/unit/maintenance/test_planner_contract.py); merging it riskeddestabilizing that surface for a decomposition-only benefit. Instead, the
two orchestrators now share target resolution (
resolve_or_default) andtarget 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_backfillnever calls the.maintenance-statecursor machinery) -- this is now documented inexecute_replay's docstring and covered by dedicated CLI-only resumetests in
test_resume.py, rather than asserted as a full-code-path merge.Verification
AC matrix (polylogue-71ey)
explicitly non-replayable with a surface-visible reason;
superseded_raw_snapshots succeeds through the real explicit-target CLI
route. Satisfied.
TestCatalogReplayEqualityintests/unit/maintenance/test_targets.pyderives expected replayabilityfrom the live catalog +
REPAIR_HANDLERS(no hardcoded target list);TestExplicitSupersededRawSnapshotsRoute.test_cli_run_explicit_target_succeedsdrives 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).
polylogue ops maintenance run --dry-runexecutes thedocumented run-all set and returns success; deleting default expansion
makes the real-route test fail. Satisfied.
resolve_or_default()isthe single default-expansion implementation used by all three
surfaces;
TestRealAdapterTargetlessRunAllexercises the real CLI,MCP, and HTTP routes.
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) areshared;
test_three_adapters_agree_on_targetless_target_setprovesreal-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.
HTTP/MCP failure behavior. Satisfied.
TestFailedEnvelopeSurfacesdrives a real handler failure through allthree adapters and asserts exit code / HTTP 422 / MCP typed error.
devtools verify --quickpass. Satisfied -- see Verification above.Ref polylogue-71ey