Repository navigation
fix(cron): keep a job's next run at its wall time across a dst change - #32403
Conversation
A cron job's advertised next run and its timer boundary were computed by handing croniter an aware start in the job's zone. croniter 2 then shifts any run that lies past a DST change by the offset change a second time: a 03:00 job read 04:00 PST the day before the fall-back, a 22:00 job 21:00 PDT the day before the spring-forward, and is_due refused the advertised instant. Step the zone's naive wall clock instead and attach the zone to the result, as the schedule label already does. A repeated wall time whose first instant is not after now takes its second; a spring-forward gap resolves as fold=0 does, as before. Builds on #24864. Closes #24853
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS No design-level concerns. Both next-run callers now go through one helper that steps the zone's wall clock, the same way the schedule label already did. The due decision is unchanged, and nothing is taken away. [DESIGN-REVIEWED] 35ea1d5 Description read[DESCRIPTION-READ] 4e4cd6db3f643da93c0df21946f091222ba058caa7cac80886575f43d59fc380 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks: this is a fix for linked issue #24853, and four of the new test rows fail on base. It works on the code that computes the next run, and both next-run paths now share one helper. Notes
What this change shipsInventory (4 items) — 3 justifiedIntent: a DST-zone user sees, and the timer wakes on, the wall time their cron job is set for. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] 35ea1d5 Description read[DESCRIPTION-READ] b86f70deb8b6d6ac80f75afb90e0b0e5aa6e5e4efa263f2ccab3e6936f4a2961 That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Tier 1 auto-approve: fix (3 files). Criteria: no conflict, no requested changes, security path denylist clean, design-doc gate clean, security checklist all-NO, no reviewer-lane findings, readiness signal fresh for this head SHA, declared category matches the diff. Category: bug fix: cron next-run is stepped on the zone wall clock before the zone is attached, so a DST change no longer shifts it twice; tests added. Spec files changed as a ride-along (a minority of the diff on both file count and changed lines), not reviewed as a design decision: docs/system-specs/modules/learn-cron-dashboard.md.
…#32403) A cron job's advertised next run and its timer boundary were computed by handing croniter an aware start in the job's zone. croniter 2 then shifts any run that lies past a DST change by the offset change a second time: a 03:00 job read 04:00 PST the day before the fall-back, a 22:00 job 21:00 PDT the day before the spring-forward, and is_due refused the advertised instant. Step the zone's naive wall clock instead and attach the zone to the result, as the schedule label already does. A repeated wall time whose first instant is not after now takes its second; a spring-forward gap resolves as fold=0 does, as before. Builds on #24864. Closes #24853 (cherry picked from commit 83ec532)
Problem / Motivation
Goal: A cron job's "Next run" and its timer wake name the wall time the job is configured for, also when the next run falls after a daylight-saving change.
A job
0 3 * * *inAmerica/Los_Angeles, looked at on 2026-10-31, shows its next run as 2026-11-01 04:00 PST instead of 03:00, andis_duerefuses that advertised instant. A0 22 * * 1-5job read on the Friday before the fall-back shows Monday 23:00 PST instead of 22:00; the day before the spring-forward a0 22 * * *job shows 21:00 PDT.Why it matters
Every user whose zone observes daylight saving sees a wrong "Next run" for every cron job whose next run lies past the change, twice a year, and the timer arms on that wrong instant. Runs still happen only because the timer also polls every 30 seconds.
Not a goal
is_due, skip dates, backoff and the poll cap are untouched.*/15), as before; the poll still runs those slots._cron_occurrence_ts(the occurrence a run belonged to, for the same-occurrence and zone-change checks): it spans a minute or one run, not a DST change.What changed (motivation → approach → change)
A cron job's "Next run", and the instant its timer wakes on, now read the wall time the job is set for when that run falls after a daylight-saving change: 03:00 PST, not 04:00. When the job actually runs does not change.
The wrong time came from how the next run was asked for.
compute_next_run_tsand the timer boundary_next_cron_boundary_tshanded croniter a start carrying the job's zone, and croniter 2 then moves any run past a DST change by the offset change a second time. The schedule label already avoided this by stepping the plain wall clock.Both paths now go through one small helper,
_next_wall_clock_ts: croniter steps the zone's wall clock with no zone attached, and the zone is attached to the wall time it names. When the fall-back repeats that wall time and its first instant is not after now, the second instant is taken, so the result is never in the past. A wall time the spring-forward skips resolves as before (02:30 runs at 03:30 PDT). The cron spec (learn-cron-dashboard.md, Per-Job Timezone) says this.Builds on #24864 by @leonlaiyc.
Backwards compatibility
Compatible: no stored field, payload shape or due decision changes; only the next-run instant across a DST change moves to the configured wall time.
Removes nothing: the diff only changes how an existing next-run instant is computed.
Tests
test/test_cron_dst_next_run.pychecks, for the day before the fall-back, a Friday before it, the day before the spring-forward, a spring-forward gap time and the second pass of the repeated hour, thatcompute_next_run_tsand_next_cron_boundary_tsboth name the configured wall time and thatis_dueis true at it. All rows use fixed instants and an explicit zone.The spring-forward gap row pins the existing resolution and passes on main too; the other four fail there.
Determinism: 20/20 runs at
-n0, 10/10 at-n 4 --dist loadgroup --max-worker-restart=2besidetest_cron_dst_double_fire.pyandtest_cron_next_wake_boundary.py, and a shuffled order (seed 24853) of this file withtest_cron_dst_double_fire.py, all green.Proof: PROVEN test/test_cron_dst_next_run.py::test_the_next_run_is_the_configured_wall_time[0 3 * * *-now0-expected0], test/test_cron_dst_next_run.py::test_the_next_run_is_the_configured_wall_time[0 22 * * 1-5-now1-expected1], test/test_cron_dst_next_run.py::test_the_next_run_is_the_configured_wall_time[0 22 * * *-now2-expected2], test/test_cron_dst_next_run.py::test_the_next_run_is_the_configured_wall_time[30 1 * * *-now4-expected4] (head 55e3d3317d99)
Manual verification
N/A — unit coverage sufficient: the change is pure date arithmetic, pinned at fixed instants on both functions that read it.
Related Issues
Closes #24853
Sibling sweep
Swept: git grep -n "croniter(" -- src/
Sibling: src/kiro_crew/cron_service/schedule.py:946 -- not affected -- the other croniter calls in this file step UTC (117), a naive clock (146, and the schedule label at 179), or span one minute or one run with an aware start (
_cron_occurrence_ts, 946), never a DST changePattern harvest
Rule candidate: review-prompt
Pattern: croniter iterated from an aware zoneinfo start shifts a run past a DST change twice; step the naive wall clock and attach the zone
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license.