Repository navigation
feat(maintenance): idempotent resumable replay (#1147) - #1161
Conversation
Adds polylogue/maintenance/replay.py implementing the execute half of the typed maintenance planner from #1144. Targets supported in this PR: session_insights, action_event_read_model, dangling_fts (plus message_type_backfill and wal_checkpoint, which already converge). Resume substrate is a per-operation JSON state file under <archive_root>/.maintenance-state/. The cursor encodes the index of the next target to run; a successful replay clears the file, an interrupted replay leaves it for resume. The cursor advances after both successful and failed targets so resume cannot stack duplicate failure samples or re-run already-completed work. Per-target failures are isolated: a raise becomes a typed FailureSample, repair functions reporting success=False are surfaced as RepairReportedFailure, and unsupported targets are reported as UnsupportedReplayTargetError rather than silently succeeding. `polylogue maintenance run` gains --operation-id and --resume, with per-target progress emitted on stderr so a caller can checkpoint externally if it owns its own state substrate. Closes #1147 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (7)
✨ 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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9504255b4c
ℹ️ 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".
|
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. |
Summary
Adds the execute half of the typed maintenance planner: a per-target
replay loop with idempotent re-runs, durable resume via an on-disk
cursor, isolated per-target failure handling, and structured progress
reporting. Wires it into
polylogue maintenance runbehind--operation-idand--resume.Problem
#1144 landed the typed
BackfillOperationcontract (withresume_cursor,failure_samples,metrics,scope) via PR #1157,but no executor used those fields end-to-end. The existing
execute_backfillpath droverun_selected_maintenanceas oneatomic op, which meant:
resume_cursorfield onBackfillOperationwas alwaysNone.#1147 closes this gap so that maintenance work survives interruptions
without re-doing committed targets and without skipping uncommitted
ones.
Solution
New module
polylogue/maintenance/replay.py:execute_replay(config, targets, *, operation_id, resume_cursor, dry_run, persist_state, progress_callback)runs the resolvedtargets in catalog order, dispatching through a typed
_REPLAY_DISPATCHtable to the existing repair functions(
repair_session_insights,repair_action_event_read_model,repair_dangling_fts,repair_message_type_backfill,repair_wal_checkpoint).target:N(next target index) withsentinel
donefor completion._decode_cursorclamps invalidvalues to 0 so a corrupt state file cannot silently skip work.
<archive_root>/.maintenance-state/<operation_id>.jsonafter eachtarget. Successful completion clears the file; failure leaves it
so resume picks up where the operation stopped.
FailureSampleentries(
kind=ExceptionClassName,locator=target:<name>); repairfunctions reporting
success=FalsebecomeRepairReportedFailure; unsupported targets becomeUnsupportedReplayTargetError. Failure samples remain bounded byBoundedFailureSamples.from_samples(MAX_FAILURE_SAMPLES=50).ReplayProgresssnapshots are passed to an optional callback,including
operation_id,target,processed/total,cursor,and
in_flight_failures.CLI
polylogue maintenance run:--operation-id(resume by id) and--resume(explicitcursor) flags;
kind,locator, andmessage;execute_backfillcall.Topology manifest updated (
docs/plans/topology-target.yaml) toregister
polylogue/maintenance/replay.py;render-allregenerateddocs/topology-status.mdanddocs/verification-catalog.mdto match.Alternatives rejected: persisting state in a new SQLite table —
explicitly out of scope for this PR (
polylogue/storage/sqlite/isowned by another agent worktree). A JSON state file under
archive_rootis sufficient for the AC and inherits free atomicwrites via the
tmp + replacepattern.Verification
AC matrix (issue #1147):
maintenance run --target Xtwice converges — pinned bytest_second_run_makes_no_further_changes(second op reportsaffected_rows == 0).operation_idresumes from stored cursor;no target rebuilt twice, none skipped — pinned by
test_kill_mid_run_resumes_from_persisted_cursor(asserts exactper-target call counts across the two invocations).
test_supported_targets_cover_ac_required_set.test_single_target_failure_does_not_abort_others,test_repair_reported_failure_surfaces_as_failure_sample,test_failure_samples_remain_bounded,test_unsupported_target_is_typed_failure_not_silent./ last cursor / in-flight failures — pinned by
test_progress_callback_fires_per_target; mirrored by the newstderr progress block in the CLI.
target failure isolation — covered by the new test files.
Closes #1147
🤖 Generated with Claude Code