Repository navigation
fix(repo): a cell does not prepare or start after Ctrl-C has set the halt - #935
Conversation
…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>
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 5 selected item(s). CI at Review details
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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
🚀 New features to boost your workflow:
|
vchamarthi
left a comment
There was a problem hiding this comment.
🟢 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 |
Summary
On
main,_stop_on_interrupt(dokimi/dokimi/repos/runner.py) runspool.shutdown(wait=False, cancel_futures=True)first andhalt_and_kill_started()after it, and nothing checks the halt when a cell begins: only the agent container is refused (_trackincontainer.py). A worker that takes a queued cell between the interrupt and the halt, or after the cancel, goes through_reserve,prepare_workspaceand 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 onmain's code: with the halt set before the workers run, the cell function is reached (AssertionError: a cell started after the haltin the new test), and the halt is stillFalsewhen 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 theKeyboardInterrupthandler 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_interruptcallshalt_and_kill_started()beforepool.shutdown(wait=False, cancel_futures=True); both stay in the retry loop, with thestartedlogic unchanged. Its docstring says the signal-wait window remains.run_batch'sone(cell)calls_drop_if_halted(name)right after the cell name, before the unsupported and_reservecode. The cell raisesBatchInterrupted(the same exception_trackraises), so nothing is reserved, prepared or recorded and a resume runs it again. The check is a helper becauserun_batchwas 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/test_repo_interrupt.py: a cell that starts after the halt drops without callingrun_cell, preparing a workspace, creating a run directory or reserving spend; and_stop_on_interruptsets the halt before it cancels the pool. No existing test is edited;test_ctrl_c_starts_no_queued_cellis untouched.Risk
A cell that starts while the halt is set now raises
BatchInterruptedinstead 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 changerepo-evaluation-contract.md(their hunks there are elsewhere in the file, not near §9's Ctrl-C paragraph). The edits here are inrun_batch'sone()(one added line, away from therun_cellcall that #781 changes), the new_drop_if_haltedand_stop_on_interrupt, and one paragraph of §9; #787 changesAgentOptionsandexecution_record. I read their diffs of these files and none touches the same lines.Testing
On Linux, at
9b58e8a(onmaind4023b9):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.main's code (withcontainer.haltedadded to it so the test can call it),tests/test_repo_interrupt.pygives2 failed, 8 passed: the cell-after-halt test fails ona cell started after the halt, the order test onassert ([False] and False is True)._drop_if_haltedcall fails the cell-after-halt test; cancelling before the halt in_stop_on_interruptfails the order test.repo runwith 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
pytestpassesruff,mypy, and schema checks passAGENTS.mdraise/exit and test names the doc, contract or issue it traces to.github/.licenserc.yaml)