Recovery
When a phase misses its contract, Yokai does not stop at once. It repairs bookkeeping, or asks a read-only turn to diagnose the miss and pick the next action. Every path ends with the same contract check.
What recovery is for
Many phase misses are small. The agent forgot to commit a file. A build folder ended up in the tree. The sensors passed but the card was never marked done. Halting the run for these wastes a night of unattended work. Recovery handles them and still refuses to declare anything done on its own.
Recovery is on by default:
# .koi/yokai.yml
recovery: true # false halts immediately on a miss
The cycle
- A miss happens: a contract check fails, Build does not converge, or a phase stalls (no progress in two runs in a row; the first miss is a plain retry).
- If the gate is green and only bookkeeping is unfinished, Yokai runs one Repair turn.
- Otherwise, or if Repair did not resolve it, a Diagnose turn reads the failure and names the next action:
fix,repairorgrant_build. - The supervisor re-checks the contract. If the phase is still not done, the cycle continues.
The three turns
| Turn | Can edit | Does |
|---|---|---|
| Repair | Commits, .gitignore, the card status |
Commits a deliverable left behind, ignores regenerable noise (node_modules/, dist/, caches) with git rm --cached, or marks the card done when the gate is green and the commit already exists. Never touches product code, never amends. |
| Diagnose | Nothing, it is read-only | Reads FEEDBACK.md, earlier saves and the miss, then returns one line of JSON: {"next": "fix", "diagnosis": "...", "guide": null}. It cannot halt. If its answer cannot be parsed, Yokai grants another Build. |
| Fix | Files under .koi/, the board and notes, .gitignore |
Repairs the run itself: a wrong sensor path, a broken phase file, a missing ignore rule. Never product source. Product code changes belong to Build. |
A granted Build skips Plan and runs a full Build budget, steered by the guide Diagnose wrote. In the cockpit it looks like any other Build.
The turns use their own model tiers. Diagnose (role triage), Repair and Fix default to the ultra band. You can lower them with roles.triage.tier, roles.repair.tier or roles.fix.tier.
Reopening a done card
If the gate is red after Seal, the supervisor reopens only that card as todo and restores nextAction to /junji next in the same write. The next run re-enters the phase.
Remember that Seal already replaced the card's description with the outcome. A reopened card does not get its original scope back. The scope is still in .koi/run/phases/phase-NN-*.md, which Plan reuses because the file exists.
Records
Each recovery episode is a save: a Markdown file in .koi/run/saves/ (0001.md, 0002.md, ...) with what failed, the diagnosis, what was tried and the outcome. .koi/run/RECOVERY.md indexes them. Saves are records, not snapshots. "Going back" means re-entering the run from the current files, not restoring an old tree.
There is no limit on cycles or saves. What stops recovery:
--max-costor--max-tokens, if you set them.- You pressing
xto abort. --guarded.
Example
P3 seals and the contract check finds dist/ uncommitted. The gate is green, so Yokai runs Repair. The agent adds dist/ to .gitignore, makes a new commit and reports {"decision": "ignored dist/ build output", "why": "regenerated by npm run build", "pointer": "a1b2c3d"}. The contract passes on the next check and P3 is done. .koi/run/saves/0001.md records the episode.
What can go wrong
- Diagnose keeps granting Build and the sensors stay red. Read
.koi/run/saves/andFEEDBACK.md. The phase plan may be wrong, or the check may expose a real design gap. Stop the run, fix the plan, and relaunch. Set--max-costfor unattended nights. - Repair leaves a path dirty. It refuses to guess about files that look like product source. Diagnose takes over; if it is still unclear, commit or delete the file yourself.
- You want the old fail-fast behaviour. Set
recovery: false. Any contract or Build miss then halts at once.