Skip to content

Fail background jobs interrupted by shutdown#515

Merged
msaroufim merged 2 commits into
mainfrom
agent/recover-interrupted-jobs
Jul 14, 2026
Merged

Fail background jobs interrupted by shutdown#515
msaroufim merged 2 commits into
mainfrom
agent/recover-interrupted-jobs

Conversation

@msaroufim

@msaroufim msaroufim commented Jul 13, 2026

Copy link
Copy Markdown
Member

What changed

  • catch worker cancellation while a background submission is active
  • atomically mark the interrupted job as failed with a clear resubmission message
  • update only pending/running rows so a completion racing with shutdown cannot be overwritten

Why

KernelBot stores accepted submissions in an in-memory worker queue. During a deployment, cancelling a worker propagated CancelledError through the active submission task, but that exception bypassed the normal failure handlers. The database row therefore remained running indefinitely, as happened to submission 873664.

Benefits

  • deployment-interrupted submissions no longer appear to run forever
  • users receive a terminal status and an actionable request to resubmit
  • the conditional database update protects successfully completed jobs from shutdown races

This intentionally does not auto-retry submissions: automatic retry could duplicate an execution that already reached Modal before the local worker was terminated.

Validation

  • uv run pytest tests/test_background_submission_manager.py -q (10 passed, including shutdown against real PostgreSQL)
  • uv run pytest tests/test_leaderboard_db.py::test_leaderboard_submission_basic -q (1 passed)
  • uv run ruff check src/libkernelbot/background_submission_manager.py tests/test_background_submission_manager.py
  • git diff --check

@github-actions

Copy link
Copy Markdown

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  src/libkernelbot
  background_submission_manager.py 288-289, 335-336
  leaderboard_db.py
  utils.py
Project Total  

This report was generated by python-coverage-comment-action

@msaroufim msaroufim marked this pull request as ready for review July 14, 2026 00:19
@msaroufim msaroufim merged commit 4ae1eda into main Jul 14, 2026
4 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.

1 participant