Skip to content

Preserve trailing command output while bounding inherited-pipe waits #1194

Closed

Description

@joelagnel

Problem

CommandRunner waits for redirected stdout and stderr EOF after the direct child exits, but gives every command only 250 ms for the asynchronous output callbacks to finish draining.

}
// A surviving descendant can keep inherited pipe handles open after the child
// exits. Preserve output already in flight without charging the command's full
// timeout to an EOF that may never arrive.
await Task.WhenAny(
Task.WhenAll(stdoutClosed.Task, stderrClosed.Task),

The bounded drain was introduced to prevent setup from hanging when a surviving descendant inherits the redirected pipe handles. The immediate motivating command was the Welcome-page WSL inspection:

wsl.exe --list --quiet

var logger = new SetupLogger(filePath: null, LogLevel.Warn);
var result = new CommandRunner(logger)
.RunAsync(WslConstants.WslExePath, ["--list", "--quiet"], TimeSpan.FromSeconds(5))
.GetAwaiter()
.GetResult();
var hasDistro = InterpretDistroList(result, targetDistroName);

That inherited-handle scenario is legitimate, but the 250 ms escape now applies to all CommandRunner and RunInWslAsync calls, including commands whose complete output is parsed as JSON or checked for trailing success markers. Examples include:

wsl.exe -d <distro> -- bash -c "<path-prefix> && openclaw nodes list --json"
wsl.exe -d <distro> -- bash -c "<path-prefix> && openclaw devices approve --latest --json"
wsl.exe -d <distro> -- bash -c "<path-prefix> && openclaw qr --json"

The setup flow also checks trailing markers such as GATEWAY_CONFIGURED, CONFIGURED_OK, OPENCLAW_FRESH_WSL_READY, and WINDOWS_NODE_CONTEXT_READY.

Impact

If output callbacks are still draining when the 250 ms delay wins, setup can receive truncated JSON or miss a final success marker despite a successful child exit. This can produce parse failures or false setup failures.

Expected behavior

  • Preserve complete stdout and stderr when the direct child closed its pipe handles normally.
  • Keep a bounded escape for the case where surviving descendants retain inherited handles.
  • Preserve existing process timeout and caller-cancellation behavior.
  • Do not regress the no-hang behavior for orphan or background WSL descendants.

Tests

  • Add a high-volume command whose required JSON or marker is emitted at the end and assert that it is captured.
  • Retain the existing descendant-keeps-pipes-open test.
  • Cover stdout and stderr draining.
  • Cover timeout and caller cancellation.

Raised by @larroy during the PR #1178 review follow-up.

Activity

  1. added
    clawsweeper:fix-shape-clear
    clawsweeper:queueable-fix
    clawsweeper:source-repro
    impact:other
    issue-rating: 🦞 diamond lobster
    no-stale
    P2
    on Aug 21, 2026
  2. clawsweeper commented on Aug 21, 2026

    @clawsweeper

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed September 7, 2026, 9:12 PM ET / September 8, 2026, 01:12 UTC.

    Summary
    Current main still allows successful commands to return before stdout and stderr finish draining. The cap is now three seconds rather than 250 ms, but the reported mechanism remains. The open repair at #1361 explicitly owns this work.

    Likely related people: shanselman and Dallin Romney are low-confidence routing candidates based on the repair discussion and recent area history.

    Reproducibility: yes. source establishes a clear trigger: pending output callbacks when the normal drain budget expires cause an early result snapshot. A failing runtime reproduction was not executed in this read-only review.

    Next step
    Review and resolve #1361 before closing this issue; its explicit ownership rules out dispatching another repair.

    Review details

    Best possible solution:

    Normal exits should drain both streams to EOF within existing capture-size limits, honor caller cancellation, and reserve bounded escape for explicit inherited-pipe inspections and timeout cleanup.

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

    Yes, source establishes a clear trigger: pending output callbacks when the normal drain budget expires cause an early result snapshot. A failing runtime reproduction was not executed in this read-only review.

    Is this the best way to solve the issue?

    Yes, the linked repair's separation of normal EOF draining from explicit inherited-pipe escape addresses the mechanism more directly than increasing a universal delay.

    AGENTS.md: found and applied where relevant.

    Codex review notes: model internal, reasoning medium; reviewed against 6d1056270082.

    Label changes

    Label justifications:

    • P1: Premature output snapshots can turn successful provisioning and pairing commands into setup failures, consistent with the recorded human priority escalation.
    • impact:other: The affected behavior is setup command-result integrity, causing incomplete JSON or missing completion markers.
    Evidence reviewed

    What I checked:

    • Current main retains the premature-return mechanism: The checkout matches fetched main. RunAsync races both stream-closure tasks against an unconditional drain delay before taking output snapshots. GetOutputDrainBudget returns at most three seconds on normal exits, and zero if the command deadline has elapsed. RunInWslAsync delegates to this same path. (src/OpenClaw.SetupEngine/CommandRunner.cs:222, 6d1056270082)
    • Output completeness affects setup success: The bootstrap-token step parses captured QR JSON and returns a setup failure if parsing fails. ConfigureGatewayStep likewise requires its trailing GATEWAY_CONFIGURED marker even when the command exits successfully. (src/OpenClaw.SetupEngine/MintBootstrapTokenStep.cs:32, 6d1056270082)
    • Current tests preserve the cap rather than complete normal draining: Tests cover inherited-pipe escape, stdin timeout and cancellation, and drain budgets of zero or three seconds. This file does not yet contain the requested high-volume trailing-marker regression. (tests/OpenClaw.SetupEngine.Tests/CommandRunnerTests.cs:138, 6d1056270082)
    • An open repair already owns the issue: The supplied GitHub closingPullRequests record identifies Preserve normal setup command output drains #1361 as open and unmerged, with explicit closing linkage to this issue. Its body preserves karkarl's earlier design, describes full normal EOF draining and explicit bounded WSL inspections, and reports native WSL runs capturing trailing markers. Earlier attempts fix(setup): preserve trailing command output while bounding inherited-pipe waits #1207 and fix(setup): preserve normal command output drains #1343 closed without merging. (756ed2453468)
    • Feature-history routing: Available file history includes recent output-drain work by Dallin Romney and WSL encoding work by Scott Hanselman. Raw commit records verified their author identities, but missing historical objects prevented exact source-line parent comparisons, so these are routing candidates rather than verified introducing owners. (src/OpenClaw.SetupEngine/CommandRunner.cs, cb610b2b3d4e)
    • Inspection scope and limitations: Current source, tests, root policy, and available commit records were read successfully. Historical blame, parent-file inspection, and release-source inspection encountered missing objects whose retrieval failed because github.com could not resolve; the live PR refresh also failed. The supplied GitHub snapshot establishes the open repair. No shipped fix is claimed, and no builds or tests were executed during this read-only review. VISION.md and the requested maturity scorecard were absent. (6d1056270082)

    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)
    How this review workflow works
    • 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.
  3. added
    status: 🚢 actively landing
    on Aug 22, 2026
  4. removed
    clawsweeper:queueable-fix
    clawsweeper:fix-shape-clear
    no-stale
    on Aug 22, 2026
  5. added
    clawsweeper:linked-pr-open
    on Aug 30, 2026
  6. 7 remaining items

  7. added
    P1
    and removed
    P2
    on Sep 4, 2026
  8. added this to the 9/30 MXC Release milestone on Sep 4, 2026
  9. added
    status: 🚢 actively landing
    on Sep 5, 2026
  10. removed
    status: 🚢 actively landing
    on Sep 7, 2026
  11. added
    clawsweeper:linked-pr-open
    clawsweeper:no-new-fix-pr
    and removed
    clawsweeper:queueable-fix
    clawsweeper:fix-shape-clear
    no-stale
    on Sep 7, 2026
  12. added
    status: 🚢 actively landing
    on Sep 8, 2026
  13. removed
    status: 🚢 actively landing
    on Sep 8, 2026
  14. locked as resolved and limited conversation to collaborators on Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1clawsweeper:linked-pr-openclawsweeper:no-new-fix-prclawsweeper:source-reproimpact:otherissue-rating: 🦞 diamond lobster

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions