#14382: cron: record lastErrorReason in job state
app: web-ui
gateway
size: XS
Cluster:
Cron Job Management Fixes
This PR adds `lastErrorReason` to cron job state and populates it by classifying the last error string via `resolveFailoverReasonFromError` (billing/rate_limit/auth/timeout/format).
Motivation: groundwork for reason-aware cron guardrails (#14376). Today cron backoff is consecutive-error based but reason-agnostic; surfacing the classified reason improves observability and enables policy decisions in follow-up changes.
Changes
- Add `lastErrorReason?: FailoverReason` to `CronJobState` (types + gateway schema).
- Populate `job.state.lastErrorReason` when a job run ends in `error`.
Notes
- This PR does **not** change scheduling policy/backoff behavior yet; it only records the reason.
- Lint passed; targeted tests run for failover-error classification.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adds a `lastErrorReason` field to cron job state, wires it into the gateway cron schema, and populates it in the cron timer service by classifying the last error string via `resolveFailoverReasonFromError`.
The change fits into the existing cron state tracking (lastStatus/lastError/lastDurationMs/consecutiveErrors) by providing a structured reason alongside the raw error text, enabling future reason-aware guardrails without changing current backoff policy.
<h3>Confidence Score: 3/5</h3>
- This PR is close to safe to merge but currently contains a definite TypeScript module syntax error.
- The core logic change is small and localized, but `src/cron/types.ts` places an `import` after other statements, which will break parsing/compilation until fixed.
- src/cron/types.ts
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#13065: fix(cron): Fix "every" schedule not re-arming after gateway restart
by trevorgordon981 · 2026-02-10
75.3%
#8698: fix(cron): default enabled to true for new jobs
by emmick4 · 2026-02-04
75.2%
#8578: fix(cron): add failure limit and exponential backoff for isolated t...
by Baoxd123 · 2026-02-04
75.1%
#8837: fix(cron): guard against undefined job.state in printCronList
by fxd-jason · 2026-02-04
75.1%
#12303: fix(cron): correct nextRunAtMs calculation and prevent timer stall
by colddonkey · 2026-02-09
74.7%
#5179: fix(cron): recover stale running markers
by thatdaveb · 2026-01-31
74.6%
#12747: fix: catch up missed cron-expression job runs on restart
by obin94-commits · 2026-02-09
73.7%
#8825: fix: prevent cron infinite retry loop with exponential backoff
by dbottme · 2026-02-04
73.5%
#21915: Cron: add startup session reaper timing metrics
by mneves75 · 2026-02-20
73.0%
#12982: fix(cron): prevent status/list from advancing overdue job nextRunAtMs
by hclsys · 2026-02-10
72.7%