Skip to content

fix(sandbox): stop local subprocesses on cancellation - #3652

Merged
yuhezhang-ai merged 3 commits into
mainfrom
bug-hunter/2026-09-23-local-cancellation
Oct 1, 2026
Merged

yuhezhang-ai merged 3 commits into
mainfrom
bug-hunter/2026-09-23-local-cancellation

Conversation

@yaoyu-33

@yaoyu-33 yaoyu-33 commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Cancelling an in-flight local sandbox command previously left its subprocess group running, allowing background children to keep writing into the task workspace. Timeout cleanup also missed children when their shell had already exited, because looking up the departed shell's process-group ID failed.

Handle cancellation in the existing process-group kill and bounded reap block, then re-raise CancelledError. Use the session leader PID directly as the process-group ID so cleanup still reaches children after shell exit. Preserve the timeout result contract and the bounded reap behavior introduced in #2863.

The real-subprocess regression exercises the public AsyncSandbox API for cancellation and timeout, each with a waiting shell and an exited shell. It waits for the child to start and the requested shell state before starting the provider's timeout, confirms the timeout result or propagated cancellation, then releases the child's pending write and verifies that it cannot write afterward.

This is a focused lifecycle bug fix; no separate issue or API migration is needed.

Validation at f027228bc5a55ecd2a6b2e923251df29455839aa:

  • python -m pytest --import-mode=importlib tests/unit_tests/test_local_provider.py -o addopts='' -o log_cli=false -q — 13 passed.
  • The exited-shell timeout regression fails because the child writes after timeout with the pre-fix provider from a6c5fb04f^, and passes with the final provider.
  • pre-commit run --all-files and git diff --check — passed.
  • The review-fix commit includes DCO sign-off. Full core/sandbox coverage and the eight-shard server suite were not rerun locally for this test-only follow-up. The complete PR remains full-scope under CI classification.
  • Model rollout: N/A for this subprocess-cleanup fix; the follow-up changes only regression coverage.

@copy-pr-bot

copy-pr-bot Bot commented Sep 23, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@yaoyu-33
yaoyu-33 marked this pull request as ready for review September 28, 2026 23:08
@yaoyu-33 yaoyu-33 added needs-review PR is ready for code review and waiting on a reviewer area:sandbox Sandbox providers, isolation, and sandbox runtime contracts bug Something isn't working complexity:low Localized change in one scope with a small, straightforward review surface labels Sep 28, 2026
@github-actions github-actions Bot added the sla:triage-overdue Review assignment is over the one-business-day SLA label Sep 29, 2026
Comment thread tests/unit_tests/test_local_provider.py Resolved
@github-actions github-actions Bot removed the sla:triage-overdue Review assignment is over the one-business-day SLA label Sep 30, 2026
@yuhezhang-ai yuhezhang-ai added the waiting-on-customer Waiting on the original author to respond label Sep 30, 2026
@yaoyu-33 yaoyu-33 removed the needs-review PR is ready for code review and waiting on a reviewer label Sep 30, 2026
@yaoyu-33

yaoyu-33 commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test f027228

@yaoyu-33

yaoyu-33 commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

@yuhezhang-ai The timeout-after-shell-exit case is covered in f027228. The test waits for shell exit before starting the timeout, checks the timeout result, and verifies that the child cannot write afterward. It fails against the older provider; all 13 local-provider tests and all-file pre-commit pass. CI has been requested for the updated head. Could you take another look?

@yuhezhang-ai yuhezhang-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.

Reviewed the follow-up at f027228. The timeout-after-shell-exit regression addresses my optional suggestion and preserves the timeout result checks. Production code is unchanged from the completed review. All 13 local-provider tests pass locally, along with focused lint, formatting, and diff checks. No blocking code findings remain.

The full core/sandbox coverage and eight-shard server suite are still running; merge after those checks pass.

@yuhezhang-ai
yuhezhang-ai added this pull request to the merge queue Oct 1, 2026
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/36903734298

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA-NeMo/Gym/actions/runs/36904471129

Merged via the queue into main with commit 740a88b Oct 1, 2026
41 checks passed
@yuhezhang-ai
yuhezhang-ai deleted the bug-hunter/2026-09-23-local-cancellation branch October 1, 2026 18:46

This branch was previously deployed

1 inactive deployment
public — f027228b Deployed Oct 1, 2026 by copy-pr-bot[bot] via release / finalize / notify #4121
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:sandbox Sandbox providers, isolation, and sandbox runtime contracts bug Something isn't working complexity:low Localized change in one scope with a small, straightforward review surface waiting-on-customer Waiting on the original author to respond

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants