Skip to content

fix(setup): preserve normal command output drains - #1343

Closed
karkarl wants to merge 1 commit into
mainfrom
fix-inherited-pipe-drain-1194
Closed

karkarl wants to merge 1 commit into
mainfrom
fix-inherited-pipe-drain-1194

Conversation

@karkarl

@karkarl karkarl commented Sep 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #1194

CommandRunner still applied a universal post-exit drain cap, so a cleanly exited command could return before queued stdout or stderr callbacks delivered trailing JSON or success markers. This PR waits for both redirected streams to close on normal exits, preserves caller cancellation while waiting, and keeps bounded waits only for timeout cleanup or explicit WSL inspection calls that can inherit pipe handles.

Closed PR #1207 had the right shape, but it was closed as an obsolete conflicting branch. This reapplies the narrow fix against current main, including the current three-second inherited-pipe cap.

Required proof pools

  • windows-wsl-gateway-e2e: setup WSL inspection command behavior changed; maintainer-scheduled real gateway setup proof should verify the product path before merge.

Validation

  • $env:OPENCLAW_REPO_ROOT=(Get-Location).Path; .\build.ps1 - passed, all builds succeeded.
  • $env:OPENCLAW_REPO_ROOT=(Get-Location).Path; dotnet test .\tests\OpenClaw.SetupEngine.Tests\OpenClaw.SetupEngine.Tests.csproj --no-restore --filter FullyQualifiedName~CommandRunnerTests - passed, 12/12.
  • $env:OPENCLAW_REPO_ROOT=(Get-Location).Path; dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore - passed, 3937 passed, 32 skipped.
  • $env:OPENCLAW_REPO_ROOT=(Get-Location).Path; $env:OPENCLAW_TRAY_DATA_DIR=Join-Path (Get-Location).Path '.tray-test-data'; dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore - passed, 2858/2858.
  • Rubber-duck code review - no significant issues found after fixing cancellation during normal post-exit drain.

Real behavior proof

  • RunAsync_DrainsHighVolumeStdoutAndStderrThroughTrailingMarkers emits 8,000 stdout lines and 8,000 stderr lines plus final STDOUT_MARKER and STDERR_MARKER; current head captures all lines and both trailing markers.
  • WaitForOutputDrainAsync_WaitsPastCommandDeadlineOnNormalExit proves normal exits no longer return just because the old drain cap or remaining command deadline elapsed.
  • WaitForOutputDrainAsync_CancellationInterruptsNormalPostExitDrain proves caller cancellation remains honored while waiting for normal stream closure.
  • RunAsync_ReturnsWhenDescendantKeepsOutputPipesOpen now uses allowInheritedPipeHandleEscape: true and still returns within the bounded inherited-pipe wait.
  • windows-wsl-gateway-e2e is not run locally; it is a maintainer-scheduled proof pool.

MXC and system.run were not touched, so .\scripts\validate-mxc-e2e.ps1 was not required.

Wait for stdout and stderr EOF on normal CommandRunner exits so trailing output is not lost. Keep the inherited-pipe escape bounded behind an explicit opt-in for WSL inspection commands.

Co-authored-by: Copilot App <[email protected]>
@clawsweeper

clawsweeper Bot commented Sep 6, 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 P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. 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

Codex review: blocked before merge. Reviewed September 7, 2026, 6:06 PM ET / 22:06 UTC.

ClawSweeper review

What this changes

Preserves trailing setup-command output by waiting for stream closure on normal exits, while retaining bounded waits for timeout cleanup and selected WSL inspections.

Merge readiness

⛔ Blocked before merge - 4 items remain

This remains a useful candidate fix: current main and the latest release still cap normal output drains. No discrete introduced correctness defect was found, and the collaborator-authored work remains under active ownership.

Priority: P2
Reviewed head: 3a3d31a83188d819f479cffa57ac5468998db1c2
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused implementation with useful regression coverage and no concrete correctness finding; native availability coverage remains unresolved.
Proof confidence 🌊 off-meta tidepool Not applicable: The collaborator-authored PR is exempt from the ordinary contributor proof gate. Reported real-process tests exercise CommandRunner output capture and inherited pipes; the separate repository-required Windows/WSL pool remains a maintainer verification, including inspection of the successful E2E run.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The collaborator-authored PR is exempt from the ordinary contributor proof gate. Reported real-process tests exercise CommandRunner output capture and inherited pipes; the separate repository-required Windows/WSL pool remains a maintainer verification, including inspection of the successful E2E run.
Evidence reviewed 7 items Introduced drain behavior: The reviewed runner waits for both streams using caller cancellation on normal exits. Only timeout cleanup and explicit inherited-pipe callers retain the bounded drain. RunInWslAsync uses the normal path.
Current main still needs the central fix: Fetched main still races stream closure against GetOutputDrainBudget for every command. Its newer WSL encoding handling does not eliminate the universal drain cap.
Latest release comparison: The supplied latest release, v2026.7.1-4, also contains the universal bounded post-exit drain rather than this branch's normal EOF wait.
Findings None None.
Security None None.

How this fits together

The setup engine runs Windows processes and WSL commands, then interprets their output to configure and verify the local gateway. Its command runner controls process timeouts, cancellation, and collection of stdout and stderr.

flowchart TD
  A[Setup and recovery steps] --> B[Windows or WSL command]
  B --> C[Process exits or times out]
  C --> D{Timeout or inspection escape?}
  D -->|Yes| E[Bounded output drain]
  D -->|No| F[Wait for stream closure or cancellation]
  E --> G[Output and status returned to setup]
  F --> G
Loading

Decision needed

Question Recommendation
Does the successful setup E2E run establish the declared Windows/WSL fresh-setup and recovery coverage for the new EOF-only default? Verify the existing E2E evidence: Accept the run if its artifacts establish non-skipped current-head fresh-setup and recovery coverage, obtaining the declared pool evidence for any remaining gap.

Why: The native pool is maintainer-scheduled, and the supplied successful check lacks inspectable scenario results in this review.

Before merge

  • Resolve merge risk (P2) - Normal non-inspection commands now wait beyond their process timeout for stream closure. If a WSL descendant retains a pipe, fresh setup or existing-install recovery could remain stalled until caller cancellation.
  • Resolve merge risk (P1) - The successful setup E2E check is encouraging, but its detailed results were unavailable to this reviewer; satisfaction of the declared native proof pool remains unverified.
  • Complete next step (P2) - Resolve the reported merge conflicts, confirm the declared native fresh-setup and recovery evidence, and mark the draft ready after validation of the resulting head.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and test LOC Production +91/-32 (net +59); tests +90/-4 (net +86) Production growth implements the explicit drain policy and caller opt-ins, with focused regression coverage.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #1194
Summary: This PR is the active candidate for the linked output-drain issue; the earlier attempt closed without merging.

Members:

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

Merge-risk options

Maintainer options:

  1. Establish native no-hang coverage (recommended)
    Verify fresh setup and existing-install recovery complete with the new drain behavior before accepting its availability tradeoff.
  2. Pause pending the native pool
    Keep the branch open while capacity-dependent WSL validation remains unresolved.

Technical review

Best possible solution:

Keep the focused drain distinction, with native fresh-setup and existing-install recovery evidence establishing that complete output and responsive cancellation coexist without inherited-pipe stalls.

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

Yes, from source: current main can return when its drain budget expires before stdout and stderr reach EOF. This review did not execute a failing reproduction.

Is this the best way to solve the issue?

Yes, provisionally: explicit inspection escapes are a focused way to preserve normal output, but native setup and recovery evidence must establish that the selected callers cover the inherited-handle cases.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 88822d342567.

Labels

Label justifications:

  • P2: This is a focused setup-output reliability repair without evidence of a current widespread outage.
  • merge-risk: 🚨 availability: Removing the default post-exit bound can stall setup if a non-opted-in command leaves inherited output handles open.
  • 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 collaborator-authored PR is exempt from the ordinary contributor proof gate. Reported real-process tests exercise CommandRunner output capture and inherited pipes; the separate repository-required Windows/WSL pool remains a maintainer verification, including inspection of the successful E2E run.

Evidence

What I checked:

  • Introduced drain behavior: The reviewed runner waits for both streams using caller cancellation on normal exits. Only timeout cleanup and explicit inherited-pipe callers retain the bounded drain. RunInWslAsync uses the normal path. (src/OpenClaw.SetupEngine/CommandRunner.cs:204, 3a3d31a83188)
  • Current main still needs the central fix: Fetched main still races stream closure against GetOutputDrainBudget for every command. Its newer WSL encoding handling does not eliminate the universal drain cap. (src/OpenClaw.SetupEngine/CommandRunner.cs, 88822d342567)
  • Latest release comparison: The supplied latest release, v2026.7.1-4, also contains the universal bounded post-exit drain rather than this branch's normal EOF wait. (src/OpenClaw.SetupEngine/CommandRunner.cs, c7c6fb06be03)
  • Focused coverage and reported validation: Tests exercise the real runner with 8,000 lines per stream and trailing markers, retain the opted-in descendant-pipe case, and cover cancellation and waiting beyond the process deadline. The captured PR body reports 12 focused tests passing, a successful build, 3,937 Shared tests passing with 32 skipped, and 2,858 Tray tests passing. No build or tests were executed during this read-only review. (tests/OpenClaw.SetupEngine.Tests/CommandRunnerTests.cs:82, 3a3d31a83188)
  • Required native proof remains a maintainer verification: The declared windows-wsl-gateway-e2e pool requires a real product-path run, nonzero test counts, and redacted results. The captured body says that pool was not run locally; supplied checks now report Setup and connect E2E success. Retrieving its detailed output failed because api.github.com was unreachable, so this review cannot establish whether that run satisfies the outstanding fresh-setup and recovery coverage. Captured context identity: c0b927418bc0af1b022a286f6ce82ba1354b7f59958d9c54aa9d24072e0c5f8a. (.github/proof-pools.json:342, 3a3d31a83188)
  • Related work and review continuity: The PR explicitly targets Preserve trailing command output while bounding inherited-pipe waits #1194. The earlier fix(setup): preserve trailing command output while bounding inherited-pipe waits #1207 is closed unmerged, so it is not a replacement landing path. The previous review examined this same head, reported no findings, and requested native fresh-setup and existing-install recovery evidence. Current context also reports draft status and merge conflicts. (3a3d31a83188)

Likely related people:

  • shanselman: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Dallin Romney: 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.

  • Confirm current-head native evidence covers fresh setup and existing-install recovery, using non-skipped counts and redacted results from the declared proof pool.

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 (1 earlier review cycle)
  • reviewed 2026-09-06T06:16:46.991Z sha 3a3d31a :: blocked before merge. :: none

@shanselman shanselman added the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Sep 7, 2026
@shanselman

Copy link
Copy Markdown
Collaborator

Superseded by #1361 (Preserve normal setup command output drains), rebuilt on current main with the current WSL UTF-8 behavior, the newer Windows-node inspection call site, and a source-compatible public API. Thank you @karkarl for the focused design and regression coverage; the replacement commit credits your contribution.

@shanselman shanselman closed this Sep 7, 2026
@shanselman shanselman removed the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal priority bug or improvement with limited blast radius. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preserve trailing command output while bounding inherited-pipe waits

2 participants