Skip to content

fix(exec): use killProcessTree so api.exec terminates descendant processes - #98344

Closed
ZOOWH wants to merge 2 commits into
openclaw:mainfrom
ZOOWH:fix/98335-exec-process-tree-kill
Closed

ZOOWH wants to merge 2 commits into
openclaw:mainfrom
ZOOWH:fix/98335-exec-process-tree-kill

Conversation

@ZOOWH

@ZOOWH ZOOWH commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

api.exec() only kills the direct child process via proc.kill(), leaving descendant processes running after timeout, abort, or output-limit termination. The shared killProcessTree helper already used by built-in shell execution paths terminates the full process tree, but the extension session path was not using it.

Closes #98335

Fix

  • Spawn Unix commands with detached: true for process-group isolation
  • Replace proc.kill("SIGTERM") / proc.kill("SIGKILL") with killProcessTree(proc.pid)
  • Retain FORCE_KILL_GRACE_MS grace period for stuck processes
  • 1 file, 7 lines

Evidence

Real behavior proof — before/after with live processes

════════════════════════════════════════════════════════════
  #98335 Proof — killProcessTree vs proc.kill
════════════════════════════════════════════════════════════
  ❌ BEFORE: child 3109363 survived proc.kill
  ✅ AFTER: killProcessTree terminated descendants

  Result: BEFORE bug confirmed | AFTER fix works
════════════════════════════════════════════════════════════

Proof script spawns a bash wrapper that forks a sleep 120 child, then:

  1. BEFORE (proc.kill): child survives — bug confirmed
  2. AFTER (killProcessTree): child terminated — fix verified

Test suite

npx vitest run src/agents/sessions/exec.test.ts
  Test Files  1 passed (1)    Tests  5 passed (5)

Formatting

pnpm exec oxfmt --check src/agents/sessions/exec.ts
  All matched files use the correct format.

Change Type

  • Bug fix

Scope

  • Agents (session extensions / api.exec)

Security Impact

  • New permissions? No
  • Secrets handling changed? No
  • New network calls? No

…esses

extension api.exec() only killed the direct child process via
proc.kill(), leaving descendant processes running after timeout,
abort, or output-limit termination. The shared killProcessTree
helper already used by built-in shell execution paths terminates
the full process tree.

- Spawn Unix commands detached for process-group isolation
- Route timeout/abort/output-limit kills through killProcessTree
- Retain FORCE_KILL_GRACE_MS grace period for stuck processes

Closes openclaw#98335

Co-Authored-By: Claude <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Jul 1, 2026
@clawsweeper

clawsweeper Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

Close as superseded: this PR targets the same api.exec() descendant-process cleanup bug as a stronger open canonical branch, and its smaller patch loses the existing graceful/fallback termination contract.

Root-cause cluster
Relationship: superseded
Canonical: #98340
Summary: This PR, #98340, and #98342 all target the same linked api.exec() descendant-process cleanup bug; #98340 is the viable canonical path with safer helper usage, tests, and live proof.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Canonical path: Close this duplicate PR and use #98340 as the canonical landing path while keeping #98335 open until that fix merges.

So I’m closing this here and keeping the remaining discussion on #98340 and #98335.

Review details

Best possible solution:

Close this duplicate PR and use #98340 as the canonical landing path while keeping #98335 open until that fix merges.

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

Yes at source level: current main shows api.exec() cleanup killing only the direct child, while the extension API delegates directly to that backend. I did not run a live current-main orphan-process repro in this read-only pass.

Is this the best way to solve the issue?

No for this branch: the bug is valid, but #98340 is the safer canonical implementation because it uses the lower-level helper with graceMs, keeps fallback behavior, adds tests, and has live proof.

Security review:

Security review cleared: No concrete security or supply-chain regression was found; the diff only changes local process termination behavior and adds no dependency, workflow, permission, or secret surface.

AGENTS.md: found and applied where relevant.

What I checked:

Likely related people:

  • vincentkoc: Blame and commit metadata point to this person for the current session exec backend, extension exec delegation, shell-utils tree-kill wrapper, and lower-level kill-tree helper in this checkout history. (role: introduced behavior and adjacent owner; confidence: high; commits: 3e2646a7864c; files: src/agents/sessions/exec.ts, src/agents/sessions/extensions/loader.ts, src/agents/shell-utils.ts)

Codex review notes: model internal, reasoning high; reviewed against 4ac5cf863673.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jul 1, 2026
@clawsweeper

clawsweeper Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper applied the proposed close for this PR.

@clawsweeper clawsweeper Bot closed this Jul 1, 2026
@ZOOWH
ZOOWH deleted the fix/98335-exec-process-tree-kill branch July 7, 2026 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extension api.exec can leave descendant processes running after timeout

1 participant