Skip to content

fix(tier3): give the Windows process-tree kill longer than a plain reap - #687

Merged
chrisknvidia merged 3 commits into
mainfrom
fix/christopherk/windows-tree-kill-budget
Nov 16, 2026
Merged

chrisknvidia merged 3 commits into
mainfrom
fix/christopherk/windows-tree-kill-budget

Conversation

@chrisknvidia

@chrisknvidia chrisknvidia commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

On Windows, a Harbor run that times out or exceeds its output limit is stopped with taskkill /PID <pid> /T /F. The product waited 5 seconds for taskkill to finish, the same budget it uses to reap a process that has already been signalled. When taskkill needed longer, the product killed taskkill itself and raised:

RuntimeError: Harbor process-tree cleanup could not be confirmed

That has two effects for a Windows user. The tree kill is cut short, so descendants may be left running. And the run's own error ("timed out after ...", "output exceeded the ... limit", with the last output) is replaced by the cleanup error.

It also shows up as a flaky test. Tier 2 (windows-latest) failed this way on 10 Nov in test_bounded_harbor_process_drops_partial_secret_at_output_limit:

subprocess.TimeoutExpired: Command '['C:\\Windows\\System32\\taskkill.exe', '/PID', '3172', '/T', '/F']' timed out after 5.0 seconds

The same job failed again on 14 Nov in test_bounded_harbor_process_failure_reaps_windows_descendants[timeout]:

AssertionError: Regex pattern did not match.
  Actual message: 'Harbor process-tree cleanup could not be confirmed'

That log shows the cleanup error but not what caused it, so the 5 second timeout is the likely cause there, not a confirmed one.

Cause

In the 10 Nov job the failing test was the first in the session to reach taskkill. The next six taskkill calls in the same run all finished, and averaged well under 1.5 seconds each. So this looks like a slow first call on a fresh machine, not a hang. taskkill /T has to look the task tree up before it kills anything. I have no measurement of how long the slow call needed, only that it was more than 5 seconds.

Fix

The tree kill gets its own bound, _HARBOR_WINDOWS_TREE_KILL_SECONDS = 30.0. Everything else keeps the 5 second reap budget: the wait after taskkill itself is killed, the wait for the root process, and the POSIX path.

The 30-second bound covers waiting for taskkill, rather than the entire cleanup. The code still attempts to kill and reap a hung taskkill and fails closed if cleanup cannot be confirmed.

Please look at

  • The number. 30 seconds is a hang guard, not a measured value. It is far from both sides: normal calls take about a second, and a real hang is unbounded. If you would rather have a different bound, it is one constant.
  • The longer failure-path budget. One tree-cleanup helper can wait 30 seconds for taskkill, 5 seconds to reap a killed taskkill, and 5 seconds to reap the Harbor root: 40 seconds of configured waits, versus 15 previously. The surrounding runner can retry tree cleanup and then join its output and stdin threads for 5 seconds each. If both attempts and both joins exhaust those budgets, their sum is 90 seconds versus 40 previously. Process creation and OS calls add overhead, so these are wait-budget totals, not strict wall-clock guarantees.

Verification

  • I am familiar with the Contributing Guidelines

  • Added or updated focused tests

  • Updated documentation for user-visible changes (none needed)

  • Ran make lint (ruff check on the changed files)

  • Ran make test

  • Ran make build

  • Did not add credentials, private datasets, or proprietary benchmark content

  • New test test_windows_tree_cleanup_gives_taskkill_longer_than_a_plain_reap uses a fake process, so it runs on every OS. One case has taskkill take twice the reap budget and checks cleanup succeeds without killing it. The other has taskkill never return and checks it is killed and cleanup fails closed.

  • With the tree kill put back on the 5 second budget, both cases fail.

  • tests/test_harbor_runner_status.py passes: 160 passed, 2 skipped (macOS, Python 3.12). The 2 skipped are the real-Windows tests.

Hosted validation at 88343ba8: Windows job 133554358314 succeeded on Windows Server 2025 / CPython 3.12.10. Its command selected tests/test_harbor_runner_status.py and its aggregate was 5,076 passed, 172 skipped. The quiet log does not report individual taskkill timings, and it does not prove a slow first call exceeded five seconds or that the rare historical failure is eliminated. Three additional scaled real-subprocess controls cover successful delayed cleanup, the shorter-budget failure, and hung-tool termination.

Not verified:

  • The flake is rare (two failures seen in about ten days), so a green run on this PR does not prove it is gone.
  • The full suite was not run locally.

Release Impact

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

One entry under Fixed.

On Windows a Harbor run that times out or exceeds its output limit is
stopped with taskkill /T /F. The product waited 5 seconds for taskkill,
the budget it uses to reap a process that was already signalled. When
taskkill needed longer, it was killed and the run failed with 'Harbor
process-tree cleanup could not be confirmed' in place of its own error.
Tier 2 (windows-latest) failed this way on 10 and 14 Nov.

The tree kill now has its own 30 second bound. The other waits keep the
5 second budget, and a taskkill that never returns is still killed and
still fails closed.

Signed-off-by: Christopher Kevin <christopherk@nvidia.com>

@rng1995 rng1995 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.

Independent review of 88343ba8: no actionable issues found in the changed code. Focused validation and its scope are recorded inline.

@rng1995 rng1995 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.

Reviewed at 88343ba8. One P3 inline. The bound change and the fake-process test are correct; the focused Windows-cleanup tests pass locally (6 passed).

The Windows branch of the process-tree kill ignored end_grace, so after a
second Ctrl+C ("skips wait") the forced-cancel path could still block for the
full 30 s taskkill budget.

Wait for taskkill in short slices instead of one blocking call. Once end_grace
is set and taskkill is still running, stop waiting, kill it and fail closed
as for a timeout, since the tree was not confirmed stopped. The normal wait
budget and the 5 s reap budgets are unchanged.

Tests drive the wait with a simulated clock: forced cancellation returns
promptly and fails closed, an unforced slow taskkill is still waited out, and
a taskkill that finishes despite the force is kept.

Signed-off-by: Christopher Kevin <christopherk@nvidia.com>
@chrisknvidia
chrisknvidia marked this pull request as ready for review November 16, 2026 21:05
devin-ai-integration[bot]

This comment was marked as resolved.

Signed-off-by: Christopher Kevin <christopherk@nvidia.com>
@chrisknvidia
chrisknvidia merged commit 7f9d2c5 into main Nov 16, 2026
27 checks passed
@chrisknvidia
chrisknvidia deleted the fix/christopherk/windows-tree-kill-budget branch November 16, 2026 21:23
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