Repository navigation
fix(tier3): stop running and queued Harbor jobs on Ctrl+C - #291
Conversation
Every Harbor job runs on a worker thread in its own process group or session, and Python delivers Ctrl+C only to the main thread. Pressing Ctrl+C during `tier3 evaluate` therefore left the running Harbor jobs going: the agent pool's executor exit waited for them to finish and then still started agents queued behind --max-agents, so the command appeared to hang for the rest of the run. When an interrupt escapes the agent pool, the coordinator now cancels queued agents and then sets a cancellation event that is passed down to every Harbor launch. The bounded Harbor runner checks the event before launching and on each output poll; once it is set, the runner contains the process group or task tree with the existing timeout teardown and raises a BaseException-derived cancellation, so ordinary failure handlers do not move on to the next condition or stop-on-pass attempt. Progress reports the unfinished stages and the run as interrupted instead of failed unexpectedly. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cancellation reused the timeout teardown, which sends SIGTERM and kills the Harbor process group 0.1 seconds later. Harbor handles SIGTERM by stopping its trial environments, and the secure Docker environment removes the main container when an exec is interrupted, but neither could finish in that window. Ctrl+C could therefore leave trial containers and in-container agent processes running. An interrupted job now gets SIGTERM and up to 30 seconds for the leader to exit before the group is killed. The coordinator reports the agents that are stopping, and a second Ctrl+C ends the wait; a third one propagates. Timeout and output-overflow teardown keep the short grace, and Windows still stops the task tree with taskkill. _run_harbor also checks the cancellation before refreshing Google ADC credentials, so a queued condition or stop-on-pass attempt makes no token request after an interrupt. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
rng1995
left a comment
There was a problem hiding this comment.
Reviewed the full diff plus runner.py in context, and ran lint and the tests locally. No P1/P2/P3 findings.
Checked: the cancellation flag is honored before the credential refresh, before launch, and in the poll loop; queued agents are cancelled before any worker is released; the BaseException subclass bypasses every except Exception retry/record path (sequential --stop-on-pass, condition pool, agent pool); the grace period ends early on a second Ctrl+C and a third propagates; Windows keeps the immediate taskkill path; progress reports interrupted rather than unexpected failure. CHANGELOG entry is under Unreleased/Fixed and the docs match the behavior.
Local results: ruff check clean; the 14 new cancel/interrupt tests pass. In the full test_harbor_runner_status.py + test_tier3_progress.py run, test_bounded_harbor_process_timeout_preserves_redacted_diagnostic_tail failed with a 0.1s timeout on my slow machine. It fails identically on origin/main, so it is a pre-existing timing flake, not this PR.
Reviewed with Claude Code.
4965bb1 to
21858e0
Compare
Conflicts: CHANGELOG.md (kept both Unreleased/Fixed entries). Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
chrisknvidia
left a comment
There was a problem hiding this comment.
I traced the interrupt path through the agent pool, both condition paths and the bounded process runner and found nothing blocking. The order is right: the queue is drained before the flag is set, the gate runs before the ADC refresh and before Popen, the cancellation is a BaseException so no except Exception or the OSError/RuntimeError mapping can turn it into a failed attempt, and the second and third Ctrl+C behave as described (after the third, the executor exit only joins workers that are already being SIGKILLed). The new tests would fail without the fix. One optional follow-up in the notes.
Not blocking, and fine as a follow-up: only SIGINT is handled. If the CLI itself gets SIGTERM or SIGHUP (a CI cancel, kill, closing the terminal), the process just dies and the Harbor sessions keep running exactly as before. Mapping SIGTERM to KeyboardInterrupt on the main thread of the command would reuse this whole path.
Conflicts: CHANGELOG.md kept main's new Fixed entries unchanged and moved the Ctrl+C entry to the end of Fixed, after main's new entries; src/skillevaluator/tier3/harbor/runner.py keeps both new _run_agent_pair keyword parameters (main's with_agent_import_path and this branch's cancellation), which already flows to both job launch paths. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve conflicts with main: keep main's new Unreleased entry in CHANGELOG.md and put this PR's entry after it; in runner.py keep both the PR's cancellation keyword and main's additional_arms/additional_arm_errors (#321) in _run_agent_pair and its caller. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve the CHANGELOG.md conflict: keep main's Ctrl+C entry (#291) and add this PR's SkillSpector partial-scan entry after it. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve runner.py conflicts with the Ctrl+C cancellation from #291: keep both the PR's n_concurrent keyword and main's cancellation keyword on _run_stop_on_pass_variant and on its call in _run_agent_pair. The PR's per-case workers already pass cancellation to _run_harbor, so concurrent stop-on-pass cases stop on Ctrl+C like the sequential path did. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve the CHANGELOG.md conflict: keep main's Ctrl+C entry (#291) and add this PR's RAGAS scorer entry after it. Signed-off-by: Narendran Raghavan <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Pressing Ctrl+C during
tier3 evaluatedid not stop the run. Every Harbor job runs on a worker thread (agent pool, then condition pool, then_run_bounded_harbor_process) in its own POSIX session or Windows process group. Python delivers Ctrl+C only to the main thread, which sits in the agent pool'swait()loop. As a result:KeyboardInterruptleft thewith ThreadPoolExecutorblock, andshutdown(wait=True)blocked until every running Harbor job finished on its own. Harbor's poll loop never checked for cancellation, and by default it has no outer deadline.--max-agentsstill started after the interrupt, because the executor exit does not cancel pending work.A test-local reproduction on
mainsends a real SIGINT while two agents run withmax_agents=1and the stand-in Harbor command spawns a grandchild. After the interrupt,run_harbor_evalblocked for 120 s and launched both of the queued agent's jobs. The runner-level regression test below covers the same scenario.What changes:
_run_harbor_eval_implcreates a_HarborRunCancellation(arequestedand aforcedevent). It is passed to each agent worker through_run_agent_pair,_run_stop_on_pass_variantand_run_harbor, down to_run_bounded_harbor_process.BaseException) escapes the agent pool loop, the coordinator callsexecutor.shutdown(cancel_futures=True)and then setsrequested. Queued agents are cancelled before any worker is released, so none of them can start. The coordinator then waits for the running agents and marks each one as "stopping Harbor jobs; press Ctrl+C again to skip up to 30s of environment cleanup". A second Ctrl+C setsforced. A third one propagates._run_harborchecks the cancellation before refreshing Google ADC credentials, so a queued condition or--stop-on-passattempt makes no token request after an interrupt._run_bounded_harbor_processchecks it again beforePopenand on each output poll. A job that has not started is never launched._HARBOR_RUN_CANCEL_GRACE_SECONDS) for the Harbor leader to exit, then SIGKILLs and reaps the group. Harbor 0.24 maps SIGTERM toKeyboardInterruptand stops its trial environments. The default secure Docker environment removes the main container when an exec is interrupted. Settingforcedends the wait at once. Timeout and output-overflow teardown keep their existing 0.1 s grace._HarborRunCancelledErrorderives fromBaseException, likeKeyboardInterruptandasyncio.CancelledError. Handlers that record ordinary job failures (except Exception, or_run_harbor'sOSError/RuntimeError/UnicodeErrormapping) therefore cannot turn a cancellation into a failed attempt and move on to the next condition or attempt.KeyboardInterrupt,run_harbor_evalcallsfail_unfinished(interrupted=True). Open stages then read "interrupted before completion" and the run reads "Tier 3 evaluation interrupted" instead of "unexpected failure" / "failed unexpectedly". The progress state is stillfailed, so renderers, exit codes andProgressStatedo not change.docs/tier3-live-evaluation.mdxbullet next to the Harbor process-group cleanup notes describes the grace period, the second Ctrl+C, and how to find leftover Compose containers. CHANGELOG: an entry under Unreleased / Fixed.Limits:
taskkill /T /F, because Harbor handles no Windows signal for cleanup. The docs explain how to list leftovers by Compose project label.interruptedprogress state. Those are a separate presentation change.Existing behavior retained
_terminate_harbor_process_tree:killpgwith an EPERM/ESRCH-aware group probe, or verified System32taskkill /T /Fon Windows) and the_run_bounded_harbor_processBaseExceptioncleanup path (reader/stdin thread reaping, cleanup-failure notes). Cancellation reuses both. It only passes a longer grace that a second Ctrl+C can end, and only on POSIX.start_new_session/CREATE_NEW_PROCESS_GROUPisolation, the bounded and redacted output collection, and the_RunProgressLifecyclesingle-terminal-event guarantee, unchanged.unexpected_worker_error, per-agent failed rows) and itsProgressStatevocabulary. No new state was added.run_harbor_evalstill finalizes transient Harbor artifacts on every exception path. After an interrupt, that happens only after the workers have stopped their Harbor jobs.Verification
docs/tier3-live-evaluation.mdx)make lint(ruff check src tests)make test: ran the runner-dependent modules instead (results below)make build: not run locallyRegression tests:
tests/test_harbor_runner_status.py::test_bounded_harbor_process_cancellation_lets_harbor_finish_cleanup(POSIX): a stand-in Harbor whose SIGTERM handler takes 0.5 s to write a cleanup marker. Cancellation raises_HarborRunCancelledErroronly after the marker exists. With the timeout's 0.1 s grace the marker is never written and the test fails.tests/test_harbor_runner_status.py::test_bounded_harbor_process_cancellation_kills_harbor_that_ignores_sigterm[forced|grace-expired](POSIX): a stand-in that ignores SIGTERM is killed once the cancellation is forced (grace set to 300 s) or once the grace expires (grace set to 0.3 s).tests/test_harbor_runner_status.py::test_bounded_harbor_process_cancellation_reaps_descendants(POSIX): a real stand-in Harbor process whose grandchild ignores SIGTERM. The grandchild is reaped before it can write its survival marker.tests/test_harbor_runner_status.py::test_bounded_harbor_process_never_launches_after_cancellation: a requested cancellation preventsPopenentirely.tests/test_harbor_runner_status.py::test_run_harbor_checks_cancellation_before_refreshing_credentials:_run_harborraises before the Google ADC refresh and before any launch.tests/test_harbor_runner_status.py::test_agent_pair_launches_nothing_after_cancellation[False|True]: both the parallel-condition and the stop-on-pass paths forward the cancellation, propagate it, and launch no further condition or attempt.tests/test_tier3_progress.py::test_interrupt_cancels_running_agent_and_never_starts_queued_agents: aKeyboardInterruptdelivered on the coordinator thread while the first of two agents runs withmax_agents=1. The running agent observes the cancellation, the queued agent never starts, and progress ends with "Tier 3 evaluation interrupted". On unmodifiedmainit fails with['codex', 'opencode'] == ['codex'], which is the queued agent launching after the interrupt.tests/test_tier3_progress.py::test_second_interrupt_forces_running_agents_to_stop: a first Ctrl+C makes the agent report "stopping Harbor jobs", and a second one setsforcedand ends the wait.Results:
pytest(serial) ontests/test_harbor_runner_status.py,tests/test_tier3_progress.pyandtests/test_harbor_timeout_recovery.py: 266 passed, 2 skipped.pytest -n 6on every module that imports the Harbor runner, plustests/tier3andtests/cli: 10,364 passed, 16 skipped, 23 failed. All 23 failures are environment-dependent or timing-sensitive and also fail on unmodifiedmain(details below).ruff check src testspasses.ruff format --checkpasses onrunner.pyand the changed test files.scripts/check_oss_boundary.pypasses.Not verified: a live Harbor run against Docker or a cloud sandbox, and Windows.
Local failures that also fail on unmodified main
tests/tier3/test_judge_failure_artifacts.py::test_generated_custom_only_script_*(13 cases): the generated script runs under the host's/usr/bin/python33.9, which rejectsisinstance(value, int | float). Same 13 failures on unmodifiedmain.tests/test_harbor_secure_docker_environment.py::test_sidecar_retains_*(2 cases): depend on host environment variables.tests/test_harbor_runtime_preflight.py::test_bedrock_model_probe_*(6 cases): the Bedrock probe classifies a malformed proxy, an invalid region or an invalid AWS environment asunavailableinstead ofinvalid_configurationon this host during the full run. They depend on the live AWS SDK/network path, not on this change: the malformed-proxy cases also failed on unmodifiedmain, and a later run of the whole module passed on both trees.test_bounded_harbor_process_timeout_preserves_redacted_diagnostic_tailandtests/test_harbor_local_mode.py::test_streamed_timeout_callback_matches_result_and_contains_descendantsmiss their sub-second deadlines (the stand-in process must write output within 0.1 s). Repeated isolated runs pass on this branch and on unmodifiedmain.Release Impact
CHANGELOG.md🤖 Generated with Claude Code