Read PR, linked issues, and comments.
UnderstandAnalyzed relevant source files and changelogs.
UnderstandInvestigated SDK fetch and proxy setup behavior.
UnderstandPrepared detailed review with findings and recommendations.
VerifyYou are given one or more GitHub PR URLs: https://github.com/badlogic/pi-mono/pull/939
For each PR URL, do the following in order:
packages/*/CHANGELOG.md files. Report whether an entry exists. If missing, state that a changelog entry is required before merge and that you will add it if the user decides to merge. Follow the changelog format rules in AGENTS.md. Verify:
### Breaking Changes, ### Added, ### Fixed, etc.)Fixed foo ([#123](https://github.com/badlogic/pi-mono/pull/123) by [@user](https://github.com/user))### Breaking Changes, not just ### FixedOutput format per PR: PR: Changelog:
If no issues are found, say so under Bad and Ugly.
>cd /Users/badlogic/workspaces/pi-mono && gh pr view 939 --json title,body,comments,commits,files,author,labels,state,baseRefName,headRefName>cd /Users/badlogic/workspaces/pi-mono && gh pr diff 939Now let me read the linked issue #931:
>cd /Users/badlogic/workspaces/pi-mono && gh issue view 931 --json title,body,comments,labels,state,authorLet me read the relevant source files to understand the context:
Let me check the changelog for packages/ai and packages/coding-agent:
Now let me check the coding-agent README and docs to see if proxy documentation would be needed:
>cd /Users/badlogic/workspaces/pi-mono && rg -l "proxy" packages/coding-agent/README.md packages/coding-agent/docs/*.md 2>/dev/null | head -5>cd /Users/badlogic/workspaces/pi-mono && rg -l "proxy|HTTP_PROXY" packages/ai/README.md 2>/dev/null | head -5>cd /Users/badlogic/workspaces/pi-mono && rg "proxy|HTTP_PROXY" packages/ai/README.md packages/coding-agent/README.md --context 2The current README refers to "proxy" in the context of API endpoint proxies (like baseUrl), not HTTP_PROXY environment variables. Let me check if undici is already a dependency:
>cd /Users/badlogic/workspaces/pi-mono && cat packages/ai/package.json | grep undici>cd /Users/badlogic/workspaces/pi-mono && cat packages/coding-agent/package.json | grep undici>cd /Users/badlogic/workspaces/pi-mono && cat package.json | grep undiciundici is not currently a dependency. Let me check if Node's native fetch uses undici under the hood:
>node -e "console.log(typeof globalThis.fetch)"Let me now understand the issue better by checking the original issue description. The issue #931 mentions that for fetch based SDKs, they suggest using undici to set up the dispatcher. Let me see if the approach is correct by checking how undici.setGlobalDispatcher works:
>cd /Users/badlogic/workspaces/pi-mono && node -e "
const { EnvHttpProxyAgent, setGlobalDispatcher } = require('undici');
console.log('EnvHttpProxyAgent exists:', !!EnvHttpProxyAgent);
console.log('setGlobalDispatcher exists:', !!setGlobalDispatcher);
" 2>&1 || echo "undici not installed"The PR adds undici which is not currently a dependency. This is a problem because:
undici to any package.jsonLet me verify the PR doesn't touch package.json files:
>cd /Users/badlogic/workspaces/pi-mono && gh pr diff 939 | grep -E "^diff|package.json"Confirmed. The PR imports undici but doesn't add it as a dependency. Let me also check if undici is bundled with newer Node.js versions:
>node -e "const undici = require('node:undici'); console.log('exists:', !!undici?.EnvHttpProxyAgent)" 2>&1 || echo "not available as node:undici"The PR has a fundamental issue. Now let me also check if this approach even works for all SDK calls. The SDKs (Anthropic, OpenAI, Google GenAI) have their own HTTP clients:
>cd /Users/badlogic/workspaces/pi-mono && rg "new (Anthropic|OpenAI|GoogleGenerativeAI)" packages/ai/src --type ts | head -10Now let me see if the Anthropic SDK respects setGlobalDispatcher:
>cd /Users/badlogic/workspaces/pi-mono && rg "httpAgent|agent|dispatcher|fetch" node_modules/@anthropic-ai/sdk/src/*.ts 2>/dev/null | head -20The Anthropic SDK uses its own fetch implementation. The setGlobalDispatcher from undici affects the global fetch, but the SDK might use its own bundled fetch. Let me check the issue description more carefully:
Looking at issue #931:
- for
httpbased SDK (e.g., amazon bedrock client), useproxy-agentto set up http agent.- for
fetchbased SDK (e.g., openai and anthropic),
- in
node, useundicito set up the dispatcher offetch- in
bun, there is built-in support for these environment variables
The key insight is that Node.js 18+ uses undici under the hood for its native fetch. So calling setGlobalDispatcher should affect the native fetch. However, the SDKs might use their own fetch implementation.
Let me check if this approach is valid:
>cd /Users/badlogic/workspaces/pi-mono && cat node_modules/@anthropic-ai/sdk/src/shims/node-runtime.ts 2>/dev/null | head -50>cd /Users/badlogic/workspaces/pi-mono && find node_modules/@anthropic-ai/sdk -name "*.ts" -exec grep -l "fetch" {} \; 2>/dev/null | head -5>cd /Users/badlogic/workspaces/pi-mono && cat node_modules/@anthropic-ai/sdk/shims/node-runtime.mjs 2>/dev/null | head -20>cd /Users/badlogic/workspaces/pi-mono && ls node_modules/@anthropic-ai/sdk/ 2>/dev/null>cd /Users/badlogic/workspaces/pi-mono && cat node_modules/@anthropic-ai/sdk/core/fetch-utils.mjs 2>/dev/null | head -30>cd /Users/badlogic/workspaces/pi-mono && ls node_modules/@anthropic-ai/sdk/core/>cd /Users/badlogic/workspaces/pi-mono && cat node_modules/@anthropic-ai/sdk/internal/shims.mjs | head -50The Anthropic SDK uses the global fetch by default (typeof fetch !== 'undefined'). This means setGlobalDispatcher should work because Node.js 18+'s native fetch uses undici internally.
However, there's still the issue that undici needs to be added as a dependency.
Let me also check the PR's placement of the proxy setup code. The issue is that the code is placed at the top of files, which means it runs at import time:
>cd /Users/badlogic/workspaces/pi-mono && gh pr diff 939 | head -40Now I have enough information to provide the review.
PR: https://github.com/badlogic/pi-mono/pull/939
Changelog:
packages/ai/CHANGELOG.md or packages/coding-agent/CHANGELOG.md. A changelog entry is required before merge and will be added if the user decides to merge.Good:
EnvHttpProxyAgent which automatically reads standard proxy environment variables (HTTP_PROXY, HTTPS_PROXY, NO_PROXY, and lowercase variants)Bad:
undici but doesn't add it to any package.json. The code will fail at runtime with Cannot find module 'undici'.undici to:
packages/ai/package.json (for generate-models.ts)packages/coding-agent/package.json (for main.ts)http based SDK requiring proxy-agent. This PR only handles fetch-based providers.Ugly:
npm run generate-models command, not runtime usage.Questions or Assumptions:
packages/ai instead, so all downstream packages get it automatically?Change summary:
undici.EnvHttpProxyAgent for Node.js native fetchpackages/ai/scripts/generate-models.ts and packages/coding-agent/src/main.tsTests: