error-recoverer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseError Recoverer
错误恢复器
Detects, classifies, and recovers from errors during autonomous coding sessions.
可在自主编码会话中检测、分类并恢复错误。
Quick Start
快速开始
Handle Error
处理错误
python
from scripts.error_recoverer import ErrorRecoverer
recoverer = ErrorRecoverer(project_dir)
result = await recoverer.handle_error(error, context)
if result.recovered:
print(f"Recovered via: {result.strategy}")
else:
print(f"Failed: {result.reason}")python
from scripts.error_recoverer import ErrorRecoverer
recoverer = ErrorRecoverer(project_dir)
result = await recoverer.handle_error(error, context)
if result.recovered:
print(f"Recovered via: {result.strategy}")
else:
print(f"Failed: {result.reason}")Automatic Recovery
自动恢复
python
@recoverer.with_recovery
async def risky_operation():
# Operation that might fail
passpython
@recoverer.with_recovery
async def risky_operation():
# Operation that might fail
passError Recovery Workflow
错误恢复工作流
┌─────────────────────────────────────────────────────────────┐
│ ERROR RECOVERY FLOW │
├─────────────────────────────────────────────────────────────┤
│ │
│ 1. DETECT │
│ ├─ Catch exception │
│ ├─ Parse error message │
│ └─ Extract error context │
│ │
│ 2. CLASSIFY │
│ ├─ Determine error category │
│ ├─ Assess severity level │
│ └─ Check if recoverable │
│ │
│ 3. STRATEGIZE │
│ ├─ Query causal memory for similar errors │
│ ├─ Select recovery strategy │
│ └─ Prepare recovery action │
│ │
│ 4. RECOVER │
│ ├─ Execute recovery strategy │
│ ├─ Verify recovery success │
│ └─ Store error→solution chain │
│ │
│ 5. ESCALATE (if recovery fails) │
│ ├─ Rollback to checkpoint │
│ ├─ Create detailed error report │
│ └─ Signal for human intervention │
│ │
└─────────────────────────────────────────────────────────────┘┌─────────────────────────────────────────────────────────────┐
│ ERROR RECOVERY FLOW │
├─────────────────────────────────────────────────────────────┤
│ │
│ 1. 检测 │
│ ├─ 捕获异常 │
│ ├─ 解析错误信息 │
│ └─ 提取错误上下文 │
│ │
│ 2. 分类 │
│ ├─ 确定错误类别 │
│ ├─ 评估严重程度 │
│ └─ 检查是否可恢复 │
│ │
│ 3. 制定策略 │
│ ├─ 查询因果内存以查找类似错误 │
│ ├─ 选择恢复策略 │
│ └─ 准备恢复操作 │
│ │
│ 4. 恢复 │
│ ├─ 执行恢复策略 │
│ ├─ 验证恢复成功 │
│ └─ 存储错误→解决方案链路 │
│ │
│ 5. 升级(若恢复失败) │
│ ├─ 回滚到检查点 │
│ ├─ 创建详细错误报告 │
│ └─ 发出人工干预请求 │
│ │
└─────────────────────────────────────────────────────────────┘Error Categories
错误类别
| Category | Examples | Recovery Strategy |
|---|---|---|
| Transient | Network timeout, rate limit | Retry with backoff |
| Resource | File not found, permission denied | Fix path/permissions |
| Syntax | Parse error, invalid JSON | Fix syntax errors |
| Logic | Test failure, assertion error | Debug and fix code |
| Environment | Missing dependency, version mismatch | Install/update deps |
| Unrecoverable | Disk full, OOM | Escalate immediately |
| 类别 | 示例 | 恢复策略 |
|---|---|---|
| 临时错误 | 网络超时、速率限制 | 带退避的重试 |
| 资源错误 | 文件未找到、权限拒绝 | 修复路径/权限 |
| 语法错误 | 解析错误、无效JSON | 修复语法错误 |
| 逻辑错误 | 测试失败、断言错误 | 调试并修复代码 |
| 环境错误 | 依赖缺失、版本不匹配 | 安装/更新依赖 |
| 不可恢复错误 | 磁盘已满、内存不足 | 立即升级处理 |
Recovery Strategies
恢复策略
python
class RecoveryStrategy(Enum):
RETRY = "retry" # Simple retry
RETRY_BACKOFF = "backoff" # Exponential backoff
ROLLBACK = "rollback" # Restore checkpoint
FIX_AND_RETRY = "fix_retry" # Apply fix, then retry
SKIP = "skip" # Skip and continue
ESCALATE = "escalate" # Human interventionpython
class RecoveryStrategy(Enum):
RETRY = "retry" # Simple retry
RETRY_BACKOFF = "backoff" # Exponential backoff
ROLLBACK = "rollback" # Restore checkpoint
FIX_AND_RETRY = "fix_retry" # Apply fix, then retry
SKIP = "skip" # Skip and continue
ESCALATE = "escalate" # Human interventionIntegration Points
集成点
- memory-manager: Query/store causal chains
- checkpoint-manager: Rollback on failure
- coding-agent: Provide fixes for code errors
- progress-tracker: Log error metrics
- memory-manager: 查询/存储因果链
- checkpoint-manager: 失败时回滚
- coding-agent: 为代码错误提供修复方案
- progress-tracker: 记录错误指标
References
参考资料
- - Error classification
references/ERROR-CATEGORIES.md - - Strategy details
references/RECOVERY-STRATEGIES.md
- - 错误分类说明
references/ERROR-CATEGORIES.md - - 策略详细说明
references/RECOVERY-STRATEGIES.md
Scripts
脚本
- - Core recovery logic
scripts/error_recoverer.py - - Error classification
scripts/error_classifier.py - - Retry with backoff
scripts/retry_handler.py - - Strategy implementations
scripts/recovery_strategies.py
- - 核心恢复逻辑
scripts/error_recoverer.py - - 错误分类器
scripts/error_classifier.py - - 带退避的重试处理器
scripts/retry_handler.py - - 策略实现
scripts/recovery_strategies.py