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---5
6# Recovery Skill
7
8<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>
11
12<capabilities>
13- Resuming workflows after context window exhaustion
14- Recovering from session interruptions
15- Reconstructing workflow state from artifacts and gate files
16- Identifying and continuing from last completed step
17- Preventing duplicate work during recovery
18</capabilities>
19
20<instructions>
21<execution_process>
22
23## When to Use
24
25- Context window exhausted mid-workflow
26- Session interrupted or lost
27- Need to resume from last completed step
28- Workflow state needs reconstruction
29
30## Step 1: Identify Last Completed Step
31
321. **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 step
36
372. **Review reasoning files** for progress:
38 - Location: `.claude/context/history/reasoning/{workflow_id}/`
39 - Read reasoning files up to last completed step
40 - Extract context and decisions made
41
423. **Identify artifacts created**:
43 - Check artifact registry: `.claude/context/artifacts/registry-{workflow_id}.json`
44 - List all artifacts created up to last step
45 - Verify artifact files exist
46
47## Step 2: Load Plan Documents
48
491. **Read plan document** (stateless):
50 - Load `plan-{workflow_id}.json` from artifact registry
51 - Extract current workflow state
52 - Identify completed vs pending tasks
53
542. **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 dependencies
58
593. **Understand current state**:
60 - Map completed tasks to plan
61 - Identify next steps
62 - Check for dependencies
63
64## Step 3: Context Recovery
65
661. **Load artifacts from last completed step**:
67 - Read artifact registry
68 - Load all artifacts with validation_status: "pass"
69 - Verify artifact integrity
70
712. **Read reasoning files for context**:
72 - Load reasoning files from completed steps
73 - Extract key decisions and context
74 - Understand workflow progression
75
763. **Reconstruct workflow state**:
77 - Combine plan, artifacts, and reasoning
78 - Create recovery state document
79 - Validate state consistency
80
81## Step 4: Resume Execution
82
831. **Continue from next step**:
84 - Identify next step after last completed
85 - Load step requirements from plan
86 - Prepare inputs for next step
87
882. **Planner updates plan status** (stateless):
89 - Update plan-{workflow_id}.json with current status
90 - Mark completed steps
91 - Update progress tracking
92
933. **Orchestrator coordinates next agents**:
94 - Pass recovered artifacts to next step
95 - Resume workflow execution
96 - Monitor for additional interruptions
97
98</execution_process>
99
100## Failure Classification
101
102When a task fails, classify the failure type:
103
104| 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 |
111
112## Circular Fix Detection
113
114**Iron Law**: If the same approach has been tried 3+ times without success, STOP.
115
116When circular fix is detected:
117
1181. **Stop** the current approach immediately
1192. **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 intervention
122
123**Detection Algorithm**:
124
125- Extract keywords from current approach (excluding stop words)
126- Compare with keywords from last 3 attempts
127- If Jaccard similarity > 30% for 2+ attempts, flag as circular
128
129**Example**:
130
131```
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 instead
136```
137
138## Attempt Count Thresholds
139
140| 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 |
146
147## References
148
149See `references/` for detailed patterns:
150
151- `failure-types.md` - Failure classification details and indicators
152- `recovery-actions.md` - Recovery action decision tree and execution
153- `merge-strategies.md` - File merge strategies for multi-agent scenarios
154
155<best_practices>
156
157## Recovery Validation Checklist
158
159- [ ] Last completed step identified correctly
160- [ ] Plan document loaded and validated
161- [ ] All artifacts from completed steps available
162- [ ] Reasoning files reviewed for context
163- [ ] Workflow state reconstructed accurately
164- [ ] No duplicate work will be performed
165- [ ] Next step inputs prepared
166- [ ] Recovery logged in reasoning file
167
168</best_practices>
169
170<error_handling>
171
172## Error Handling
173
174- **Missing plan document**: Request planner to recreate plan from requirements
175- **Missing artifacts**: Request artifact recreation from source agent
176- **Corrupted artifacts**: Request artifact recreation with validation
177- **Incomplete reasoning**: Use artifact registry and gate files to reconstruct state
178
179</error_handling>
180</instructions>
181
182<examples>
183<usage_example>
184**Recovery after context loss**:
185
186```bash
187# 1. Check gate files for last completed step
188ls .claude/context/history/gates/{workflow_id}/
189
190# 2. Load plan document
191cat .claude/context/artifacts/plan-{workflow_id}.json
192
193# 3. Review reasoning files
194cat .claude/context/history/reasoning/{workflow_id}/*.json
195
196# 4. Resume from next step
197```
198
199</usage_example>
200
201<usage_example>
202**Natural language invocation**:
203
204```
205"Resume the workflow from where we left off"
206"Recover the workflow state and continue"
207"What was the last completed step?"
208```
209
210</usage_example>
211</examples>
212
213## Related
214
215- Planner Agent: `.claude/agents/core/planner.md`
216- Memory files: `.claude/context/memory/`
217
218## Memory Protocol (MANDATORY)
219
220**Before starting:**
221
222```bash
223cat .claude/context/memory/learnings.md
224```
225
226**After completing:**
227
228- New pattern -> `.claude/context/memory/learnings.md`
229- Issue found -> `.claude/context/memory/issues.md`
230- Decision made -> `.claude/context/memory/decisions.md`
231
232> ASSUME INTERRUPTION: Your context may reset. If it's not in memory, it didn't happen.