Heuristic:0x4m4 Hexstrike ai Recovery Strategy Scoring
| Knowledge Sources | |
|---|---|
| Domains | Error_Handling, Recovery, Optimization |
| Last Updated | 2026-10-10 00:00 GMT |
Overview
Formula for scoring recovery strategies by balancing success probability (discounted by attempt count) against time cost, ensuring the system prefers fast high-probability strategies early and escalates only when exhausted.
Description
When a security tool fails, HexStrike's IntelligentErrorHandler must choose the best recovery strategy from a set of candidates. Each strategy has a base success_probability, an estimated_time (in seconds), and a max_attempts limit. The scoring formula discounts the success probability by 10% for each prior attempt, then subtracts the time cost (normalized by dividing by 1000). The strategy with the highest score is selected. This ensures the system prefers quick, likely-to-succeed strategies first, and only escalates to slower or lower-probability options when earlier attempts fail.
Usage
Use this heuristic when designing or tuning error recovery systems with multiple candidate strategies. Apply it whenever the IntelligentErrorHandler or execute_command_with_recovery needs to select between retry, reduced scope, alternative tool, parameter adjustment, or human escalation strategies.
The Insight (Rule of Thumb)
- Action: Score each viable strategy using score = adjusted_probability - (estimated_time / 1000.0)
- Value: adjusted_probability = success_probability * (0.9 ^ (attempt_count - 1))
- Trade-off: Higher success probability strategies are preferred, but high time cost penalizes slow strategies. The 0.9 decay factor means the 4th attempt sees a ~27% probability reduction (0.9^3 = 0.729).
- Filter: Only strategies where attempt_count <= max_attempts are considered viable.
- Escalation: If no strategies are viable, escalate to human immediately.
Reasoning
The formula balances two competing goals: maximizing the chance of success and minimizing wasted time. The exponential decay (0.9^(n-1)) models the real-world observation that repeated attempts at the same recovery strategy have diminishing returns—the underlying issue is likely persistent. The time penalty (/1000) ensures that a strategy estimated to take 300 seconds (e.g., human escalation) is only selected when faster alternatives have been exhausted. For example, a strategy with success_probability=0.7 and estimated_time=30 on the first attempt scores 0.7 - 0.03 = 0.67, while a slower strategy with success_probability=0.9 and estimated_time=300 scores 0.9 - 0.3 = 0.6. The faster strategy wins early, but if it fails, the decay shifts the balance.
Code Evidence
Strategy scoring from `hexstrike_server.py:2031-2043`:
# Score strategies based on success probability and estimated time
scored_strategies = []
for strategy in viable_strategies:
# Adjust success probability based on previous failures
adjusted_probability = strategy.success_probability * (0.9 ** (context.attempt_count - 1))
# Prefer strategies with higher success probability and lower time
score = adjusted_probability - (strategy.estimated_time / 1000.0)
scored_strategies.append((score, strategy))
# Return strategy with highest score
scored_strategies.sort(key=lambda x: x[0], reverse=True)
return scored_strategies[0][1]
Viable strategy filtering from `hexstrike_server.py:2017-2018`:
viable_strategies = [s for s in strategies if context.attempt_count <= s.max_attempts]
Escalation fallback from `hexstrike_server.py:2020-2029`:
if not viable_strategies:
return RecoveryStrategy(
action=RecoveryAction.ESCALATE_TO_HUMAN,
parameters={"message": f"All recovery strategies exhausted for {context.tool_name}", "urgency": "high"},
max_attempts=1, backoff_multiplier=1.0,
success_probability=0.9, estimated_time=300
)