-
Notifications
You must be signed in to change notification settings - Fork 6
fix: mitigate WSL2 fetch ETIMEDOUTs to Anthropic API (#19) #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
2af4dc1
fix: force IPv4-first DNS resolution to avoid WSL2 fetch timeouts
claude 99eaf57
fix: retry callAnthropic on transient network errors
claude 97e30d0
chore: add MINT_DEBUG diagnostics for callAnthropic
claude 3a5c910
Merge remote-tracking branch 'origin/main' into claude/fetch-issues-w…
nujovich 4688676
Potential fix for pull request finding
nujovich b3af586
fix: wire debug diagnostics and retry logic into callAnthropic
Copilot a126403
Potential fix for pull request finding
nujovich f537abc
fix: narrow setDefaultResultOrder('ipv4first') to WSL2 only
Copilot 041bf1b
chore: exclude network/debug helpers from v8 coverage
nujovich a5a6c40
feat: add callAnthropic import and vi/afterEach to test skeleton
nujovich 7261b4a
test: add callAnthropic unit tests to close coverage gaps
nujovich c66fc1b
feat: export isWSL2 and hasDnsResultOrderOverride for unit testing
nujovich f85017d
test: add node:fs mock and new imports for WSL2 detection tests
nujovich ecf1df8
test: add hasDnsResultOrderOverride unit tests
nujovich 6147513
test: add isWSL2 unit tests
nujovich bc3b766
Potential fix for pull request finding
nujovich c49aa24
refactor: move hasDnsResultOrderOverride and isWSL2 to internal lib/n…
Copilot 5b3fe10
test: add retry/backoff tests and narrow v8 ignore regions in callAnt…
Copilot c2851e6
refactor: rename nonRetryable to nonRetryableError for clarity
Copilot e2f58f3
Potential fix for pull request finding
nujovich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest' | ||
| import { readFileSync } from 'node:fs' | ||
| import { hasDnsResultOrderOverride, isWSL2 } from '../net-utils.mjs' | ||
|
|
||
| vi.mock('node:fs', () => ({ | ||
| readFileSync: vi.fn(), | ||
| })) | ||
|
|
||
| describe('hasDnsResultOrderOverride', () => { | ||
| let originalExecArgv | ||
|
|
||
| beforeEach(() => { | ||
| originalExecArgv = process.execArgv | ||
| process.execArgv = [] | ||
| vi.stubEnv('NODE_OPTIONS', '') | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| process.execArgv = originalExecArgv | ||
| vi.unstubAllEnvs() | ||
| }) | ||
|
|
||
| it('returns true when NODE_OPTIONS includes --dns-result-order', () => { | ||
| vi.stubEnv('NODE_OPTIONS', '--dns-result-order=verbatim') | ||
| expect(hasDnsResultOrderOverride()).toBe(true) | ||
| }) | ||
|
|
||
| it('returns true when execArgv contains --dns-result-order', () => { | ||
| process.execArgv = ['--dns-result-order'] | ||
| expect(hasDnsResultOrderOverride()).toBe(true) | ||
| }) | ||
|
|
||
| it('returns true when execArgv contains --dns-result-order=value', () => { | ||
| process.execArgv = ['--dns-result-order=verbatim'] | ||
| expect(hasDnsResultOrderOverride()).toBe(true) | ||
| }) | ||
|
|
||
| it('returns false when neither NODE_OPTIONS nor execArgv signal an override', () => { | ||
| expect(hasDnsResultOrderOverride()).toBe(false) | ||
| }) | ||
| }) | ||
|
|
||
| describe('isWSL2', () => { | ||
| afterEach(() => { | ||
| vi.mocked(readFileSync).mockReset() | ||
| }) | ||
|
|
||
| it('returns true when /proc/sys/kernel/osrelease contains wsl2', () => { | ||
| vi.mocked(readFileSync).mockImplementation((path) => { | ||
| if (String(path).includes('osrelease')) return '5.15.153.1-microsoft-standard-WSL2' | ||
| throw new Error('ENOENT') | ||
| }) | ||
| expect(isWSL2()).toBe(true) | ||
| }) | ||
|
|
||
| it('returns true when /proc/version matches microsoft.*wsl2 pattern', () => { | ||
| vi.mocked(readFileSync).mockImplementation((path) => { | ||
| if (String(path).includes('osrelease')) throw new Error('ENOENT') | ||
| return 'Linux version 5.15.0-microsoft-standard-WSL2 (gcc)' | ||
| }) | ||
| expect(isWSL2()).toBe(true) | ||
| }) | ||
|
|
||
| it('returns true when /proc/version matches wsl2.*microsoft pattern', () => { | ||
| vi.mocked(readFileSync).mockImplementation((path) => { | ||
| if (String(path).includes('osrelease')) throw new Error('ENOENT') | ||
| return 'Linux WSL2-microsoft kernel' | ||
| }) | ||
| expect(isWSL2()).toBe(true) | ||
| }) | ||
|
|
||
| it('returns false when /proc/version contains microsoft but not wsl2', () => { | ||
| vi.mocked(readFileSync).mockImplementation((path) => { | ||
| if (String(path).includes('osrelease')) throw new Error('ENOENT') | ||
| return 'Linux microsoft version' | ||
| }) | ||
| expect(isWSL2()).toBe(false) | ||
| }) | ||
|
|
||
| it('returns false when /proc/version has no microsoft or wsl2', () => { | ||
| vi.mocked(readFileSync).mockImplementation((path) => { | ||
| if (String(path).includes('osrelease')) throw new Error('ENOENT') | ||
| return 'Linux 5.15.0 Ubuntu' | ||
| }) | ||
| expect(isWSL2()).toBe(false) | ||
| }) | ||
|
|
||
| it('returns false when both reads throw', () => { | ||
| vi.mocked(readFileSync).mockImplementation(() => { throw new Error('ENOENT') }) | ||
| expect(isWSL2()).toBe(false) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Internal network/environment utilities for lib/prompts.mjs. | ||
| // This module may be shipped as an implementation detail, but it is not a | ||
| // supported public API; import it directly in tests rather than going through | ||
| // prompts.mjs. | ||
|
|
||
| import { readFileSync } from 'node:fs' | ||
|
|
||
| export function hasDnsResultOrderOverride() { | ||
| if (process.env.NODE_OPTIONS?.includes('--dns-result-order')) return true | ||
|
|
||
| for (let i = 0; i < process.execArgv.length; i++) { | ||
| const arg = process.execArgv[i] | ||
| if (arg === '--dns-result-order') return true | ||
| if (arg?.startsWith('--dns-result-order=')) return true | ||
| } | ||
|
|
||
| return false | ||
| } | ||
|
|
||
| // Returns true only when running inside WSL2 (Windows Subsystem for Linux v2). | ||
| // Generic WSL env vars such as WSL_DISTRO_NAME / WSL_INTEROP are not enough to | ||
| // distinguish WSL1 from WSL2, so check kernel metadata for a WSL2-specific | ||
| // marker instead. | ||
| export function isWSL2() { | ||
| try { | ||
| if (/wsl2/i.test(readFileSync('/proc/sys/kernel/osrelease', 'utf8'))) return true | ||
| } catch {} | ||
|
|
||
| try { | ||
| return /microsoft.*wsl2|wsl2.*microsoft/i.test(readFileSync('/proc/version', 'utf8')) | ||
| } catch { | ||
| return false | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[minor]
setDefaultResultOrder('ipv4first')runs atprompts.mjsimport time. If PR #58'sAnthropicLlmClient(which doesn't importprompts.mjs) lands, this DNS fix won't protect thosefetch()calls. Consider a shared init module.