Skip to content

Detect findings that survive a claimed fix and stop the loop before the iteration budget is spent #83

Closed

Description

@datacas

Problem

The resolve → rereview loop can't tell "not converging yet" from "the same finding keeps coming back". The only guards are:

  • the iteration limit: run_cycle.run_cycle (max_iterations, default 3, scripts/run_cycle.py:611) and the orchestrator skills (default 6);
  • the skills' no-progress guard, which fires only when the same head SHA and the same open finding set repeat (cc-orchestrator step 10; cc-orca-orchestrator No-progress guard). The runtime has no equivalent.

A resolver that pushes a commit which doesn't fix the finding changes the head, so the no-progress guard never fires and the budget is spent on the same finding.

This happened on PR #74. Folding its trusted comment history with review_contract.parse_comment gives:

REV-001  open@CCR-001 → resolved@CCT-002 → open@CCR-003 → not_applicable@CCT-003 → open@CCR-004 → not_applicable@CCT-004

The resolver claimed a resolution twice (once as a fix, once as not applicable), and the next rereview reopened it each time. No guard fired.

Current behavior

  • Stable IDs already give identity: REV-xxx is never renumbered or reused (review_contract.next_finding_id, collision checks in recover_comment_history).
  • recover_comment_history folds history into the latest state and drops the transitions needed to see a reopen.
  • CycleRecorder.failed_attempts / previous_failed_attempts count failed dispatches, not failed fixes. This issue must not overload that field.

Existing architecture involved

  • scripts/review_contract.py: parse_comment, recover_comment_history, Finding
  • scripts/run_cycle.py: the resolve/rereview loop, advance, stop
  • scripts/cycle.py: CycleRecorder._pre_routing, close
  • Result shapes: resolve finding_outcomes, rereview verified_findings (both readable after run_cycle: read finding counts from each review skill's documented result shape #81)
  • skills/cc-orchestrator, skills/cc-orca-orchestrator: per-iteration head SHA and open IDs, which they already record
  • skills/cc-resolve-comments: Triage

Proposed behavior

  1. One definition, pure, in review_contract.py.

    A finding survives a claimed fix exactly when all three hold:

    • (a) same ID: the same REV-xxx ID, which the contract already makes stable identity;
    • (b) claim: a resolution run (a CCT-… triage run, or a resolve structured result) publishes that ID with status resolved or not_applicable;
    • (c) rejection: the next review run after that resolution run (the first later CCR-…, or the next rereview result) publishes the same ID with status open (structured: still_open or open).

    Each (claim, next review) pair counts at most once.

    The claim is the status the resolver published, not the disposition. Dispositions (valid, incorrect, …) are frozen at triage and say whether the finding was right, not whether it was fixed. A resolver that marks a finding incorrect and publishes it not_applicable has made a claim. A resolver that marks it valid but leaves it open has made none.

    Within one comment or result, the last header for an ID is the run's position. The Allow Claude in read-only roles via isolated worktrees #74 triage comments republish REV-001 as open and then as resolved in the same run, and only resolved counts.

    These are not survivals and must not be counted:

    Sequence Name Why not
    open@CCR → open@CCT → open@CCR persisting the resolver never claimed it. The existing no-progress guard and the iteration limit cover it
    resolved@CCT → resolved@CCR confirmed fix —
    resolved@CCT → not_applicable@CCR scope removed the reviewer agreed it no longer applies
    resolved@CCR → … → open@CCR with no claim in between regression a different phenomenon. It is reported as a regression, not counted here
    a claim followed by a rereview that couldn't run or returned no readable result unknown no rejection was observed, so nothing is counted

    Worked example, PR Allow Claude in read-only roles via isolated worktrees #74 REV-001:

    CCR-001 open        (new)
    CCT-001 open        no claim
    CCR-002 open        persisting — not a survival
    CCT-002 resolved    claim #1
    CCR-003 open        rejection → survival 1
    CCT-003 not_applicable  claim #2
    CCR-004 open        rejection → survival 2
    

    Result: {"REV-001": 2}.

    The function takes an ordered sequence of records and returns survival counts per ID. It works on parsed comments (skills, analysis) and on findings mapped from structured results (runtime). recover_comment_history is unchanged.

  2. Runtime. run_cycle tracks survivals from the in-cycle structured results through that function.

  3. Escalation ladder (named constants, not configuration):

    • 1st survival of an ID: the next resolve prompt names those IDs and requires the agent to:
    • 2nd survival of the same ID: stop with HUMAN_INTERVENTION before dispatching another resolve. The stop reason names the IDs.
    • No automatic model/profile/provider change. The router escalates only on declared signals (docs/routing.md). Escalating on repeats is a routing decision for later, informed by the signal below.

    Why 2. One survival can be an honestly incomplete fix. Two survivals of one ID across different heads is the Allow Claude in read-only roles via isolated worktrees #74 pattern, and it is exactly what neither existing guard catches. With the runtime's default of 3 iterations, the ladder only bites when the budget would otherwise be spent on one finding.

  4. Runtime parity. run_cycle also applies the skills' existing no-progress guard: same head_sha and same open set → HUMAN_INTERVENTION.

  5. Orchestrator skills. Both orchestrators apply the same ladder from the IDs they already record per iteration.

  6. Dispositions stay frozen. A survival is status history, never a disposition change.

Scope

review_contract.py (one function), run_cycle.py loop, cycle.py signal and close fields, the two orchestrator skills, one paragraph in cc-resolve-comments, and docs (review-cycle.md Exit conditions, telemetry.md).

Non-goals

  • No switching models or profiles.
  • No semantic matching of findings reported under different IDs. The ID is the identity, and reviewers must already reuse IDs.
  • No change to dispositions or to the comment contract.
  • No change to max_iterations defaults. The runtime/skill mismatch (3 vs 6) is noted, not changed here.

Design constraints

Acceptance criteria

  • The pure function returns {"REV-001": 2} for the Allow Claude in read-only roles via isolated worktrees #74 history (fixture built from headers only, no prose).
  • Every row of the "not survivals" table has a unit test that returns 0 for that ID. That covers persisting, confirmed fix, scope removed, regression, and unknown.
  • A resolver that leaves a finding open with disposition valid is not a claim. A resolver that publishes not_applicable with disposition incorrect is.
  • Multiple headers for one ID in one run: only the last one counts.
  • Scripted cycle: a finding reported resolved by resolve and still_open by the next rereview:
    • after the first survival, the next resolve prompt contains the ID and the directive;
    • after the second, the cycle stops with HUMAN_INTERVENTION and no third resolve is dispatched.
  • Scripted cycle with the same head and the same open set stops as no-progress.
  • A finding that is reopened once and then approved completes normally.

Tests / verification

Unit tests for the function (legacy headers and - dispositions included), tests/test_run_cycle.py scripted cycles, and a validate-package.py check that both orchestrators state the ladder.

Dependencies

Telemetry / schema impact

Bump SCHEMA_VERSION (next free); payload-only and additive.

  • repeated_findings (count): IDs that survived at least one claimed fix before this routing. An observed pre-routing signal on resolve/rereview rows, added to PRE_ROUTING_SIGNALS["observed"] and FIELD_LIMITS.
  • stop_reason (token) on the cycle row: approved, iteration_limit, no_progress, repeated_findings, stage_not_completed, dispatch_failed, local_only.
  • cc-stats shows stop reasons and cycles with repeated findings. Older rows read as unknown.

Backwards compatibility

No result or comment shape changes. Cycles that converge behave exactly as today.

Suggested implementation areas

scripts/review_contract.py, scripts/run_cycle.py, scripts/cycle.py, scripts/telemetry.py, scripts/stats.py, skills/cc-orchestrator/SKILL.md, skills/cc-orca-orchestrator/SKILL.md, skills/cc-resolve-comments/SKILL.md, docs/review-cycle.md, docs/telemetry.md, docs/instrumentation.md.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions