Skip to content

fix(tier3): stop running and queued Harbor jobs on Ctrl+C - #291

Merged
rng1995 merged 5 commits into
mainfrom
naren/port-tier3-cancellation
Nov 4, 2026
Merged

rng1995 merged 5 commits into
mainfrom
naren/port-tier3-cancellation

Conversation

@rng1995

@rng1995 rng1995 commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

Pressing Ctrl+C during tier3 evaluate did 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's wait() loop. As a result:

  • The KeyboardInterrupt left the with ThreadPoolExecutor block, and shutdown(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.
  • Agents queued behind --max-agents still started after the interrupt, because the executor exit does not cancel pending work.
  • The terminal showed nothing happening after Ctrl+C. To the user, the CLI hung for the rest of the run while trials (and model spend) continued.

A test-local reproduction on main sends a real SIGINT while two agents run with max_agents=1 and the stand-in Harbor command spawns a grandchild. After the interrupt, run_harbor_eval blocked 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_impl creates a _HarborRunCancellation (a requested and a forced event). It is passed to each agent worker through _run_agent_pair, _run_stop_on_pass_variant and _run_harbor, down to _run_bounded_harbor_process.
  • If an interrupt (or any other BaseException) escapes the agent pool loop, the coordinator calls executor.shutdown(cancel_futures=True) and then sets requested. 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 sets forced. A third one propagates.
  • _run_harbor checks the cancellation before refreshing Google ADC credentials, so a queued condition or --stop-on-pass attempt makes no token request after an interrupt. _run_bounded_harbor_process checks it again before Popen and on each output poll. A job that has not started is never launched.
  • A running job gets a graceful stop instead of the timeout teardown. Its process group receives SIGTERM, and the runner waits up to 30 seconds (_HARBOR_RUN_CANCEL_GRACE_SECONDS) for the Harbor leader to exit, then SIGKILLs and reaps the group. Harbor 0.24 maps SIGTERM to KeyboardInterrupt and stops its trial environments. The default secure Docker environment removes the main container when an exec is interrupted. Setting forced ends the wait at once. Timeout and output-overflow teardown keep their existing 0.1 s grace.
  • _HarborRunCancelledError derives from BaseException, like KeyboardInterrupt and asyncio.CancelledError. Handlers that record ordinary job failures (except Exception, or _run_harbor's OSError/RuntimeError/UnicodeError mapping) therefore cannot turn a cancellation into a failed attempt and move on to the next condition or attempt.
  • On KeyboardInterrupt, run_harbor_eval calls fail_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 still failed, so renderers, exit codes and ProgressState do not change.
  • Docs: the docs/tier3-live-evaluation.mdx bullet 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:

  • Containers and in-container agent processes can still be left running in three cases: after a second Ctrl+C, when Harbor's cleanup takes longer than 30 seconds, and on Windows. On Windows the Harbor task tree is still stopped with taskkill /T /F, because Harbor handles no Windows signal for cleanup. The docs explain how to list leftovers by Compose project label.
  • Not in this PR: the redesigned borderless progress renderer and an interrupted progress state. Those are a separate presentation change.

Existing behavior retained

  • The Harbor process-tree teardown (_terminate_harbor_process_tree: killpg with an EPERM/ESRCH-aware group probe, or verified System32 taskkill /T /F on Windows) and the _run_bounded_harbor_process BaseException cleanup 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_GROUP isolation, the bounded and redacted output collection, and the _RunProgressLifecycle single-terminal-event guarantee, unchanged.
  • The agent pool's handling of unexpected worker errors (unexpected_worker_error, per-agent failed rows) and its ProgressState vocabulary. No new state was added.
  • run_harbor_eval still finalizes transient Harbor artifacts on every exception path. After an interrupt, that happens only after the workers have stopped their Harbor jobs.

Verification

  • I am familiar with the contributing guidelines
  • Added focused regression tests
  • Updated documentation for user-visible changes (docs/tier3-live-evaluation.mdx)
  • Ran make lint (ruff check src tests)
  • Ran make test: ran the runner-dependent modules instead (results below)
  • Ran make build: not run locally
  • Did not add credentials, private datasets, or proprietary benchmark content

Regression 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 _HarborRunCancelledError only 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 prevents Popen entirely.
  • tests/test_harbor_runner_status.py::test_run_harbor_checks_cancellation_before_refreshing_credentials: _run_harbor raises 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: a KeyboardInterrupt delivered on the coordinator thread while the first of two agents runs with max_agents=1. The running agent observes the cancellation, the queued agent never starts, and progress ends with "Tier 3 evaluation interrupted". On unmodified main it 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 sets forced and ends the wait.

Results:

  • pytest (serial) on tests/test_harbor_runner_status.py, tests/test_tier3_progress.py and tests/test_harbor_timeout_recovery.py: 266 passed, 2 skipped.
  • pytest -n 6 on every module that imports the Harbor runner, plus tests/tier3 and tests/cli: 10,364 passed, 16 skipped, 23 failed. All 23 failures are environment-dependent or timing-sensitive and also fail on unmodified main (details below).
  • ruff check src tests passes. ruff format --check passes on runner.py and the changed test files.
  • scripts/check_oss_boundary.py passes.

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/python3 3.9, which rejects isinstance(value, int | float). Same 13 failures on unmodified main.
  • 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 as unavailable instead of invalid_configuration on 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 unmodified main, and a later run of the whole module passed on both trees.
  • Under parallel load, test_bounded_harbor_process_timeout_preserves_redacted_diagnostic_tail and tests/test_harbor_local_mode.py::test_streamed_timeout_callback_matches_result_and_contains_descendants miss their sub-second deadlines (the stand-in process must write output within 0.1 s). Repeated isolated runs pass on this branch and on unmodified main.

Release Impact

  • No user-visible release note needed
  • Updated CHANGELOG.md

🤖 Generated with Claude Code

rng1995 and others added 2 commits October 30, 2026 12:00
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 rng1995 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

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 chrisknvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

rng1995 and others added 2 commits November 3, 2026 09:45
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]>
@rng1995
rng1995 merged commit 53329d6 into main Nov 4, 2026
21 checks passed
@rng1995
rng1995 deleted the naren/port-tier3-cancellation branch November 4, 2026 18:56
rng1995 added a commit that referenced this pull request Nov 4, 2026
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]>
rng1995 added a commit that referenced this pull request Nov 5, 2026
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]>
rng1995 added a commit that referenced this pull request Nov 5, 2026
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]>
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.

2 participants