Skip to content

fix(core): retry failed ripgrep resolution and sanitize PowerShell 5.1 module path on Windows - #41015

Closed
Yuxin-Qiao wants to merge 1 commit into
anomalyco:devfrom
Yuxin-Qiao:fix/ripgrep-windows-resolution
Closed

Yuxin-Qiao wants to merge 1 commit into
anomalyco:devfrom
Yuxin-Qiao:fix/ripgrep-windows-resolution

Conversation

@Yuxin-Qiao

@Yuxin-Qiao Yuxin-Qiao commented Aug 7, 2026 •

Copy link
Copy Markdown

Summary

Fixes both root causes of grep/glob failing on Windows from #40623:

  • Failed ripgrep resolution was cached forever. RipgrepBinary.filepath wrapped the locate/download/extract effect in Effect.cached, which memoizes failures as well as successes. A single failed download or extraction (e.g. the PowerShell issue below) poisoned every grep/glob call in that process — even after the user fixed the environment (e.g. placed rg.exe in ~/.cache/opencode/bin/) — until opencode was restarted. Replaced with a single-flight memo that caches only successful resolutions, so the next call retries.
  • Zip extraction breaks when launched from MSIX PowerShell 7. Extraction spawns powershell.exe (Windows PowerShell 5.1) with Expand-Archive, and the child inherits PSModulePath from the launching shell. When opencode is started from the Microsoft Store (MSIX) build of PowerShell 7, that variable lists the Core-edition module directory first; the 5.1 module autoloader deems it incompatible and stops searching, so Expand-Archive fails with CouldNotAutoloadMatchingModule and the downloaded zip is never extracted. The child now gets a pinned PSModulePath pointing at the inbox 5.1 module directory (%SystemRoot%\System32\WindowsPowerShell\v1.0\Modules) when the resolved shell is powershell.exe. pwsh.exe spawns are untouched.

Test

  • Added packages/core/test/ripgrep-binary.test.ts:
    • memoizeSuccess memoizes a successful resolution (runs once)
    • memoizeSuccess retries a failed resolution instead of caching the failure, then caches the eventual success
    • windowsPowerShell5ModulePath honors SystemRoot and falls back to C:\Windows
  • bun test test/ripgrep.test.ts test/ripgrep-binary.test.ts test/filesystem/search.test.ts — 8 pass / 0 fail
  • bun run typecheck (tsgo) — clean
  • oxlint — no new warnings (the unbound-method pattern matches the existing Semaphore.makeUnsafe(1).withPermit usage in session/runner/llm.ts)

Refs #40623

…1 module path on Windows

Two Windows grep/glob failures from anomalyco#40623:

- the ripgrep resolution was wrapped in Effect.cached, which memoizes
  failures too, so one failed download/extraction poisoned every grep
  and glob call until the process was restarted. Replace it with a
  single-flight memo that only caches successful resolutions, so the
  next call retries.
- zip extraction spawns powershell.exe, which inherits PSModulePath
  from the launching shell. When opencode is launched from the MSIX
  build of PowerShell 7, that path lists the Core-edition modules
  first and Expand-Archive autoload fails inside the 5.1 child. Pin
  the child's PSModulePath to the inbox 5.1 module directory.
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Aug 7, 2026
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant