Skip to content

fix(cron): serialize get_due_jobs writes and add parallel state corruption regression tests - #16509

Closed
chinadbo wants to merge 1 commit into
NousResearch:mainfrom
chinadbo:fix/b3-cron-job-state-corruption
Closed

fix(cron): serialize get_due_jobs writes and add parallel state corruption regression tests#16509
chinadbo wants to merge 1 commit into
NousResearch:mainfrom
chinadbo:fix/b3-cron-job-state-corruption

Conversation

@chinadbo

Copy link
Copy Markdown
Contributor

Summary

  • get_due_jobs() in cron/jobs.py called load_jobs() + conditional save_jobs() without holding _jobs_file_lock, creating a race with concurrent mark_job_run() and advance_next_run() calls from the thread pool
  • Fix: wrap get_due_jobs() body with _jobs_file_lock for its entire load+save cycle, consistent with all other write paths
  • Add 2 concurrency regression tests: 3 simultaneous mark_job_run() calls verify no state overwrites; 10-thread stress test verifies all jobs land with correct last_status

Test plan

  • tests/cron/test_jobs.py — 2 new concurrency tests in TestMarkJobRunConcurrency
  • 249 cron tests pass, 5 skipped (croniter-dependent, expected)

🤖 Generated with Claude Code

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cron Cron scheduler and job management labels Apr 27, 2026
get_due_jobs() called load_jobs() and save_jobs() without holding
_jobs_file_lock, creating a race with the locked mark_job_run() and
advance_next_run(). Wrap get_due_jobs() with the lock (delegating to a
new _get_due_jobs_locked() inner function) so all load→modify→save
cycles are serialised. Add two regression tests: one verifying 3
concurrent mark_job_run() calls each land their correct last_status and
last_run_at without overwrites, and a stress test confirming 10 parallel
calls each increment their job's completed count to exactly 1.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@teknium1

teknium1 commented May 4, 2026

Copy link
Copy Markdown
Contributor

Salvaged via #19874 onto current main - your commit authorship was preserved. Thanks!

@teknium1 teknium1 closed this May 4, 2026
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 P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants