Skip to content

fix(agents): reject cancelled foreground commands - #115694

Merged
steipete merged 1 commit into
mainfrom
codex/s19-exec-foreground-cancellation
Jul 29, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/s19-exec-foreground-cancellation

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Closes #105681
Supersedes #105726, with its original contributor credited as a commit co-author.

What Problem This Solves

Fixes an issue where cancelling a running foreground shell command returned a normal failed tool result instead of stopping tool execution with an AbortError. A pending yield timer could also incorrectly promote the cancelled command into a background task.

Why This Change Was Made

Track cancellation only while the command is genuinely in the foreground. Stop its pending promotion timer, terminate and fully settle the real child process, then reject with the existing canonical AbortError and preserve the original cancellation reason as its cause. Already-backgrounded processes, ordinary failures, process timeouts, output suppression, and normal yield ownership retain their existing behavior.

User Impact

A stop or cancellation reliably ends an in-flight foreground command without producing misleading shell output or registering a phantom background task. Intentionally detached background jobs remain alive and finish normally after the originating tool signal is cancelled.

Evidence

Independently reproduced the issue against fresh main and actual spawned Node child processes on Blacksmith Testbox tbx_01kyp8p0bnry09xrf031y5n3p3; no process supervisor or shell mocks were used by the new process regressions.

Before the fix, both real foreground cases failed identically:

FAIL finalizes and rejects an aborted real foreground execution
FAIL finalizes and rejects an aborted real foreground execution before the yield timer
AssertionError: promise resolved instead of rejecting
exitReason: manual-cancel
exitSignal: SIGTERM
status: failed
PASS keeps a real background process running after its tool signal aborts

After the fix, the same Blacksmith lease passed all foreground, yield-race, real background-child, non-abort, timeout, output-suppression, and run-abort-wrapper coverage:

pnpm test src/agents/bash-tools.exec-task-wiring.test.ts src/agents/bash-tools.test.ts src/agents/bash-tools.exec.background-abort.test.ts src/agents/bash-tools.exec-foreground-failures.test.ts src/agents/agent-tools.abort.test.ts
Test Files  5 passed (5)
Tests       69 passed (69)

pnpm check:changed
exit 0; core and test typechecks, formatting, changed-file lint, dependency, SDK, cycle, migration, and repository guard checks all passed

.agents/skills/autoreview/scripts/autoreview --mode uncommitted --engine codex --model gpt-5.6-sol --thinking xhigh
autoreview clean: no accepted/actionable findings reported

Thanks to @zw-xysk for the original report and fix direction in #105726; the commit retains their co-author credit while adding actual-child red/green proof, canonical abort causes, and the pre-registration yield-race guard.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Jul 29, 2026
@steipete
steipete force-pushed the codex/s19-exec-foreground-cancellation branch from 9602362 to 187c790 Compare July 29, 2026 07:08
@steipete
steipete merged commit 7c6eba5 into main Jul 29, 2026
122 of 124 checks passed
@steipete
steipete deleted the codex/s19-exec-foreground-cancellation branch July 29, 2026 08:22
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Jul 29, 2026
* origin/main: (100 commits)
  fix(hooks): kill gog process tree on gmail-watcher shutdown (#112452)
  fix(memory): avoid phantom continuation pages (#115722)
  fix(agents): reject cancelled foreground commands (#115694)
  fix(telegram): prevent false empty replies after message-tool delivery (#115588)
  refactor: unify session cost rollup scans (#115749)
  fix(agents): honor completed semantic command exits (#115737)
  feat(agents): persist last-used session model as the agent default (#115717)
  feat(openai): support GPT-Live over backend WebSocket (#115622)
  fix(ui): unify sidebar thread density (#115646)
  feat(ui): path-based agent and panel URLs on Settings > Agents (#115673)
  feat(gateway): serve HTTP byte ranges on media routes (#115667)
  refactor: consolidate Teams and Zoom meeting plugin shells (#115707)
  fix(browser): release unread CDP response streams (#115675)
  feat(ui): move settings save feedback into the sidebar footer (#115679)
  fix(plugins): enforce hook security invariants (#115701)
  refactor: deduplicate extension normalization primitives (#115650)
  feat(gateway): add least-privilege voice-node pairing (#115712)
  fix(ui): restore in-flight assistant replies after reconnect (#115691)
  fix(whatsapp): infer native media from filenames (#115725)
  fix(system-agent): avoid TUI startup catalog preparation (#113136)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Tool-Call Aborts are Treated as Successful Execution Results Instead of Throwing AbortErrors (Bash Exec)

1 participant