Files
Jyotisha/frontend/src/lib/rectification-run-budget.ts
T
jesse-ux 8b982baf64
Independent Staging Quality Gate / validate (push) Canceled after 4m2s
Independent Staging Quality Gate / publish (push) Canceled after 0s
fix(rectification): 分类器失败、引擎忙、整轮超时不再归因错
点选题把分类器两次异常说成用户没说清(BUG-722);引擎 429 被压成坏了且重算静默失败(BUG-723);两次 attempt 总预算大于路由 maxDuration(BUG-724)。本单只改归因:classifier_unavailable 请用户重发、busy 分档并可见「这次没有重新比较」、整轮 225s 预算不够则 host fallback。不改计费、分类模型、并发闸门。
2026-09-16 07:06:57 +08:00

28 lines
1.0 KiB
TypeScript

/**
* 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;
}