Skip to content

fix(process): preserve arguments through Windows batch wrappers - #133185

Merged
steipete merged 5 commits into
mainfrom
codex/qa-20260830-windows-argv-red
Aug 30, 2026
Merged

steipete merged 5 commits into
mainfrom
codex/qa-20260830-windows-argv-red

Conversation

@steipete

@steipete steipete commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Windows batch wrappers silently lose empty arguments, split tabs, remove carets, and merge an argument ending in a quoted backslash with the next argument. The child can exit successfully while receiving different input. A native Windows reproduction confirmed seven failures before this repair; ordinary arguments, spaces, quotes, and all seven unsafe-character rejection controls passed.

Why This Change Was Made

buildWindowsCmdExeCommandLine owns the guarded batch serialization shared by process runners, supervisor fallback, Gmail watcher, TUI local authentication, and terminal PTYs. It previously quoted only spaces and double quotes, escaped carets outside the protected quote context, and omitted the CRT backslash rules.

The serializer now quotes every token and consumes each backslash run once before doubling embedded quotes. This preserves empty strings, tabs, carets, and trailing backslashes without a quadratic regex scan. The existing rejection of &, |, <, >, %, CR, and LF is unchanged. The single-use escape helper and conditional outer-quote path are removed.

Terminal PTYs pass the finished cmd argument tail through node-pty's documented preescaped string API, preventing a second layer of quote escaping. Direct executable and extracted npm Node entrypoint paths retain argument arrays. Redundant COMSPEC parameter forwarding is removed; its lookup and fallback semantics are unchanged.

User Impact

Allowed arguments retain their exact values through Windows batch wrappers. No dependencies, configuration, environment options, permissions, or shell fallback policy change.

Evidence

  • Native Windows before run at d2103056a350d438233c094fc2ca0888f9ea3430: seven intended argument failures and ten passed controls. Recorded outcomes.
  • Native candidate coverage includes 42 batch invocations across plain, spaced, and caret-containing wrapper paths; three real batch PTY cases covering the argument matrix; an ordinary direct Node control including literal shell metacharacters; and seven unchanged unsafe-character rejection controls. PTY proof reads the owned child's recorded argv independently of terminal display encoding.
  • First native after run at af04f67c8821fc93b4c71853ea928cd678bcbd3e: all 42 batch cases, three batch PTY cases, and seven rejection controls passed. The direct executable matrix exposed the separate dependency limitation described below; the overall job failed.
  • Local owner/caller tests: 109 passed, 58 Windows-only skips. The final test corrections separately passed 13 tests with 53 native skips. These skips are not native after proof. A test-table lint error and two obsolete Gmail Windows command-string expectations were corrected without production changes.
  • Independent review inspected the actual Execa and pinned Windows node-pty serialization contracts. Microsoft documents the CRT argument parsing rules.

Final-head native Windows verification passed: Windows test-2, exact 93f45c768decd3a3946edc3c6e9e591872667a86, passed all 53 added cases: 42 batch invocations, three batch PTY matrices, one ordinary direct-executable PTY control, and seven rejection controls. The process shard passed 114 tests with one unrelated skip; all 14 Windows job shards passed. The complete local eight-file check-changed gate also passed. Final-head CI is green. The native landing workflow merged this repair as 1f017332a6528; canonical main ancestry and the two production files were verified after landing.

The latest ClawSweeper rank-up move requested the owner repair plus passing exact-head native evidence; both are now supplied.

Named follow-up: node-pty single-character whitespace argument loss. The unchanged direct-executable array path drops a tab-only argument because pinned node-pty quotes whitespace only when the argument has more than one character. The failed direct matrix and exact native log above are preserved as before evidence for a separate dependency-owner repair proposal; no xfail/skip or dependency patch is included here. The direct control now states its actual ordinary-argument scope and verifies that shell metacharacters remain allowed. This PR does not claim that the full direct-executable matrix passes.

Production: +23/-23, net 0. Tests: +119/-12, net +107. The regression existed in the inspected stable release; introduction provenance is unknown. The earlier test-only integration-path CI selection omission is tracked separately and is not changed here.

@clawsweeper

clawsweeper Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Aug 30, 2026
@steipete
steipete marked this pull request as ready for review August 30, 2026 08:05
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 30, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 30, 2026
@clawsweeper

clawsweeper Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 4:53 AM ET / 08:53 UTC.

ClawSweeper review

What this changes

The PR changes Windows batch-wrapper serialization so permitted arguments such as empty strings, tabs, carets, quotes, and trailing backslashes reach child programs unchanged in command runners and terminal PTYs.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open for normal maintainer handling: this active maintainer PR repairs a reproduced Windows argument-corruption bug, has exact-head native after-proof, and no concrete patch defect was found.

Priority: P2
Reviewed head: 93f45c768decd3a3946edc3c6e9e591872667a86

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Strong exact-head native regression proof and a net-neutral shared-owner repair support high merge readiness, subject to the remaining required CI.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The changed owners are the shared cmd.exe serializer and the batch-fallback PTY handoff; the PR supplies linked exact-head native Windows evidence that exercises real .cmd wrappers through the process runner and node-pty, reads the child’s recorded argv, and reports all 53 added cases passing after the repair.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The changed owners are the shared cmd.exe serializer and the batch-fallback PTY handoff; the PR supplies linked exact-head native Windows evidence that exercises real .cmd wrappers through the process runner and node-pty, reads the child’s recorded argv, and reports all 53 added cases passing after the repair.
Evidence reviewed 6 items Shared serialization owner: The introduced serializer quotes each permitted token, retains rejection of cmd.exe metacharacters, and is the canonical batch-wrapper path used by the shell-free process runner.
Caller and sibling coverage: The standard command runner calls the canonical Windows invocation resolver, while Gmail, supervisor child processes, and TUI local auth also use the same command-line builder.
PTY boundary: Only unresolved batch wrappers take the cmd.exe fallback; the PR passes its prepared command tail as a string to avoid a second quoting pass, while resolved direct executables retain argument arrays.
Findings None None.
Security None None.

How this fits together

OpenClaw’s process layer launches local tools from argument arrays. On Windows, batch wrappers go through cmd.exe before reaching the child program, including interactive terminal PTYs.

flowchart LR
  A[Tool arguments] --> B[Process launcher]
  B --> C[Batch wrapper detection]
  C --> D[Windows command serialization]
  D --> E[cmd.exe or terminal PTY]
  E --> F[Batch wrapper]
  F --> G[Child program arguments]
Loading

Before merge

  • Resolve merge risk (P1) - Required exact-head checks were still in progress in the captured PR state; land only after the required checks complete green.
  • Resolve merge risk (P1) - The reviewer could not independently inspect the pinned node-pty source/type contract because it is absent locally and network DNS was unavailable; exact native Windows after-proof nonetheless covers the changed batch-PTY behavior.
  • Complete next step (P2) - No mechanical repair remains: this is a current maintainer-authored PR with no actionable finding, awaiting normal exact-head CI and maintainer handling.
Agent review details

Security

None.

PR surface

Source 0, Tests +107. Total +107 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 2 23 23 0
Tests 6 119 12 +107
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 142 35 +107

Review metrics

Metric Value Why it matters
Production versus regression coverage production +23/-23; tests +119/-12 The bug fix is production net-neutral and adds native Windows coverage at the actual cmd.exe and PTY boundaries.

Stored data model

Persistent data-model change detected: serialized state: src/process/windows-command.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Retain the centralized guarded serializer and the string-tail PTY handoff, then land after exact-head CI is green; keep the acknowledged unchanged direct node-pty tab-only behavior as a separate dependency-owner follow-up.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Retain the centralized guarded serializer and the string-tail PTY handoff, then land after exact-head CI is green; keep the acknowledged unchanged direct node-pty tab-only behavior as a separate dependency-owner follow-up.

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

Yes. The linked native Windows before run recorded seven failures in the real .cmd-to-Node path, and the exact-head after run reports those batch and PTY matrices passing.

Is this the best way to solve the issue?

Yes. The repair belongs in the shared batch serialization owner used by command runners and known batch-wrapper callers, rather than adding caller-specific escaping or fallbacks.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The changed owners are the shared cmd.exe serializer and the batch-fallback PTY handoff; the PR supplies linked exact-head native Windows evidence that exercises real .cmd wrappers through the process runner and node-pty, reads the child’s recorded argv, and reports all 53 added cases passing after the repair.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove merge-risk: 🚨 automation: Current PR review selected no merge-risk labels.

Label justifications:

  • P2: This fixes silent argument corruption for Windows batch-wrapper launches, with a bounded platform-specific blast radius.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The changed owners are the shared cmd.exe serializer and the batch-fallback PTY handoff; the PR supplies linked exact-head native Windows evidence that exercises real .cmd wrappers through the process runner and node-pty, reads the child’s recorded argv, and reports all 53 added cases passing after the repair.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed owners are the shared cmd.exe serializer and the batch-fallback PTY handoff; the PR supplies linked exact-head native Windows evidence that exercises real .cmd wrappers through the process runner and node-pty, reads the child’s recorded argv, and reports all 53 added cases passing after the repair.

Evidence

What I checked:

  • Shared serialization owner: The introduced serializer quotes each permitted token, retains rejection of cmd.exe metacharacters, and is the canonical batch-wrapper path used by the shell-free process runner. (src/process/windows-command.ts:175, af04f67c8821)
  • Caller and sibling coverage: The standard command runner calls the canonical Windows invocation resolver, while Gmail, supervisor child processes, and TUI local auth also use the same command-line builder. (src/process/exec-spawn.ts:38, 93f45c768dec)
  • PTY boundary: Only unresolved batch wrappers take the cmd.exe fallback; the PR passes its prepared command tail as a string to avoid a second quoting pass, while resolved direct executables retain argument arrays. (src/process/terminal-pty.ts:55, 93f45c768dec)
  • Native before-and-after behavior: The PR body and author follow-up link an exact-head native Windows job for 93f45c7 that passed 42 batch invocations, three batch-PTY matrices, a direct-executable control, and seven rejection controls after the earlier seven-failure reproduction. (src/process/windows-command.test.ts:181, 93f45c768dec)
  • Current-main and history check: Fetched main 039187a still has the prior selective-quoting serializer and array PTY cmd tail; neither the repair commit nor PR head is an ancestor of it. Blame identifies the recent process-area history, but the predecessor is a shallow boundary, so original regression introduction remains unknown. (src/process/windows-command.ts:175, bf8288f2ce1a)
  • Dependency signal and inspection limitation: The PTY owner directly imports @lydell/node-pty and changes its spawn argument shape; the pinned version is 1.2.0-beta.15. This checkout has no installed package source and DNS prevented upstream retrieval, so the dependency’s type/source contract could not be independently inspected. (package.json:2063, 93f45c768dec)

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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-30T08:17:02.181Z sha d210305 :: needs maintainer review before merge. :: none
  • reviewed August 30, 2026, 4:27 AM ET / 08:27 UTC sha unknown :: needs maintainer review before merge. :: none

@steipete

Copy link
Copy Markdown
Contributor Author

Native Windows reproduction confirmed at d210305 in Windows test-2.

The real .cmd → Node replay failed seven cases: leading/middle/trailing empty arguments disappeared; an embedded tab split one argument into two; a tab-only argument disappeared; left^right became leftright; and a quoted path ending in a backslash absorbed the following argument. Each subprocess still exited successfully, so these were silent argument changes.

Ordinary arguments, spaces, embedded quotes, and all seven prohibited-character rejection controls passed. The process test shard reported 7 failed, 71 passed, and 1 skipped; the reproduction cases themselves were 7 failed and 10 passed.

The shared serializer repair is in progress. This is before-proof only: no native passing repair or merge readiness is claimed yet. Production's existing prohibited-character policy will stay unchanged.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 30, 2026
@steipete steipete changed the title chore: reproduce Windows batch argument loss (test-only) fix(process): preserve arguments through Windows batch wrappers Aug 30, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Native Windows after proof passed on 93f45c768decd3a3946edc3c6e9e591872667a86: Windows test-2 job. All 53 added cases passed: 42 batch invocations across plain/spaced/caret wrapper paths, three real batch PTY matrices, one ordinary direct Node PTY control, and seven unchanged unsafe-character rejection controls. The process shard passed 114 tests with one unrelated skip; all 14 Windows job shards passed. The full local eight-file changed gate passed too.

The latest ClawSweeper rank-up request is addressed by the shared serializer repair and this exact-head result. Production remains +23/-23, net 0. Final required CI is still pending, so no landing is claimed yet.

The earlier expanded direct-executable matrix also revealed an existing pinned node-pty defect: a single tab argument disappears in its unchanged array serializer. That exact failing evidence remains in the earlier job and is preserved for the separately owned node-pty single-character whitespace argument loss dependency repair proposal. This PR does not patch that dependency, add an xfail/skip, or claim the full direct matrix passes. Its ordinary direct control verifies literal arguments, including shell metacharacters that must stay allowed; the full batch matrix is unchanged.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. labels Aug 30, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready evidence for 93f45c768decd3a3946edc3c6e9e591872667a86.

The shared guarded batch serializer now quotes every token and handles backslash runs once under the cmd/CRT contract. Its PTY caller uses node-pty's documented preescaped string seam; native executable and extracted npm entrypoint arrays remain unchanged. The old one-use escape helper, conditional outer quoting, and redundant COMSPEC forwarding are removed. Production +23/-23, net 0; tests +119/-12.

Native before showed seven argument-corruption failures. Final-head native Windows proof passed all 53 added cases, including three real batch PTY matrices and the ordinary direct-executable control. The runner used PR merge ref b28760193d797418a76e5d01bdc7142bf04d3d78; independent byte comparison bound both production files and the regression test to the reviewed head. All 14 Windows job shards passed.

The complete local eight-file changed gate passed. Scoped P0 autoreview and independent source/dependency/native-evidence review found no remaining actionable issue in this repair. The latest ClawSweeper rank-up request—owner repair plus passing exact-head native proof—is addressed.

The unchanged direct node-pty single-whitespace defect remains a separately owned dependency proposal, with its failing native evidence preserved. This PR neither patches that dependency nor claims the full direct matrix passes; no xfail/skip was added.

Final-head CI is green. Native review artifacts are validated; proceeding through the repository prepare/merge flow.

@steipete
steipete merged commit 1f01733 into main Aug 30, 2026
257 of 259 checks passed
@steipete
steipete deleted the codex/qa-20260830-windows-argv-red branch August 30, 2026 08:56
@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 31, 2026
…claw#133185)

* test(process): reproduce Windows batch argument loss

* test(process): route batch argv probe through Windows CI

* fix(process): preserve arguments through Windows batch wrappers

* test(process): avoid spread when expanding Windows argv cases

* test(process): align caller coverage with batch quoting contract
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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.

1 participant