Skip to content

fix(exec): preserve sandbox cleanup outcomes and Linux group retirement - #139948

Merged
steipete merged 1 commit into
mainfrom
codex/one-shot-cleanup-followup-135868
Sep 6, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/one-shot-cleanup-followup-135868

Conversation

@steipete

@steipete steipete commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Related: #135868, #139517, #139657

What Problem This Solves

Fixes an issue where one-shot agent commands could report uncertain cleanup after a successful command in a reusable sandbox. A backend finalizer failure could conversely leave the cleanup outcome marked closed. On Linux installations without /bin/ps, normal owned command cleanup could not observe that its process group was ready to retire.

This is a focused follow-up to the landed process and runtime stages of #135868. The active update and recovery stages remain separate.

Why This Change Was Made

The supervisor now distinguishes cleanup of all execution, locally owned execution, and command transport. Ordinary one-shot tools preserve the backend's configured sandbox lifetime while still joining command finalization and requiring host process-tree cleanup. Strict outer executors retain their requirement. Backend-finalizer errors record uncertainty at the finalizer owner before the exec registry retires the session.

Host commands requiring tree cleanup reject the unsupported native PTY capability before starting it, allowing the existing exec fallback to run the command once as an owned child and show a warning. Linux group observation reads procfs, sharing the existing zombie/thread decision; the external host still owns proof that the kernel process group has disappeared. Darwin keeps its existing process census.

User Impact

Reusable sandbox commands can complete without a false cleanup failure, actual finalizer failures remain visible to the cleanup owner, and Linux group retirement works without a fixed ps executable path. Terminal-dependent commands may fail when the existing non-PTY fallback is required; this behavior is documented.

Evidence

  • On main-based production, the Linux regression had 10 intended failures, the public one-shot builder had 3, and the finalizer suite had 3 failures with 1 passing control. The unchanged regression files pass after the fix: 26 Linux cases, 3 builder cases, and 4 finalizer cases.
  • 99 additional tests passed across supervisor scope ownership, mocked relay cleanup, registry, cleanup timeouts, local TUI, and temporary worker state.
  • Fresh independent review found no actionable P0–P2 findings. Targeted formatting and diff checks passed.
  • Native Linux validation passed four selected cases on Blacksmith Testbox, using Node 24.19.0 and pnpm 12.3.4: ordinary child-group cancellation, retained descendant cleanup, real exec completion waiting on a controlled finalizer, and temporary backend env-file deletion. The exact runtime/test tree was verified before execution; the lease stopped successfully. Docker operations were mocked in the env-file case. The final source differs from the native-test tree only in the two typecheck shard configurations.
  • Full changed-file checks passed, including core and all test types, lint, guards, dead exports, and runtime import cycles. Their initial failure identified agents-root at 721 files against the unchanged 720 cap. The three related exec-runtime tests now belong to the existing agents-tools graph (root 718, tools 146); the compiler ownership check passes. No tests are omitted or compiler settings relaxed.

The focused tests use controlled adapters and finalizers; they are not live Docker, SSH, or NixOS installation proof. No configuration, SQLite schema, protocol, public plugin SDK, or MCP cleanup API changes are introduced.

Production delta: +112/-38 (net +74). Linux procfs support accounts for +48; explicit cleanup ownership, joining the existing finalizer registry, and preserving failure facts account for +26. Tests and support: +509/-36; docs: +11/-0.

Maintainer review resolution

Retain the documented PTY fallback for scopes requiring process-tree cleanup. It refuses an unsupported cleanup capability before execution and runs once through the existing owned-child path with a visible warning. Unscoped and transport-only PTY execution remain available and covered; terminal-dependent commands in strict scopes retain the stated limitation. A native PTY tree owner is separate work, not a compatibility shim in this repair.

No stored data model changes: service-child-group-ownership.ts only reads the kernel's transient /proc process census (or existing Darwin ps output). Its GroupMember values are local iteration results; they are neither serialized nor persisted. No database, table, schema version, record shape, migration, configuration format, or upgrade reader/writer changes. The automated data-model classification is a false positive, so no migration is required. The native state-schema guard and all core/test typecheck graphs passed.

Keep reusable sandbox lifetimes with the backend, join command finalizers,
and retain their cleanup failures while requiring host tree settlement.
Reject unsupported owned PTY requests before spawning so exec falls back once.
Use procfs for Linux group retirement without a fixed ps executable path.

Follow-up to #135868 after #139517 and #139657. Move the three related
exec-runtime test roots to the existing tools typecheck graph, preserving
the 720-root cap and complete coverage.
@clawsweeper

clawsweeper Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime commands Command implementations agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Sep 6, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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 Sep 6, 2026
@clawsweeper

clawsweeper Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 6, 2026, 4:48 AM ET / 08:48 UTC.

ClawSweeper review

What this changes

The PR preserves reusable sandbox lifetimes, joins command finalizers, retains cleanup failures, and uses Linux procfs to determine when owned process groups can retire.

Merge readiness

⛔ Blocked before merge - 2 items remain

This remains useful follow-up work absent from the supplied main revision. No actionable correctness defect was found; the maintainer-authored PR explicitly documents its terminal compatibility tradeoff.

Priority: P2
Reviewed head: 6bbc02afae9c347cef521f952f665b8324d2fd08

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful regression coverage and a clearly stated terminal compatibility tradeoff.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored PR is exempt from the ordinary contributor proof gate; its captured evidence reports native Linux cancellation and finalization coverage, with live Docker, SSH, and NixOS coverage explicitly unclaimed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored PR is exempt from the ordinary contributor proof gate; its captured evidence reports native Linux cancellation and finalization coverage, with live Docker, SSH, and NixOS coverage explicitly unclaimed.
Evidence reviewed 8 items Pinned introduction and current-main comparison: The complete introduced changes were inspected against merge-base 3b53aee. Comparing the four central production files with supplied main still shows the cleanup-policy, finalizer-failure, and procfs changes as outstanding. Endpoint drift was not treated as PR-owned work.
Cleanup ownership and finalizer settlement: The tool builder joins supervisor cleanup and the existing exec registry. The registry retains sessions through backend finalization, and finalizer exceptions now mark the originating cleanup receipt uncertain before session retirement.
Linux census cannot certify cleanup by itself: The new procfs census handles disappearing foreign processes conservatively and shares the existing zombie/thread check. The external relay host still requires an ESRCH result from the kernel process-group probe before confirming extinction.
Findings None None.
Security None None.

How this fits together

OpenClaw’s exec tools send host and sandbox commands through a process supervisor. Cleanup results tell the surrounding agent invocation when command resources have settled and whether releasing its state is safe.

flowchart TD
  A[Agent command] --> B[Cleanup policy]
  B --> C[Owned host process tree]
  B --> D[Sandbox command transport]
  C --> E[Native cleanup confirmation]
  D --> F[Backend finalizer]
  E --> G[Joined cleanup outcome]
  F --> G
  G --> H[Release state or retain uncertainty]
Loading

Before merge

  • Resolve merge risk (P1) - Terminal-dependent host commands in tree-required scopes can stop working when their PTY request falls back to a child process; the maintainer-authored proposal explicitly accepts and documents this limitation.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +74, Tests +473, Docs +11. Total +558 across 19 files.

View PR surface stats
Area Files Added Removed Net
Source 8 112 38 +74
Tests 10 509 36 +473
Docs 1 11 0 +11
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 19 632 74 +558

Review metrics

Metric Value Why it matters
Production versus validation growth Production net +74; tests and typecheck support net +473 The PR explains production growth as Linux procfs support plus explicit cleanup ownership and retained failure facts.

Stored data model

Persistent data-model change detected: serialized state: src/process/supervisor/service-child-group-ownership.ts, unknown-data-model-change: src/process/supervisor/service-child-group-ownership.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Retain the documented PTY limitation (recommended)
    Accept the stated terminal compatibility tradeoff while preserving reliable cleanup for host commands.
  2. Separate terminal support work
    If terminal-dependent one-shot commands must remain supported, defer that behavior until a native PTY process-tree owner can provide cleanup evidence.

Technical review

Best possible solution:

Keep sandbox lifetimes backend-owned and cleanup outcomes truthful, retaining the documented terminal fallback wherever native PTY cannot provide process-tree closure evidence.

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

Yes, from source: supplied main applies strict tree cleanup to reusable sandbox execution, omits cleanup-receipt recording on finalizer failure, and requires /bin/ps for Linux retirement. No runtime reproduction was executed during this review.

Is this the best way to solve the issue?

Yes. The patch repairs the existing cleanup owners and registry join, preserves strict outer executors, and leaves kernel extinction confirmation intact; its terminal limitation is explicitly documented.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 279d42d4be3f.

Labels

Label changes:

  • add P2: This repairs bounded command-cleanup failures without evidence of a widespread urgent outage.
  • add merge-risk: 🚨 compatibility: Tree-required host commands now lose native terminal semantics through the documented child-process fallback.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer-authored PR is exempt from the ordinary contributor proof gate; its captured evidence reports native Linux cancellation and finalization coverage, with live Docker, SSH, and NixOS coverage explicitly unclaimed.

Label justifications:

  • P2: This repairs bounded command-cleanup failures without evidence of a widespread urgent outage.
  • merge-risk: 🚨 compatibility: Tree-required host commands now lose native terminal semantics through the documented child-process fallback.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer-authored PR is exempt from the ordinary contributor proof gate; its captured evidence reports native Linux cancellation and finalization coverage, with live Docker, SSH, and NixOS coverage explicitly unclaimed.

Evidence

What I checked:

  • Pinned introduction and current-main comparison: The complete introduced changes were inspected against merge-base 3b53aee. Comparing the four central production files with supplied main still shows the cleanup-policy, finalizer-failure, and procfs changes as outstanding. Endpoint drift was not treated as PR-owned work. (src/process/supervisor/supervisor.ts:219, 6bbc02afae9c)
  • Cleanup ownership and finalizer settlement: The tool builder joins supervisor cleanup and the existing exec registry. The registry retains sessions through backend finalization, and finalizer exceptions now mark the originating cleanup receipt uncertain before session retirement. (src/agents/bash-tools.exec-runtime.ts:828, 6bbc02afae9c)
  • Linux census cannot certify cleanup by itself: The new procfs census handles disappearing foreign processes conservatively and shares the existing zombie/thread check. The external relay host still requires an ESRCH result from the kernel process-group probe before confirming extinction. (src/process/supervisor/service-child-relay-host.ts:343, 6bbc02afae9c)
  • Focused regression coverage: Inspected tests cover mixed host/backend cleanup, retained host failures, finalizer failures before and during joining, strict-scope precedence, and one execution through the PTY fallback. These are source-inspected tests; this review did not execute them. (src/process/supervisor/supervisor.one-shot-tools.test.ts:135, 6bbc02afae9c)
  • Intentional terminal compatibility change: Tree-required native PTY requests are rejected before launch, allowing exec’s existing child fallback. The PR body and documentation explicitly acknowledge that terminal-dependent commands may fail; unrestricted and transport-only PTY execution remain covered. Public docs: docs/gateway/background-process.md. (docs/gateway/background-process.md:106, 6bbc02afae9c)
  • Native evidence and inspection limitation: The captured PR body reports four native Linux cases covering child-group cancellation, retained descendants, real exec finalization, and temporary env-file cleanup at https://github.com/openclaw/openclaw/actions/runs/34021609907. It explicitly distinguishes mocked Docker operations from native process execution and says only typecheck configurations changed afterward. GitHub API and browser retrieval failed in this environment, so the linked logs were not independently inspected.

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

@steipete
steipete merged commit 2d345fa into main Sep 6, 2026
195 checks passed
@steipete
steipete deleted the codex/one-shot-cleanup-followup-135868 branch September 6, 2026 09:10
@steipete

steipete commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 7, 2026
Keep reusable sandbox lifetimes with the backend, join command finalizers,
and retain their cleanup failures while requiring host tree settlement.
Reject unsupported owned PTY requests before spawning so exec falls back once.
Use procfs for Linux group retirement without a fixed ps executable path.

Follow-up to openclaw#135868 after openclaw#139517 and openclaw#139657. Move the three related
exec-runtime test roots to the existing tools typecheck graph, preserving
the 720-root cap and complete coverage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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.

1 participant