Skip to content

fix(agentenv): settle cancelled long runs and preserve teardown receipts - #11095

Merged
gensokyo-dev merged 5 commits into
mainfrom
fix/agentenv-cancellation-10676
Nov 15, 2026
Merged

gensokyo-dev merged 5 commits into
mainfrom
fix/agentenv-cancellation-10676

Conversation

@N0zoM1z0

@N0zoM1z0 N0zoM1z0 commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

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) and npm run check:fast all 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).

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Adolanium and others added 4 commits November 15, 2026 12:03
…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]>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The latest changes appear safe to merge; no blocking issue was found.

Summary

This PR stops timed-out or cancelled commands with escalating signals and keeps unsettled jobs until computer teardown is confirmed.

  • Timed-out exports escalate signals and report when command output is incomplete.
  • Unsettled command receipts stay available through cancellation retries.
  • Computer close clears unsettled runs after teardown is verified.

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
Loading

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]>
@gensokyo-dev
gensokyo-dev merged commit ce9bdc5 into main Nov 15, 2026
5 of 13 checks passed
@gensokyo-dev
gensokyo-dev deleted the fix/agentenv-cancellation-10676 branch November 15, 2026 12:20
morluto added a commit that referenced this pull request Nov 15, 2026
…e claim

#11095 called ProviderCleanupError.resolveCleanup(), which #10855 removed,
so main stopped typechecking. Each retained failure's release claim already
reads job membership, so clearing the jobs after a verified computer
teardown is what releases them.
@morluto morluto added bug Something isn't working area: mcp MCP server, transport, and tool registration labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: mcp MCP server, transport, and tool registration bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] AgentEnv long-run timeout or cancel stays pending and blocks computer close

4 participants