Skip to content

Recover interrupted writing stages from durable scoped checkpoints #503

Done

Description

@datacas

Problem and verified cause

Dirty stage resumes use CycleRecorder._match_handoff in scripts/cycle.py and Handoffs.match in scripts/quota_state.py. Ownership records are created after a completed quota-exhausted process with unchanged HEAD and publication boundaries. This covers #389, not arbitrary interruption. Dispatch-attempt records already exist before execution, but do not preserve recoverable content after every interruption. A manual commit does not establish runtime attribution.

Scope

Extend existing attempt history and journal with durable, versioned recovery checkpoints; reuse Git objects and private recovery refs for content instead of introducing another state engine. Bind repository, task, PR, cycle, stage, attempt, workspace, branch, HEAD/tree, configuration and checkpoint chain. Persist intent before edits and complete checkpoints only after content is durable. Preserve original evidence.

Acceptance criteria

Design decisions (2026-11-29)

IR-001 Adoption. Edits after the last completed checkpoint are adopted only by an explicit operator command: the operator inspects the exact fingerprint (staged, unstaged and eligible untracked content); identity and time are recorded; the fingerprint is recomputed immediately before consumption and recovery stops if it changed. Adoption is bound to repository, cycle, task, PR, stage, attempt, workspace, HEAD and checkpoint; consumption is single-use, atomic and crash-idempotent. Provenance is operator_adopted, a separate contract from #389's operator_attested, reusing its fingerprint, identity, audit and single-use primitives where appropriate. The original checkpoint and evidence are preserved and adoption is a new event. No executor adopts its own ambiguous edits. Adoption never establishes executor authorship, grants permissions, counts as functional verification or bypasses mandatory checks or the secret exclusions.

IR-002 Retention and coverage. Lifecycle-based, never time-based. Private recovery refs and their reachable objects are kept until the checkpoint is consumed, the cycle is terminal and no active recovery depends on them; interrupted cycles and integrity failures are never pruned automatically; abandoned checkpoints need an explicit operator discard. Pruning is explicit, supports --dry-run, and is auditable, concurrency-safe and idempotent; fingerprints, metadata and provenance survive content pruning. Refs protect objects from ordinary git gc/git prune and are never published. Captured: text and binary content exactly, staged and unstaged states separately, eligible untracked files, Git-representable modes, symlinks without dereferencing, submodules by gitlink SHA only; dirty submodules are detected and reported as unsupported. Excluded: ignored files, identified secrets, sockets, devices and FIFOs. A checkpoint with excluded or unrestorable relevant content is never reported as complete. Tests cover ordinary GC, repeated recovery, interrupted pruning and active dependencies.

IR-003 Secrets. A documented, versioned, user-extensible secret-path exclusion list (for example .env* except templates such as .env.example, *.pem, *.key, *.p12, *.pfx, id_rsa, id_ed25519, .npmrc, .netrc, .pypirc, .aws/credentials, credentials.json, secrets.json) applies to tracked, staged, unstaged and untracked content, plus ignored files. Existing secret-content detection is reused when available, without adding a dependency. Exclusion and detection run before anything is written to the Git object store, and fail closed when a required check cannot complete. Excluded files stay untouched; only their path and reason code are recorded, never content. Coverage gaps are reported. Docs state that path exclusion and content scanning reduce exposure but cannot guarantee every secret is detected. Tests cover tracked and untracked secrets, ignored files, template exceptions, custom patterns, scanner failure and preservation of excluded files.

Dependencies and exclusions

Builds on closed #389; general recovery deliberately extends its quota-only scope. Related #262 and #323 have different responsibilities. No publication, remote rewrite or consolidation in this issue; quota-policy changes are limited to the absorbed #525 handoff. Add temporary-repository integration tests, with no production repository fixtures.

Update docs/routing.md, docs/review-cycle.md, persistence documentation and capability-parity audit where applicable. Planning: P1, M1; urgent because interrupted writing stages can require manual recovery.

Activity

  1. added
    enhancement
    priority: urgent
    P1
    on Nov 17, 2026
  2. added a commit that references this issue on Nov 30, 2026
  3. datacas commented on Nov 30, 2026

    @datacas
    OwnerAuthor

    Findings on PR #554 head be91c43 that superseded reviews reported and the latest review (2026-11-30 15:30, comment 7283100590) does not repeat. They are recorded here before those review comments are deleted to clear a finding-ID clash across interrupted reviews (toolkit bug filed separately). Full original comments are archived on the owner's host.

    From review comment 7273378790 (2026-11-30T08:48:57Z)

    [REV-001] · medium · open · - · blocks:no — Permission rerun after a quota handoff is verified against the stale quota checkpoint

    Path: scripts/cycle.py (_route_attempt, _check_checkpoint_handoff). _route_attempt runs _check_checkpoint_handoff for every number > 0 while run.checkpoint_handoff is set, and nothing clears it after the fallback starts. The stage allows a third attempt, a rerun after a permission answer (for number in range(3)). If the fallback edits the worktree and then asks for a permission, attempt 2 is verified against the quota checkpoint. The fingerprint or HEAD no longer matches, so the rerun is blocked with "the worktree is not the quota checkpoint". The result is a stop after the user already answered the permission. Evidence is from code reading; no test covers handoff followed by a permission rerun (not executed).

    From review comment 7273378790 (2026-11-30T08:48:57Z)

    [REV-002] · low · open · - · blocks:no — Checkpoint settled by reconcile_pending after a crash never verifies as matches

    Path: scripts/recovery_checkpoints.py (reconcile_pending, verify). After a crash following the ref, the row is completed with fingerprint=None plus fingerprint_unrecorded, and the status stays complete. verify then compares current["fingerprint"] != None, so an untouched worktree reports fingerprint_changed and the automatic handoff gate rejects it. It fails safe, but the crash test does not assert the state. Storing the fingerprint in the commit metadata would avoid it. Code reading only.

    From review comment 7273378790 (2026-11-30T08:48:57Z)

    [REV-003] · low · open · - · blocks:no — Retention doc and code disagree on interrupted checkpoints

    Path: docs/recovery-checkpoints.md, scripts/recovery_checkpoints.py (consume, prunable). The doc says interrupted checkpoints are never pruned. consume marks every complete or incomplete checkpoint of the scope consumed after a later successful stage, and prunable has no filter on kind='interrupted'. After the cycle is terminal an explicit prune can remove them. Align the doc or exclude the kind.

    Documentation: docs/recovery-checkpoints.md is new, and docs/README.md, configuration.md, routing.md, telemetry.md, instrumentation.md, review-cycle.md, capability-parity-audit.md (PA-53, PA-54) and CHANGELOG.md are updated. Nothing missing was found.

    Security triage: the deterministic rule did not fire (no CI, secret-file, agent-config path or label changed; the runtime plan has security_required: false). By own judgement the secret-exclusion and Git-object handling were read inline: staged, unstaged and untracked paths are excluded before objects are written, scanning fails closed, and ignored files are not captured. cc-security-review was not run, so security_audit_ran=false. No vulnerability was found.

    Acceptance criteria (tests.version=2): The criteria are numbered in the order of the request. AC-1 to AC-6 (recovery, integrity, ambiguous edits, writer lock, crash injection, retention and secrets) and AC-8 to AC-13 (#525 handoff, tests, routing page) are covered by tests/test_recovery_checkpoints.py and tests/test_quota_handoff.py, which pass. AC-7 (recovery grants no approval) is covered by the docs only, with no dedicated test, so it stays open. The abrupt-termination test uses os._exit, not SIGKILL.

    Checks run:

    Check Result
    python3 -m unittest tests.test_quota_handoff tests.test_recovery_checkpoints tests.test_quota_resume 63 tests OK
    python3 scripts/validate-package.py VALID
    basedpyright 0 errors, 0 warnings
    python3 -m unittest discover -s tests 2,856 tests OK (1 skipped), 676 s; it outlasted the 10 min foreground limit and finished in the background

    CI (parallel policy, state only): pass: Classify the change, Skills, manifests, and Bash installer, Windows test shard (windows-1/2/3). Fail: Windows test shard (windows-4) and PowerShell installer. main passes at its head. I could not read the failing job logs (gh run view is refused in this stage), so the cause is unknown.

    Residual risk: REV-001 is unexecuted. The two failing Windows jobs are new on this head and need the CI gate. A lock cannot attribute edits made outside the toolkit, as the doc discloses.

    ORCHESTRATION_RESULT (JSON)

    ORCHESTRATION_RESULT
    {"skill": "cc-initial-review", "status": "REVIEW_PASSED_AWAITING_CI", "issue_provider": "github", "issue_id": "503", "code_host": "github", "change_request_id": "554", "change_request_url": "#554", "pr_number": 554, "issue_number": 503, "head_sha": "be91c436bd2259e2fecd676169180d5de305e67a", "reviewed_head_sha": "be91c436bd2259e2fecd676169180d5de305e67a", "security_audit_ran": false, "review_run_id": "CCR-20261130-001", "reviewer": {"profile": "reviewer", "provider": "anthropic", "model_requested": "claude-sonnet-5-5", "model_resolved": null, "effort": "high"}, "plan_id": "plan-cycle-a3f8cac5ed4d443c95afb98862ec18de", "revision": 16, "digest": "f9a38a65d6fea7a83bec5718fe7c3e5aaf6227ee9f3d2ae549bb1cc246277177", "findings": [{"id": "REV-001", "severity": "medium", "status": "open", "disposition": "-", "blocks_approval": false, "category": "correctness", "path": "scripts/cycle.py", "line": 710}, {"id": "REV-002", "severity": "low", "status": "open", "disposition": "-", "blocks_approval": false, "category": "correctness", "path": "scripts/recovery_checkpoints.py", "line": 1303}, {"id": "REV-003", "severity": "low", "status": "open", "disposition": "-", "blocks_approval": false, "category": "documentation", "path": "docs/recovery-checkpoints.md", "line": 233}], "blocking_findings": [], "checks": {"head_sha": "be91c436bd2259e2fecd676169180d5de305e67a", "passed": 5, "failed": 2, "pending": 0}, "tests": {"version": 2, "conclusion": "passed", "commands": [{"command": "python3 -m unittest tests.test_quota_handoff tests.test_recovery_checkpoints tests.test_quota_resume", "result": "passed"}, {"command": "python3 scripts/validate-package.py", "result": "passed"}, {"command": "basedpyright", "result": "passed"}, {"command": "python3 -m unittest discover -s tests", "result": "passed"}], "acceptance": [{"id": "AC-1", "status": "met"}, {"id": "AC-2", "status": "met"}, {"id": "AC-3", "status": "met"}, {"id": "AC-4", "status": "met"}, {"id": "AC-5", "status": "met"}, {"id": "AC-6", "status": "met"}, {"id": "AC-7", "status": "open"}, {"id": "AC-8", "status": "met"}, {"id": "AC-9", "status": "met"}, {"id": "AC-10", "status": "met"}, {"id": "AC-11", "status": "met"}, {"id": "AC-12", "status": "met"}, {"id": "AC-13", "status": "met"}]}, "blocking": false}
    END_ORCHESTRATION_RESULT

    From review comment 7282461874 (2026-11-30T15:07:13Z)

    [REV-002] · low · open · - · blocks:no — Same-process lock re-entry

    Path: scripts/recovery_checkpoints.py (WriterLock.acquire, release).
    When the lock file names this process's PID and host, acquire replaces it and reports success instead of ConcurrentWriter. Two recorders in one process (threads, or an embedding caller) can then both write the same worktree. The first holder's release removes the lock under the second. docs/recovery-checkpoints.md and PA-53 promise that a second toolkit writer is refused. Evidence: code inspection; the stages in the current driver run sequentially, so this is latent. Suggested fix: refuse same-PID re-entry unless the lock object is the same instance.

    Acceptance criteria (AC-1 to AC-13)

    Each has a check in the executed tests below (63 targeted, then the full suite).

    • AC-1, AC-2, AC-5 (crash and repeat): test_recovery_checkpoints CaptureAndRestoreTests, CrashInjectionTests (including os._exit).
    • AC-3: IntegrityTests, AdoptionTests.
    • AC-4: WriterLockTests, test_quota_handoff.WriterAndAdoptionTests; the limit is disclosed in the docs.
    • AC-6: SecretTests, SubmoduleTests, RetentionTests, test_ordinary_gc_keeps_checkpoint_objects.
    • AC-7: prompt and stop texts, PA-53, PA-54 and the docs; the automatic path stops only itself.
    • AC-8 to AC-13 (Quota exhaustion in a writing stage stops the cycle with dirty_workspace instead of handing the worktree to the fallback #525 AC-1 to AC-5): test_quota_handoff.AutomaticHandoffTests (AC-1 implement, AC-2 resolve, AC-3 both exhausted, AC-4 one reroute), docs/routing.md new section.

    Security triage

    The deterministic rule did not fire (no CI, secret, key, agent-configuration path or label matched). The reviewer's reading found the change handles secret exclusion, but the audit was skipped as no sensitive surface (authentication, authorization, public API, dependency) changed. The secret-exclusion code was read inline. It fails closed on path, content, size and read errors. Residual: a file rewritten between the scan and update-index is flagged changed_during_capture (checkpoint incomplete), but its object may already be in the private object store. A separate cc-security-review pass did not run.

    Verification (executed in this stage, head be91c43)

    Check Command Result
    recovery-tests python3 -m unittest tests.test_recovery_checkpoints tests.test_quota_handoff tests.test_quota_resume pass: 63 tests, 12 s
    validate-package python3 scripts/validate-package.py pass: VALID: 16 skills
    basedpyright basedpyright pass: 0 errors, 0 warnings
    unittest-default python3 -m unittest exit 0, 0 tests run (discovery finds none; no evidence)
    configured-test python3 -m unittest discover -s tests pass: exit 0, 2856 tests, 1 skipped, 751 s. It passed the 600 s foreground limit, was moved to the background by the harness and its exit was read afterwards.

    Windows behaviour (the lock's dead-process path, POSIX modes) was not executed here.

    CI (read once, parallel policy; not findings)

    gh pr checks 554: pass: Classify the change, Skills, manifests, and Bash installer, Windows test shard windows-1, windows-2, windows-3. fail: Windows test shard (windows-4) after 17m20s (it holds test_recovery_checkpoints and test_quota_handoff), PowerShell installer after 3 s. The failure logs are not readable in this stage (gh run view is not in the review command table), so the cause is unknown. The CI gate waits for and decides on these checks.

    Documentation

    docs/recovery-checkpoints.md (new), routing.md, review-cycle.md, telemetry.md, instrumentation.md, configuration.md, capability-parity-audit.md (PA-53, PA-54), README.md index and CHANGELOG.md are updated. The PR description lists the documentation reviewed. No missing page found. Capability parity (#450): the new stops cover the automatic path only; the operator can still inspect, restore, adopt or run any operation directly.

    Residual risks

    Locks exclude toolkit writers only (disclosed). Secret detection reduces exposure and cannot guarantee it. Windows has no process-group exit proof, so a quota stop there still stops.

    The 2026-11-29 21:16 review also reported the stale-quota-checkpoint rerun (its REV-002) and the retention doc/code mismatch (its REV-004), the same issues as the first and third items above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1enhancementpriority: urgent

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions