Skip to content

fix(cron): prevent long-running scheduled scripts from running twice - #64365

Merged
kshitijk4poor merged 1 commit into
NousResearch:mainfrom
kshitijk4poor:fix/63406-salvage
Jul 14, 2026
Merged

fix(cron): prevent long-running scheduled scripts from running twice#64365
kshitijk4poor merged 1 commit into
NousResearch:mainfrom
kshitijk4poor:fix/63406-salvage

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Summary

Salvage of #63406 (CI blocked for first-time contributor). Keeps the run_claim alive for one-shot jobs while blocking script paths run (no_agent and pre-agent wake-gate scripts), preventing a second scheduler scan from dispatching the same job when the script outlives the claim TTL.

Sibling of #62002/#62014 (which added heartbeat for the agent path but missed the script paths).

Changes

  • cron/scheduler.py: adds _run_job_script_with_claim_heartbeat() — wraps _run_job_script with a daemon-thread heartbeat for one-shot jobs with a claim owner. Uses contextvars.copy_context() to preserve scheduler-scoped ContextVar state. Captures the claim owner at dispatch time so a stale runner can't refresh a replacement owner's claim.
  • Replaces both _run_job_script calls in the no_agent path and the pre-agent wake-gate path.
  • Tests: test_script_claim_heartbeat_keeps_job_alive_past_ttl, test_script_heartbeat_uses_captured_claim_owner, test_script_heartbeat_skips_recurring_jobs.

Attribution

Cherry-picked from @morluto's #63406 with authorship preserved.

Validation

15 passed (3 new + 12 existing cron tests). ruff + py_compile clean.

@alt-glitch alt-glitch added type/bug Something isn't working comp/cron Cron scheduler and job management sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages P1 High — major feature broken, no workaround labels Jul 14, 2026
@kshitijk4poor
kshitijk4poor merged commit cd53718 into NousResearch:main Jul 14, 2026
59 of 61 checks passed
@kshitijk4poor
kshitijk4poor deleted the fix/63406-salvage branch August 5, 2026 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cron Cron scheduler and job management P1 High — major feature broken, no workaround sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants