Skip to content

fix(scheduler): don't process unfinished intervals for crons with an hour range - #6320

Open
Naman-Gururani wants to merge 1 commit into
SQLMesh:mainfrom
Naman-Gururani:fix/cron-floor-window
Open

Naman-Gururani wants to merge 1 commit into
SQLMesh:mainfrom
Naman-Gururani:fix/cron-floor-window

Conversation

@Naman-Gururani

Copy link
Copy Markdown

Description

Models with a cron like 0 9-17 * * * can silently lose rows.

Outside of the cron's hours, cron_floor can return a time in the future:

now:        2026-12-02 20:30
cron_floor: 2026-12-03 08:00   (expected 2026-12-02 17:00)

So a sqlmesh run in the evening processes an interval that hasn't ended and marks it as complete. The rows that arrive later in that interval are never loaded, and there's no error. In my DuckDB test the model ended up with 386 of 390 rows.

cron_floor always called get_prev(estimate=True), even though its own default is estimate=False. The estimate uses the gap between the next few ticks, which looks hourly here. Now it passes on its own estimate argument.

Each cron_floor call gets slower, from about 55 to 107 µs for @hourly on my machine.

Test Plan

  • New test test_missing_intervals_cron_with_hour_range. It fails on main.
  • I ran the fast tests in tests/core, tests/schedulers and tests/utils on main and on this branch. Both runs hang near the end on my Windows machine, in test_context.py. The 2,511 tests that finished in both runs had the same results.

Checklist

  • I have run make style and fixed any issues (I ran ruff on the two files)
  • I have added tests for my changes (if applicable)
  • All existing tests pass (make fast-test) (see the test plan)
  • My commits are signed off (git commit -s) per the DCO

…hour range

For a cron like `0 9-17 * * *`, `cron_floor` could return a time in the
future outside of the cron's hours, because it estimated the previous
tick. The run then marked an interval that hadn't ended as complete, and
the rows that arrived later were never loaded.

Signed-off-by: Naman Gururani <gururaninaman@gmail.com>
@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

_Node.cron_floor now passes its estimate argument to get_prev. Previously, it always used estimate=True. This prevents scheduled runs from marking unfinished intervals complete for crons with an hour range, such as 0 9-17 * * *. Adds test_missing_intervals_cron_with_hour_range in tests/core/test_snapshot.py. Test results: not available.

Scope: +1/-1 lines, excluding tests and docs. Changed file under sqlmesh/core: sqlmesh/core/node.py. No changes under sqlmesh/utils.

cron_floor now uses the caller’s estimate value for the previous-run lookup. A new test checks missing intervals for an hourly schedule restricted to 09:00–17:00.

Changes: Cron floor estimate handling

Layer / File(s) Summary
Apply estimate setting to cron flooring
sqlmesh/core/node.py, tests/core/test_snapshot.py
cron_floor passes its estimate argument to get_prev. The test checks that a 20:30 timestamp floors to 17:00 and yields missing intervals from 15:00 through 17:00.

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Bug fix

Suggested labels: Scheduler: Built-in

Suggested reviewers: mday-io

Merge Risk: Minimal · up to 86f2a

This change stops scheduled runs from marking unfinished intervals complete for crons restricted to certain hours, and a regression test covers that case. No merge-blocking risk was found; the only cost is a small per-call slowdown in cron flooring.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: cron_floor with an hour range no longer lets the scheduler process intervals that have not finished. The raw summary and objectives both describe passing the estimate …
Description check Passed The description follows the template sections: Description, Test Plan, and Checklist. It explains the bug with a concrete example (cron_floor returning 2026-12-03 08:00 instead of 2026-12-02 17:00), t…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: cron_floor with an hour range no longer lets the scheduler process intervals that have not finished. The raw summary and objectives both describe passing the estimate argument through to get_prev, and a new test for the hour-range case. The title uses the fix(scheduler) prefix and is specific enough for a teammate scanning history.

Full details: Description check

Explanation

The description follows the template sections: Description, Test Plan, and Checklist. It explains the bug with a concrete example (cron_floor returning 2026-12-03 08:00 instead of 2026-12-02 17:00), the cause (get_prev always using estimate=True), the performance cost, and the new test. Checklist items are partly unchecked, and the author says the full fast test suite hung on Windows, so the test results are incomplete. The required information is still present.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between edb8cc0 and 86f2ae8.

Files selected for processing: 2

  • sqlmesh/core/node.py
  • tests/core/test_snapshot.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

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.

1 participant