# Feature: Review rework limit

**Pattern**: Phase 3 sends accepted blocking findings back to Phase 2 for rework. How many times it may do that before the run stops is one number, resolved in one place, so the phase docs, the escalation script and the circuit-breaker cannot disagree about it.

The range is 1 to 3 and the default is <!-- fact:reworkDefault -->2<!-- /fact -->. The ceiling, <!-- fact:reworkCap -->3<!-- /fact -->, is the schema cap on `phases["2"].reworkCount`.

## Contract

With limit N, review sends work back to development N times, every rework is reviewed again, and the run stops when a review still has accepted findings after N reworks: N reworks, at most N + 1 reviews. `state.phases["2"].reworkCount` counts the reworks; `retryCount` counts build and component-dispatch retries and is a separate counter. `retryCount` is cumulative across the run (nothing resets it between Phase 2 entries) with its own cap of 3, so build retries can stop a run independently of the review limit. A state file without `reworkCount` counts from zero.

`next` is idempotent per review iteration: it records `phases["2"].reworkForIteration` (the length of `reviewIterations`) in the same write that increments `reworkCount`, and asked again for that iteration it answers `rework` without recording. A resumed run whose `reworkForIteration` equals the number of `reviewIterations` re-enters the rework instead of deciding again.

## Resolution

`node $HOME/.claude/scripts/review-rounds.mjs get [--state "$STATE_FILE"] [--json | --value]`. First valid value wins:

| Source | Where it lives | Set by |
|---|---|---|
| `flag` | `state.reviewRounds` | `--review-rounds N` on `/multi-agent`, stored by Phase 0 (`review-rounds.mjs record`) |
| `repo` | `prefs.projects.<project>.maxReworkCycles` | `/multi-agent:review-rounds N --repo` |
| `global` | `prefs.global.review.maxReworkCycles` | `/multi-agent:review-rounds N` |
| `default` | the schema default | nothing set |

`<project>` is the main repository's folder name as is, the value of `state.project`; the command and the run use the same key. A stored value outside 1 to 3, or not an integer, is ignored and listed under `ignored[]`; it is never clamped. In an autopilot run (`state.autopilot`, or `MULTI_AGENT_UNATTENDED=1`) with the circuit-breaker enabled, `prefs.global.autopilotCircuitBreaker.maxReworkCycles` lowers the result and the source reads `breaker`; it never raises it. `--json` also reports `configured` (before that bound) and `breakerCap`.

## Where a run reads it

| Step | Reads |
|---|---|
| Phase 0, right after `agent-state.json` is created, when the input carried `--review-rounds N` | writes `state.reviewRounds` |
| Phase 3 Step 4, accepted blocking or important findings | `review-rounds.mjs next --state "$STATE_FILE"`: `rework` (after recording `reworkCount + 1`) or `rule` (`reworkCount >= limit`; the comparison is `shouldRule` in the script) |
| `rule` | `rework-rulings.mjs` on the current triage; `escalate` stops the run and records autopilot trigger 3 |
| Phase 2 re-entry | reads neither the limit nor the count |
| Rework dispatch | `rework-escalation.mjs`, whose last round is the limit and whose round is `reworkCount` |

Attended and autopilot runs take the same path. At the limit every open finding is ruled on (`escalate` or `parked`): a blocking or security finding stops the run for the user, and the rest continue to Phase 4 as follow-ups.

## Changing it

`/multi-agent:review-rounds` with no argument shows the value and its source and asks. `status` prints, `1`, `2` or `3` sets it globally, `--repo` scopes it to the current repository, `reset` removes the override. Setting needs an explicit argument in an unattended run, which never opens a picker.
