Overview
Failure analysis system that identifies failure types from error output and exit codes, generates recovery strategies, and suggests alternative tools from a pre-configured mapping.
Description
The FailureRecoverySystem class provides a complementary failure analysis to IntelligentErrorHandler. Its analyze_failure method matches error output text against failure_patterns (timeout, permission_denied, not_found, network_error, rate_limited, authentication_required) and analyzes exit codes (124=timeout, 126=permission). It returns a confidence-scored dict with failure type, recovery strategies, and alternative tools from the tool_alternatives mapping (e.g. nmap → rustscan/masscan/zmap).
Usage
- Failure analysis: Call analyze_failure(error_output, exit_code) to get failure type, confidence, and recovery strategies
- Alternative tools: The returned dict includes alternative_tools from the tool_alternatives mapping
- Integration: Used by execute_command_with_recovery when SWITCH_TO_ALTERNATIVE_TOOL is selected
Code Reference
Source Location
- Repository: HexStrike AI
- File: hexstrike_server.py
- Lines: L4449-4542 (FailureRecoverySystem class)
Signature
class FailureRecoverySystem:
def __init__(self):
self.tool_alternatives: Dict[str, List[str]] # tool → alternative tool names
self.failure_patterns: Dict[str, List[str]] # failure_type → keyword patterns
def analyze_failure(self, error_output: str, exit_code: int) -> Dict[str, Any]:
"""Analyze failure and suggest recovery strategies."""
def _extract_tool_name(self, error_output: str) -> str:
"""Extract tool name from error output by matching known tool names."""
Import
from hexstrike_server import FailureRecoverySystem
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| error_output |
str |
Yes |
Error message text from failed execution
|
| exit_code |
int |
Yes |
Process exit code (124=timeout, 126=permission)
|
Outputs
| Name |
Type |
Description
|
| failure_type |
str |
Identified failure category
|
| confidence |
float |
0.0-1.0 confidence in the classification
|
| recovery_strategies |
List[str] |
Human-readable recovery strategy descriptions
|
| alternative_tools |
List[str] │ Alternative tool names from tool_alternatives mapping
|
Usage Examples
Analyzing a Tool Failure
from hexstrike_server import FailureRecoverySystem
frs = FailureRecoverySystem()
# Analyze a timeout failure
result = frs.analyze_failure(
error_output="nmap scan timed out after 60 seconds",
exit_code=124
)
print(f"Failure type: {result['failure_type']}") # "timeout"
print(f"Confidence: {result['confidence']:.0%}")
print(f"Recovery: {result['recovery_strategies']}")
print(f"Alternatives: {result['alternative_tools']}")
# Alternatives: ['rustscan', 'masscan', 'zmap']
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.