# Feature: Rework model escalation (Phase 2 re-entry, Phase 3 Step 4)

**Pattern**: a rework round that dispatches the same model with the same findings tends to produce the same fix. Two signals say the current rung is not enough: the round is the **last** one the rework cap allows, or `review-delta.mjs` reported findings **still present** after the previous round's fix. On either, the fresh dev agent for the next round runs one rung up the model-fallback ladder (`fable -> opus -> sonnet -> haiku`, `features/model-fallback.md`), and only one. The decision is a pure function in `scripts/rework-escalation.mjs`, never a model's judgement.

## Prefs

`prefs.global.reworkEscalation`:

| Field | Default | Meaning |
|---|---|---|
| `reworkEscalation.enabled` | `true` | Master switch. `false` keeps every rework round on the rung the dev dispatch resolved to. |
| `reworkEscalation.maxTier` | `opus` | Highest rung an escalation may reach. `fable` additionally needs `modelFallback.fableEnabled: true`. |

On by default because it fires at most on the rounds where a failure costs the most (the last one, or one that repeats the previous attempt), moves one rung, and stops at `opus`. Every existing cost control outranks it.

## The call (before each rework dispatch)

```bash
node $HOME/.claude/scripts/cost-budget-check.mjs --task-id "$TASK_ID" --prefs "$PREFS_FILE" >/dev/null; BUDGET_RC=$?
STILL=$(jq '.reviewIterations[-1].delta.counts.stillPresent // 0' "$STATE_FILE")
REWORK_ROUND=$(jq '.phases["2"].reworkCount // 1' "$STATE_FILE")
ESC=$(node $HOME/.claude/scripts/rework-escalation.mjs --iteration "$REWORK_ROUND" \
  --still-present "$STILL" --current-tier "$DEV_TIER" --budget-exit "$BUDGET_RC" \
  --prefs "$PREFS_FILE" --state "$STATE_FILE" ${FELL_BACK:+--fallen-back})
```

The script resolves the review limit itself (1 to 3, default 2, the repo setting and the autopilot bound included), so the call passes no `--max-iterations`. `REWORK_ROUND` is the rework round about to run, 1-based: `state.phases["2"].reworkCount`, which Phase 3 Step 4 recorded before this dispatch (`retryCount` counts build retries and is not read here); `DEV_TIER` is the rung the Phase 2 dev dispatch resolves to without this override (persona and routing, `skills/shared/core/multi-agent/SKILL.md`), so escalations never compound; `FELL_BACK` is set when this run emitted a `model_fallback` metric. Pass `BUDGET_RC` on every call: without `--budget-exit` the budget counts as disabled only when `costBudget.enabled` is not `true`, otherwise the rung holds with `budget-unchecked`. Prefs come from `--prefs`, then `$MULTI_AGENT_PREFS`, then `~/.claude/multi-agent-preferences.json`. `--state` records the result as `reviewIterations[-1].reworkEscalation`, including a refusal and its reason, and in an autopilot run lists an escalation in `decisions[]` (`features/autopilot-decisions.md`). Exit 2 or 3: log `rework.escalation_skipped`, dispatch on `DEV_TIER`; it never blocks the rework.

| `reason` | Meaning |
|---|---|
| `escalated` | Dispatch on `toTier` |
| `not-triggered` | Neither the last round nor a still-present finding |
| `disabled` / `past-cap` | Switch off, or the cap has already stopped Phase 2 |
| `run-fell-back` | The run degraded; it is never re-upgraded mid-run |
| `budget-warn` / `budget-exceeded` / `budget-unknown` | `cost-budget-check.mjs` exit 10 / 11 / other |
| `budget-unchecked` | No `--budget-exit` while `prefs.global.costBudget.enabled` is `true`: an unrun check is no evidence the budget has room |
| `unknown-tier` / `top-of-ladder` | Not an Anthropic rung, or nothing above it |
| `fable-off` / `at-ceiling` | The next rung is fable with the rung off, or above `maxTier` |

Telemetry: `log-metric.sh "$TASK_ID" 2 rework.escalation escalate= from= to= reason=`.

## The escalated dispatch

`escalate: true` -> `PHASE_MODEL_OVERRIDE=<toTier>` for that one dev dispatch (the override outranks routing, so the fable and ceiling checks above are the only ones that apply). The agent is **fresh**: no forked history, no conversation. It gets files:

- `$WORKTREE/.pipeline/triage-round-$REWORK_ROUND.json`: the persisted findings of the review that sent this round back (accepted, with fingerprints)
- `$WORKTREE/.pipeline/rework-attempt-$((REWORK_ROUND-1)).diff`: the prior attempt's change, written by the orchestrator before the dispatch as `git diff <round start>..HEAD` (round 0 starts at the run's base), so the escalated agent sees what was tried without the conversation that tried it
- `delta.stillPresent[]` quoted first, as Phase 2 re-entry item 7 already requires

An escalation is per dispatch: the next round asks again from `DEV_TIER`, so the rework never sits more than one rung above the dev dispatch.
