- Integrate ActionMonitor into ChatGPT GitOps API for failure tracking - Add ErrorClassifier with permission, git, runtime, system, secret violation error types - Add FailureRouter to route errors to correct recovery agents (openclaw/hermes/windows_codex_app) - Add RecoveryController orchestrating full pipeline: capture→classify→route→plan→execute→validate→record - Update error_classifier to include ClientResponseError, rate limit, and secret_violation patterns - All 8 integration tests passing (ActionMonitor, ErrorClassifier, FailureRouter, RecoveryController, API 500 scenario) - Push baseline to V1R2C2 with tag v1r2c2-baseline
90 lines
2.9 KiB
Python
90 lines
2.9 KiB
Python
"""V1R2C2 Error Classifier Module.
|
|
|
|
Classifies action failures by type and recovery priority.
|
|
"""
|
|
|
|
from typing import Any, Dict, Optional
|
|
|
|
# Error type patterns
|
|
ERROR_PATTERNS = {
|
|
'permission_error': [
|
|
'permission denied', 'unauthorized', 'forbidden', 'not allowed',
|
|
'access denied', 'credentials', 'authentication failed',
|
|
'token invalid', 'read-only', 'owner_approval_required',
|
|
'direct_main_push', 'protected_branch',
|
|
],
|
|
'git_error': [
|
|
'git failed', 'git error', 'paths', 'did not match', 'not a git repository',
|
|
'merge conflict', 'push rejected', 'fetch failed',
|
|
'remote', 'repository', 'fatal:', 'refs/heads',
|
|
],
|
|
'runtime_error': [
|
|
'connection refused', 'timeout', 'service unavailable', 'unreachable',
|
|
'server error', '500', '503', 'process crash', 'memory',
|
|
'clientresponseerror', 'responseerror',
|
|
'rate limit',
|
|
],
|
|
'validation_error': [
|
|
'invalid', 'required', 'missing', 'bad request', '400',
|
|
'malformed', 'unexpected',
|
|
],
|
|
'system_error': [
|
|
'disk full', 'out of memory', 'file system', 'kernel',
|
|
'oom', 'oom-kill', 'segfault', 'signal',
|
|
],
|
|
'secret_violation': [
|
|
'secret_rejected',
|
|
],
|
|
}
|
|
|
|
# Recovery priority mapping
|
|
RECOVERY_PRIORITY = {
|
|
'permission_error': 'openclaw_auto_repair',
|
|
'git_error': 'openclaw_auto_repair',
|
|
'runtime_error': 'hermes_escalation',
|
|
'validation_error': 'openclaw_auto_repair',
|
|
'system_error': 'windows_codex_escalation',
|
|
'secret_violation': 'windows_codex_escalation',
|
|
'unknown': 'openclaw_auto_repair',
|
|
}
|
|
|
|
|
|
class ErrorClassifier:
|
|
"""Classify action failures by analyzing error strings."""
|
|
|
|
@staticmethod
|
|
def classify(error: str) -> Dict[str, Any]:
|
|
"""Classify an error message into error type and recovery priority.
|
|
|
|
Returns:
|
|
dict with 'error_type', 'recovery_priority', 'matched_patterns'
|
|
"""
|
|
error_lower = error.lower()
|
|
matched = []
|
|
|
|
for etype, patterns in ERROR_PATTERNS.items():
|
|
for pattern in patterns:
|
|
if pattern in error_lower:
|
|
matched.append(etype)
|
|
break
|
|
|
|
# Determine primary error type
|
|
if not matched:
|
|
error_type = 'unknown'
|
|
else:
|
|
# Priority order: permission > git > system > runtime > validation
|
|
for priority_type in ['permission_error', 'git_error', 'system_error', 'secret_violation', 'runtime_error', 'validation_error']:
|
|
if priority_type in matched:
|
|
error_type = priority_type
|
|
break
|
|
else:
|
|
error_type = matched[0]
|
|
|
|
recovery_priority = RECOVERY_PRIORITY.get(error_type, 'openclaw_auto_repair')
|
|
|
|
return {
|
|
'error_type': error_type,
|
|
'recovery_priority': recovery_priority,
|
|
'matched_patterns': matched,
|
|
}
|