Skip to content

refactor(F0): recover a missing structured result as pending verification - #200

Merged
datacas merged 2 commits into
mainfrom
task-174
Oct 7, 2026
Merged

datacas merged 2 commits into
mainfrom
task-174

Conversation

@datacas

@datacas datacas commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Closes #174

Work item: #174 (depends on #172, closed via #195).

Summary

When a stage did its work but omitted its structured result, the runtime can now recover a conservative recovered_pending_verification state from attempt-attributed PR-comment evidence and advance to verification instead of stopping. Recovery never infers APPROVED or READY_FOR_MANUAL_MERGE.

  • Contract (schema 2): the runtime injects its attempt_id into implement/review/resolve/rereview prompts; skills publish a <!-- code-cycle-stage {JSON} --> receipt with repo, change_request_id, stage, attempt_id, full head_sha, status, and explicit finding_outcomes. Claimed IDs come only from this receipt, never from finding headers. Run-line examples now show schema:2; schema-1 lines stay readable.
  • Evidence reader (GitHub, gh): reads the open PR and full paginated comment history, accepts only review.trusted_authors, requires exactly one receipt matching repository, PR, stage, attempt and SHA, the checked-out head must equal the PR head, and any BLOCKED/FAILED receipt or published result for that attempt vetoes recovery.
  • Transitions: recovered implement → review; recovered resolve (including comment-only, no push) → rereview, whose structured result must report the recovered head and confirm or reopen every claimed ID. A reopened claim feeds the survivals ladder and normal resolution loop. A recovered review/rereview is re-dispatched once for a structured verdict; a second missing result stops.
  • Storage (telemetry schema 16): append-only stage_recoveries (references only, triggers reject UPDATE/DELETE); the dispatch_attempts row stays failed.
  • Other code hosts keep the existing missing-result stop.

Diagnosis

  • Symptom: 9/42 cycles in the baseline stopped as stage_not_completed; in Record verified work-item resolution outcomes #120 the fix was pushed and the PR comment published, but no structured block was emitted, so the cycle stopped and needed a manual --from rereview.
  • Hypothesis (issue): the cycle has no state between "structured result" and "stop". Confirmed in code: run_cycle.advance → unfinished() stopped on any missing structured result (unreadable_result/no_error_report), and published evidence had no attempt attribution, so it could not be safely trusted.
  • Reproduction: feature request; not a defect reproduction. The new tests drive the missing-result path through a real git checkout and a gh fixture binary.
  • Invariant: a verdict comes only from a structured verifier result for the same repository, PR, stage, attempt and head SHA; recovered evidence may only advance to verification.
  • Related work (basic search): refactor(F0): classify dispatch failures by real cause and record whether the attempt started #172 / refactor(runtime): classify dispatch failures and track start evidence #195 (dispatch-failure classification, prerequisite, merged). No duplicates.
  • Fix shape: one recovery branch inside advance() plus one append-only table; no new stage flag.
  • Decision: implement (feature_request).

Work units

Unit Behaviour Files Tests Verification Rollback
WU-1 Schema-16 append-only recovery references; failed attempt preserved scripts/telemetry.py, docs/telemetry.md, tests/test_work_item_outcomes.py test_work_item_outcomes (schema 16) full suite below dependent on revert of WU-2 (WU-2 writes the table)
WU-2 Schema-2 receipt contract, attempt-id prompt injection, GitHub evidence reader, recovery transitions and verification gate, docs/skills scripts/review_contract.py, scripts/executors.py, scripts/run_cycle.py, skills/cc-{implement-issue,initial-review,resolve-comments,rereview}/SKILL.md, docs/review-cycle.md, CHANGELOG.md, tests/test_stage_recovery.py tests/test_stage_recovery.py (15 tests, 11 subtests): implement→review, comment-only resolve→rereview, reopened claim→second resolve + survivals, review/rereview redispatch once, unstructured verifier cannot approve, SHA/attempt/repo/PR/stage/BLOCKED rejections, untrusted & tokenless evidence, duplicate receipts, wrong verifier head/missing claim, remote head change, schema-15 upgrade, gh non-zero exit, parser full suite below independent

Verification (agent-reported)

  • python3 -m pytest tests/test_stage_recovery.py -q → exit 0, 15 passed, 11 subtests passed
  • python3 scripts/validate-package.py → exit 0, VALID: 15 skills … shared sections in sync
  • python3 -m unittest discover -s tests → exit 0, Ran 1175 tests … OK

Environment: the recovery tests set their own Git identity and put a fixture gh first on PATH; they share no global Git config or credentials with this machine. The gh fixture is a shebang script, so StageRecoveryTests is skipped on Windows (the parser test still runs there). Local run was Linux/WSL only; Windows is covered only by CI.

Notes

Record recovered_pending_verification separately from the dispatch attempt,
which keeps its failed outcome. Rows hold references only and reject updates
and deletions.

Refs #174
…ation

A stage that omitted its structured result may advance to verification when
exactly one trusted, attempt-attributed schema-2 receipt matches the repository,
PR, stage, attempt and head SHA and does not contradict a BLOCKED or FAILED
result. Recovered implement and resolve stages advance to review or rereview,
which must confirm every claimed finding at the recovered head; a recovered
review is re-dispatched once for a structured verdict. Recovery never infers
APPROVED or READY_FOR_MANUAL_MERGE.

Refs #174
@datacas

datacas commented Oct 7, 2026

Copy link
Copy Markdown
Owner Author

Checks on head a5ceaa92b15af357d437adc48601a105ee7615bd (push and pull_request runs): Skills, manifests, and Bash installer: pass ×2; PowerShell installer: pass ×2. No check failed or pending.

@datacas

datacas commented Oct 7, 2026

Copy link
Copy Markdown
Owner Author

[CCR-20261007-001] · reviewer · anthropic/claude-sonnet-5-5→? · high · schema:1

Initial review: PR #200 (work item #174)

Status: APPROVED at head a5ceaa92b15af357d437adc48601a105ee7615bd. There are no blocking findings, and three low findings that do not block.

Scope reviewed

The complete accumulated diff (982 lines, SHA-256 eb1c4aea…e616dc, merge base c7ac710) was read in sections. It covers 13 files: scripts/{executors,review_contract,run_cycle,telemetry}.py, the four stage SKILL.md files, docs/{review-cycle,telemetry}.md, CHANGELOG.md, and two test files. The diff file's head matches the PR head.

Project conventions applied: AGENTS.md (Serena and Context7 are optional; neither was needed because the change is project code plus the gh CLI) and .code-cycle.yml (review.trusted_authors: [datacas]).

The change matches the stated invariant. A recovered stage only advances to verification. The verdict comes from a structured verifier result bound to the same repository, PR, stage, attempt, and head. The reviewer traced these paths:

  • advance() recovery for implement, resolve, review, and rereview.
  • The post-verification re-read of the evidence.
  • The claim and verified-ID subset check.
  • Rejection of a second missing result.
  • Append-only stage_recoveries with its triggers.
  • The schema-15 upgrade.

Findings

[REV-001] · low · open · - · blocks:no — The injected prompt never states the stage token the receipt must carry

scripts/executors.py:2174, scripts/run_cycle.py:1450-1460

The runtime appends "…with schema: 2, repo, change_request_id, stage, attempt_id…" but never says which stage value to write. compose() only names the skill (Run cc-initial-review …), while recovery_evidence requires stage == role (review, resolve, and so on) and raises on any mismatch. An agent that writes initial-review or cc-initial-review produces a receipt that stops the cycle ("evidence scope does not match") instead of being ignored. The result is no worse than the old stop, so it does not block, but it defeats the feature for a likely mistake. Suggested fix: append stage: <role> literally to the injected text.

[REV-002] · low · open · - · blocks:no — Run-line examples still show schema:1 after SCHEMA_VERSION became 2

scripts/review_contract.py:14-15, docs/instrumentation.md:29-32

The PR updates the examples in docs/review-cycle.md and the four skills. The module docstring and docs/instrumentation.md still publish schema:1 as the current format, so the documentation disagrees with SCHEMA_VERSION = 2. Both formats parse, so this is documentation drift only.

[REV-003] · low · open · - · blocks:no — A rejected recovery replaces the original missing-result reason in the stop message

scripts/run_cycle.py:1795-1799

Before this change a missing result stopped with reported.explain(role) ("the review reported no structured result"). Now any missing-result stop on GitHub reads <role> recovery rejected: <reason>, for example "recovery requires exactly one attributable comment receipt". The stop reason stays stage_not_completed, but the operator no longer sees that the root cause was the missing structured result. No test asserts the stop message. Suggested fix: keep both facts, for example "…reported no structured result; recovery rejected: …".

Security triage

  • Rule half: no security_review.always_when rule is declared in .code-cycle.yml, so the toolkit defaults were used. The defaults list authentication, authorization, user input, environment configuration, and security tooling. None of those paths or labels match, and the PR has no labels.
  • Reviewer half (fired): the change adds a trust decision (an author allow-list that gates recovery of a verdict path), parses untrusted comment text, runs gh and git subprocesses, and writes to the telemetry store. The security audit therefore ran.
  • Degraded: the audit was done inline against cc-security-review's criteria and was not delegated to that skill.
  • Result: no vulnerabilities found. Details:
    • Only trusted_authors comments are folded. An empty list rejects recovery.
    • Subprocess calls use argument lists with no shell. The PR number is checked against the provider's number before reuse.
    • Receipt text is validated (full SHA, ID patterns, closed status vocabulary).
    • Telemetry stores references only (PR ID, SHA, comment ID).
    • Evidence is re-read after verification, so a head change or a second receipt stops the cycle.
    • Recovery can only advance to verification and never approves.

Commands run and observed results

All were executed locally on the PR head.

Command Result
python3 -m pytest tests/test_stage_recovery.py -q exit 0, 15 passed, 11 subtests passed
python3 -m unittest discover -s tests exit 0, Ran 1175 tests … OK
python3 scripts/validate-package.py exit 0, VALID: 15 skills … shared sections in sync
gh api --help (flag check) --paginate --slurp is supported (gh 2.92.0)

Unverified

  • Windows: StageRecoveryTests is skipped there because the gh fixture is a shebang script (only the parser test runs). Windows is covered only by the PowerShell installer CI job, not by these tests.
  • Real GitHub end-to-end recovery was not run. The tests drive a gh fixture binary, so live API pagination and author metadata are unverified.
  • The prompt-injection text was read but not exercised against a real executor (see REV-001).

CI (head a5ceaa9)

gh pr checks 200 shows 4 passed and 0 failed or pending: Skills, manifests, and Bash installer ×2 and PowerShell installer ×2 (push and pull_request). .github/workflows/validate.yml defines these jobs and release.yml is not a PR gate. No expected check is missing.

Residual risks

  • A recovered stage is trusted only as far as the same-login receipt, because trusted_authors is the operator's own account. The verification gate is the real control, and it is exercised by tests.
  • Historical comments without an attempt_id are intentionally not recovered, as the PR states.

Verdict

APPROVED. blocking_findings: []. The three low findings can be addressed here or in a follow-up. No merge was performed.

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.

refactor(F0): recover a missing structured result as pending verification

1 participant