Repository navigation
fix(scheduler): a cron's next fire time never goes backwards at a DST fall-back (#3940) - #3951
Merged
Merged
Conversation
… fall-back (#3940) APScheduler 3.11.0's CronTrigger answered a fire time earlier than the previous one at every fall-back for minute-stepped crons with hour='*' in a zone leaving summer time (*/30 in Europe/Lisbon: 01:00Z, 00:30Z, 01:00Z, ...), with pytz and zoneinfo zones alike. Job._get_run_times never returned: the scheduler pinned a core and grew without bound, and two hosts ran out of memory on 2026-10-25. The US fall-back is 2026-11-01. - APScheduler 3.11.0 -> 3.11.3 (fixed since 3.11.1) in the scheduler and backend images, kept equal per the #1823 parity guard. - tests/requirements-test.txt pins apscheduler==3.11.3 exactly. Its >=3.11.0 floor let CI run a fixed release while the images ran the broken one, so a fold test could pass on a broken production. - MonotonicCronTrigger (src/scheduler/cron_trigger.py), registered for every user schedule: an answer not after the previous fire time is retried from previous + 1s in UTC (on 3.11.0 that alone yields the correct schedule), else clamped to previous + 1 minute in UTC. Logged once per trigger; never returns None. Compared and added on UTC instants: same-zone datetimes compare by wall clock, and local arithmetic resets fold. - The #1823 _add_job tests stub MonotonicCronTrigger, the name the service now constructs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
obasilakis
approved these changes
Oct 26, 2026
obasilakis
left a comment
Contributor
There was a problem hiding this comment.
Approving. Mutation-checked: on APScheduler 3.11.0 all 10 fall-back cases go red; reverting the trigger registration, the UTC comparison, the UTC fallback or the retry each turns specific tests red. Ran the real job loop for Lisbon, London, Berlin, New York and Los Angeles under both tz libraries; fire times are monotonic and match 3.11.3.
Before merge:
- Add the
uilabel. The PR touchesdocker/, so the high-risk lane needsfrontend-e2e, which was skipped. dev-ciis red (#3931); wait for green.- US fall-back is 2026-11-01 06:00 UTC, so this needs to reach
mainand deploy before then.
Non-blocking:
docs/memory/feature-flows/scheduling.md:728still saysapscheduler==3.11.0.docs/memory/feature-flows/scheduler-service.md:180and:747describe_add_jobregistering a plainCronTrigger; should nameMonotonicCronTriggerand #3940.- #3940 items 3 (scheduler memory limit) and 4 (healthcheck that sees the job loop) have no follow-up issue yet.
src/scheduler/cron_trigger.py: when the retry returnsNonebecauseend_datehas passed, the guard still synthesizes a fire one minute later. Unreachable today (user schedules set no end date); returningNonethere would close it.
5 tasks
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
At a DST fall-back, APScheduler 3.11.0's
CronTriggeranswers a fire time earlier than the previous one for a minute-stepped cron withhour='*'in a zone leaving summer time. For*/30in Europe/Lisbon it cycles 01:00Z, 00:30Z, 01:00Z, …, and it does the same with pytz andzoneinfozones.Job._get_run_timesthen never returns: the scheduler pins a core and grows without bound. That took down two production hosts on 2026-10-25. The US fall-back is 2026-11-01 06:00 UTC.APScheduler
3.11.0→3.11.3(fixed since 3.11.1) in the scheduler and backend images, kept equal per the bug: legacy IANA timezone aliases (Europe/Kiev et al.) crash schedule creation with a 500 — pytz accepts, APScheduler's zoneinfo lookup can't resolve them inside the shipped image #1823 parity guard.tests/requirements-test.txtpinsapscheduler==3.11.3exactly. Its>=3.11.0floor let CI run a fixed release while the images ran the broken one, so a fold test could pass on a broken production (the bug: legacy IANA timezone aliases (Europe/Kiev et al.) crash schedule creation with a 500 — pytz accepts, APScheduler's zoneinfo lookup can't resolve them inside the shipped image #1823 lesson; a local venv here was on 3.11.2).Guard:
MonotonicCronTrigger(src/scheduler/cron_trigger.py), registered by_add_jobfor every user schedule. When the trigger answers a time that isn't after the previous one:previous + 1sin UTC, which on 3.11.0 alone gives the correct schedule at every fold;previous + 1 minutein UTC.It logs once per trigger and never returns
None(which would remove the job). All comparisons and arithmetic use UTC instants: two datetimes with the same zone compare by wall clock, and local arithmetic resetsfold, so either mistake lets a backwards time through inside the repeated hour.Verified against the local stack
I reproduced the job loop (
Job._get_run_timesjust after the fold, trigger built the way_add_jobbuilds it) in two images, each with--network noneand a 256 MiB limit. The live scheduler was not touched.*/30, 11-01*/30, 10-25trinity-661-scheduler(APScheduler 3.11.0)The branch image's real
SchedulerService._add_jobregistersMonotonicCronTrigger.Changes
docker/scheduler/requirements.txt,docker/backend/Dockerfile,src/scheduler/pyproject.toml,tests/requirements-test.txt: the version pinssrc/scheduler/cron_trigger.py(new) andsrc/scheduler/service.py: the guard and its wiringtests/unit/test_3940_cron_dst_fold.py(new, 28 tests),tests/registry.jsontests/unit/test_1823_scheduler_permanent_classification.py: its 4 stubs patchMonotonicCronTrigger, the name_add_jobnow constructsdocs/memory/requirements/scheduling.md, plus a learnings fragment on the version-floor trapTest Plan
cd tests && pytest unit/test_3940_cron_dst_fold.py: 28 passed on the pinned 3.11.3. It covers:_add_job.tests/scheduler_tests: 235 passed.Merging to
devis not enough: this has to be onmainand deployed before 2026-11-01 06:00 UTC. Any instance still on 3.11.0 with anAmerica/**/Nschedule will spin at the US fall-back. Until it's deployed, the stopgap is to pause such schedules or move them to UTC.Follow-ups, out of scope here: a
mem_limitforschedulerindocker-compose.prod.yml, and a healthcheck that reflects the job loop (/healthstayed green while the process spun).Fixes #3940
🤖 Generated with Claude Code