Repository navigation
fix(checkpoint): reconcile active run timeline - #694
Conversation
Preserve superseded runs for audit while excluding them from active replay, resume, ACP, and result projections. Task: coding-agent/.opencode/prompts/tasks/checkpoint-active-run-timeline.md
|
Warning Review limit reached
Next review available in: 37 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. 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: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (11)
📝 WalkthroughWalkthroughThis change adds checkpoint-based runtime-run supersession across JSONL, SQLite, and PostgreSQL. Restore operations retain superseded runs and events for audit, while active-run queries exclude them across session, ACP, HTTP, CLI, and WebUI flows. ChangesCheckpoint active-run timeline
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant SessionManager
participant RuntimeStore
participant RuntimeQueryService
participant WebUI
Client->>SessionManager: restore checkpoint
SessionManager->>RuntimeStore: restore checkpoint and supersede later runs
RuntimeStore-->>SessionManager: retain runs and events with metadata
WebUI->>SessionManager: request active runtime runs
SessionManager->>RuntimeQueryService: list active runtime runs
RuntimeQueryService-->>WebUI: return non-superseded runs
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 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.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
coding-agent/src/coding_agent/stores/runtime_store.py (1)
1068-1086: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winClaim paths do not exclude superseded runs, allowing post-checkpoint runs to still execute.
restore_checkpoint_statemarks a still-unclaimed run as superseded without changing itsstatusfield. All threeclaim_attached_executor_runimplementations select candidates bystatus IN ('requested', 'expired')and executor metadata only, so a superseded run remains claimable. Once claimed, a worker executes it, replaying a run created after the restored checkpoint — the exact outcome the checkpoint-restore feature is meant to prevent.
coding-agent/src/coding_agent/stores/runtime_store.py#L1068-L1086: addAND superseded_at IS NULLto thecandidateCTE'sWHEREclause inPGRuntimeStore._CLAIM_ATTACHED_EXECUTOR_RUN_SQL. This also fixesdurable_pg.py's fenced claim path, since it reuses this constant.coding-agent/src/coding_agent/stores/runtime_store.py#L648-L699: addrun.superseded_at is Noneto the candidate list comprehension inSQLiteRuntimeStore.claim_attached_executor_run.coding-agent/src/coding_agent/stores/durable_local.py#L1031-L1101: addrun.superseded_at is Noneto the candidate list comprehension inSQLiteLocalDurableStore.claim_attached_executor_run.🐛 Proposed fix for the PostgreSQL claim query
WITH candidate AS ( SELECT run_id FROM agent_runs WHERE status IN ('requested', 'expired') AND metadata->>'executor_ref_kind' IN ('external_worker', 'local_attached') AND metadata->>'executor_kind' = $2 AND ($1::text IS NULL OR session_id = $1) + AND superseded_at IS NULL ORDER BY started_at, run_id LIMIT 1 FOR UPDATE SKIP LOCKED )🐛 Proposed fix for the SQLite claim candidate filters
candidates = [ run for run in candidates if run.metadata.get("executor_ref_kind") in {"external_worker", "local_attached"} and run.metadata.get("executor_kind") == executor_kind + and run.superseded_at is None ]🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@coding-agent/src/coding_agent/stores/runtime_store.py` around lines 1068 - 1086, Claim candidate filters must exclude superseded runs. In coding-agent/src/coding_agent/stores/runtime_store.py:1068-1086, update PGRuntimeStore._CLAIM_ATTACHED_EXECUTOR_RUN_SQL to require superseded_at IS NULL; this also covers durable_pg.py’s reused fenced path. In coding-agent/src/coding_agent/stores/runtime_store.py:648-699 and coding-agent/src/coding_agent/stores/durable_local.py:1031-1101, update the candidate comprehensions in SQLiteRuntimeStore.claim_attached_executor_run and SQLiteLocalDurableStore.claim_attached_executor_run to require run.superseded_at is None.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@coding-agent/src/coding_agent/server/session_manager.py`:
- Around line 2952-2961: Update _restore_checkpoint() to persist the reconciled
session.current_turn_id through _restore_checkpoint_durable_state() before
completing the durable restore path. Ensure the value selected from
latest_active_run is materialized via Session.to_store_data() so checkpoint
reloads retain the current run ID.
---
Outside diff comments:
In `@coding-agent/src/coding_agent/stores/runtime_store.py`:
- Around line 1068-1086: Claim candidate filters must exclude superseded runs.
In coding-agent/src/coding_agent/stores/runtime_store.py:1068-1086, update
PGRuntimeStore._CLAIM_ATTACHED_EXECUTOR_RUN_SQL to require superseded_at IS
NULL; this also covers durable_pg.py’s reused fenced path. In
coding-agent/src/coding_agent/stores/runtime_store.py:648-699 and
coding-agent/src/coding_agent/stores/durable_local.py:1031-1101, update the
candidate comprehensions in SQLiteRuntimeStore.claim_attached_executor_run and
SQLiteLocalDurableStore.claim_attached_executor_run to require run.superseded_at
is None.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 1c98bf15-0a7f-47ae-9869-2deba02952d8
📒 Files selected for processing (23)
coding-agent/.opencode/prompts/tasks/checkpoint-active-run-timeline.mdcoding-agent/docs/adr/0075-checkpoint-restore-active-run-timeline.mdcoding-agent/postmortem/index.yamlcoding-agent/postmortem/patterns/PM-0027-reconcile-runtime-projections-on-checkpoint-restore.mdcoding-agent/src/coding_agent/acp/server.pycoding-agent/src/coding_agent/cli/local_runtime.pycoding-agent/src/coding_agent/runs/query.pycoding-agent/src/coding_agent/server/http_server.pycoding-agent/src/coding_agent/server/session_manager.pycoding-agent/src/coding_agent/stores/durable_local.pycoding-agent/src/coding_agent/stores/durable_pg.pycoding-agent/src/coding_agent/stores/runtime_store.pycoding-agent/tests/acp/test_compat_harness.pycoding-agent/tests/acp/test_server.pycoding-agent/tests/cli/test_local_runtime.pycoding-agent/tests/coding_agent/test_jsonl_runtime_store.pycoding-agent/tests/coding_agent/test_pg_durable_fencing.pycoding-agent/tests/coding_agent/test_pg_runtime_store.pycoding-agent/tests/coding_agent/test_runtime_query_service.pycoding-agent/tests/coding_agent/test_sqlite_local_durable_fencing.pycoding-agent/tests/coding_agent/test_sqlite_runtime_store.pycoding-agent/tests/ui/test_http_server.pycoding-agent/webui/app/src/App.test.tsx
Task packet: coding-agent/.opencode/prompts/tasks/checkpoint-active-run-timeline.md
Goal
Restore a checkpoint without replaying, resuming, or reporting runs created after that checkpoint, while preserving superseded runs and events for audit.
Task packet:
coding-agent/.opencode/prompts/tasks/checkpoint-active-run-timeline.mdADR:
coding-agent/docs/adr/0075-checkpoint-restore-active-run-timeline.mdChanges
superseded_by_checkpoint_idandsuperseded_atacross JSONL, SQLite, and PostgreSQL runtime records.current_turn_idafter restore.Non-goals
Verification
git diff --checkpassed.current_turn_id.Risk
Existing checkpoints infer the run boundary from
started_at > checkpoint.created_at; checkpoint capture and restore are serialized with active turns by ADR-0010. Real PostgreSQL and production smoke remain deployment gates.Rollback
Revert commit
066e7b1a33f28bf78515fea2e5396c68d731ad6e. The added nullable columns may remain safely unused after rollback; no run/event records are deleted.Summary by CodeRabbit
New Features
Bug Fixes
Documentation