Record a strategy attempt. Args: strategy: Strategy name used error_type: Type of error being fixed success: Whether strategy succeeded duration: Time taken in seconds context: Additional context Returns:
(self, strategy: str, error_type: str,
success: bool, duration: float = 0.0,
context: Dict = None)
| 223 | warning(f"Failed to save strategy tracker: {e}") |
| 224 | |
| 225 | def record_attempt(self, strategy: str, error_type: str, |
| 226 | success: bool, duration: float = 0.0, |
| 227 | context: Dict = None) -> StrategyRecord: |
| 228 | """ |
| 229 | Record a strategy attempt. |
| 230 | |
| 231 | Args: |
| 232 | strategy: Strategy name used |
| 233 | error_type: Type of error being fixed |
| 234 | success: Whether strategy succeeded |
| 235 | duration: Time taken in seconds |
| 236 | context: Additional context |
| 237 | |
| 238 | Returns: |
| 239 | StrategyRecord for the attempt |
| 240 | """ |
| 241 | record = StrategyRecord(strategy, error_type, success, duration, context) |
| 242 | self._recent_records.append(record) |
| 243 | |
| 244 | # Keep only last 100 records in memory |
| 245 | if len(self._recent_records) > 100: |
| 246 | self._recent_records = self._recent_records[-100:] |
| 247 | |
| 248 | # Update stats |
| 249 | if strategy not in self._stats: |
| 250 | self._stats[strategy] = StrategyStats(strategy) |
| 251 | self._stats[strategy].record(success, duration, error_type) |
| 252 | |
| 253 | self._save_tracker() |
| 254 | |
| 255 | # Log result |
| 256 | if success: |
| 257 | log_success(f"Strategy '{strategy}' succeeded ({duration:.2f}s)") |
| 258 | else: |
| 259 | warning(f"Strategy '{strategy}' failed for {error_type}") |
| 260 | |
| 261 | return record |
| 262 | |
| 263 | def get_best_strategy(self, error_type: str, |
| 264 | min_attempts: int = 3) -> Optional[str]: |