Error Recovery Patterns
Overview
Systematic approach to handling and recovering from common errors during task execution. Provides recovery strategies, retry patterns, and fallback approaches for different error types.
Common Error Types
1. Compilation Errors
Symptoms:
- TypeScript compilation fails
- Syntax errors (missing braces, semicolons)
- Type mismatches
- Import path errors
- Method name mismatches
Recovery Strategy:
- Read error message carefully: Understand what's wrong
- Fix syntax/type errors immediately: Don't proceed with broken code
- Re-run compilation check:
npx tsc --noEmit
- If errors persist: Check for missing imports or type definitions
Common Patterns:
- Syntax errors: Check for missing/extra braces, parentheses, semicolons
- Type mismatches: Verify interface compatibility, check actual types
- Import errors: Use relative paths, check file existence
- Method name mismatches: Check actual method names in source code
When to skip: Never skip compilation errors - must fix before proceeding
2. Test Failures
Symptoms:
- Tests fail with assertion errors
- Tests timeout
- Tests are flaky (pass/fail intermittently)
- Test setup/teardown fails
Recovery Strategy:
- Read test output: Understand what failed and why
- Classify failure: Is test flaky or code broken?
- Fix code if broken: Update implementation to match test expectations
- Skip test if flaky: Document why test was skipped
- Re-run tests: Verify fix or skip
Common Patterns:
- Assertion failures: Code doesn't match test expectations
- Timeouts: Test takes too long (increase timeout or optimize code)
- Flaky tests: Non-deterministic behavior (seed RNG, fix timing)
- Setup failures: Test environment not configured correctly
When to skip: Only skip if test is flaky and not critical for task
3. Tool Failures
Symptoms:
- API errors (401, 403, 500)
- Network timeouts
- Invalid credentials
- Tool unavailable
- Rate limiting
Recovery Strategy:
- Check error message: Understand root cause
- If API key missing/invalid: Skip tool usage (don't retry)
- If network timeout: Retry with exponential backoff (max 3 times)
- If tool unavailable: Use alternative approach
- Document fallback: Explain why alternative was used
Common Patterns:
- API errors: Check credentials, verify API key, check rate limits
- Network timeouts: Retry with delays, check network connectivity
- Tool unavailable: Service down, use alternative tool
- Rate limiting: Wait and retry, or use alternative approach
When to skip: Skip if tool consistently failing or not critical
4. Browser Testing Failures
Symptoms:
- Browser commands timeout
- Elements not found
- Test seam unavailable
- Scene navigation fails
Recovery Strategy:
- Check timeout: Increase timeout or use polling
- Verify element exists: Check DOM, wait for element
- Check test seam: Verify
window.__TEST__ is available
- Use fallback: Console logs, screenshots, code review
Common Patterns:
- Timeouts: Increase timeout, use polling instead of fixed wait
- Element not found: Wait for element, check selector
- Test seam unavailable: Check scene initialization, wait for ready
- Navigation fails: Verify scene key, check scene registration
When to skip: Skip if browser testing not critical, use code review instead
Retry Patterns with Limits
Exponential Backoff
Pattern:
- First retry: 1 second delay
- Second retry: 2 second delay
- Third retry: 4 second delay
- After 3 retries: Skip and use alternative
When to use:
- Transient failures (timeouts, network issues)
- Likely to succeed on retry
- No alternative available
When NOT to use:
- API key errors (won't succeed on retry)
- Tool unavailable (service down)
- Invalid credentials (won't succeed on retry)
Retry Limits
Maximum retries: 3 attempts
After 3 retries:
- Skip tool/step
- Use alternative approach
- Document why skipped
Fallback Strategies
Strategy 1: Use Alternative Tool
When primary tool fails:
- Use different tool with same functionality
- Example:
agent-browser fails → use code review + compilation check
Pattern:
- Identify alternative tool
- Try alternative
- If alternative works, continue
- If alternative fails, try next fallback
Strategy 2: Graceful Degradation
When cost-incurring tool fails:
- Use free alternative
- Example: ElevenLabs TTS fails → use console.log for verification
Pattern:
- Check if free alternative exists
- Use free alternative
- Document why alternative was used
Strategy 3: Skip Non-Critical Steps
When step is not critical:
- Skip step and continue
- Document why skipped
- Example: Visual verification skipped → use code review
Pattern:
- Verify step is not critical
- Skip step
- Document why skipped
- Continue with remaining steps
Strategy 4: Code Review + Compilation Check
When browser testing fails:
- Use code review to verify implementation
- Run TypeScript compilation check
- Verify logic matches requirements
Pattern:
- Review code changes
- Run
npx tsc --noEmit
- Verify logic matches requirements
- Document verification method
Error Classification
Critical Errors (Must Fix)
- Compilation errors: Code won't run
- Type errors: Type safety violated
- Syntax errors: Code invalid
Action: Fix immediately, don't proceed
Non-Critical Errors (Can Skip)
- Visual verification: Can use code review
- Optional features: Not required for task
- Cost-incurring tools: Can use free alternatives
Action: Skip if alternative available
Transient Errors (Retry)
- Network timeouts: Likely to succeed on retry
- Rate limiting: Wait and retry
- Temporary service issues: Retry with backoff
Action: Retry with exponential backoff (max 3 times)
Recovery Workflow
Step 1: Classify Error
- Read error message: Understand what failed
- Identify error type: Compilation, test, tool, browser
- Determine severity: Critical, non-critical, transient
Step 2: Choose Recovery Strategy
- Critical errors: Fix immediately
- Non-critical errors: Skip if alternative available
- Transient errors: Retry with backoff
Step 3: Execute Recovery
- Fix errors: Update code, fix syntax, correct types
- Retry with backoff: Wait and retry (max 3 times)
- Use alternative: Switch to different tool/approach
- Skip step: Document why skipped
Step 4: Verify Recovery
- Re-run checks: Compilation, tests, verification
- Verify fix: Confirm error is resolved
- Document recovery: Explain what was done
Best Practices
- Fix errors immediately: Don't accumulate errors
- Use retries wisely: Only for transient failures
- Have fallback strategies: Always know alternative approach
- Document recoveries: Explain why alternative was used
- Don't retry forever: Set limits (max 3 retries)
Resources
agent-workflow-guidelines skill - General workflow guidelines
loop-detection-prevention skill - Prevent infinite retry loops
typescript-incremental-check skill - TypeScript error patterns
1---2name: error-recovery-patterns3description: Document common error types, provide recovery strategies, retry patterns with limits, and fallback strategies. Use when encountering compilation errors, test failures, tool failures, or other execution errors. Provides systematic approach to error handling and recovery.4---56# Error Recovery Patterns78## Overview910Systematic approach to handling and recovering from common errors during task execution. Provides recovery strategies, retry patterns, and fallback approaches for different error types.1112## Common Error Types1314### 1. Compilation Errors1516**Symptoms**:17- TypeScript compilation fails18- Syntax errors (missing braces, semicolons)19- Type mismatches20- Import path errors21- Method name mismatches2223**Recovery Strategy**:241. **Read error message carefully**: Understand what's wrong252. **Fix syntax/type errors immediately**: Don't proceed with broken code263. **Re-run compilation check**: `npx tsc --noEmit`274. **If errors persist**: Check for missing imports or type definitions2829**Common Patterns**:30- **Syntax errors**: Check for missing/extra braces, parentheses, semicolons31- **Type mismatches**: Verify interface compatibility, check actual types32- **Import errors**: Use relative paths, check file existence33- **Method name mismatches**: Check actual method names in source code3435**When to skip**: Never skip compilation errors - must fix before proceeding3637### 2. Test Failures3839**Symptoms**:40- Tests fail with assertion errors41- Tests timeout42- Tests are flaky (pass/fail intermittently)43- Test setup/teardown fails4445**Recovery Strategy**:461. **Read test output**: Understand what failed and why472. **Classify failure**: Is test flaky or code broken?483. **Fix code if broken**: Update implementation to match test expectations494. **Skip test if flaky**: Document why test was skipped505. **Re-run tests**: Verify fix or skip5152**Common Patterns**:53- **Assertion failures**: Code doesn't match test expectations54- **Timeouts**: Test takes too long (increase timeout or optimize code)55- **Flaky tests**: Non-deterministic behavior (seed RNG, fix timing)56- **Setup failures**: Test environment not configured correctly5758**When to skip**: Only skip if test is flaky and not critical for task5960### 3. Tool Failures6162**Symptoms**:63- API errors (401, 403, 500)64- Network timeouts65- Invalid credentials66- Tool unavailable67- Rate limiting6869**Recovery Strategy**:701. **Check error message**: Understand root cause712. **If API key missing/invalid**: Skip tool usage (don't retry)723. **If network timeout**: Retry with exponential backoff (max 3 times)734. **If tool unavailable**: Use alternative approach745. **Document fallback**: Explain why alternative was used7576**Common Patterns**:77- **API errors**: Check credentials, verify API key, check rate limits78- **Network timeouts**: Retry with delays, check network connectivity79- **Tool unavailable**: Service down, use alternative tool80- **Rate limiting**: Wait and retry, or use alternative approach8182**When to skip**: Skip if tool consistently failing or not critical8384### 4. Browser Testing Failures8586**Symptoms**:87- Browser commands timeout88- Elements not found89- Test seam unavailable90- Scene navigation fails9192**Recovery Strategy**:931. **Check timeout**: Increase timeout or use polling942. **Verify element exists**: Check DOM, wait for element953. **Check test seam**: Verify `window.__TEST__` is available964. **Use fallback**: Console logs, screenshots, code review9798**Common Patterns**:99- **Timeouts**: Increase timeout, use polling instead of fixed wait100- **Element not found**: Wait for element, check selector101- **Test seam unavailable**: Check scene initialization, wait for ready102- **Navigation fails**: Verify scene key, check scene registration103104**When to skip**: Skip if browser testing not critical, use code review instead105106## Retry Patterns with Limits107108### Exponential Backoff109110**Pattern**:111- **First retry**: 1 second delay112- **Second retry**: 2 second delay113- **Third retry**: 4 second delay114- **After 3 retries**: Skip and use alternative115116**When to use**:117- Transient failures (timeouts, network issues)118- Likely to succeed on retry119- No alternative available120121**When NOT to use**:122- API key errors (won't succeed on retry)123- Tool unavailable (service down)124- Invalid credentials (won't succeed on retry)125126### Retry Limits127128**Maximum retries**: 3 attempts129130**After 3 retries**:1311. Skip tool/step1322. Use alternative approach1333. Document why skipped134135## Fallback Strategies136137### Strategy 1: Use Alternative Tool138139**When primary tool fails**:140- Use different tool with same functionality141- Example: `agent-browser` fails → use code review + compilation check142143**Pattern**:1441. Identify alternative tool1452. Try alternative1463. If alternative works, continue1474. If alternative fails, try next fallback148149### Strategy 2: Graceful Degradation150151**When cost-incurring tool fails**:152- Use free alternative153- Example: ElevenLabs TTS fails → use console.log for verification154155**Pattern**:1561. Check if free alternative exists1572. Use free alternative1583. Document why alternative was used159160### Strategy 3: Skip Non-Critical Steps161162**When step is not critical**:163- Skip step and continue164- Document why skipped165- Example: Visual verification skipped → use code review166167**Pattern**:1681. Verify step is not critical1692. Skip step1703. Document why skipped1714. Continue with remaining steps172173### Strategy 4: Code Review + Compilation Check174175**When browser testing fails**:176- Use code review to verify implementation177- Run TypeScript compilation check178- Verify logic matches requirements179180**Pattern**:1811. Review code changes1822. Run `npx tsc --noEmit`1833. Verify logic matches requirements1844. Document verification method185186## Error Classification187188### Critical Errors (Must Fix)189190- **Compilation errors**: Code won't run191- **Type errors**: Type safety violated192- **Syntax errors**: Code invalid193194**Action**: Fix immediately, don't proceed195196### Non-Critical Errors (Can Skip)197198- **Visual verification**: Can use code review199- **Optional features**: Not required for task200- **Cost-incurring tools**: Can use free alternatives201202**Action**: Skip if alternative available203204### Transient Errors (Retry)205206- **Network timeouts**: Likely to succeed on retry207- **Rate limiting**: Wait and retry208- **Temporary service issues**: Retry with backoff209210**Action**: Retry with exponential backoff (max 3 times)211212## Recovery Workflow213214### Step 1: Classify Error2152161. **Read error message**: Understand what failed2172. **Identify error type**: Compilation, test, tool, browser2183. **Determine severity**: Critical, non-critical, transient219220### Step 2: Choose Recovery Strategy2212221. **Critical errors**: Fix immediately2232. **Non-critical errors**: Skip if alternative available2243. **Transient errors**: Retry with backoff225226### Step 3: Execute Recovery2272281. **Fix errors**: Update code, fix syntax, correct types2292. **Retry with backoff**: Wait and retry (max 3 times)2303. **Use alternative**: Switch to different tool/approach2314. **Skip step**: Document why skipped232233### Step 4: Verify Recovery2342351. **Re-run checks**: Compilation, tests, verification2362. **Verify fix**: Confirm error is resolved2373. **Document recovery**: Explain what was done238239## Best Practices2402411. **Fix errors immediately**: Don't accumulate errors2422. **Use retries wisely**: Only for transient failures2433. **Have fallback strategies**: Always know alternative approach2444. **Document recoveries**: Explain why alternative was used2455. **Don't retry forever**: Set limits (max 3 retries)246247## Resources248249- `agent-workflow-guidelines` skill - General workflow guidelines250- `loop-detection-prevention` skill - Prevent infinite retry loops251- `typescript-incremental-check` skill - TypeScript error patterns