/** * Single definition of rectification Agent wall-clock budgets. * * Attempt cap stays at 210s (BUG-388). The whole-run budget is strictly less * than the route `maxDuration` so a retry cannot start a second attempt that * the edge will cut (BUG-059 / BUG-724). */ export const RECTIFICATION_AGENT_ATTEMPT_TIMEOUT_MS = 210_000; export const RECTIFICATION_RUN_BUDGET_MS = 225_000; export const RECTIFICATION_MIN_RETRY_ATTEMPT_MS = 20_000; export const RECTIFICATION_AGENT_ROUTE_MAX_DURATION_S = 240; export function attemptTimeoutForRemainingBudget( remainingMs: number, attemptCapMs = RECTIFICATION_AGENT_ATTEMPT_TIMEOUT_MS, ): number { if (!Number.isFinite(remainingMs) || remainingMs <= 0) return 0; if (!Number.isFinite(attemptCapMs) || attemptCapMs <= 0) return 0; return Math.min(attemptCapMs, remainingMs); } export function canStartRetryAttempt( remainingMs: number, minAttemptMs = RECTIFICATION_MIN_RETRY_ATTEMPT_MS, ): boolean { return Number.isFinite(remainingMs) && remainingMs >= minAttemptMs; }