Repository navigation
fix(agentenv): settle cancelled long runs and preserve teardown receipts - #11095
Merged
Merged
Conversation
…leanup A timed-out or cancelled AgentEnv command could stay pending after one SIGINT, or while a descendant outside the process group held stderr. The host then refused to close the computer. Escalate SIGINT, SIGTERM, and SIGKILL. Publish an incomplete result when stderr stays open. Tear the computer down anyway, and clear the retained command only after that teardown is confirmed.
The stop sequence ended when the leader exited, so a same-session child that ignored SIGINT never received SIGTERM or SIGKILL. A later release could also see settled: false and drop the command receipt. Keep signaling processes that are still in the leader's session, checked in /proc immediately before each signal. Save that receipt on the existing cleanup error before returning the unsettled result.
Cancellation ended the signal sequence when the stderr reader finished. A same-session child that closed stderr and ignored SIGINT never received SIGTERM or SIGKILL, and the result said the command had settled. Keep that sequence while a same-session child is alive, including after stderr has closed.
Preserve observed unsettled command facts before cleanup so pending or failed cancellation cannot erase available output and exit observations. Include the settled state in retained receipts. Refs #10676 Related: #10675 Co-authored-by: gensokyo-dev <[email protected]>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Contributor
[Medium impact] The latest changes appear safe to merge; no blocking issue was found. SummaryThis PR stops timed-out or cancelled commands with escalating signals and keeps unsettled jobs until computer teardown is confirmed.
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Poll command] --> B{Settled?}
B -->|Yes| C[Return outcome]
B -->|No| D[Keep observed receipt]
D --> E[Request cancellation]
E --> F{Stop confirmed?}
F -->|Yes| G[Clear job and keep receipt]
F -->|No| H[Retain job and receipt]
H --> I[Close computer]
I --> J{Teardown confirmed?}
J -->|Yes| K[Resolve retained cleanup]
J -->|No| H
Reviews (2) · Last reviewed commit: "fix(agentenv): preserve explicit unknown..." · Reviewed by Greptile |
Retain a controller-attested null exit_code alongside an unsettled result instead of dropping it from the receipt. Co-authored-by: gensokyo-dev <[email protected]>
19 tasks
This was referenced Nov 15, 2026
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
Timed-out or cancelled AgentEnv exports could stay pending forever: the long-run supervisor sent SIGINT only once and waited indefinitely for inherited stderr. Close then skipped computer teardown while the command remained unconfirmed.
Fixes #10676. This builds on the three commits in #10675 by @Adolanium, preserving their authorship, and adds a verified missing case: a polled unsettled result must survive a later pending or failed cancellation request. It supersedes that PR's overlapping implementation.
Change and boundaries
The Linux supervisor escalates SIGINT/TERM/KILL for the owned session, continues after leader exit, and bounds stderr draining on timeout/cancellation. A descendant in another session remains unsignaled and produces an unsettled, incomplete result. Host cleanup retains that job and its observed receipt until verified computer teardown; failed reader cleanup still keeps the computer available for retry. No new tool inputs, execution capabilities, providers or dependencies. Scope decision: not applicable to this lifecycle repair.
Polling now retains an unsettled command's exit, output size, stderr, timeout/cancellation and settled facts before requesting cleanup. A failed or pending cancel cannot erase the observation. Existing shared process-supervision ownership and reader/judge responsibilities remain separate.
Evidence and validation
Linux Python controller:
taskset -c 0,1 python3 -m unittest bridge.agentenv.test_capture.LongRunTest— 14 passed. Covers resistant leaders, inherited stderr outside the session, surviving same-session children, stderr closing during cancellation, ownership refusal and late start.Restoring main's capture.py reproduces the held-stderr failure: the new terminal-result test gets a pending result instead. The fixture releases its descendant afterward.
npm run test:local -- src/desktop/BuildComputerLongRuns.test.ts src/application/desktop/DesktopBuildComputers.cleanup.test.ts src/desktop/AgentEnvComputer.test.ts src/desktop/AgentEnvComputerHelper.cleanup.test.ts— 31 passed. Two receipt regressions fail on fix(agentenv): settle cancelled long runs without blocking computer cleanup #10675's final implementation and pass here; a third red-to-green case preserves explicit null exit status.npm run test:focused -- tests/boundary/mcp/buildComputerMcp.test.ts tests/boundary/providers/buildComputerLifecycle.test.ts— 30 passed, including compiled stdio MCP, cancel during close, late startup and cleanup retry with simulated computers.npm run check:fast— passed on the final nullable-field adjustment.npm run docs:check— passed, including 8 consistency tests.npm run verify:test-discovery— passed; 3644 files discovered exactly once.Changed-file formatting and
git diff --check— passed.Checks use two CPU cores. AgentEnv runner is not installed: real AgentEnv/Docker computer deployment and teardown were not exercised; Python tests execute the real controller with owned fixture commands, and host/MCP computers are simulated.
Remote validation
Greptile passed on final head 13640ff with no inline findings. Codex review could not run because the repository quota was exhausted. Required GitHub Actions jobs remain queued without a runner; remote CI is not reported as passed. Merged with the user-authorized maintainer bypass after the local checks and final Greptile review; real-provider limits are recorded above.
Post-merge integration verification
The initial branch checks used base 29dd58c. Main's #10855 removed resolveCleanup during validation; merging #11095 left the new verified-teardown loop calling that removed API. This was an integration mistake in this PR. Main commit 144d6f9 removes the obsolete push and lets errors read the existing job-owner release claim. On main 5b5ca68, the 22 focused long-run/computer-cleanup tests, runtime build (
npm run build:cached) andnpm run check:fastall pass. No duplicate follow-up PR was opened for the same landed correction.Author readiness
Human owner: @N0zoM1z0 (PR-author declaration exemption in CONTRIBUTING.md).