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.4version: 1.0.05model: sonnet6invoked_by: both7user_invocable: true8tools: [Read, Write, Edit, Bash, Glob, Grep]9error_handling: graceful10streaming: supported11verified: false12lastVerifiedAt: 2026-02-19T05:29:09.098Z13source: builtin14trust_score: 10015provenance_sha: 94594ed6c501d7f816metadata:17 source: https://skillmd.com/skills/oimiragieo/recovery18---1920# Recovery Skill2122<identity>23Recovery Skill - Workflow recovery protocol for resuming workflows after context loss, session interruption, or errors. Handles state reconstruction, artifact recovery, and seamless workflow continuation.24</identity>2526<capabilities>27- Resuming workflows after context window exhaustion28- Recovering from session interruptions29- Reconstructing workflow state from artifacts and gate files30- Identifying and continuing from last completed step31- Preventing duplicate work during recovery32</capabilities>3334<instructions>35<execution_process>3637## When to Use3839- Context window exhausted mid-workflow40- Session interrupted or lost41- Need to resume from last completed step42- Workflow state needs reconstruction4344## Step 1: Identify Last Completed Step45461. **Check gate files** for last successful validation:47 - Location: `.claude/context/history/gates/{workflow_id}/`48 - Find highest step number with validation_status: "pass"49 - This is the last successfully completed step50512. **Review reasoning files** for progress:52 - Location: `.claude/context/history/reasoning/{workflow_id}/`53 - Read reasoning files up to last completed step54 - Extract context and decisions made55563. **Identify artifacts created**:57 - Check artifact registry: `.claude/context/artifacts/registry-{workflow_id}.json`58 - List all artifacts created up to last step59 - Verify artifact files exist6061## Step 2: Load Plan Documents62631. **Read plan document** (stateless):64 - Load `plan-{workflow_id}.json` from artifact registry65 - Extract current workflow state66 - Identify completed vs pending tasks67682. **Load relevant phase plan** (if multi-phase):69 - Check if project is multi-phase (exceeds phase_size_max_lines threshold)70 - Load active phase plan: `plan-{workflow_id}-phase-{n}.json`71 - Understand phase boundaries and dependencies72733. **Understand current state**:74 - Map completed tasks to plan75 - Identify next steps76 - Check for dependencies7778## Step 3: Context Recovery79801. **Load artifacts from last completed step**:81 - Read artifact registry82 - Load all artifacts with validation_status: "pass"83 - Verify artifact integrity84852. **Read reasoning files for context**:86 - Load reasoning files from completed steps87 - Extract key decisions and context88 - Understand workflow progression89903. **Reconstruct workflow state**:91 - Combine plan, artifacts, and reasoning92 - Create recovery state document93 - Validate state consistency9495## Step 4: Resume Execution96971. **Continue from next step**:98 - Identify next step after last completed99 - Load step requirements from plan100 - Prepare inputs for next step1011022. **Planner updates plan status** (stateless):103 - Update plan-{workflow_id}.json with current status104 - Mark completed steps105 - Update progress tracking1061073. **Orchestrator coordinates next agents**:108 - Pass recovered artifacts to next step109 - Resume workflow execution110 - Monitor for additional interruptions111112</execution_process>113114## Failure Classification115116When a task fails, classify the failure type:117118| Failure Type | Indicators | Recovery Action |119| ------------------- | -------------------------------------------------- | ------------------------------- |120| BROKEN_BUILD | Build errors, syntax errors, module not found | ROLLBACK + fix |121| VERIFICATION_FAILED | Test failures, validation errors, assertion errors | RETRY with fix (max 3 attempts) |122| CIRCULAR_FIX | Same error 3+ times, similar approaches repeated | SKIP or ESCALATE |123| CONTEXT_EXHAUSTED | Token limit reached, maximum length exceeded | Compress context, continue |124| UNKNOWN | No pattern match | RETRY once, then ESCALATE |125126## Circular Fix Detection127128**Iron Law**: If the same approach has been tried 3+ times without success, STOP.129130When circular fix is detected:1311321. **Stop** the current approach immediately1332. **Document** what was tried (approaches, errors, files)1343. **Try fundamentally different approach** (different library, different pattern, simpler implementation)1354. **If still failing, ESCALATE** to human intervention136137**Detection Algorithm**:138139- Extract keywords from current approach (excluding stop words)140- Compare with keywords from last 3 attempts141- If Jaccard similarity > 30% for 2+ attempts, flag as circular142143**Example**:144145```146Attempt 1: "Using async await for fetch"147Attempt 2: "Using async/await with try-catch"148Attempt 3: "Trying async await pattern again"149=> CIRCULAR FIX DETECTED - Stop and try callback pattern instead150```151152## Attempt Count Thresholds153154| Failure Type | Max Attempts | Then Action |155| ------------------- | ------------ | -------------------------------- |156| VERIFICATION_FAILED | 3 | SKIP + ESCALATE |157| UNKNOWN | 2 | ESCALATE |158| BROKEN_BUILD | 1 | ROLLBACK (if good commit exists) |159| CIRCULAR_FIX | 0 | Immediately SKIP |160161## References162163See `references/` for detailed patterns:164165- `failure-types.md` - Failure classification details and indicators166- `recovery-actions.md` - Recovery action decision tree and execution167- `merge-strategies.md` - File merge strategies for multi-agent scenarios168169<best_practices>170171## Recovery Validation Checklist172173- [ ] Last completed step identified correctly174- [ ] Plan document loaded and validated175- [ ] All artifacts from completed steps available176- [ ] Reasoning files reviewed for context177- [ ] Workflow state reconstructed accurately178- [ ] No duplicate work will be performed179- [ ] Next step inputs prepared180- [ ] Recovery logged in reasoning file181182</best_practices>183184<error_handling>185186## Error Handling187188- **Missing plan document**: Request planner to recreate plan from requirements189- **Missing artifacts**: Request artifact recreation from source agent190- **Corrupted artifacts**: Request artifact recreation with validation191- **Incomplete reasoning**: Use artifact registry and gate files to reconstruct state192193</error_handling>194</instructions>195196<examples>197<usage_example>198**Recovery after context loss**:199200```bash201# 1. Check gate files for last completed step202ls .claude/context/history/gates/{workflow_id}/203204# 2. Load plan document205cat .claude/context/artifacts/plan-{workflow_id}.json206207# 3. Review reasoning files208cat .claude/context/history/reasoning/{workflow_id}/*.json209210# 4. Resume from next step211```212213</usage_example>214215<usage_example>216**Natural language invocation**:217218```219"Resume the workflow from where we left off"220"Recover the workflow state and continue"221"What was the last completed step?"222```223224</usage_example>225</examples>226227## Related228229- Planner Agent: `.claude/agents/core/planner.md`230- Memory files: `.claude/context/memory/`231232## Memory Protocol (MANDATORY)233234**Before starting:**235236```bash237cat .claude/context/memory/learnings.md238```239240**After completing:**241242- New pattern -> `.claude/context/memory/learnings.md`243- Issue found -> `.claude/context/memory/issues.md`244- Decision made -> `.claude/context/memory/decisions.md`245246> ASSUME INTERRUPTION: Your context may reset. If it's not in memory, it didn't happen.