fix(cron): prevent long-running scheduled scripts from running twice - #63406
Closed
morluto wants to merge 1 commit into
Closed
fix(cron): prevent long-running scheduled scripts from running twice#63406morluto wants to merge 1 commit into
morluto wants to merge 1 commit into
Conversation
Collaborator
|
Merged via #64365. Your commit cherry-picked with authorship preserved (rebase-merge). The test coverage (heartbeat-keeps-job-alive, captured-claim-owner, skips-recurring) is excellent — especially the threading.Event-based barriers for deterministic race-window reproduction. |
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.
What does this PR do?
Prevents long-running one-shot scheduled scripts from being started a second time while their original execution is still active.
One-shot jobs use a time-limited run claim to prevent duplicate execution. Existing code refreshes that claim while the agent is running, but not while either blocking script path is running:
no_agentScripts can run longer than the claim lifetime. Once the claim appears stale, another scheduler scan can claim and start the same job again.
This PR keeps the existing owner-bound claim alive while either script path is running. The heartbeat:
Recurring, unclaimed, and quick jobs are unchanged. Script timeout, output, delivery, and wake-gate behavior are also unchanged.
Related Issue
Follow-up to #62002, #62014, and #62155.
No new issue was opened because this is a missed sibling path of the existing run-claim heartbeat fix. Searches of open and merged PRs found no submitted fix covering the blocking script paths.
Type of Change
Changes Made
How to Test
uv pip install -e '.[all,dev]' pytest tests/cron/test_script_claim_heartbeat.py tests/cron/test_scheduler.py tests/cron/test_jobs.py -qResult:
The warnings are existing unawaited-coroutine warnings outside this change.
Also validated:
git diff --check: cleanTested on Linux with Python 3.12.3.
Checklist
Code
Documentation & Housekeeping
AGENTS.mdupdate is neededScreenshots / Logs
Not applicable. This change affects background cron coordination and is covered by the regression tests above.
Reviewer Guidance
Suggested review order:
cron/scheduler.pytests/cron/test_script_claim_heartbeat.py