Skip to content

fix(process): await process-tree cleanup before cancellation settles - #98539

Merged
steipete merged 2 commits into
mainfrom
codex/extension-exec-awaited-cleanup
Aug 26, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/extension-exec-awaited-cleanup

Conversation

@steipete

@steipete steipete commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Cancelled extension and Bash commands could report completion while descendant processes remained alive.

Repair

Route both execution owners through the canonical process-tree termination controller while preserving existing per-caller grace periods and Windows CI coverage.

Verification

A real spawned SIGTERM-resistant parent/child failed before the fix and passes afterward. Exact-head focused proof: 65 tests passed; two platform-specific tests skipped. Independent review and secret scanning passed. Broader local typechecking is blocked by unrelated pre-existing dependency mismatches.

@steipete steipete self-assigned this Jul 1, 2026
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Jul 1, 2026
@steipete
steipete force-pushed the codex/extension-exec-awaited-cleanup branch from 17d40cf to 473706b Compare July 1, 2026 09:55
@clawsweeper

clawsweeper Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 25, 2026, 7:49 PM ET / 23:49 UTC.

ClawSweeper review

What this changes

The PR routes extension-command and Bash cancellation through a shared process-tree termination controller and adds regression coverage.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep open: the central Bash timeout path still selects force mode, whose shared settlement path returns immediately on POSIX, so a timed-out Bash command can reject before descendants have exited.

Priority: P1
Reviewed head: 6fa02cb8c5d23e7b41ab7ef3c3bc74269ec02f47

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The shared refactor is useful, but the central Bash cancellation guarantee remains incomplete.
Proof confidence 🌊 off-meta tidepool Not applicable: Not applicable to this MEMBER-authored PR; the branch includes a real extension-runner test, but no equivalent real Bash process-tree proof.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Not applicable to this MEMBER-authored PR; the branch includes a real extension-runner test, but no equivalent real Bash process-tree proof.
Evidence reviewed 5 items Current-main baseline: Current main still has the boolean tree-cleanup path, which records a settle deadline for every tree termination; the PR introduces the force-mode exception.
Bash bypasses settlement: The changed Bash caller explicitly selects force mode.
Force mode returns before cleanup is observed: The controller's settle method returns unless the mode is graceful, while POSIX force termination only sends SIGKILL synchronously.
Findings 1 actionable finding [P1] Await force-mode cleanup before rejecting Bash
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/agents/sessions/exec.real.test.ts

Result: PASS (completed)

[test] starting test/vitest/vitest.agents-support.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-98539-6L0AYF/target

 ✓  agents-support  src/agents/sessions/exec.real.test.ts (1 test) 6101ms
     ✓ does not resolve a timeout while a SIGTERM-resistant descendant is alive  6098ms

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  23:50:22
   Duration  7.61s (transform 1.18s, setup 951ms, import 202ms, tests 6.10s, environment 0ms)

[test] passed 1 Vitest shard in 13.51s
[test] starting test/vitest/vitest.agents-support.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-98539-6L0AYF/target

 ✓  agents-support  src/agents/sessions/exec.real.test.ts (1 test) 6092ms
     ✓ does not resolve a timeout while a SIGTERM-resistant descendant is alive  6089ms

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  23:50:36
   Duration  6.89s (transform 395ms, setup 445ms, import 119ms, tests 6.09s, environment 0ms)

[test] passed 1 Vitest shard in 12.69s

Assertions:

  • PASS expect_output: does not resolve a timeout while a SIGTERM-resistant descendant is alive

How this fits together

Extension command execution and the built-in Bash tool spawn local subprocess trees. Their cancellation paths use the shared termination controller before reporting a timeout or abort back to the agent.

flowchart LR
A[Agent command] --> B[Bash or extension runner]
B --> C[Termination controller]
C --> D[Process tree]
D --> E[Cleanup settlement]
E --> F[Timeout or abort result]
Loading

Before merge

  • Await force-mode cleanup before rejecting Bash (P1) - Bash selects force here, but settle() immediately returns for that mode in src/process/exec-termination.ts:130. On POSIX, SIGKILL is only sent synchronously, so the shell can settle and reject the timeout while a descendant remains alive. This is the prior P1 still present on the current head; add an awaited group-exit condition and a real Bash parent/child regression.
  • Resolve merge risk (P1) - On POSIX, a timed-out Bash command can reject once its shell exits while force-killed descendants are still terminating, leaving agent execution state ahead of actual cleanup.
  • Resolve merge risk (P1) - The bug-fix branch adds net 21 production/tooling lines; that growth is warranted only if the shared controller becomes the authoritative owner of force-mode cleanup settlement.
  • Complete next step (P2) - This protected maintainer PR has a concrete P1 in its central Bash path; it needs an author/maintainer revision and real Bash boundary proof.

Findings

  • [P1] Await force-mode cleanup before rejecting Bash — src/agents/sessions/tools/bash.ts:100
Agent review details

Security

None.

PR surface

Source +21, Tests +253, Config 0. Total +274 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 6 75 54 +21
Tests 3 266 13 +253
Docs 0 0 0 0
Config 1 1 1 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 342 68 +274

Review metrics

Metric Value Why it matters
Production versus test LOC production/tooling +76/-55 (net +21); tests +266/-13 (net +253) The shared lifecycle refactor is acceptable only if it supplies the missing authoritative settlement guarantee; the added mock coverage does not prove the Bash path.

Stored data model

Persistent data-model change detected: serialized state: src/agents/sessions/exec.real.test.ts, serialized state: src/agents/sessions/exec.test.ts, serialized state: src/agents/sessions/exec.ts, serialized state: src/agents/sessions/tools/bash-termination.test.ts, serialized state: src/agents/sessions/tools/bash.ts, unknown-data-model-change: src/agents/sessions/exec.real.test.ts, and 4 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Repair force-mode settlement (recommended)
    Make force mode await real Bash process-tree cleanup and add a real SIGTERM-resistant parent/child regression before merge.

Technical review

Best possible solution:

Make the shared controller await bounded process-group disappearance for Bash force mode, preserving immediate signaling, and prove it with a real Bash parent/child timeout regression.

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

Yes—use a Bash parent that spawns a SIGTERM-resistant child, then time out the Bash call and verify the child is gone before rejection. This read-only review did not execute that scenario.

Is this the best way to solve the issue?

No—the shared controller is the right owner, but its force branch deliberately bypasses settlement; it needs an awaited group-exit condition rather than a mocked delay.

Full review comments:

  • [P1] Await force-mode cleanup before rejecting Bash — src/agents/sessions/tools/bash.ts:100
    Bash selects force here, but settle() immediately returns for that mode in src/process/exec-termination.ts:130. On POSIX, SIGKILL is only sent synchronously, so the shell can settle and reject the timeout while a descendant remains alive. This is the prior P1 still present on the current head; add an awaited group-exit condition and a real Bash parent/child regression.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: The built-in Bash timeout path can report cancellation while descendants remain alive, affecting active agent command execution.
  • merge-risk: 🚨 availability: Merging leaves the central cancellation guarantee incomplete, allowing background descendants to outlive a completed timeout result.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: Not applicable to this MEMBER-authored PR; the branch includes a real extension-runner test, but no equivalent real Bash process-tree proof.

Evidence

What I checked:

Likely related people:

  • steipete: Current-head blame attributes the Bash integration and controller settlement lines to this author. (role: introduced current termination-controller integration; confidence: high; commits: 6fa02cb8c5d2; files: src/agents/sessions/tools/bash.ts, src/process/exec-termination.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Add a real Bash SIGTERM-resistant parent/child timeout test that proves rejection occurs only after the descendant exits.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-08-18T07:36:08.847Z sha cb77e26 :: found issues before merge. :: [P1] Rebase the Windows regression into the current shard layout
  • reviewed August 23, 2026, 9:17 AM ET / 13:17 UTC sha unknown :: found issues before merge. :: [P1] Rebase the Windows regression into the current shard layout
  • reviewed 2026-08-25T22:37:52.825Z sha 9a1961a :: needs changes before merge. :: [P1] Wait for forced POSIX termination before settling Bash

@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. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. and removed merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 1, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Jul 30, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 9, 2026
@steipete steipete closed this Aug 10, 2026
@steipete steipete reopened this Aug 10, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 10, 2026
@steipete
steipete force-pushed the codex/extension-exec-awaited-cleanup branch 3 times, most recently from f272378 to d9aaf4f Compare August 10, 2026 13:58
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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 Aug 10, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 10, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 23, 2026
@steipete
steipete force-pushed the codex/extension-exec-awaited-cleanup branch from cb77e26 to cebe9a9 Compare August 25, 2026 21:26
@openclaw-barnacle openclaw-barnacle Bot removed the scripts Repository scripts label Aug 25, 2026
@steipete steipete changed the title fix: await extension api.exec process-tree cleanup fix(process): await process-tree cleanup before cancellation settles Aug 25, 2026
@steipete
steipete force-pushed the codex/extension-exec-awaited-cleanup branch from cebe9a9 to 9a1961a Compare August 25, 2026 22:31
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. and removed P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. labels Aug 25, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready verification on exact head 6fa02cb: cancellation now settles only after platform-owned process-tree termination completes. Fresh full-branch P1 review and all 201 hosted checks are clean; 65 focused tests pass. Six real Bash timeout runs spawned 96 SIGTERM-resistant descendants, and every descendant was already dead at the cancellation rejection boundary. ClawSweeper force-mode polling suggestion intentionally not applied: synchronous SIGKILL of the detached process group passed the 96-process real proof, while speculative polling would add PID-reuse and zombie risk. Upstream contracts personally verified in codex-rs/core/src/exec.rs and codex-rs/utils/pty/src/process_group.rs.

@steipete
steipete merged commit 316c341 into main Aug 26, 2026
201 checks passed
@steipete
steipete deleted the codex/extension-exec-awaited-cleanup branch August 26, 2026 03:05
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 26, 2026
…penclaw#98539)

* fix(process): await process-tree cleanup before cancellation settles

* fix(process): remove unused process-tree options re-export
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 merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant