Skip to content

fix(wsl): budget the whole command line, not just the script - #16032

Merged
nwparker merged 2 commits into
mainfrom
nwparker/wsl-argv-budget
Aug 23, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/wsl-argv-budget

Conversation

@nwparker

@nwparker nwparker commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​30 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​29
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​31 $\color{#cf222e}{\Huge{\mathbf{−}}}$​5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​26

ELI5

When Orca runs a script inside WSL it can hand it over two ways: as an argument
on the command line, or piped to the shell's stdin. Argv is the better default —
it leaves the script's own stdin free, so a hook that runs ssh -T doesn't
swallow the rest of itself.

But Windows caps a command line at 32,767 characters, so past some size the
script has to go back to stdin. The threshold measured the script.

The cap doesn't apply to the script. It applies to the whole line — which also
carries PATH=<the user's login PATH> and HOME=. A WSL login PATH includes
the translated Windows PATH and is routinely a few KB, occasionally far more.

So the size that mattered and the size being checked were different numbers.

The band

With a long enough login PATH:

Hook size Delivery Result
7,999 chars argv (under threshold) CreateProcess refuses — hook fails
8,001 chars stdin (over threshold) runs fine

Making a hook bigger fixed it. The user sees "setup hook failed" with
nothing pointing at length, and the workaround is counter-intuitive enough that
nobody would find it.

Needs a login PATH around 24.6 KB before the band opens, so it is rare — but a
PATH that size is legal, and the failure is silent about its cause.

What changed

Build the argv form, measure the finished line, and use it only if it fits;
otherwise the script goes to stdin exactly as before. The measurement charges
quoting for every argument, so it over-estimates — the safe direction for a cap.

Proof of no regression

  • Ordinary scripts still travel in argv, so a hook's stdin stays free — the
    ssh -T fix from refactor(wsl): delete the environment-policy layer the reviews kept failing on #16007 is unaffected and still pinned.
  • Genuinely huge scripts still go to stdin. The hook-relay installer, which
    embeds a base64 JS bundle, is unchanged.
  • New test: a 7,000-char script — deliberately under any script-only
    threshold — with a 27 KB PATH must land on stdin. Verified to bind: with the
    old rule restored it fails.
  • src/main/wsl + hooks: 136 passed. Lint and typecheck exit 0.

Worth recording: my first attempt at that test used echo + 7,999 chars, which
is 8,004 — over the old threshold, so it flipped either way and passed against
both rules. It proved nothing until the script was genuinely under 8,000.

User-facing trade-offs

None. No script that worked before changes delivery unless it was in the
failing band, where it now works. No wire, persisted state, settings, or IPC
change.

The argv/stdin threshold measured `script.length`, but the cap applies to the
finished command line -- which also carries `PATH=<login PATH>` and `HOME=`.
A login PATH is itself a few KB.

That produced a perverse band: with a long enough PATH, a 7,999-char hook was
placed on argv and CreateProcess refused it, while the SAME hook at 8,001 chars
flipped to stdin and ran. Size decided how a hook behaved, in the wrong
direction, and the failure looked like "your setup hook failed" with nothing
pointing at length.

Now the argv form is built, measured, and only used if the whole line fits;
otherwise the script goes to stdin as before. The count over-estimates slightly
(it charges quoting for every argument) because over-counting is the safe
direction for a cap.

The regression test uses a 7,000-char script -- deliberately under any
script-only threshold -- with a 27KB PATH, and asserts it lands on stdin. My
first attempt used 7,999 + `echo `, which is 8,004 and flipped under the old
rule too, so it passed either way and proved nothing.

Credit: Grok.
@coderabbitai

coderabbitai Bot commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cdbeeba9-7def-437d-a55d-b78bcd37cdc9

📥 Commits

Reviewing files that changed from the base of the PR and between 2940e5f and 10e135c.

📒 Files selected for processing (2)
  • src/main/wsl/wsl-runner.test.ts
  • src/main/wsl/wsl-runner.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

The WSL runner now includes quote and backslash escaping in command-line length estimates. Delivery selection measures the complete spawned WSL command, including the executable and execution arguments. A test verifies stdin delivery for a 26,000-quote script when escaping exceeds the Windows command-line limit.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the problem, implementation, regression coverage, and trade-offs, but it omits several required template sections and checklist items. Add the required Linked Issue, Visual Proof with N/A justification, Testing checklist, AI Disclosure, Review, boundary, Notes, and final Checklist sections.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: budgeting the complete WSL command line instead of only the script.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Two under-counts the review found in the estimator I added.

The doc comment claimed it over-counts. It did not: libuv escapes every `"`
and doubles a backslash run before a quote, so a quote-dense script costs more
than its length. And `wsl.exe` plus `-d <distro> --exec` are prepended AFTER
the measurement, so ~45 characters of the budget were never counted.

Together those put a quote-heavy ~26KB script on argv and over the real 32767
ceiling -- where the old script-only rule would have sent it to stdin and it
would have run. A narrower band than the one this PR removes, but the same
shape of bug, so worth closing before merge rather than after.

Now charges one character per `"` or backslash and measures the full spawn
line. New test: 26,000 quote characters must land on stdin; verified to fail
with the quoting charge removed.
@nwparker
nwparker merged commit e26f849 into main Aug 23, 2026
47 checks passed
@nwparker
nwparker deleted the nwparker/wsl-argv-budget branch August 23, 2026 07:57
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 23, 2026
…i#16032)

* fix(wsl): budget the whole command line, not just the script

The argv/stdin threshold measured `script.length`, but the cap applies to the
finished command line -- which also carries `PATH=<login PATH>` and `HOME=`.
A login PATH is itself a few KB.

That produced a perverse band: with a long enough PATH, a 7,999-char hook was
placed on argv and CreateProcess refused it, while the SAME hook at 8,001 chars
flipped to stdin and ran. Size decided how a hook behaved, in the wrong
direction, and the failure looked like "your setup hook failed" with nothing
pointing at length.

Now the argv form is built, measured, and only used if the whole line fits;
otherwise the script goes to stdin as before. The count over-estimates slightly
(it charges quoting for every argument) because over-counting is the safe
direction for a cap.

The regression test uses a 7,000-char script -- deliberately under any
script-only threshold -- with a 27KB PATH, and asserts it lands on stdin. My
first attempt used 7,999 + `echo `, which is 8,004 and flipped under the old
rule too, so it passed either way and proved nothing.

Credit: Grok.

* fix(wsl): charge quoting and measure the line that is actually spawned

Two under-counts the review found in the estimator I added.

The doc comment claimed it over-counts. It did not: libuv escapes every `"`
and doubles a backslash run before a quote, so a quote-dense script costs more
than its length. And `wsl.exe` plus `-d <distro> --exec` are prepended AFTER
the measurement, so ~45 characters of the budget were never counted.

Together those put a quote-heavy ~26KB script on argv and over the real 32767
ceiling -- where the old script-only rule would have sent it to stdin and it
would have run. A narrower band than the one this PR removes, but the same
shape of bug, so worth closing before merge rather than after.

Now charges one character per `"` or backslash and measures the full spawn
line. New test: 26,000 quote characters must land on stdin; verified to fail
with the quoting charge removed.

(cherry picked from commit e26f849)
CodeHourra pushed a commit to CodeHourra/orca that referenced this pull request Aug 23, 2026
…i#16032)

* fix(wsl): budget the whole command line, not just the script

The argv/stdin threshold measured `script.length`, but the cap applies to the
finished command line -- which also carries `PATH=<login PATH>` and `HOME=`.
A login PATH is itself a few KB.

That produced a perverse band: with a long enough PATH, a 7,999-char hook was
placed on argv and CreateProcess refused it, while the SAME hook at 8,001 chars
flipped to stdin and ran. Size decided how a hook behaved, in the wrong
direction, and the failure looked like "your setup hook failed" with nothing
pointing at length.

Now the argv form is built, measured, and only used if the whole line fits;
otherwise the script goes to stdin as before. The count over-estimates slightly
(it charges quoting for every argument) because over-counting is the safe
direction for a cap.

The regression test uses a 7,000-char script -- deliberately under any
script-only threshold -- with a 27KB PATH, and asserts it lands on stdin. My
first attempt used 7,999 + `echo `, which is 8,004 and flipped under the old
rule too, so it passed either way and proved nothing.

Credit: Grok.

* fix(wsl): charge quoting and measure the line that is actually spawned

Two under-counts the review found in the estimator I added.

The doc comment claimed it over-counts. It did not: libuv escapes every `"`
and doubles a backslash run before a quote, so a quote-dense script costs more
than its length. And `wsl.exe` plus `-d <distro> --exec` are prepended AFTER
the measurement, so ~45 characters of the budget were never counted.

Together those put a quote-heavy ~26KB script on argv and over the real 32767
ceiling -- where the old script-only rule would have sent it to stdin and it
would have run. A narrower band than the one this PR removes, but the same
shape of bug, so worth closing before merge rather than after.

Now charges one character per `"` or backslash and measures the full spawn
line. New test: 26,000 quote characters must land on stdin; verified to fail
with the quoting charge removed.
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
…i#16032)

* fix(wsl): budget the whole command line, not just the script

The argv/stdin threshold measured `script.length`, but the cap applies to the
finished command line -- which also carries `PATH=<login PATH>` and `HOME=`.
A login PATH is itself a few KB.

That produced a perverse band: with a long enough PATH, a 7,999-char hook was
placed on argv and CreateProcess refused it, while the SAME hook at 8,001 chars
flipped to stdin and ran. Size decided how a hook behaved, in the wrong
direction, and the failure looked like "your setup hook failed" with nothing
pointing at length.

Now the argv form is built, measured, and only used if the whole line fits;
otherwise the script goes to stdin as before. The count over-estimates slightly
(it charges quoting for every argument) because over-counting is the safe
direction for a cap.

The regression test uses a 7,000-char script -- deliberately under any
script-only threshold -- with a 27KB PATH, and asserts it lands on stdin. My
first attempt used 7,999 + `echo `, which is 8,004 and flipped under the old
rule too, so it passed either way and proved nothing.

Credit: Grok.

* fix(wsl): charge quoting and measure the line that is actually spawned

Two under-counts the review found in the estimator I added.

The doc comment claimed it over-counts. It did not: libuv escapes every `"`
and doubles a backslash run before a quote, so a quote-dense script costs more
than its length. And `wsl.exe` plus `-d <distro> --exec` are prepended AFTER
the measurement, so ~45 characters of the budget were never counted.

Together those put a quote-heavy ~26KB script on argv and over the real 32767
ceiling -- where the old script-only rule would have sent it to stdin and it
would have run. A narrower band than the one this PR removes, but the same
shape of bug, so worth closing before merge rather than after.

Now charges one character per `"` or backslash and measures the full spawn
line. New test: 26,000 quote characters must land on stdin; verified to fail
with the quoting charge removed.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…i#16032)

* fix(wsl): budget the whole command line, not just the script

The argv/stdin threshold measured `script.length`, but the cap applies to the
finished command line -- which also carries `PATH=<login PATH>` and `HOME=`.
A login PATH is itself a few KB.

That produced a perverse band: with a long enough PATH, a 7,999-char hook was
placed on argv and CreateProcess refused it, while the SAME hook at 8,001 chars
flipped to stdin and ran. Size decided how a hook behaved, in the wrong
direction, and the failure looked like "your setup hook failed" with nothing
pointing at length.

Now the argv form is built, measured, and only used if the whole line fits;
otherwise the script goes to stdin as before. The count over-estimates slightly
(it charges quoting for every argument) because over-counting is the safe
direction for a cap.

The regression test uses a 7,000-char script -- deliberately under any
script-only threshold -- with a 27KB PATH, and asserts it lands on stdin. My
first attempt used 7,999 + `echo `, which is 8,004 and flipped under the old
rule too, so it passed either way and proved nothing.

Credit: Grok.

* fix(wsl): charge quoting and measure the line that is actually spawned

Two under-counts the review found in the estimator I added.

The doc comment claimed it over-counts. It did not: libuv escapes every `"`
and doubles a backslash run before a quote, so a quote-dense script costs more
than its length. And `wsl.exe` plus `-d <distro> --exec` are prepended AFTER
the measurement, so ~45 characters of the budget were never counted.

Together those put a quote-heavy ~26KB script on argv and over the real 32767
ceiling -- where the old script-only rule would have sent it to stdin and it
would have run. A narrower band than the one this PR removes, but the same
shape of bug, so worth closing before merge rather than after.

Now charges one character per `"` or backslash and measures the full spawn
line. New test: 26,000 quote characters must land on stdin; verified to fail
with the quoting charge removed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant