Skip to content

fix(mxc): bound termination and output drain cleanup - #1166

Closed
miketripblog wants to merge 2 commits into
openclaw:mainfrom
miketripblog:local/issue-1122-bounded-mxc-cleanup
Closed

miketripblog wants to merge 2 commits into
openclaw:mainfrom
miketripblog:local/issue-1122-bounded-mxc-cleanup

Conversation

@miketripblog

@miketripblog miketripblog commented Aug 15, 2026 •

Copy link
Copy Markdown

Summary

This addresses NODE-2 in issue #1122. It intentionally does not close #1122 because that issue contains multiple findings.

Root cause

Cancellation could block synchronously in process-tree termination. The normal launcher-exit path could also wait indefinitely when a descendant retained inherited stdout or stderr handles. The first bounded-kill implementation could retain one dedicated worker per permanently blocked kill.

Change

  • Bounds process-tree kill and redirected-output drain waits.
  • Caps process-tree kill workers process-wide at eight.
  • Waits for transient worker capacity within the existing cleanup timeout, then uses only the remaining timeout for the kill.
  • Releases worker capacity on completion and worker-start failure.
  • Preserves cancellation, result, containment, approval, and output semantics.

Regression coverage

  • A blocking kill cannot pin the caller.
  • Ten repeated permanently blocked kills start no more than eight process-wide workers, all callers remain bounded, and capacity recovers after release.
  • A kill queued behind eight workers starts when transient capacity returns inside the same cleanup budget.
  • A real descendant retaining inherited redirected handles cannot pin a completed launcher result.

Validation

Current head: bb12539e

  • powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\build.ps1: passed. Shared, CLI, WinNode CLI, SetupEngine, and WinUI built successfully; documentation validation passed for 46 Markdown files.
  • dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore --filter FullyQualifiedName~Mxc: 200 passed, 7 environment-gated skips, 0 failed.
  • dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore: 3,698 passed, 32 skipped, 4 failed. The four failures are unchanged ExecReusableCommandBinderTests failures and all four reproduced on pristine base fc9add75 in a detached temporary worktree.
  • dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore: 2,469 passed, 0 skipped, 0 failed.
  • python .\.agents\skills\autoreview\scripts\autoreview --mode local ...: clean, with no accepted or actionable findings after the concurrency and test-determinism fixes.

The four base-reproduced Shared failures are:

  • CarrierPayloadWithExplicitRelativePath_IsNotTreatedAsAmbiguous
  • AcceptedSpaceGrammar_MatchesRealCmdChildArgv
  • AcceptedMultiElementTail_MatchesRealCmdChildArgv
  • AcceptedTabGrammar_MatchesRealCmdChildArgv

Real behavior proof

Current-head local Windows process regressions passed:

Repeated blocked-kill regression:
10 attempts
8 process-wide workers started
all attempts returned within the cleanup bound
worker capacity recovered after release

Transient saturation regression:
8 worker slots occupied
9th kill waited without starting
1 slot released
9th kill started and completed inside its cleanup budget

MXC-focused result:
Failed: 0, Passed: 200, Skipped: 7, Total: 207

The descendant-retained-handle test launches a real Windows child process that inherits stdout and stderr handles after its parent exits. The parent result returned successfully inside the bound, and the test cleaned up the descendant.

Proof limitation

Gateway MXC E2E was not run because this task explicitly prohibited Gateway MXC E2E. It is not presented as passed. No Gateway, pairing, permission, credential, or Pavilion install path was used.

Security and capability impact

No new permissions, identity, pairing, network, sandbox, or command authority.

@clawsweeper

clawsweeper Bot commented Aug 15, 2026 •

Copy link
Copy Markdown

🦞👀
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.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. P1 Urgent regression or broken agent/channel workflow affecting real users now. 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. labels Aug 15, 2026
@clawsweeper

clawsweeper Bot commented Aug 15, 2026 •

Copy link
Copy Markdown

Codex review: needs real behavior proof before merge. Reviewed September 9, 2026, 8:19 PM ET / September 10, 2026, 00:19 UTC (Revision 5).

ClawSweeper review

What this changes

Bounds cleanup waits for sandboxed Windows commands, caps blocked termination workers at eight, and adds Windows process regression tests.

Merge readiness

⛔ Blocked before merge - 6 items remain

This remains useful work: current main and the latest release retain the blocking paths. Both previously reported defects remain unresolved, and the supplied Windows process evidence does not satisfy the repository’s required MXC integration proof.

Priority: P1
Reviewed head: bb12539e90255f49f3b384cd9360d8949fd72a27

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused reliability work with meaningful partial proof, but two unresolved defects and required native validation prevent merge readiness.
Proof confidence 🦐 gold shrimp (3/6) Needs stronger real behavior proof before merge: The captured current-head Windows output provides meaningful partial proof of MxcExecutor’s bounded return and worker recovery using real child processes and injected killers. It explicitly omits the repository-required real Gateway-to-node-to-wxc-exec MXC validation, so the native integration gate remains unmet. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) 2 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The captured current-head Windows output provides meaningful partial proof of MxcExecutor’s bounded return and worker recovery using real child processes and injected killers. It explicitly omits the repository-required real Gateway-to-node-to-wxc-exec MXC validation, so the native integration gate remains unmet. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 9 items Current main still needs the cleanup fix: Current main still calls the process-tree killer synchronously and uses unbounded WaitForExit on normal completion.
Latest release retains the same paths: The supplied latest release, v2026.7.1-4, also retains synchronous termination and the unbounded successful-output drain.
Introduced output-loss trigger: The new normal-completion timeout snapshots line-event buffers without EOF. BeginOutputReadLine and BeginErrorReadLine do not deliver an unterminated final line while a descendant retains the pipe.
Findings 2 actionable findings [P2] Preserve newline-free output before returning from the bounded drain
[P2] Wait for a complete PID before parsing the descendant file
Security None None.

How this fits together

MXC runs approved Windows commands inside an AppContainer through wxc-exec. Its executor receives cancellation and process output, then returns command results to the Windows node.

flowchart TD
 A[Approved Windows command] --> B[AppContainer executor]
 B --> C[wxc-exec launcher]
 C --> D[Exit or cancellation]
 D --> E[Bounded termination and output drain]
 E --> F[Command result]
 F --> G[Windows node]
Loading

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The captured current-head Windows output provides meaningful partial proof of MxcExecutor’s bounded return and worker recovery using real child processes and injected killers. It explicitly omits the repository-required real Gateway-to-node-to-wxc-exec MXC validation, so the native integration gate remains unmet. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Preserve newline-free output before returning from the bounded drain (P2) - This prior finding remains unresolved. If the launcher writes stdout or stderr without a newline and exits while a descendant retains that pipe, the line reader cannot publish the trailing text until EOF. The new deadline snapshots an empty or incomplete builder and returns success, permanently losing already-written output. Capture available chunks independently of newline/EOF and cover both streams under a retained-handle timeout.
  • Wait for a complete PID before parsing the descendant file (P2) - This prior finding remains unresolved. File.Exists can become true before Set-Content finishes writing or releases the file. ReadAllTextAsync or int.Parse can then fail before descendantPid is assigned, making the regression flaky and leaving cleanup with PID zero. Publish the PID atomically or retry until a complete valid PID can be read, while retaining a reliable cleanup target.
  • Resolve merge risk (P1) - Successful command results can silently omit unterminated stdout or stderr when the new drain deadline expires.
  • Resolve merge risk (P1) - The supplied proof does not exercise the actual wxc-exec integration through the required Gateway MXC path.
  • Complete next step (P2) - Resolve both findings and provide current-head required Windows validation, including MXC E2E console/TRX evidence. Redact credentials, IP addresses, private endpoints, and user paths. Update the PR body to trigger re-review; if it does not, ask a maintainer to comment @clawsweeper re-review.

Findings

  • [P2] Preserve newline-free output before returning from the bounded drain — src/OpenClaw.Shared/Mxc/MxcExecutor.cs:217-218
  • [P2] Wait for a complete PID before parsing the descendant file — tests/OpenClaw.Shared.Tests/Mxc/MxcExecutorTests.cs:344-345
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and test growth production +66 net lines; tests +281 lines The production growth implements bounded termination workers, with four new regression scenarios.

Merge-risk options

Maintainer options:

  1. Preserve output within the cleanup bound (recommended)
    Repair partial-line capture and prove existing successful-output behavior alongside bounded cleanup before landing.

Technical review

Best possible solution:

Keep bounded cleanup and worker limits while capturing available output independently of line endings, with reliable descendant cleanup and current-head native MXC validation.

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

Yes, source establishes the blocking termination and inherited-pipe paths; the supplied Windows runs exercise them. This read-only review did not execute a current-main reproduction.

Is this the best way to solve the issue?

Not yet: bounding cleanup in the existing executor is appropriate, but retaining line-based capture loses partial output at the new deadline, and the descendant test has a publication race.

Full review comments:

  • [P2] Preserve newline-free output before returning from the bounded drain — src/OpenClaw.Shared/Mxc/MxcExecutor.cs:217-218
    This prior finding remains unresolved. If the launcher writes stdout or stderr without a newline and exits while a descendant retains that pipe, the line reader cannot publish the trailing text until EOF. The new deadline snapshots an empty or incomplete builder and returns success, permanently losing already-written output. Capture available chunks independently of newline/EOF and cover both streams under a retained-handle timeout.
    Confidence: 0.98
  • [P2] Wait for a complete PID before parsing the descendant file — tests/OpenClaw.Shared.Tests/Mxc/MxcExecutorTests.cs:344-345
    This prior finding remains unresolved. File.Exists can become true before Set-Content finishes writing or releases the file. ReadAllTextAsync or int.Parse can then fail before descendantPid is assigned, making the regression flaky and leaving cleanup with PID zero. Publish the PID atomically or retry until a complete valid PID can be read, while retaining a reliable cleanup target.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 3edc9b1b5b6e.

Labels

Label justifications:

  • P1: The existing MXC cleanup paths can hold Windows node invocation slots indefinitely.
  • merge-risk: 🚨 compatibility: The new successful-output deadline can return success while dropping output previously delivered at EOF.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The captured current-head Windows output provides meaningful partial proof of MxcExecutor’s bounded return and worker recovery using real child processes and injected killers. It explicitly omits the repository-required real Gateway-to-node-to-wxc-exec MXC validation, so the native integration gate remains unmet. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Current main still needs the cleanup fix: Current main still calls the process-tree killer synchronously and uses unbounded WaitForExit on normal completion. (src/OpenClaw.Shared/Mxc/MxcExecutor.cs:191, 3edc9b1b5b6e)
  • Latest release retains the same paths: The supplied latest release, v2026.7.1-4, also retains synchronous termination and the unbounded successful-output drain. (src/OpenClaw.Shared/Mxc/MxcExecutor.cs, c7c6fb06be03)
  • Introduced output-loss trigger: The new normal-completion timeout snapshots line-event buffers without EOF. BeginOutputReadLine and BeginErrorReadLine do not deliver an unterminated final line while a descendant retains the pipe. (src/OpenClaw.Shared/Mxc/MxcExecutor.cs:217, bb12539e9025)
  • PID publication race: The descendant writes its PID with Set-Content, but the parent waits only for File.Exists before reading and parsing. Failure before assignment leaves descendantPid at zero and bypasses targeted cleanup. (tests/OpenClaw.Shared.Tests/Mxc/MxcExecutorTests.cs:344, bb12539e9025)
  • Review continuity: The September 4 completed review already raised both findings against this exact head. The older unlimited-worker concern is addressed by the process-wide semaphore and recovery coverage. (bb12539e9025)
  • Captured proof and validation: The supplied body at sourceRevision 373b4e7227c4dc9d81352fe82e1db9b9fde449e4526a5407161869b31621b11d records bounded Windows process runs, eight-worker saturation and recovery, 200 passing MXC tests, a passing build and Tray suite, and four Shared failures reportedly reproduced on base. It explicitly says Gateway MXC E2E was not run. The live body read matched this account. No build, tests, or reviewer helper were executed during this read-only review. (bb12539e9025)

Likely related people:

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

Rank-up moves

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

  • Preserve unterminated stdout and stderr under a retained-handle timeout and add focused regression coverage.
  • Make PID publication or consumption reliable so descendant cleanup survives the test’s synchronization boundary.
  • After repairs, rerun required build, Shared, Tray, and MXC E2E validation and attach current-head redacted console/TRX evidence.

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 (4 earlier review cycles)
  • reviewed 2026-08-15T23:37:50.094Z sha de9e2cb :: needs real behavior proof before merge. :: [P1] Cap abandoned process-kill workers
  • reviewed 2026-08-16T14:23:09.109Z sha bb12539 :: needs real behavior proof before merge. :: [P1] Provide the required MXC end-to-end validation
  • reviewed 2026-08-29T16:59:41.345Z sha bb12539 :: needs real behavior proof before merge. :: [P1] Run the required MXC end-to-end validation
  • reviewed 2026-09-04T23:58:09.742Z sha bb12539 :: needs real behavior proof before merge. :: [P2] Preserve newline-free output before returning from the bounded drain | [P2] Wait for a complete PID before parsing the descendant file

@miketripblog
miketripblog marked this pull request as ready for review August 16, 2026 14:20
@miketripblog

Copy link
Copy Markdown
Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 16, 2026 •

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 16, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. label Sep 4, 2026
@shanselman shanselman added the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Sep 10, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. label Sep 10, 2026
@shanselman shanselman removed the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Sep 10, 2026
@shanselman

Copy link
Copy Markdown
Collaborator

Superseded by #1387 (fix(mxc): bound termination and output drain cleanup), rebuilt from current main with deterministic bounded-cleanup and final-output regression coverage. The replacement remains draft and blocked on non-skipping windows-wsl-mxc proof.

@shanselman shanselman closed this Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P1 Urgent regression or broken agent/channel workflow affecting real users now. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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.

Consolidated audit handoff for maintainer triage

2 participants