Skip to content

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

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

Copy link
Copy Markdown

Issue for this PR

Closes #40623

Type of change

  • Bug fix

What does this PR do?

grep/glob fail on Windows for two independent reasons, both fixed here.

  1. Failed ripgrep resolution was cached forever. RipgrepBinary.filepath wrapped the locate/download/extract effect in Effect.cached, which memoizes failures as well as successes. One failed download or extraction poisoned every grep/glob call in that process until opencode was restarted — even after the user fixed the environment. Replaced with a single-flight memo that caches only successful resolutions, so the next call retries.
  2. 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.

How did you verify your code works?

  • 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 (re-run after rebasing onto latest dev)
  • bun run typecheck (tsgo) — clean

Screenshots / recordings

N/A — core fix, no UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

…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.
@Yuxin-Qiao

Copy link
Copy Markdown
Author

Closing for now — I'm a bit tired and don't have bandwidth to keep maintaining this, and there's been no review activity.\n\nThe fix (retry failed ripgrep resolution + sanitize PowerShell 5.1 module path on Windows — fix/ripgrep-windows-resolution 994d6b6) is still valid if the Windows issue remains. The branch is kept at https://github.com/Yuxin-Qiao/opencode-fix/tree/fix/ripgrep-windows-resolution and can be picked up / reopened by anyone. Happy to hand it over to future maintainers. Thanks!

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.

Grep tool fails on Windows: ripgrep extraction broken by MSIX PowerShell 7 PSModulePath, and failures are cached until restart

1 participant