Skip to content

Commit e86512f

Browse files
authored
fix(cron): honor permanent provider classifications (#114113)
1 parent f68f68b commit e86512f

4 files changed

Lines changed: 53 additions & 5 deletions

File tree

‎src/cron/retry-hint.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ describe("resolveCronExecutionRetryHint", () => {
2020
).toEqual({ retryable: true, category: "rate_limit" });
2121
});
2222

23+
it("does not let transient error text override a permanent provider classification", () => {
24+
expect(
25+
resolveCronExecutionRetryHint({
26+
error: "HTTP 429: all available credits have been exhausted",
27+
classifiedReason: "billing",
28+
}),
29+
).toEqual({ retryable: false });
30+
});
31+
2332
it("treats common network error codes as network when retryOn only includes network", () => {
2433
for (const code of [
2534
"EAI_AGAIN",

‎src/cron/retry-hint.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { FailoverReason } from "../agents/embedded-agent-helpers/types.js";
2+
13
/** Classifies cron run failures for retry policy decisions. */
24
export type CronRetryOn = "rate_limit" | "overloaded" | "network" | "timeout" | "server_error";
35

@@ -10,7 +12,7 @@ type CronRetryHint = {
1012
type CronRetryHintInput = {
1113
error: string | undefined;
1214
retryOn?: CronRetryOn[];
13-
classifiedReason?: string | null;
15+
classifiedReason?: FailoverReason | null;
1416
executionStarted?: boolean;
1517
};
1618

@@ -56,9 +58,12 @@ export function resolveCronExecutionRetryHint(input: CronRetryHintInput): CronRe
5658
}
5759
const keys = retryOn?.length ? retryOn : (Object.keys(TRANSIENT_PATTERNS) as CronRetryOn[]);
5860
const classified = classifiedReason ?? undefined;
59-
if (classified && keys.includes(classified as CronRetryOn)) {
60-
// Structured provider classifications win over brittle message regexes when allowed.
61-
return { retryable: true, category: classified as CronRetryOn };
61+
if (classified) {
62+
// Structured provider classifications are authoritative. Falling through
63+
// would let incidental transient text override a permanent reason.
64+
return keys.includes(classified as CronRetryOn)
65+
? { retryable: true, category: classified as CronRetryOn }
66+
: { retryable: false };
6267
}
6368
for (const key of keys) {
6469
if (TRANSIENT_PATTERNS[key]?.test(error)) {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Retry-decision tests preserve provider classifications before cron message matching.
2+
import { describe, expect, it } from "vitest";
3+
import { resolveTransientCronRetryDecision } from "./timer-trigger.js";
4+
5+
describe("resolveTransientCronRetryDecision", () => {
6+
it("keeps permanent-looking and transient provider classifications distinct", () => {
7+
const error = "HTTP 429: all available credits have been exhausted";
8+
9+
expect(
10+
resolveTransientCronRetryDecision({
11+
error,
12+
errorClassification: { kind: "reason", reason: "billing" },
13+
consecutiveErrors: 1,
14+
}),
15+
).toEqual({
16+
retryable: false,
17+
consecutiveErrors: 1,
18+
reason: "permanent error",
19+
});
20+
21+
expect(
22+
resolveTransientCronRetryDecision({
23+
error,
24+
errorClassification: { kind: "reason", reason: "rate_limit" },
25+
consecutiveErrors: 1,
26+
}),
27+
).toMatchObject({
28+
retryable: true,
29+
consecutiveErrors: 1,
30+
retryCategory: "rate_limit",
31+
reason: "transient retry",
32+
});
33+
});
34+
});

‎src/cron/service/timer-trigger.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export function resolveTransientCronRetryDecision(params: {
6060
cronConfig?: CronConfig;
6161
error: string | undefined;
6262
errorClassification?: CronRunErrorClassification;
63-
lastErrorReason?: string;
63+
lastErrorReason?: CronJob["state"]["lastErrorReason"];
6464
executionStarted?: boolean;
6565
consecutiveErrors: number | undefined;
6666
}): TransientCronRetryDecision {

0 commit comments

Comments
 (0)