Skip to content

fix(wsl): bound the line-ending sample's index scan, not just its matches - #29552

Merged
nwparker merged 2 commits into
mainfrom
fix/wsl-line-ending-sample-bounded-scan
Oct 16, 2026
Merged

nwparker merged 2 commits into
mainfrom
fix/wsl-line-ending-sample-bounded-scan

Conversation

@nwparker

@nwparker nwparker commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​76 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​74
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​16 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​9

ELI5

When a WSL repo lives on a Windows drive (/mnt/c/...), Orca peeks at a sample of files to learn whether Windows Git wrote them with Windows line endings. That peek was supposed to look at a couple hundred files, but in some repos it ended up reading every file in the repo over the slow Windows-drive bridge. Stage, discard and commit sat waiting on it. Now the peek stops after a fixed number of files, whatever it finds.

What Changed

Before: the sample ran git ls-files --eol | grep <eligible files> | head -n 200. The head only counts lines that pass the filter. In a repo with * text=auto in .gitattributes, no line passes, so head never fills up, never closes the pipe, and git keeps going. ls-files --eol opens each working file to inspect it, so git read the whole repo across the Windows-drive mount until the 15 s timeout. A timeout counts as a failure, so it retried (backing off from 30 s up to 10 min), and every stage, discard or commit with no fresh sample waited about 15 s for the next attempt.

After: the script is git ls-files --eol | head -n 2000 | grep <eligible files> | head -n 200. The first head caps how many index entries git lists, and so how many files it reads, whether or not anything matches. The second head still caps the sample at 200. A repo with nothing eligible now gets a fast "inconclusive" answer instead of a timeout. That answer is cached and falls back to autocrlf=input exactly as before.

Mechanism: once the first head has its 2000 lines it exits, and git dies of SIGPIPE on its next write. Git restores the default SIGPIPE handling at startup, so this holds on every git version Orca supports. The real stop point is 2000 entries plus whatever fits in the pipe and stdio buffers, which is still a fixed bound. The new cap is LINE_ENDING_SCAN_LIMIT (10 × the 200-file sample cap). It is passed as $3 through the existing runWslProcess argv path, which uses buildWslExecArgs / --exec, so wsl.exe never expands $.

Why

The audit's suggestion was to cap the raw scan rather than only the matches, and that is what this does. The alternatives were:

  • Sampling a fixed pathspec: this guesses at repo layout and can miss the files that matter.
  • A shorter timeout: this still reads files until the timer fires, and still turns a slow repo into a failure that keeps retrying.

2000 entries is 10× the sample size. In a normal repo the 200 eligible files are found well inside it, so the answer is unchanged. Where they aren't, the existing "inconclusive → autocrlf=input" fallback applies, the same result the timeout path ended in.

Git compatibility: ls-files --eol is Git 2.10+ (baseline 2.25), and head -n is POSIX.

Linked Issue

Follow-up to #27778 (which added the line-ending sample). Found in a post-merge performance audit.

Visual Proof

N/A: no UI change. The effect is that git writes stop stalling on Windows-drive WSL repos with * text=auto.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Measured on macOS (APFS) with a generated 200,001-file repo using the real script and real git 2.x:

Repo Old pipeline New pipeline
* text=auto (nothing eligible) 20.98 s / 23.71 s / 21.13 s (would exceed the 15 s timeout) 0.30 s / 0.12 s / 0.09 s
no attributes (all eligible) 0.19 s / 0.06 s / 0.05 s, 200 lines 0.11 s / 0.07 s / 0.07 s, 200 lines

This was a local disk, not a Windows drive mounted in WSL. There, each file read is far slower, which makes the old unbounded case much worse and the bounded one still capped. I did not have a WSL machine for a drvfs timing.

New src/main/git/wsl-windows-checkout-sample-script.test.ts runs the exact SAMPLE_SCRIPT under /bin/sh against a stand-in git whose ls-files never ends (yes):

  • With nothing eligible, the pipeline finishes promptly with empty output. With the old script it hung until the 10 s timeout (verified by temporarily reverting).
  • With every line eligible, it still returns exactly 200 sample lines.

Skipped on Windows, where there is no /bin/sh. The probe test now asserts the extra argv value. pnpm tc, the WSL checkout tests, and check:code-quality:changed pass.

AI Disclosure

Review

An adversarial review found nothing blocking. It confirmed the SIGPIPE stop, the argv and quoting, the exit-code behaviour (no pipefail, so the last head decides) and Git 2.25 compatibility. A stale doc comment it flagged is fixed. Noted but unchanged: a repo whose first 2000 entries hold only a handful of eligible files decides on that smaller run. The bias toward the start of the path order was already there, over a wider window.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Only affects WSL git commands whose working directory is on a Windows drive. Native, SSH and plain-WSL repos are untouched.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 11 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5a5d7634-8441-45b3-97f0-92bd5f2fdc30
📥 Commits

Reviewing files that changed from the base of the PR and between b1b632e46eb772464f0109db9b0f61ce35777552 and c2a3c84.

📒 Files selected for processing: 4
  • src/main/git/wsl-windows-checkout-git-config.ts
  • src/main/git/wsl-windows-checkout-git-probe.test.ts
  • src/main/git/wsl-windows-checkout-git-probe.ts
  • src/main/git/wsl-windows-checkout-sample-script.test.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 72411cc2-3a8a-47c5-b041-528f24b6cbc6
📥 Commits

Reviewing files that changed from the base of the PR and between 2cf8d9b and b1b632e46eb772464f0109db9b0f61ce35777552.

📒 Files selected for processing: 4
  • src/main/git/wsl-windows-checkout-git-config.ts
  • src/main/git/wsl-windows-checkout-git-probe.test.ts
  • src/main/git/wsl-windows-checkout-git-probe.ts
  • src/main/git/wsl-windows-checkout-sample-script.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

📝 Walkthrough

The WSL line-ending probe now uses a 2,000-entry scan limit in addition to its 200-file sample limit. The script limits git ls-files --eol output before filtering eligible entries, then applies the sample limit. Tests cover an endless output source, eligible and ineligible entries, and the limits passed to the WSL runner.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to b1b63

This change makes the WSL line-ending check return quickly in large repositories that have few eligible files. It falls back to the existing default when the sample is inconclusive. No merge-blocking risk was identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: bounding the WSL line-ending sample's index scan.
Description check Passed The description is complete and relevant. It includes the required explanation, change details, rationale, linked issue reference, visual-proof statement, testing evidence, AI disclosure section, revi…
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.
Full details: Description check

Explanation

The description is complete and relevant. It includes the required explanation, change details, rationale, linked issue reference, visual-proof statement, testing evidence, AI disclosure section, review notes, scope considerations, and checklist.

✨ Finishing Touches: 💡 2
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

…ches

The WSL-on-Windows-drive line-ending sample piped ls-files --eol through grep
then head, so when no entry was eligible (* text=auto) head never closed the
pipe and every file was read over drvfs until the 15 s timeout, which stage,
discard and commit waited on after each backoff. Cap the raw ls-files output
before the grep.

Follow-up to #27778.
@nwparker
nwparker force-pushed the fix/wsl-line-ending-sample-bounded-scan branch from b1b632e to c2a3c84 Compare October 16, 2026 09:16
@nwparker
nwparker merged commit 088fefb into main Oct 16, 2026
33 checks passed
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