Repository navigation
fix(subagents): confirm teardown after cancellation drains - #4
Merged
Conversation
Zsanz3
merged commit Sep 21, 2026
f86b766
into
Zsanz3:cursor/fix-batch-bookkeeping-overlap-adc2
3 checks passed
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.
Follow-up to bytedance#5253, based on
d42a748bd3ffacb338e1d1efb97932b6ba176085. This PR contains only the additional teardown-confirmation fix and its regressions.Why
request_cancel_background_task()cancels the cross-thread Future returned byasyncio.run_coroutine_threadsafe(). That Future invokes its done callbacks before the isolated-loop task has finished cancellation. Currentlyforget_future()setsexecution_teardown_eventat this point, allowing the batch supervisor to accept teardown while the child is still draining cleanup.The regression blocks the real
SandboxLeaseManager.release_async()around a controlled synchronous release. On the base revision, teardown is already acknowledged while release is blocked and the result is still RUNNING.What changed
run_with_timeout()'sfinally, after child cleanup. The Future callback still removes its submission handle.This does not change ordinary FAILED-result retry handling or the bounded teardown wait / lease-expiry recovery policy.
Surface area
Bug fix verification
Both new cases in
tests/test_subagent_executor.py::TestCooperativeCancellationfail on the current bytedance#5253 head and pass with this commit:test_cancelled_future_does_not_confirm_execution_teardowntest_cancel_before_isolated_loop_dispatch_still_confirms_teardownThe model body is mocked; submission, cross-thread cancellation, and the sandbox-release shield/drain helper execute production code. This is not a red/green claim against upstream main, which does not yet contain bytedance#5253's teardown event. No live model or sandbox integration test was run.
Validation
Windows, Python 3.12.10, project dependencies installed with
uv sync --locked:ruff check .andruff format --check .: passed.pytest -m 'not live' --ignore=tests/blocking_io tests/; blocking suites usedpytest tests/blocking_io.test_extension_task_lifecycle.py::test_notification_timeout_is_one_shared_budget(20 ms budget); it subsequently passed standalone and in 20 repeated runs on both revisions. The base-only failure wastest_mcp_task_service.py::test_run_once_releases_claim_when_driver_is_missing_or_fails(strict time comparison); standalone it again failed on base and passed on the patched revision. Those tests and their implementations are unchanged, but the differing outcomes have not been fully diagnosed.The full local suite is not green. These results document the baseline and observed differences, rather than claiming complete validation.
AI assistance
Tool(s) used: OpenAI Codex.
How it was used: Codex investigated the cancellation path, wrote the implementation and regression tests, and ran local validation.