Recovery Skill
When to Use
- Context window exhausted mid-workflow
- Session interrupted or lost
- Need to resume from last completed step
- Workflow state needs reconstruction
Step 1: Identify Last Completed Step
Check gate files for last successful validation:
- Location:
.claude/context/history/gates/{workflow_id}/
- Find highest step number with validation_status: "pass"
- This is the last successfully completed step
Review reasoning files for progress:
- Location:
.claude/context/history/reasoning/{workflow_id}/
- Read reasoning files up to last completed step
- Extract context and decisions made
Identify artifacts created:
- Check artifact registry:
.claude/context/artifacts/registry-{workflow_id}.json
- List all artifacts created up to last step
- Verify artifact files exist
Step 2: Load Plan Documents
Read plan document (stateless):
- Load
plan-{workflow_id}.json from artifact registry
- Extract current workflow state
- Identify completed vs pending tasks
Load relevant phase plan (if multi-phase):
- Check if project is multi-phase (exceeds phase_size_max_lines threshold)
- Load active phase plan:
plan-{workflow_id}-phase-{n}.json
- Understand phase boundaries and dependencies
Understand current state:
- Map completed tasks to plan
- Identify next steps
- Check for dependencies
Step 3: Context Recovery
Load artifacts from last completed step:
- Read artifact registry
- Load all artifacts with validation_status: "pass"
- Verify artifact integrity
Read reasoning files for context:
- Load reasoning files from completed steps
- Extract key decisions and context
- Understand workflow progression
Reconstruct workflow state:
- Combine plan, artifacts, and reasoning
- Create recovery state document
- Validate state consistency
Step 4: Resume Execution
Continue from next step:
- Identify next step after last completed
- Load step requirements from plan
- Prepare inputs for next step
Planner updates plan status (stateless):
- Update plan-{workflow_id}.json with current status
- Mark completed steps
- Update progress tracking
Orchestrator coordinates next agents:
- Pass recovered artifacts to next step
- Resume workflow execution
- Monitor for additional interruptions
Failure Classification
When a task fails, classify the failure type:
| Failure Type |
Indicators |
Recovery Action |
| BROKEN_BUILD |
Build errors, syntax errors, module not found |
ROLLBACK + fix |
| VERIFICATION_FAILED |
Test failures, validation errors, assertion errors |
RETRY with fix (max 3 attempts) |
| CIRCULAR_FIX |
Same error 3+ times, similar approaches repeated |
SKIP or ESCALATE |
| CONTEXT_EXHAUSTED |
Token limit reached, maximum length exceeded |
Compress context, continue |
| UNKNOWN |
No pattern match |
RETRY once, then ESCALATE |
Circular Fix Detection
Iron Law: If the same approach has been tried 3+ times without success, STOP.
When circular fix is detected:
- Stop the current approach immediately
- Document what was tried (approaches, errors, files)
- Try fundamentally different approach (different library, different pattern, simpler implementation)
- If still failing, ESCALATE to human intervention
Detection Algorithm:
- Extract keywords from current approach (excluding stop words)
- Compare with keywords from last 3 attempts
- If Jaccard similarity > 30% for 2+ attempts, flag as circular
Example:
Attempt 1: "Using async await for fetch"
Attempt 2: "Using async/await with try-catch"
Attempt 3: "Trying async await pattern again"
=> CIRCULAR FIX DETECTED - Stop and try callback pattern instead
Attempt Count Thresholds
| Failure Type |
Max Attempts |
Then Action |
| VERIFICATION_FAILED |
3 |
SKIP + ESCALATE |
| UNKNOWN |
2 |
ESCALATE |
| BROKEN_BUILD |
1 |
ROLLBACK (if good commit exists) |
| CIRCULAR_FIX |
0 |
Immediately SKIP |
References
See references/ for detailed patterns:
failure-types.md - Failure classification details and indicators
recovery-actions.md - Recovery action decision tree and execution
merge-strategies.md - File merge strategies for multi-agent scenarios
Recovery Validation Checklist
Error Handling
- Missing plan document: Request planner to recreate plan from requirements
- Missing artifacts: Request artifact recreation from source agent
- Corrupted artifacts: Request artifact recreation with validation
- Incomplete reasoning: Use artifact registry and gate files to reconstruct state
# 1. Check gate files for last completed step
ls .claude/context/history/gates/{workflow_id}/
# 2. Load plan document
cat .claude/context/artifacts/plan-{workflow_id}.json
# 3. Review reasoning files
cat .claude/context/history/reasoning/{workflow_id}/*.json
# 4. Resume from next step
"Resume the workflow from where we left off"
"Recover the workflow state and continue"
"What was the last completed step?"
Related
- Planner Agent:
.claude/agents/core/planner.md
- Memory files:
.claude/context/memory/
Memory Protocol (MANDATORY)
Before starting:
cat .claude/context/memory/learnings.md
After completing:
- New pattern ->
.claude/context/memory/learnings.md
- Issue found ->
.claude/context/memory/issues.md
- Decision made ->
.claude/context/memory/decisions.md
ASSUME INTERRUPTION: Your context may reset. If it's not in memory, it didn't happen.
1---2name: recovery3description: Workflow recovery protocol for resuming workflows after context loss, session interruption, or errors. Handles state reconstruction, artifact recovery, and seamless workflow continuation.4---56# Recovery Skill78<identity>9Recovery Skill - Workflow recovery protocol for resuming workflows after context loss, session interruption, or errors. Handles state reconstruction, artifact recovery, and seamless workflow continuation.10</identity>1112<capabilities>13- Resuming workflows after context window exhaustion14- Recovering from session interruptions15- Reconstructing workflow state from artifacts and gate files16- Identifying and continuing from last completed step17- Preventing duplicate work during recovery18</capabilities>1920<instructions>21<execution_process>2223## When to Use2425- Context window exhausted mid-workflow26- Session interrupted or lost27- Need to resume from last completed step28- Workflow state needs reconstruction2930## Step 1: Identify Last Completed Step31321. **Check gate files** for last successful validation:33 - Location: `.claude/context/history/gates/{workflow_id}/`34 - Find highest step number with validation_status: "pass"35 - This is the last successfully completed step36372. **Review reasoning files** for progress:38 - Location: `.claude/context/history/reasoning/{workflow_id}/`39 - Read reasoning files up to last completed step40 - Extract context and decisions made41423. **Identify artifacts created**:43 - Check artifact registry: `.claude/context/artifacts/registry-{workflow_id}.json`44 - List all artifacts created up to last step45 - Verify artifact files exist4647## Step 2: Load Plan Documents48491. **Read plan document** (stateless):50 - Load `plan-{workflow_id}.json` from artifact registry51 - Extract current workflow state52 - Identify completed vs pending tasks53542. **Load relevant phase plan** (if multi-phase):55 - Check if project is multi-phase (exceeds phase_size_max_lines threshold)56 - Load active phase plan: `plan-{workflow_id}-phase-{n}.json`57 - Understand phase boundaries and dependencies58593. **Understand current state**:60 - Map completed tasks to plan61 - Identify next steps62 - Check for dependencies6364## Step 3: Context Recovery65661. **Load artifacts from last completed step**:67 - Read artifact registry68 - Load all artifacts with validation_status: "pass"69 - Verify artifact integrity70712. **Read reasoning files for context**:72 - Load reasoning files from completed steps73 - Extract key decisions and context74 - Understand workflow progression75763. **Reconstruct workflow state**:77 - Combine plan, artifacts, and reasoning78 - Create recovery state document79 - Validate state consistency8081## Step 4: Resume Execution82831. **Continue from next step**:84 - Identify next step after last completed85 - Load step requirements from plan86 - Prepare inputs for next step87882. **Planner updates plan status** (stateless):89 - Update plan-{workflow_id}.json with current status90 - Mark completed steps91 - Update progress tracking92933. **Orchestrator coordinates next agents**:94 - Pass recovered artifacts to next step95 - Resume workflow execution96 - Monitor for additional interruptions9798</execution_process>99100## Failure Classification101102When a task fails, classify the failure type:103104| Failure Type | Indicators | Recovery Action |105| ------------------- | -------------------------------------------------- | ------------------------------- |106| BROKEN_BUILD | Build errors, syntax errors, module not found | ROLLBACK + fix |107| VERIFICATION_FAILED | Test failures, validation errors, assertion errors | RETRY with fix (max 3 attempts) |108| CIRCULAR_FIX | Same error 3+ times, similar approaches repeated | SKIP or ESCALATE |109| CONTEXT_EXHAUSTED | Token limit reached, maximum length exceeded | Compress context, continue |110| UNKNOWN | No pattern match | RETRY once, then ESCALATE |111112## Circular Fix Detection113114**Iron Law**: If the same approach has been tried 3+ times without success, STOP.115116When circular fix is detected:1171181. **Stop** the current approach immediately1192. **Document** what was tried (approaches, errors, files)1203. **Try fundamentally different approach** (different library, different pattern, simpler implementation)1214. **If still failing, ESCALATE** to human intervention122123**Detection Algorithm**:124125- Extract keywords from current approach (excluding stop words)126- Compare with keywords from last 3 attempts127- If Jaccard similarity > 30% for 2+ attempts, flag as circular128129**Example**:130131```132Attempt 1: "Using async await for fetch"133Attempt 2: "Using async/await with try-catch"134Attempt 3: "Trying async await pattern again"135=> CIRCULAR FIX DETECTED - Stop and try callback pattern instead136```137138## Attempt Count Thresholds139140| Failure Type | Max Attempts | Then Action |141| ------------------- | ------------ | -------------------------------- |142| VERIFICATION_FAILED | 3 | SKIP + ESCALATE |143| UNKNOWN | 2 | ESCALATE |144| BROKEN_BUILD | 1 | ROLLBACK (if good commit exists) |145| CIRCULAR_FIX | 0 | Immediately SKIP |146147## References148149See `references/` for detailed patterns:150151- `failure-types.md` - Failure classification details and indicators152- `recovery-actions.md` - Recovery action decision tree and execution153- `merge-strategies.md` - File merge strategies for multi-agent scenarios154155<best_practices>156157## Recovery Validation Checklist158159- [ ] Last completed step identified correctly160- [ ] Plan document loaded and validated161- [ ] All artifacts from completed steps available162- [ ] Reasoning files reviewed for context163- [ ] Workflow state reconstructed accurately164- [ ] No duplicate work will be performed165- [ ] Next step inputs prepared166- [ ] Recovery logged in reasoning file167168</best_practices>169170<error_handling>171172## Error Handling173174- **Missing plan document**: Request planner to recreate plan from requirements175- **Missing artifacts**: Request artifact recreation from source agent176- **Corrupted artifacts**: Request artifact recreation with validation177- **Incomplete reasoning**: Use artifact registry and gate files to reconstruct state178179</error_handling>180</instructions>181182<examples>183<usage_example>184**Recovery after context loss**:185186```bash187# 1. Check gate files for last completed step188ls .claude/context/history/gates/{workflow_id}/189190# 2. Load plan document191cat .claude/context/artifacts/plan-{workflow_id}.json192193# 3. Review reasoning files194cat .claude/context/history/reasoning/{workflow_id}/*.json195196# 4. Resume from next step197```198199</usage_example>200201<usage_example>202**Natural language invocation**:203204```205"Resume the workflow from where we left off"206"Recover the workflow state and continue"207"What was the last completed step?"208```209210</usage_example>211</examples>212213## Related214215- Planner Agent: `.claude/agents/core/planner.md`216- Memory files: `.claude/context/memory/`217218## Memory Protocol (MANDATORY)219220**Before starting:**221222```bash223cat .claude/context/memory/learnings.md224```225226**After completing:**227228- New pattern -> `.claude/context/memory/learnings.md`229- Issue found -> `.claude/context/memory/issues.md`230- Decision made -> `.claude/context/memory/decisions.md`231232> ASSUME INTERRUPTION: Your context may reset. If it's not in memory, it didn't happen.