Skip to content

fix(git): fence buffered WSL login-shell reads - #15060

Merged
OrcaWin merged 2 commits into
mainfrom
OrcaWin/wsl-fence-git-login-shell-reads
Aug 18, 2026
Merged

OrcaWin merged 2 commits into
mainfrom
OrcaWin/wsl-fence-git-login-shell-reads

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Aug 17, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​137 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​137
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​69 $\color{#cf222e}{\Huge{\mathbf{−}}}$​10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​59

Stack

Merge bottom-up; each PR is based on the one above it.

# PR Base
1 #15039 main fix(wsl): pass guest argv verbatim through --exec
2 #15040 #15039 fix(wsl): read machine output from a fenced login shell
3 ▶ #15060 #15040 fix(git): fence buffered WSL login-shell reads ← you are here
4 #15257 #15060 fix(git): run WSL git reads without a shell

ELI5

Same banner problem as #15040, now in git.

When Orca runs git inside WSL, it goes through the login shell, which prints the distro's welcome banner to the same pipe the answer comes back on. Two git paths read that pipe whole and never strip the banner:

  • Viewing a file — the banner gets pasted on top of the file's contents in the diff viewer.
  • Checking your SSH setting — Orca asks git "did the user configure a custom SSH command?". The banner is a non-empty answer, so Orca concludes yes, and skips the safety setting that stops SSH from hanging forever waiting for a password prompt.

Why this wasn't in #15040

I originally left the git login-shell path alone on the belief that its consumers are streaming, where fencing would break them, and that the shell-free "direct git" fast path covered the important cases. Both assumptions were wrong, and checking them is what produced this PR:

preferWslDirectGit is set by exactly one options-builder, gitStatusReadOptionsForWorktree — used only for status-adjacent reads:

$ grep -rn "preferWslDirectGit" src --include=*.ts | grep -v test
src/main/git/git-runtime-options.ts:24:  preferWslDirectGit: true
src/main/git/git-runtime-options.ts:26:  return { ...gitOptionsForWorktree(cwd, options), preferWslDirectGit: true }
src/main/git/status.ts:328:        preferWslDirectGit: true,

Every other caller uses gitOptionsForWorktree, which never sets it. So for git show, remote/config reads, history, checkout and commit, the login shell isn't a cold fallback — it is the only path, on every call.

The two sites fixed here go further and pass forceLoginShell = true, so they never take the fast path even in principle.

Streaming really is a hazard — so fencing is opt-in

The original concern was legitimate, just not universal. searchWithGitGrep and runGitLsFiles process records as they arrive (and git grep is killed early once maxResults is hit, so a closing fence may never be written). An opening marker would be glued onto their first record.

So the fence is opted into per call site rather than applied to the login-shell branch as a whole. Only the two buffered-by-construction functions opt in. The streaming consumers are untouched — and are incidentally immune anyway, since ingestGitGrepLine requires an embedded NUL and discards banner lines outright.

Binary safety

Blob content can be binary, so the payload is sliced out of the raw bytes; decoding to a string to find the fence would corrupt a PNG header. The markers are exposed on the captured command because the shared module is bundled for the renderer and so cannot reference Buffer.

Testing

Four tests, all mutation-checked — each fails with the fence disabled, with the real symptom:

test failure without the fix
blob text expected 'To run a command as administrator…' to be 'line one\nline two\n'
binary blob Buffer.compare → -1 (bytes corrupted)
SSH guard GIT_SSH_COMMAND is undefined — the BatchMode guard is gone
configured sshCommand still honored, still gets BatchMode=yes

The SSH tests drive the real public entry point (gitExecFileAsync with useConfiguredSshCommandForNetwork) and assert on the env actually handed to git, rather than adding a test-only export.

Suite compared against origin/main at test-name granularity across src/main/git and src/shared: zero new failures, and 8 test-names that fail on main pass here. Typecheck and lint gates clean.

Two git paths force the login shell unconditionally and buffer its whole
stdout, so the distro's rc banner lands in front of the payload:

- gitExecFileAsyncBuffer backs `git show :<path>` blob reads and hands
  the bytes straight to the diff/blob viewer, so the banner is prepended
  to displayed file content.
- buildNetworkSshPolicyEnv probes `core.sshCommand` and treats any
  non-empty answer as a user-configured wrapper. A banner reads as
  configured, so the code skips the `ssh -o BatchMode=yes` fallback and
  silently disarms the guard that keeps non-interactive SSH from
  hanging on a prompt.

Fencing is opt-in per call site rather than applied to the login-shell
branch as a whole: streaming consumers (`git grep`, `ls-files -z`) parse
records as they arrive, so an opening marker would be glued onto their
first record. Only these two, both buffered by construction, opt in.

Blob content can be binary, so the payload is sliced out of the raw
bytes; decoding to find the fence would corrupt it. The markers are
exposed on the captured command because the shared module is bundled for
the renderer and cannot reference Buffer.

Note this path is not a rare fallback: `preferWslDirectGit` is only set
by gitStatusReadOptionsForWorktree, so every other WSL-routed git call
takes the login shell on every invocation.
@OrcaWin
OrcaWin force-pushed the OrcaWin/wsl-fence-git-login-shell-reads branch from 4a8d8ea to d79a008 Compare August 18, 2026 09:30
@OrcaWin
OrcaWin changed the base branch from OrcaWin/wsl-clean-machine-read-output to main August 18, 2026 09:30
Satisfies the code-quality rule that flags filter-then-index.
@OrcaWin
OrcaWin force-pushed the OrcaWin/wsl-fence-git-login-shell-reads branch from d79a008 to bdc65a0 Compare August 18, 2026 09:32
@coderabbitai

coderabbitai Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

WSL login-shell command resolution can wrap stdout with generated fence markers and return capture metadata. Git command resolution propagates this option. SSH configuration probing strips the markers before parsing core.sshCommand. Raw Git reads remove markers at the byte level while preserving binary data. Tests cover shell banners, binary blobs, missing SSH configuration, and configured SSH options.

Merge Risk: 🟡 Moderate · up to bdc65

The change improves buffered WSL Git reads, but the current implementation can select an echoed shell marker instead of the real payload and return incorrect file contents, including corrupted binary data. This correctness issue should be fixed before merging.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the problem, approach, scope, and testing, but it omits most required template sections, including Linked Issue, Visual Proof, checklist, and author details. Complete the required template sections, including the linked issue, visual proof or N/A reason, testing checklist, review notes, boundary checklist, and author information.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: fencing buffered WSL login-shell Git reads.
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.
✨ Finishing Touches 💡 1
📝 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a41f5d22-c9b2-4234-82d9-f38d91a95378

📥 Commits

Reviewing files that changed from the base of the PR and between 3a9f40e and bdc65a0.

📒 Files selected for processing (3)
  • src/main/git/runner-wsl-login-shell-capture.test.ts
  • src/main/git/runner.ts
  • src/shared/wsl-login-shell-command.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 7 remain after this review.

Comment on lines +62 to +65
afterEach(() => {
Object.defineProperty(process, 'platform', { configurable: true, value: process.platform })
resetWslGitReadEnvironmentForTests()
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Restore the original platform value.

Line 63 reads process.platform after beforeEach sets it to win32. The cleanup writes win32 again. Store the original value before the hooks, then restore that value.

Proposed fix
+const originalPlatform = process.platform
+
 // ...
   afterEach(() => {
-    Object.defineProperty(process, 'platform', { configurable: true, value: process.platform })
+    Object.defineProperty(process, 'platform', { configurable: true, value: originalPlatform })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
afterEach(() => {
Object.defineProperty(process, 'platform', { configurable: true, value: process.platform })
resetWslGitReadEnvironmentForTests()
})
const originalPlatform = process.platform
afterEach(() => {
Object.defineProperty(process, 'platform', { configurable: true, value: originalPlatform })
resetWslGitReadEnvironmentForTests()
})

Comment thread src/main/git/runner.ts
Comment on lines +1216 to +1222
const beginIndex = stdout.indexOf(captured.beginMarker, 0, 'utf8')
if (beginIndex === -1) {
return stdout
}
const payloadStart = beginIndex + Buffer.byteLength(captured.beginMarker, 'utf8')
const endIndex = stdout.indexOf(captured.endMarker, payloadStart, 'utf8')
return endIndex === -1 ? stdout.subarray(payloadStart) : stdout.subarray(payloadStart, endIndex)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Use the final begin marker for raw buffers.

readStdout uses lastIndexOf because shell tracing can echo the fenced command before execution. readCapturedGitBuffer uses the first beginMarker. In that case, binary blob reads can return traced shell text instead of the blob payload.

Proposed fix
-  const beginIndex = stdout.indexOf(captured.beginMarker, 0, 'utf8')
+  const beginIndex = stdout.lastIndexOf(captured.beginMarker, stdout.length, 'utf8')

Add a raw-buffer regression case with an echoed fence before the real payload.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const beginIndex = stdout.indexOf(captured.beginMarker, 0, 'utf8')
if (beginIndex === -1) {
return stdout
}
const payloadStart = beginIndex + Buffer.byteLength(captured.beginMarker, 'utf8')
const endIndex = stdout.indexOf(captured.endMarker, payloadStart, 'utf8')
return endIndex === -1 ? stdout.subarray(payloadStart) : stdout.subarray(payloadStart, endIndex)
const beginIndex = stdout.lastIndexOf(captured.beginMarker, stdout.length, 'utf8')
if (beginIndex === -1) {
return stdout
}
const payloadStart = beginIndex + Buffer.byteLength(captured.beginMarker, 'utf8')
const endIndex = stdout.indexOf(captured.endMarker, payloadStart, 'utf8')
return endIndex === -1 ? stdout.subarray(payloadStart) : stdout.subarray(payloadStart, endIndex)

@OrcaWin
OrcaWin merged commit b7f2e17 into main Aug 18, 2026
46 checks passed
@OrcaWin
OrcaWin deleted the OrcaWin/wsl-fence-git-login-shell-reads branch August 18, 2026 09:55
paidaxingyo666 pushed a commit to paidaxingyo666/Manta that referenced this pull request Aug 21, 2026
* fix(git): fence buffered WSL login-shell reads

Two git paths force the login shell unconditionally and buffer its whole
stdout, so the distro's rc banner lands in front of the payload:

- gitExecFileAsyncBuffer backs `git show :<path>` blob reads and hands
  the bytes straight to the diff/blob viewer, so the banner is prepended
  to displayed file content.
- buildNetworkSshPolicyEnv probes `core.sshCommand` and treats any
  non-empty answer as a user-configured wrapper. A banner reads as
  configured, so the code skips the `ssh -o BatchMode=yes` fallback and
  silently disarms the guard that keeps non-interactive SSH from
  hanging on a prompt.

Fencing is opt-in per call site rather than applied to the login-shell
branch as a whole: streaming consumers (`git grep`, `ls-files -z`) parse
records as they arrive, so an opening marker would be glued onto their
first record. Only these two, both buffered by construction, opt in.

Blob content can be binary, so the payload is sliced out of the raw
bytes; decoding to find the fence would corrupt it. The markers are
exposed on the captured command because the shared module is bundled for
the renderer and cannot reference Buffer.

Note this path is not a rare fallback: `preferWslDirectGit` is only set
by gitStatusReadOptionsForWorktree, so every other WSL-routed git call
takes the login shell on every invocation.

* test(git): use findLast for the ssh-policy call lookup

Satisfies the code-quality rule that flags filter-then-index.

---------

Co-authored-by: OrcaWin <[email protected]>
dallascrilley pushed a commit to dallascrilley/orca that referenced this pull request Aug 27, 2026
* fix(git): fence buffered WSL login-shell reads

Two git paths force the login shell unconditionally and buffer its whole
stdout, so the distro's rc banner lands in front of the payload:

- gitExecFileAsyncBuffer backs `git show :<path>` blob reads and hands
  the bytes straight to the diff/blob viewer, so the banner is prepended
  to displayed file content.
- buildNetworkSshPolicyEnv probes `core.sshCommand` and treats any
  non-empty answer as a user-configured wrapper. A banner reads as
  configured, so the code skips the `ssh -o BatchMode=yes` fallback and
  silently disarms the guard that keeps non-interactive SSH from
  hanging on a prompt.

Fencing is opt-in per call site rather than applied to the login-shell
branch as a whole: streaming consumers (`git grep`, `ls-files -z`) parse
records as they arrive, so an opening marker would be glued onto their
first record. Only these two, both buffered by construction, opt in.

Blob content can be binary, so the payload is sliced out of the raw
bytes; decoding to find the fence would corrupt it. The markers are
exposed on the captured command because the shared module is bundled for
the renderer and cannot reference Buffer.

Note this path is not a rare fallback: `preferWslDirectGit` is only set
by gitStatusReadOptionsForWorktree, so every other WSL-routed git call
takes the login shell on every invocation.

* test(git): use findLast for the ssh-policy call lookup

Satisfies the code-quality rule that flags filter-then-index.

---------

Co-authored-by: OrcaWin <[email protected]>
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* fix(git): fence buffered WSL login-shell reads

Two git paths force the login shell unconditionally and buffer its whole
stdout, so the distro's rc banner lands in front of the payload:

- gitExecFileAsyncBuffer backs `git show :<path>` blob reads and hands
  the bytes straight to the diff/blob viewer, so the banner is prepended
  to displayed file content.
- buildNetworkSshPolicyEnv probes `core.sshCommand` and treats any
  non-empty answer as a user-configured wrapper. A banner reads as
  configured, so the code skips the `ssh -o BatchMode=yes` fallback and
  silently disarms the guard that keeps non-interactive SSH from
  hanging on a prompt.

Fencing is opt-in per call site rather than applied to the login-shell
branch as a whole: streaming consumers (`git grep`, `ls-files -z`) parse
records as they arrive, so an opening marker would be glued onto their
first record. Only these two, both buffered by construction, opt in.

Blob content can be binary, so the payload is sliced out of the raw
bytes; decoding to find the fence would corrupt it. The markers are
exposed on the captured command because the shared module is bundled for
the renderer and cannot reference Buffer.

Note this path is not a rare fallback: `preferWslDirectGit` is only set
by gitStatusReadOptionsForWorktree, so every other WSL-routed git call
takes the login shell on every invocation.

* test(git): use findLast for the ssh-policy call lookup

Satisfies the code-quality rule that flags filter-then-index.

---------

Co-authored-by: OrcaWin <[email protected]>
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