# Failure-resolution v2 — implementation plan

Audience: AI coding agents first.
Spec (authoritative): `docs/specs/2026-07-19-failure-resolution-v2-design.md` — read FIRST; this file only orders the work.
Workspace: `/home/user/Projects/mega-plan-harness/.worktrees/failres-quickwins` (branch `feat/failres-quickwins`). Commit per task, terse imperative message, no co-author trailer. Do NOT push, do NOT merge to main.

Order (dependencies):
1. T1 constrained fixer retry — `src/engine/gates.js` + tests
2. T2 decision-driven scope widening — `src/engine/repair.js`, `src/engine/gates.js`, wiring in `src/runner.js` + tests (consumes T1's SCOPE-REQUEST)
3. T3 gate env parity prompt — `src/runner.js` `buildTaskPrompt`, threading from `src/engine/gates.js` + tests
4. T4 wrapper-engine-down rung-1 repair — `src/fail-taxonomy.js`, `src/engine/repair.js` + tests
5. T5 lessons writer — new `src/lessons.js`, hook in `src/engine/repair.js` + tests
6. T6 outcome labeling — `src/engine/ship.js` + `src/lessons.js` + tests (needs T5)
7. T7 retrieval — `src/resolver.js`, `src/runner.js` + tests (needs T5/T6)

Done criteria, every task: spec section satisfied; new tests + full `node --test src/test/*.test.js` green (isolated rerun allowed for the known-flaky `runplan-pause` e2e only); no edits outside listed files + tests; invariants in spec § Invariants hold.

Final report: per task — what changed, test evidence, deviations from spec (if any, with reason); note EMBEDDED_*_SOURCE drift.
