fix(sandbox): finish dependency cleanup on cancellation - #4607
Merged
seratch merged 1 commit intoAug 23, 2026
Conversation
seratch
approved these changes
Aug 23, 2026
seratch
enabled auto-merge (squash)
August 23, 2026 22:07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Dependencies.aclose()stopped reverse-order cleanup as soon as an owned dependency raisedCancelledError. That left earlier owned resources open and cached a cancelled close task, so subsequent close attempts could not complete the skipped cleanup.This change records the first child cancellation, finishes exactly-once cleanup for the remaining owned dependencies, clears the container's internal state, and then propagates cancellation. Normal cleanup and non-cancellation best-effort behavior are unchanged.
Test plan
aclose()does not close either resource twice.uv run pytest tests/sandbox/test_dependencies.py::test_dependencies_aclose_finishes_owned_cleanup_before_propagating_cancellation -q— 1 passed; repeated 10 times with the same result.uv run pytest tests/sandbox/test_dependencies.py -q— 20 passed.make typecheck— mypy passed for 307 source files; Pyright reported 0 errors..agents/skills/code-change-verification/scripts/run.sh— format and lint passed; the broad suite completed with 9085 passed, 28 skipped, and 1 pre-existing failure.tests/sandbox/test_run_cwd.py::test_python_skill_uses_absolute_root_from_nested_workdirfails with the same missing output file on clean upstream23346799and is unrelated to this two-file cleanup change.git diff --check— passed.No public API, serialization format, or documentation changes.
Issue number
None filed; reproduced deterministically with local owned-resource fakes.
Checks
.agents/skills/code-change-verification/scripts/run.sh/reviewbefore submitting this PR