/** * Failure Handler * * Retry logic, systemic failure detection, and pause decisions. */ import { EventEmitter } from 'events'; import type { AutopilotConfig } from '../types.js'; /** * Failure category */ export type FailureCategory = 'transient' | 'rate_limit' | 'auth' | 'timeout' | 'validation' | 'implementation' | 'systemic' | 'unknown'; /** * Failure info */ export interface FailureInfo { ticketId: string; workerId: number; error: string; category: FailureCategory; attempt: number; timestamp: Date; retryable: boolean; retryAfterMs?: number; } /** * Failure Handler Events */ export interface FailureHandlerEvents { 'failure:recorded': FailureInfo; 'failure:systemic': { count: number; recentFailures: FailureInfo[]; }; 'failure:should_pause': { reason: string; }; 'failure:retry_scheduled': { ticketId: string; retryAfterMs: number; }; } /** * Failure Handler */ export declare class FailureHandler extends EventEmitter { private failures; private ticketAttempts; private config; constructor(config: AutopilotConfig | Partial<{ maxTicketRetries: number; systemicThreshold: number; systemicWindowMs: number; }>); /** * Record a failure */ recordFailure(info: Omit): FailureInfo; /** * Categorize error message */ private categorizeError; /** * Determine if failure is retryable */ private isRetryable; /** * Calculate retry delay based on category and attempt */ private calculateRetryDelay; /** * Detect systemic failures (many failures in short window) * Excludes rate_limit failures as they are handled separately */ private detectSystemicFailure; /** * Get attempt count for a ticket */ getAttemptCount(ticketId: string): number; /** * Check if ticket should be retried * Returns false if ticket has no recorded failures (nothing to retry) */ shouldRetry(ticketId: string): boolean; /** * Get last failure for a ticket */ getLastFailure(ticketId: string): FailureInfo | undefined; /** * Get all failures for a ticket */ getTicketFailures(ticketId: string): FailureInfo[]; /** * Clear failures for a ticket (e.g., after success) */ clearTicketFailures(ticketId: string): void; /** * Get failure statistics */ getStats(): { totalFailures: number; byCategory: Record; recentCount: number; uniqueTickets: number; }; /** * Check if should pause due to failures */ shouldPause(): { should: boolean; reason?: string; }; /** * Reset all failure tracking */ reset(): void; /** * Alias for reset - clear all failures */ clearAll(): void; /** * Get total failure count */ getFailureCount(): number; /** * Get failures within a time window */ getRecentFailures(windowMs?: number): FailureInfo[]; /** * Get failure rate (failures per minute) within a time window */ getFailureRate(windowMs?: number): number; /** * Update configuration */ updateConfig(updates: Partial): void; } /** * Create a failure handler */ export declare function createFailureHandler(config?: Partial<{ maxTicketRetries: number; systemicThreshold: number; systemicWindowMs: number; }>): FailureHandler; //# sourceMappingURL=failure-handler.d.ts.map