Skip to content

[13.x] Fix sub-minute scheduling skips at minute boundaries#59331

Merged
taylorotwell merged 3 commits intolaravel:13.xfrom
JoshSalway:fix/framework-57070
Mar 25, 2026
Merged

[13.x] Fix sub-minute scheduling skips at minute boundaries#59331
taylorotwell merged 3 commits intolaravel:13.xfrom
JoshSalway:fix/framework-57070

Conversation

@JoshSalway
Copy link
Copy Markdown
Contributor

@JoshSalway JoshSalway commented Mar 22, 2026

Fixes #57070

repeatEvents() calls endOfMinute() directly on $this->startedAt, mutating the Carbon instance on each loop iteration. This corrupts the timestamp used for scheduling decisions, causing sub-minute tasks to skip executions at minute boundaries.

Fix uses copy()->endOfMinute() to preserve the original timestamp, and adds an early return if the minute boundary is crossed mid-iteration.

Test included that verifies startedAt is not mutated — fails on the buggy code, passes with the fix.

@github-actions
Copy link
Copy Markdown

Thanks for submitting a PR!

Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

The repeatEvents() method called endOfMinute() on startedAt directly,
which mutated the Carbon instance. This caused the boundary to shift
on each iteration, leading to skipped executions. Using copy() before
endOfMinute() preserves the original timestamp. Also adds an early
return if the minute boundary is crossed mid-iteration.

Fixes laravel#57070

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JoshSalway JoshSalway force-pushed the fix/framework-57070 branch from 910566b to 0ea0cc8 Compare March 22, 2026 23:49
Confirms the Carbon mutation bug is fixed — endOfMinute() was
modifying $this->startedAt in place on each loop iteration.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JoshSalway JoshSalway changed the title [11.x] Fix sub-minute scheduling skips at minute boundaries [13.x] Fix sub-minute scheduling skips at minute boundaries Mar 25, 2026
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JoshSalway JoshSalway marked this pull request as ready for review March 25, 2026 11:50
@taylorotwell taylorotwell merged commit 7106836 into laravel:13.x Mar 25, 2026
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug Report: Laravel 'scheduled:run' skipping execution of the scheduled commands every next minute

2 participants