Skip to content

fix: stop yielded commands with their Gateway request - #166753

Merged
shakkernerd merged 2 commits into
mainfrom
fix/stop-owned-exec
Oct 8, 2026
Merged

shakkernerd merged 2 commits into
mainfrom
fix/stop-owned-exec

Conversation

@shakkernerd

@shakkernerd shakkernerd commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A command that outlives exec's yield window can keep running after the user stops its Gateway request. The model turn ends, but the command retains its process and can later produce a completion notification. This is especially confusing in the browser, where Stop appears to have finished the work.

User Impact

The browser's Stop button and typed /stop now cancel ordinary commands owned by the selected request, including commands that already returned a process handle. Gateway cancellation waits for physical process cleanup and reports uncertainty if cleanup cannot be confirmed. Retained command output remains available, and stopping a command does not create a new completion notification.

Deliberately independent background: true services remain running until their own process handle is stopped. Normal model completion, completed model receipts, unrelated work, and later human turns retain their existing behavior. This contribution covers the Gateway request and its ordinary commands; channel cancellation, completion continuations, and commands retained by native descendants have separate owners. Managed-worker behavior is unchanged.

Why This Change Was Made

Tool-call disposal and request cancellation have different lifetimes. An ordinary yielded command needs to retain its request owner after the tool call returns, while an explicitly independent service does not. The Gateway's chat.send and agent dispatch owners now carry their admitted identity through embedded execution and lazy/Code Mode tool binding into the process lifecycle.

Cancellation captures the selected owners before asynchronous work, preserves the existing actor and session-generation checks, and joins the process supervisor or sandbox's cleanup. Native finalization retains the cleanup verdict on the request owner, so a command registered after selection cannot lose its failure when process output is evicted. Accepted initial session binding and compaction update that ownership. If authority changes after cancellation was already accepted, cleanup is still observed and any uncertainty is reported without rewriting a completed model receipt. The general reply runner does not need to read Gateway cancellation registries.

Evidence

The real-Gateway browser regression fails before the repair for both the Stop button and typed /stop: the model request is interrupted while the ordinary command remains physically alive. With this change, both controls join command cleanup, cancel the existing model descendant, preserve retained output, suppress a cancellation completion notification, and allow a new instruction to complete. The native three-file browser batch passed all four cases. Before and after use the same fixture, Linux host architecture, Node 24.19.0, managed Chromium 153.0.8010.12, and 1440 × 1000 viewport.

The lifecycle regression also reproduced two lost cleanup failures after selection, late command registration, cancellation, and output eviction. Both fail before the producer repair and pass afterward. The corrected cleanup, Stop/Code Mode, and Gateway cascade batch passed 38 cases. First-turn identity, accepted/rejected compaction, newer-request isolation, completed model receipts, explicit independent services, and managed-worker preservation are covered by the focused owner suites. The nine single-worker commands passed 217 cases; overlapping runs are not summed.

The ordinary selected baseline completed 316 files: 315 passed and one skipped, with 5,492 passing and 29 skipped cases. Applicable earlier static/security, full compiler, package-boundary, and unchanged-file results are retained with their original revisions; the final private-QA build passed on the composition with #166786. That prerequisite repairs the independently reproduced Workboard manifest failure in the PR's historical CI run. Current Node/tooling CI jobs passed; the failed build and aggregate gate retain their actual historical failure status, qualified against the repaired result. Independent engineering review and the separate required automated review have no unresolved source finding.

Test cost

The following are literal pnpm test <file> --maxWorkers=1 command wall times on remote macOS arm64. CI seconds are whole shared job durations, not per-file charges; repeated job durations must not be summed.

Test file Cases Command wall CI job wall
bash-tools.exec-runtime.cleanup.test.ts 17 17.27 s 88 s
bash-tools.exec.background-abort.test.ts 4 16.30 s 88 s
run.session-prompt-state.test.ts 14 23.20 s 144 s
chat-abort.test.ts 30 13.81 s 311 s
chat.abort-cascade.test.ts 17 38.42 s 397 s
sessions.abort-dedupe-currentness.test.ts 7 26.32 s 397 s
server.chat-first-turn-binding.test.ts 1 32.04 s 447 s
worker.runtime.test.ts 86 55.88 s 302 s
vitest-ui-e2e-config.test.ts 41 18.32 s 128 s

The existing background-work browser file took 27.927 s and the two-case Stop file took 59.781 s in Vitest’s retained file-duration cache; these include real Gateway and provider lifecycle setup. Exact per-case Vitest durations were not emitted by the reporter.

The new ordinary-yield worker case takes 0.224 s; the 55.88 s command includes the existing 86-case process-lifecycle suite. The first-turn case reuses the existing Gateway fixture. The real-Gateway browser row runs through its canonical serial owner and took 179.28 s in Vitest, or 184.63 s for the native test helper including preparation. It proves the browser-to-Gateway-to-process boundary that a unit test cannot establish. Dedicated browser CI was unselected, so that skipped job supplies neither a timing nor a pass.

The complete selected UI coverage is reused from the exact-head CI run: 1,634 unit files across three shards, 676 mocked UI files across eight shards, and the browser-extension case. Their source trees, ordered selections, owners, dependency lock, pinned Bun runtime, and worker caps match the native composition. Six ordinary E2E owners also passed in that run. An extra native UI attempt lost its SSH transport and remains incomplete; it is not counted as a pass.

The remaining eight agent E2E files executed through the native owner: six files passed, with 156 passing and 19 failing cases overall. The same 19 failures reproduced on clean base 950bd83e: 17 encounter an existing auth-controller mock missing createEmbeddedAuthProfileAdmission, and two expect an older admission-error message. The affected fixture and producer paths are unchanged by this PR, and source tracing confirms the new request-owner wrapper does not change their ordering or errors. These inherited fixture failures remain recorded; they are not relabeled as passing tests. The changed cancellation behavior passes the focused lifecycle suites and real-Gateway browser scenarios.

Visual evidence

Open preview

View Before After
Stop button After Stop, the conversation is interrupted but the ordinary command is still running. After Stop, the command is stopped with retained output and manual-cancel status.
Typed /stop After Stop, the conversation is interrupted but the ordinary command is still running. After Stop, the command is stopped with retained output and manual-cancel status.

Button Stop, then typed /stop: physical cleanup and a new instruction

both-stop-controls-final.mp4

Visual verification

  • Baseline: 950bd83 with unchanged candidate fixtures (2cab941e95f0f698f014f4cf80c78a1d6c330d31)
  • Exact head: e8c75f7bb4ff90333c3bbd4e2e4caf19fd93fc2e
  • Scenario: Start an ordinary yielded command and a model helper; stop the request, inspect physical cleanup, then send a new instruction. The recording shows button Stop followed by typed /stop.
  • Runtime/build: PR head 1b79448 composed with 950bd83; tree eb2d396ccb6c599df057f44a52791a8cd6176884; assets/index-j00CxQcB.js SHA256 6749b1a519ef2cb0f80d83f24091e6a193085d7e6d8118ee364d5373c5c3e620; Node 24.19.0; Chromium 153.0.8010.12
  • Ordinary process alive when Stop replied: Before: true; after: false, for both controls
  • Preserved behavior: Model helper cancelled; retained process output remains; new instruction completes
  • Execution: Native three-file browser row: 4 cases passed; isolated Gateway and provider cleanup confirmed
  • Identical 1440 by 1000 viewport, theme, fixture, platform, Node, Chromium and capture owner
  • Both baseline cases fail at the immediate physical-cleanup assertion; zero unhandled errors
  • Both fixed cases pass and verify no cancellation completion notification
  • Served asset identity and native prebuilt generation verified before and after execution
  • Original recordings retained; factual input labels added and second scenario blank startup accelerated with the maintained renderer

@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime agents Agent runtime and tooling size: XL labels Oct 7, 2026
@shakkernerd shakkernerd self-assigned this Oct 7, 2026
@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 7, 2026, 9:44 PM ET / October 8, 2026, 01:44 UTC (Revision 5).

ClawSweeper review

What this changes

The branch makes Gateway request Stop cancel ordinary yielded commands, await physical cleanup, and report cleanup uncertainty while preserving explicitly independent services.

Example: The user starts an ordinary command and presses Stop.

  • Before: The conversation shows “Interrupted” while the command remains “Running.”
  • After: The command shows “Stopped” with manual-cancel and retains its output.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A valuable ownership repair with real browser-to-process proof, focused authority coverage, and no actionable source finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The built browser UI exercised Stop and typed /stop through a real Gateway and supervised command on Linux with Node 24.19.0 and Chromium 153.0.8010.12. Recorded before/after observations show physical process closure before the Stop response, retained output, cancelled model descendants, no new completion notification, and a successful later instruction; inspected screenshots corroborate the Stop-button result. Real-process owner suites additionally cover forbidden callers, revocation, and replacement sessions. The prepared manifest omitted the candidate slash image and recording, which were not independently viewed. Request ownership is process-local and changes no stored-data contract.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Stop interrupts the conversation but leaves its ordinary shell command running and able to produce a later notification.
Reason: Physical cancellation is a clear user expectation supported by the existing Stop and process-control contracts. The change delivers its explicitly bounded Gateway-request behavior without adding configuration or persistent state.

Merge readiness

✅ Ready for maintainer review

This PR addresses a necessary cancellation defect with convincing browser and process-lifecycle evidence. No actionable introduced bug was found, and current main still lacks the request-owned cancellation contract.

Priority: P1
Reviewed head: 1b79448d797518f72ac3b12cae28961b44884c33

Before merge

None.

Findings

None.

Provenance

  • src/agents/embedded-agent-runner/run-orchestrator.ts, session adoption, and Gateway dispatch wrappers: original intent not found (unknown: The supplemental feature-history search could not traverse unavailable older blobs in the partial clone; the patch adds request ownership around existing execution and accepted session-binding owners.)
Agent review details

How this fits together

The Gateway accepts chat and agent requests and dispatches their command tools to the process supervisor or sandbox. This change carries the accepted request identity into command execution so cancellation can reach commands after their tool calls return.

flowchart TD
  A[Chat or agent request] --> B[Accepted request owner]
  B --> C[Command tool]
  C --> D{Independent service?}
  D -->|Yes| E[Separate process lifetime]
  D -->|No| F[Request-owned process]
  G[Authorized Stop] --> B
  B --> F
  F --> H[Cleanup result and retained output]
Loading

Technical review

Best possible solution:

Keep cancellation in the existing Gateway authorization and process-lifecycle owners, with separate channel and continuation follow-ups retaining their stated boundaries.

Do we have a high-confidence way to reproduce the issue?

Yes: the real-Gateway fixture starts an ordinary yielded command, then uses composer Stop or typed /stop and checks whether its socket remains open when Stop replies. Recorded baseline failures and unchanged current-main ownership gaps support the defect; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes: separating request cancellation from disposable tool-call lifetime repairs the owning boundary while preserving independent services, normal completion, caller checks, and managed-worker lifetime.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 954012f95a6a.

Provenance checked

  • src/agents/bash-tools.exec-run.ts and src/agents/lazy-exec-tool.ts keeps the original intent (e4d602c: Separate disposable tool calls from background process lifetime so completed replies do not destroy retained services; managed-worker environment lifetime remains authoritative.)
  • src/agents/bash-tools.exec-runtime.ts and src/agents/bash-tools.exec-settlement.ts keeps the original intent (ce9a07f: Join retained supervisor descendant cleanup before reporting completion to prevent leaked child groups.)
  • src/gateway/server-methods/chat-abort-handler.ts and src/gateway/server-methods/chat-abort-runtime.ts keeps the original intent (da27b33: Bind delayed Stop effects to the original caller and exact session incarnation while preserving replacement runs and already-accepted cleanup.)
  • src/agents/bash-tools.exec-runtime.ts: completion notifications changes intended behavior with a stated reason (23462b4: Suppress unsolicited completion turns for manually cancelled commands while retaining output and notifying genuine cleanup failures.)
  • src/agents/bash-process-control.ts and src/agents/bash-process-registry.ts keeps the original intent (e25a981: Restore bounded process inspection and exact-process Stop through existing local and retained-worker owners without consuming output.)
  • ui/src/e2e/background-work.real-gateway.e2e.test.ts keeps the original intent (e25a981: Prove real process and subagent inspection, independent Stop, and preservation of the parent draft.)

Testing

Proof path: shipped entry point. Added test files: 11.

Security

None.

Evidence

What I checked:

  • Introduced patch: Reviewed the pinned merge-base-to-head delta, including request ownership, cancellation selection, process finalization, Gateway dispatch, documentation, test routing, and browser coverage. (src/infra/exec-request-context.ts:149, 1b79448d7975)
  • Still necessary on current main: Current main's process-control owner supports individual process cancellation but lacks captureExecRequestCancellation; the proposed request-owned cancellation path is absent. (src/agents/bash-process-control.ts:1, 954012f95a6a)
  • Browser before and after: Inspected prepared screenshots: the baseline Stop-button image shows Interrupted with the process still Running; the candidate image shows Stopped, manual-cancel, and the same retained output. The typed-/stop baseline also shows the surviving process. The manifest contains no prepared candidate slash screenshot or video, so those media were not independently inspected. (1b79448d7975)
  • Physical cleanup proof: The captured PR body records both controls changing process-alive-at-Stop-response from true to false, four passing real-Gateway browser cases, retained output, cancelled model descendants, no cancellation completion notification, and a successful new instruction. The browser test exercises the built UI, real Gateway, real command, and socket closure with a synthetic loopback model provider. Proof composition: head 1b79448 with main 950bd83; tree eb2d396ccb6c599df057f44a52791a8cd6176884. Captured body identity: 6ee9022e962a88b95f393fa988364100157053f4d3fedc7105e65cc99682ae6e. (ui/src/e2e/chat-stop-owned-exec.real-gateway.e2e.test.ts:197, 1b79448d7975)
  • Forbidden caller and completed receipt: The production-handler regression runs a real supervised command after model completion: unrelated-device cancellation returns unauthorized and leaves it alive, while its owning device stops it without rewriting the completed receipt. Hidden residual work is preserved by broad chat Stop. (src/gateway/server-methods/sessions.abort-dedupe-currentness.test.ts:176, 1b79448d7975)
  • Revocation and cleanup uncertainty: The cascade regression revokes the caller during accepted parent cancellation, independently observes the command PID dead, holds cleanup settlement, and verifies an uncertainty response while unauthorized descendant cancellation remains rejected. Focused passing results are recorded in the PR body. (src/gateway/server-methods/chat.abort-cascade.test.ts:195, 1b79448d7975)

Likely related people:

  • shakkernerd: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

PR surface

Source +602, Tests +1225, Docs +3. Total +1830 across 35 files.

View PR surface stats
Area Files Added Removed Net
Source 17 676 74 +602
Tests 16 1332 107 +1225
Docs 2 17 14 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 35 2025 195 +1830

Review metrics

Metric Value Why it matters
Ownership and regression coverage growth Production net +602 lines; tests/support net +1,225 lines Production growth supplies the missing request lifetime and cleanup joins; the larger supporting coverage exercises distinct process, authority, session-handoff, and browser boundaries.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Stop currently leaves ordinary commands physically running after the user cancels their Gateway request.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (4 earlier review cycles)
  • reviewed 2026-10-07T21:33:53.142Z sha 61d2f1e :: needs changes before merge. :: none
  • reviewed 2026-10-07T22:40:36.765Z sha 9e006fd2d225926405e71c4c3fc246fc1c4a2a9f :: needs changes before merge. :: none
  • reviewed 2026-10-07T23:38:47.912Z sha 1b79448 :: blocked before merge. :: none
  • reviewed 2026-10-08T01:18:13.991Z sha 1b79448 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 7, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Oct 8, 2026
@shakkernerd
shakkernerd merged commit 109bd47 into main Oct 8, 2026
176 of 180 checks passed
@shakkernerd
shakkernerd deleted the fix/stop-owned-exec branch October 8, 2026 01:54
@shakkernerd
shakkernerd restored the fix/stop-owned-exec branch October 8, 2026 01:56
@shakkernerd

Copy link
Copy Markdown
Contributor Author

Fixed: Gateway Stop now cancels ordinary yielded commands owned by the selected request and waits for their cleanup.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 8, 2026
Stop ordinary yielded commands with their selected Gateway request, wait for physical cleanup, and retain cleanup uncertainty after output eviction. Preserve explicitly independent services and suppress cancellation completion notifications.
@shakkernerd
shakkernerd deleted the fix/stop-owned-exec branch October 8, 2026 05:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant