Skip to content

fix(repo): a cell does not prepare or start after Ctrl-C has set the halt - #935

Merged
antonwolfy merged 1 commit into
intel:mainfrom
antonwolfy:fix/ctrl-c-queued-cell
Nov 18, 2026
Merged

antonwolfy merged 1 commit into
intel:mainfrom
antonwolfy:fix/ctrl-c-queued-cell

Conversation

@antonwolfy

Copy link
Copy Markdown
Contributor

Summary

On main, _stop_on_interrupt (dokimi/dokimi/repos/runner.py) runs pool.shutdown(wait=False, cancel_futures=True) first and halt_and_kill_started() after it, and nothing checks the halt when a cell begins: only the agent container is refused (_track in container.py). A worker that takes a queued cell between the interrupt and the halt, or after the cancel, goes through _reserve, prepare_workspace and the spend bookkeeping before the halt refuses its agent container, so the log and the batch spend show a cell the user did not mean to run. Replaying that on main's code: with the halt set before the workers run, the cell function is reached (AssertionError: a cell started after the halt in the new test), and the halt is still False when the queue is cancelled (assert ([False] and False is True)).

The fix is the issue's first option, narrowed to what a Python handler can do: the stop flag is the existing halt in container.py. It is set as the first thing the KeyboardInterrupt handler does, and each cell checks it before it reserves, prepares or starts anything. The second option (submit cells as workers free up) is not taken: it changes _run_cells's contract (futures, error propagation) and leaves the same window, since the signal waits for the main thread.

That window stays: Python runs the handler in the main thread only when it next executes bytecode, so a cell a worker takes before that is not stopped by this change. What is closed is every cell that starts after the halt is set.

Closes #920

Changes

  • container.halted() reads the halt under _live_lock.
  • _stop_on_interrupt calls halt_and_kill_started() before pool.shutdown(wait=False, cancel_futures=True); both stay in the retry loop, with the started logic unchanged. Its docstring says the signal-wait window remains.
  • run_batch's one(cell) calls _drop_if_halted(name) right after the cell name, before the unsupported and _reserve code. The cell raises BatchInterrupted (the same exception _track raises), so nothing is reserved, prepared or recorded and a resume runs it again. The check is a helper because run_batch was at the complexity cap of 10.
  • docs/repo-evaluation-contract.md §9: states the order (halt first) and that a cell taken after the halt is dropped before it reserves budget or prepares a workspace. The contract's promises are unchanged.
  • Tests in tests/test_repo_interrupt.py: a cell that starts after the halt drops without calling run_cell, preparing a workspace, creating a run directory or reserving spend; and _stop_on_interrupt sets the halt before it cancels the pool. No existing test is edited; test_ctrl_c_starts_no_queued_cell is untouched.
  • Changelog fragment (Fixed).

Risk

A cell that starts while the halt is set now raises BatchInterrupted instead of going on to the agent container; the halt is only set by an interrupt, and it is cleared once the workers return. The kills now run before the queue is cancelled, so a started container is killed a moment earlier. Output and stored records are unchanged otherwise.

Open PRs #781 and #787 also change runner.py, and #779, #781, #787, #891 and #898 change repo-evaluation-contract.md (their hunks there are elsewhere in the file, not near §9's Ctrl-C paragraph). The edits here are in run_batch's one() (one added line, away from the run_cell call that #781 changes), the new _drop_if_halted and _stop_on_interrupt, and one paragraph of §9; #787 changes AgentOptions and execution_record. I read their diffs of these files and none touches the same lines.

Testing

On Linux, at 9b58e8a (on main d4023b9):

  • make ci-local: 36 passed, 0 failed, 14 skipped (docker-and-network smoke, pinned Claude Code install, matrix legs, deploy and report jobs, fuzz, conda-forge, semgrep). 23536 tests passed, 19 skipped.
  • On main's code (with container.halted added to it so the test can call it), tests/test_repo_interrupt.py gives 2 failed, 8 passed: the cell-after-halt test fails on a cell started after the halt, the order test on assert ([False] and False is True).
  • Mutants: dropping the _drop_if_halted call fails the cell-after-halt test; cancelling before the halt in _stop_on_interrupt fails the order test.
  • Not run: the matrix legs on Python 3.11, 3.12 and 3.14; a real Ctrl-C against repo run with Docker.

Open questions

None.

Revert

A plain revert restores the old order (cancel, then halt) and the cell that starts after the halt. Nothing is stored.

Checklist

  • Tests added/updated and pytest passes
  • ruff, mypy, and schema checks pass
  • Docs updated (or N/A) — see the docs-drift checklist in CONTRIBUTING.md
  • Self-reviewed per "Before opening a PR" in AGENTS.md
  • Each new raise/exit and test names the doc, contract or issue it traces to
  • No ad-hoc run artifacts committed
  • New files carry the SPDX license header (or are exempt in .github/.licenserc.yaml)

…halt (intel#920)

Ctrl-C cancelled the queued cells first and set the halt after, and nothing checked the halt before a cell reserved budget and prepared its workspace: only the agent container was refused.

_stop_on_interrupt now sets the halt (and kills the started containers) before it cancels the queue, and each cell checks container.halted() first and drops with BatchInterrupted, with nothing reserved, prepared or recorded, so a resume runs it again. A cell a worker takes before the main thread runs the signal handler is still not stopped: the signal waits for the main thread.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy
antonwolfy requested a review from a team as a code owner November 18, 2026 16:01
@antonwolfy antonwolfy self-assigned this Nov 18, 2026
@exai-bot

exai-bot commented Nov 18, 2026 •

Copy link
Copy Markdown

✅ OpenCodeReview: Review complete: 0 finding(s) across 5 selected item(s).

CI at 9b58e8a: 30 passing, 3 skipped.

Review details
  • Commit reviewed: 9b58e8a against merge base d4023b9
  • Coverage: 5 files in 1 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 92k tokens (44k from cache), 34s
  • Tool calls: 7 (5 file_read, 1 ci_status, 1 local_check_results)
  • Ctrl-C handling to halt repository evaluation before the next cell: 5 files

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.84%. Comparing base (d4023b9) to head (9b58e8a).
⚠️ Report is 1 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #935   +/-   ##
=======================================
  Coverage   95.83%   95.84%           
=======================================
  Files         442      442           
  Lines       58788    58815   +27     
  Branches    10146    10145    -1     
=======================================
+ Hits        56342    56369   +27     
  Misses       1521     1521           
  Partials      925      925           
Files with missing lines Coverage Δ
dokimi/dokimi/repos/container.py 96.23% <100.00%> (+0.06%) ⬆️
dokimi/dokimi/repos/runner.py 97.76% <100.00%> (-0.21%) ⬇️

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vchamarthi vchamarthi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approved · reviewed 9b58e8a

Next: nothing required from @antonwolfy.

Verified on 9b58e8a: ✅ changed tests: 10 passed, fail on main · ✅ full suite with main merged in: 23547 passed · ✅ merges onto main · ✅ 4 broken variants of the changed code: 4 caught by the tests · 3 mutations tried · 5 edge inputs tried

13 checks behind it, each with its evidence
Area What holds How
Halt before cancel test_the_interrupt_sets_the_halt_before_it_cancels_the_queued_cells passes on the head, and the Ctrl-C tests in tests/test_repo_interrupt.py pin that the halt is set before the queue is cancelled and cleared once the workers return (10 passed on the head) tests on the head, edge input (cli)
Drop before reserve Replayed on the merge base, the cell-after-halt test fails with a cell started after the halt and the order test fails on the missing halted; both pass on the head (2 of 10 fail on main) same tests on main
Cell after halt A cell that starts while the halt is set drops with BatchInterrupted before it calls run_cell, prepares a workspace, makes a run directory or reserves spend; test_a_cell_that_starts_after_the_halt_drops_before_reserving_preparing_or_starting_an_agent passes on the head tests on the head, edge input (concurrency)
Queued cells under halt Eight cells on three workers with the halt set before the pool runs: none reaches the cell body, and the pool raises the drop from _drop_if_halted ran it, edge input (concurrency)
Empty queue An empty queue under the halt returns from _run_cells without raising ran it, edge input (collections)
Halted flag halted() is False after clear_halt(), True under halt_and_kill_started(), and False again after the clear ran it
Section 9 wording dokimi/docs/repo-evaluation-contract.md §9 and the changelog fragment say the halt is set first and a cell taken after it is dropped before it reserves budget or prepares a workspace; _stop_on_interrupt and _drop_if_halted do that, and the drop test passes on the head tests on the head, edge input (text)
Mutation of drop call Dropping the _drop_if_halted(name) call in run_batch's one is caught by the changed tests broke the code, tests caught it
Mutation of drop condition Negating the condition in _drop_if_halted is caught by the changed tests broke the code, tests caught it
Mutation of halted Returning None from halted() is caught by the changed tests broke the code, tests caught it
Callers _run_cells and _stop_on_interrupt keep their signatures and their callers in tests/test_repo_interrupt.py pass on the head; halted is new and only _drop_if_halted calls it tests on the head
Merge The PR merges onto main with no conflict merge onto main
Full local check make ci-local passes with main merged in: the whole run exits 0 full suite, main merged in

@antonwolfy
antonwolfy merged commit a598f80 into intel:main Nov 18, 2026
33 checks passed
@antonwolfy
antonwolfy deleted the fix/ctrl-c-queued-cell branch November 18, 2026 20:47
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.

repo run: a queued cell can start after Ctrl-C, before the main thread cancels the queue

4 participants