Skip to content

fix: kill extension exec descendants on timeout - #98342

Closed
qingminglong wants to merge 1 commit into
openclaw:mainfrom
qingminglong:codex/98335-exec-timeout-descendants
Closed

qingminglong wants to merge 1 commit into
openclaw:mainfrom
qingminglong:codex/98335-exec-timeout-descendants

Conversation

@qingminglong

Copy link
Copy Markdown
Contributor

Closes #98335

What Problem This Solves

Fixes an issue where session extensions using api.exec() could report a timed-out, aborted, or output-limit-killed command as killed while descendant processes launched by that command continued running in the background.

Why This Change Was Made

api.exec() now uses the existing OpenClaw process-tree termination helper for timeout, abort, and default output-limit kills. On Unix it spawns the command in a separate process group so the tree signal reaches descendants; on Windows it stays non-detached and lets the shared helper use the taskkill tree boundary. The no-PID direct-kill fallback is preserved.

User Impact

Extension authors and operators can expect api.exec() cleanup to match the built-in command execution boundary more closely: when OpenClaw reports an extension exec command as killed, wrapper-launched descendants are not left behind under the normal timeout/abort/output-limit kill paths.

Evidence

  • Claim proved: timeout, abort, and default output-limit termination paths now call killProcessTree() when a child PID is available, while preserving the direct SIGTERM/SIGKILL fallback when no PID exists.
    • node scripts/run-vitest.mjs src/agents/sessions/exec.test.ts src/process/kill-tree.test.ts
    • Result: passed 2 Vitest shards; src/agents/sessions/exec.test.ts 11 tests passed, src/process/kill-tree.test.ts 7 tests passed.
  • Claim proved: touched files are formatted and have no whitespace errors.
    • corepack pnpm exec oxfmt --check --threads=1 src/agents/sessions/exec.ts src/agents/sessions/exec.test.ts
    • Result: passed; both files use the correct format.
    • git diff --check
    • Result: passed.
  • Claim proved: the Windows real process path kills a wrapper-launched descendant after timeout.
    • Ran a local node --import tsx - proof script that invoked execCommand(process.execPath, ["-e", parentScript], process.cwd(), { timeout: 250 }), where the parent Node process spawned a marker-bearing child Node process and then idled.
    • Observed result: { "killed": true, "code": 1, "leftovers": [] } for marker OPENCLAW_EXEC_TREE_PROOF_29996_1782873839097.
  • Review gate:
    • python .agents\skills\autoreview\scripts\autoreview --mode local
    • Result: autoreview clean: no accepted/actionable findings reported; the helper also printed a late Windows GBK reader-thread decode exception after the clean verdict, but exited 0.

Not tested / proof gaps:

  • I did not run full pnpm check, full typecheck, or broad test suites per the contributor-scope instructions.
  • I did not run a live Unix descendant-process reproduction; the Unix behavior is covered by focused spawn-option and kill-tree unit tests.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S 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: the same linked bug now has a stronger canonical landing path in #98340, which is open, mergeable, implements the same process-tree cleanup with explicit helper options, and has live ExtensionAPI.exec proof.

Root-cause cluster
Relationship: superseded
Canonical: #98340
Summary: This PR, #98340, and #98344 all target the same linked api.exec descendant-process cleanup bug; the canonical PR is the viable landing path with live ExtensionAPI.exec proof.

Members:

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

Canonical path: Use #98340 as the canonical landing path, optionally preserving this PR's extra abort and no-PID regression coverage there.

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

Review details

Best possible solution:

Use #98340 as the canonical landing path, optionally preserving this PR's extra abort and no-PID regression coverage there.

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

Yes at source level. Current main and v2026.6.11 kill only the direct api.exec child, while the linked PRs and shared helper show the intended process-tree cleanup boundary.

Is this the best way to solve the issue?

No as the branch to keep open. The implementation is plausible, but #98340 is the better canonical landing path because it has the same fix shape, explicit helper options, clean mergeability, and live ExtensionAPI.exec proof.

Security review:

Security review cleared: The diff stays within existing local process termination and tests, with no new dependency, secret, CI, workflow, package, or permission surface.

AGENTS.md: found and applied where relevant.

What I checked:

Likely related people:

  • vincentkoc: Blame and commit metadata point to vincentkoc for the current session exec backend, ExtensionAPI.exec delegation, shared process-tree helper, and sibling bash cleanup path 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/sessions/tools/bash.ts)

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

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. P2 Normal backlog priority with limited blast radius. 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

Extension api.exec can leave descendant processes running after timeout

1 participant