Skip to content

fix: stop remote tools when Code Mode abandons their response - #200647

Merged
steipete merged 1 commit into
mainfrom
codex/codemode-abandoned-call-cancel
Nov 17, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/codemode-abandoned-call-cancel

Conversation

@steipete

@steipete steipete commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Related: #200601

What Problem This Solves

When a worker-hosted Code Mode tool request times out while waiting for its Gateway response, the guest receives an error but the remote tool can keep running. Its cancellation listener was removed when the transport wait rejected, leaving ongoing work without its observer.

The November 17 production incident contained nine watchdog-aborted runs (eight user turns and one subagent spawn), each stalled on callValue for 15–41 minutes. The clearer sequences showed an earlier bridge timeout/abort followed by local workspace reconciliation lease waits and another stalled host call; retries re-hung. This PR reproduces a cancellation leak consistent with that sequence, without claiming that it proves the cause of every incident lease wait.

User Impact

Abandoned worker Gateway tool invocations now receive cancellation promptly, so cooperative tools can release their resources. Parked Code Mode calls continue running and remain resumable through wait. No config, tool deadline, execution budget, watchdog threshold, protocol/schema, or lease policy changes.

Why This Change Was Made

Both incident release a117ca50 and this PR's base already create a per-request AbortController, relay cell abort, and pass that signal to host dispatch (src/agents/code-mode-state.ts:496–525). Adding another controller would duplicate the existing owner. The missing cancellation was in the worker Gateway proxy: a rejected transport wait exited before its signal aborted, and finally removed the only remote-cancellation listener.

The proxy now requests cancellation for that exact issued invocation when invokeGatewayTool rejects (src/worker/worker-gateway-tools.ts:58). It shares the existing abort handler and requests cancellation once. The Gateway's existing call controller delivers the abort to the host tool (src/gateway/worker-environments/worker-gateway-tool-runtime.ts:219–235,296–301). Reconnection retries still stay inside invokeGatewayTool; they are not abandoned attempts.

Abandoned versus parked:

  • Terminal guest completion/failure cleans remaining pending calls at src/agents/code-mode-execution.ts:550; explicit abort/error paths cancel at lines 489, 516, and 523. Successful guests first drain dispatched calls.
  • Guest-discarded request IDs cancel at src/agents/code-mode-state.ts:358–373; cell/catalog closure aborts the owner at lines 166–176; dropped/expired continuations cancel at lines 327–331.
  • An exhausted ordinary call budget parks at src/agents/code-mode-execution.ts:497, retaining pending calls. It is not abandonment. A transport wait that finally rejects is abandonment of that remote invocation even if the guest catches its error.

Lane 2559 owns lease fairness separately; no lease code is changed. #200601 supplies pending-tool attribution on watchdog aborts; this change repairs cancellation rather than diagnostic attribution. Release-note context: stop remote Gateway work when a worker Code Mode call abandons its transport response.

Evidence

The regression runs actual Node and QuickJS guests through the worker proxy and real Gateway tool owner. A synthetic host tool awaits its AbortSignal; fixed transport I/O rejects the response wait while the host remains active. On base 46982ac40764b40cd06ede122d4397a1532757c8, the regression failed in both executors at expect(signal.aborted).toBe(true): received false (2 failed, 27 skipped). With the fix, both abandonment cases abort and settle the host, and parked-then-resumed controls complete without aborting it.

Commands and results:

  • Red: pnpm test src/gateway/worker-environments/worker-gateway-tool-runtime.test.ts --maxWorkers=1 -- -t 'cancels abandoned transport calls': 2 failed / 27 skipped; 44.83s wrapper wall.
  • Green: pnpm test src/gateway/worker-environments/worker-gateway-tool-runtime.test.ts --maxWorkers=1: 29 passed; 39.50s wrapper wall, 34.34s Vitest duration (89% transform, 7% tests). The compiled-worker boundary accounts for setup cost.
  • Consumer: pnpm test src/worker/worker-gateway-tools.test.ts --maxWorkers=1: 4 passed; 47.30s wrapper wall, 42.08s Vitest duration (91% transform, 4% tests).

Net test growth is 75 lines, below the 400-line allocation threshold. Net production growth is 11 lines: a transport rejection handler and deduplication of its cancellation with signal abort. The author simplification pass retains the existing owners and cancellation protocol.

Limits: this is a production-owner integration test with synthetic transport I/O, not a deployed incident or live model replay. Sandbox shell operations forward signals (src/agents/sandbox/local-workspace.ts:294–300) and foreground exec kills its process on abort (src/agents/bash-tools.exec-run.ts:610–636). However, sandbox exec preparation calls projection.provision without a signal (src/agents/sandbox/local-workspace.ts:305–315), and buildExecSpec has no signal parameter (src/agents/sandbox/backend-handle.types.ts:79–87). Termination/checkpoint settlement also deliberately continues without the canceled call's signal (src/agents/sandbox/local-workspace.ts:217–228). Therefore this cancellation fix cannot guarantee release of a lease stuck in those paths; their behavior is unchanged.

All local checks passed: core production typecheck, a targeted two-file test typecheck, production/test type-aware lint, formatting, docs MDX validation, git diff --check, and pnpm build (3m 19.7s). Build returned zero with UI bundle-budget advisories; no UI files are changed. Exact-head CI run 44108637926 completed successfully, without retries. All 14 selected Node test jobs passed in 4,748 aggregate runner-seconds including setup. This is the complete selected test-lane cost, not a per-file or marginal cost; per-file CI timing artifacts are unavailable.

Codex autoreview of the complete local diff against 46982ac40764b40cd06ede122d4397a1532757c8, through P2: scoped-clean, no accepted/actionable findings. The reviewer received the unchanged Code Mode state/execution owners, Gateway tool runtime, and worker connection replay owner as context. It did not independently run tests in its empty sandbox.

@clawsweeper

clawsweeper Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T14:58:55.969481Z 847b6cc PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: S labels Nov 17, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 17, 2026
@steipete
steipete enabled auto-merge (squash) November 17, 2026 15:10
@steipete
steipete merged commit bb36860 into main Nov 17, 2026
144 of 146 checks passed
@steipete
steipete deleted the codex/codemode-abandoned-call-cancel branch November 17, 2026 15:12
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash auto-merge.

RomneyDa added a commit that referenced this pull request Nov 17, 2026
Backport the merged worker proxy cancellation fix to 2026.11.6.
Preserve parked Node and QuickJS calls until resumed; cancel only an
abandoned transport observer through the existing Gateway owner.

(cherry picked from commit bb36860)

Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 18, 2026
RomneyDa pushed a commit that referenced this pull request Nov 19, 2026
(cherry picked from commit bb36860)

Co-authored-by: RomneyDa <[email protected]>

Release adaptation: none; source change applies to the pinned beta baseline.

Follow-up disposition: bounded pinned-main same-path audit recorded in the lane report; cross-lane changes remain parent-owned.

(cherry picked from commit 3268deb86f53d0ba4e6d4e06c734a3043aecab48)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. docs Improvements or additions to documentation gateway Gateway runtime size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant