fix(agents): keep upgrade-plan 402s in billing

This commit is contained in:
Altay
2026-03-08 10:17:29 +03:00
parent 38dc21271e
commit 282b9186c6
3 changed files with 28 additions and 0 deletions

View File

@@ -241,6 +241,21 @@ describe("failover-error", () => {
).toBe("rate_limit");
});
it("keeps plan-upgrade 402 wrappers aligned with status-split billing payloads", () => {
const message = "Your usage limit has been reached. Please upgrade your plan.";
expect(
resolveFailoverReasonFromError({
message: `HTTP 402 Payment Required: ${message}`,
}),
).toBe("billing");
expect(
resolveFailoverReasonFromError({
status: 402,
message,
}),
).toBe("billing");
});
it("infers format errors from error messages", () => {
expect(
resolveFailoverReasonFromError({

View File

@@ -579,6 +579,12 @@ describe("classifyFailoverReasonFromHttpStatus 402 temporary limits", () =>
);
expect(classifyFailoverReasonFromHttpStatus(402, transientMessage)).toBe("rate_limit");
});
it("keeps plan-upgrade 402 limit messages in billing", () => {
const billingMessage = "Your usage limit has been reached. Please upgrade your plan.";
expect(classifyFailoverReason(`HTTP 402 Payment Required: ${billingMessage}`)).toBe("billing");
expect(classifyFailoverReasonFromHttpStatus(402, billingMessage)).toBe("billing");
});
});
describe("classifyFailoverReason", () => {

View File

@@ -219,6 +219,12 @@ const BILLING_402_HINTS = [
"add more credits",
"top up",
] as const;
const BILLING_402_PLAN_HINTS = [
"upgrade your plan",
"upgrade plan",
"current plan",
"subscription",
] as const;
const PERIODIC_402_HINTS = ["daily", "weekly", "monthly"] as const;
const RETRYABLE_402_RETRY_HINTS = ["try again", "retry", "temporary", "cooldown"] as const;
@@ -242,6 +248,7 @@ function includesAnyHint(text: string, hints: readonly string[]): boolean {
function hasExplicit402BillingSignal(text: string): boolean {
return (
includesAnyHint(text, BILLING_402_HINTS) ||
(includesAnyHint(text, BILLING_402_PLAN_HINTS) && text.includes("limit")) ||
text.includes("billing hard limit") ||
text.includes("hard limit reached") ||
(text.includes("maximum allowed") && text.includes("limit"))