Skip to content

Bound hub_fetch_run.py's Stop of Its Script With a Kill After a Timeout - #4522

Open
ptr727 wants to merge 2 commits into
developfrom
burndown/hub-fetch-run-bounded-stop
Open

ptr727 wants to merge 2 commits into
developfrom
burndown/hub-fetch-run-bounded-stop

Conversation

@ptr727

@ptr727 ptr727 commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Summary

catalog/snippets/hub_fetch_run.py stopped its uv run child in a finally with terminate() and then a wait() with no bound. The signal handler passes over a second Ctrl-C. So a script that ignores or outlasts SIGTERM held the hook or VS Code task forever. The fetched tree stayed, and the recorded signal was never re-raised.

The stop is now one stop() function, per CODESTYLE.md "Interrupts in Python". It calls terminate(), then wait(timeout=STOP_TIMEOUT) with a 10 second bound. On subprocess.TimeoutExpired it calls kill(), then wait().

Tests

tests/test_hub_fetch_run.py gains three cases.

  • An end-to-end case signals the helper while its stub uv ignores SIGTERM and sleeps past the test's 30 second timeout. The helper dies by SIGTERM, leaves no fetched tree, and leaves no process in its group. Run against the old snippet, the case fails on that 30 second timeout.
  • Two in-process cases call stop() with a short patched bound. A child that honors SIGTERM ends by it. A child ignoring SIGTERM ends by SIGKILL after the bound.

Each case starts its child in a session of its own and kills that group in a finally.

Scope

No spec entry records the snippet's bytes or digest, so nothing in spec/ changes. Re-carrying the snippet into the repositories that hold it is resync work in each of them, and is not done here.

Open question

The local review pass found that the bound's kill() reaches uv run alone. A script that outlasts SIGTERM past the bound is left running after the helper ends. The rule prescribes that exact form, so whether the stop should also reach the script is a design decision for the maintainer, filed as #4523. This pull request waits on it.

Pre-existing findings, not filed

  • scripts/secrets_sync.py, the finally around its op child: terminate() then an unbounded wait(), a correctness finding against CODESTYLE.md "Interrupts in Python". That rule says an existing script takes it when next edited, and not in an edit for the rule alone.

Owed actions

🤖 Generated with Claude Code

ptr727 and others added 2 commits November 27, 2026 09:52
The finally stop sent SIGTERM and then waited with no bound. The signal
handler passes over a second Ctrl-C, so a script ignoring SIGTERM held the
helper, its fetched tree, and the re-raised signal forever. The stop now
waits STOP_TIMEOUT seconds and then kills, per CODESTYLE.md "Interrupts in
Python".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…uv Alone

The honoring case shared the ignoring case's half-second bound, so a slow
runner could kill a child that was exiting on SIGTERM. The stop's docstring
and the end-to-end case now name what the kill reaches, which is `uv run`
rather than the script it started.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings November 27, 2026 17:57
@coderabbitai

coderabbitai Bot commented Nov 27, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@ptr727

ptr727 commented Nov 27, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 148b0485c7ec89432785e8cd5204ce0c36723024, the content this pull request carries at that commit against develop, and it recorded 0 findings.

@ptr727

ptr727 commented Nov 27, 2026

Copy link
Copy Markdown
Owner Author

Parked on #4523, a design decision: should the bounded stop's kill also reach the script uv run started, not just uv itself? This pull request waits for that answer before it merges.

Copilot AI 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.

🟡 Changes recommended

A critical active bug remains in signal-timeout cleanup: killing only the uv launcher can leave the script running against a deleted temporary tree, and the orphan-process case is unaddressed.

1 open issue
What changed in this PR

This PR bounds interrupt cleanup for hub_fetch_run.py so an interrupted run cannot wait indefinitely for its uv child, while the launcher-only kill can still leave a descendant script running.

Changes:

  • Adds a 10-second stop timeout followed by forced termination.
  • Centralizes subprocess cleanup in stop().
  • Adds end-to-end and in-process tests for graceful termination, timeout handling, signal behavior, and temporary-tree cleanup.
File Description
tests/​test_hub_fetch_run.py Adds end-to-end and in-process tests covering graceful child termination, timeout-based killing, signal handling, and temporary-tree cleanup.
catalog/​snippets/​hub_fetch_run.py Adds bounded subprocess cleanup through stop() with a 10-second timeout and forced termination fallback.

Review effort: Lite


The handler passes over a second Ctrl-C.
So a child ignoring SIGTERM would otherwise hold this process and its fetched tree forever.
The kill reaches `child` alone, which is `uv run` rather than the script it started.

This branch has not been deployed

No deployments
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