fix(cron): prevent double-fire after timezone offset migration (#28934) - #29218
Closed
Jiahui-Gu wants to merge 1 commit into
Closed
fix(cron): prevent double-fire after timezone offset migration (#28934)#29218Jiahui-Gu wants to merge 1 commit into
Jiahui-Gu wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #28934. After a Hermes timezone change (e.g.
Australia/Sydney→Europe/Berlin), recurring cron jobs whosenext_run_atwas persisted with the old offset would fire twice the same day: once early (the same UTC instant interpreted in the new tz), then again at the intended wall-clock time aftercompute_next_runre-advanced it.Root cause
cron/jobs.py::_get_due_jobs_locked()normalized storednext_run_atvia_ensure_aware()which only preserves the absolute UTC instant. A row stored as2026-05-19T21:00:00+10:00becomes2026-05-19T13:00:00+02:00after migration. At local13:02+02:00the scheduler considers it due even though the user's wall-clock intent was 21:00.Fix
Before treating a recurring
next_run_dt <= nowas due, compare the persisted offset against_hermes_now().utcoffset(). If they differ and the stored wall-clock time (offset rebased onto current tz) is still in the future, recomputenext_run_atin the current tz and skip dispatch this tick. The pre-existing stale-grace fast-forward path is untouched.Test plan
TestTimezoneMigrationDoubleFireintests/cron/test_jobs.py:next_run_at=2026-05-19T21:00:00+10:00, monkeypatches_hermes_nowto13:02+02:00get_due_jobs() == [](no early fire)next_run_atis rewritten in current tz to a future instantpytest tests/cron/test_jobs.py→ 80 passed🤖 Generated with Claude Code