fix: WSL2 Ollama networking and provider discovery diagnostics#55435
fix: WSL2 Ollama networking and provider discovery diagnostics#55435BradGroux merged 4 commits intoopenclaw:mainfrom
Conversation
- Fix Ollama stream handling for WSL2 environments - Update undici global dispatcher for WSL2 networking compatibility - Adjust provider discovery configuration - Add WSL2 networking tests
Greptile SummaryThis PR fixes WSL2 networking issues with Ollama by disabling undici's Confidence Score: 4/5Safe to merge after fixing the isWSL2Sync mock reset in beforeEach to prevent order-dependent test failures. The core production changes are sound: the WSL2 detection logic is well-established, the IPv4 override is narrowly scoped and idempotency-safe, and the diagnostics improvements are straightforward. The one actionable issue is a test-reliability gap — vi.clearAllMocks() does not reset mockReturnValue implementations, so the new WSL2 test leaves isWSL2Sync returning true for any subsequently added tests. This is a one-line fix in beforeEach and doesn't affect current test outcomes (the WSL2 test is last in its block), but it warrants resolution before merge to avoid silent future regressions. src/infra/net/undici-global-dispatcher.test.ts — needs explicit isWSL2Sync mock reset in beforeEach.
|
| Filename | Overview |
|---|---|
| src/infra/net/undici-global-dispatcher.ts | Introduces WSL2-aware resolveAutoSelectFamily: when net.getDefaultAutoSelectFamily() returns true and isWSL2Sync() confirms a WSL2 environment, the function overrides the result to false to force IPv4. |
| src/infra/net/undici-global-dispatcher.test.ts | Adds mock for ../wsl.js and a new test verifying WSL2 disables autoSelectFamily. The beforeEach doesn't reset the isWSL2Sync mock implementation, making test order slightly fragile if new tests are added after the WSL2 case. |
| src/agents/ollama-stream.ts | Error handling now appends err.cause.message to the user-facing error message and logs it separately, improving diagnostics for undici's wrapped TypeError: fetch failed errors. |
| src/agents/models-config.providers.discovery.ts | Extends Ollama discovery failure log to include the nested error.cause.message when present, mirroring the same diagnostic improvement made in ollama-stream.ts. |
Comments Outside Diff (1)
-
src/infra/net/undici-global-dispatcher.test.ts, line 78-91 (link)Missing
isWSL2Syncmock reset inbeforeEachvi.clearAllMocks()only resets call history (mock.calls,mock.results), not implementations set bymockReturnValue. The WSL2 test at line 160 setsvi.mocked(isWSL2Sync).mockReturnValue(true), and becauseclearAllMocksdoesn't reset that implementation, any test added after the WSL2 case will unexpectedly seeisWSL2Syncreturningtrue. This would silently break, e.g., the "replaces default Agent dispatcher" assertion that expectsautoSelectFamily: true.Adding an explicit reset in
beforeEachkeeps the suite order-independent:Prompt To Fix With AI
This is a comment left during a code review. Path: src/infra/net/undici-global-dispatcher.test.ts Line: 78-91 Comment: **Missing `isWSL2Sync` mock reset in `beforeEach`** `vi.clearAllMocks()` only resets call history (`mock.calls`, `mock.results`), not implementations set by `mockReturnValue`. The WSL2 test at line 160 sets `vi.mocked(isWSL2Sync).mockReturnValue(true)`, and because `clearAllMocks` doesn't reset that implementation, any test added after the WSL2 case will unexpectedly see `isWSL2Sync` returning `true`. This would silently break, e.g., the "replaces default Agent dispatcher" assertion that expects `autoSelectFamily: true`. Adding an explicit reset in `beforeEach` keeps the suite order-independent: How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/infra/net/undici-global-dispatcher.test.ts
Line: 78-91
Comment:
**Missing `isWSL2Sync` mock reset in `beforeEach`**
`vi.clearAllMocks()` only resets call history (`mock.calls`, `mock.results`), not implementations set by `mockReturnValue`. The WSL2 test at line 160 sets `vi.mocked(isWSL2Sync).mockReturnValue(true)`, and because `clearAllMocks` doesn't reset that implementation, any test added after the WSL2 case will unexpectedly see `isWSL2Sync` returning `true`. This would silently break, e.g., the "replaces default Agent dispatcher" assertion that expects `autoSelectFamily: true`.
Adding an explicit reset in `beforeEach` keeps the suite order-independent:
```suggestion
beforeEach(async () => {
vi.resetModules();
({
DEFAULT_UNDICI_STREAM_TIMEOUT_MS,
ensureGlobalUndiciEnvProxyDispatcher,
ensureGlobalUndiciStreamTimeouts,
resetGlobalUndiciStreamTimeoutsForTests,
} = await import("./undici-global-dispatcher.js"));
vi.clearAllMocks();
resetGlobalUndiciStreamTimeoutsForTests();
setCurrentDispatcher(new Agent());
getDefaultAutoSelectFamily.mockReturnValue(undefined);
vi.mocked(hasEnvHttpProxyConfigured).mockReturnValue(false);
vi.mocked(isWSL2Sync).mockReturnValue(false);
});
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix: WSL2 Ollama networking and provider..." | Re-trigger Greptile
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 98666899a6
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5c21c88fd8
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5245d00f51
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Review: WSL2 Ollama DiagnosticsVerdict: Approve -- clean, focused, and solves a real pain point for WSL2 users. Reviewed the full diff across all 4 files. This is exactly the right scope (compared to the earlier #55187 which bundled unrelated changes). Notes below from two independent review passes. What works well
Suggestions (non-blocking)
SummaryAll four items are minor hardening suggestions. The core fix is correct, minimal, and solves the reported issue in #54498. Good to merge. |
BradGroux
left a comment
There was a problem hiding this comment.
Approved. Clean, focused fix for WSL2 Ollama connectivity.
…law#55435) - Fix Ollama stream handling for WSL2 environments - Update undici global dispatcher for WSL2 networking compatibility - Adjust provider discovery configuration - Add WSL2 networking tests
…law#55435) - Fix Ollama stream handling for WSL2 environments - Update undici global dispatcher for WSL2 networking compatibility - Adjust provider discovery configuration - Add WSL2 networking tests
…law#55435) - Fix Ollama stream handling for WSL2 environments - Update undici global dispatcher for WSL2 networking compatibility - Adjust provider discovery configuration - Add WSL2 networking tests
…law#55435) - Fix Ollama stream handling for WSL2 environments - Update undici global dispatcher for WSL2 networking compatibility - Adjust provider discovery configuration - Add WSL2 networking tests
…law#55435) - Fix Ollama stream handling for WSL2 environments - Update undici global dispatcher for WSL2 networking compatibility - Adjust provider discovery configuration - Add WSL2 networking tests
fixed #54498