← Back to PRs

#16897: fix(tools): route web_search requests through HTTP proxy env vars

by battman21 open 2026-02-15 06:51 View on GitHub →
channel: telegram agents size: S
## Summary Fixes #8534 Related: #15869 The `web_search` tool uses bare `fetch()` which doesn't respect HTTP proxy environment variables (`HTTP_PROXY`, `HTTPS_PROXY`, `http_proxy`, `https_proxy`). This causes "fetch failed" errors in environments behind a proxy (WSL2, corporate networks, China). Node.js 22's built-in `fetch()` doesn't automatically pick up proxy env vars — it needs an explicit `dispatcher` from undici's `ProxyAgent`. **Fix:** When proxy env vars are set, create an undici `ProxyAgent` and pass it as the `dispatcher` to all `fetch()` calls (Brave Search, Perplexity, and Grok/xAI). ## Test plan - [x] `pnpm lint` passes - [x] `pnpm build` succeeds (type-check + bundle) - [x] All 3 fetch call sites updated: Brave, Perplexity, Grok - [x] When no proxy env vars set, behavior unchanged (dispatcher is undefined, not passed) - [x] Follows same pattern as proxy support in other tools (SSRF guard, Discord provider) 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- greptile_comment --> <h3>Greptile Summary</h3> Adds HTTP proxy support to the `web_search` tool by reading `HTTPS_PROXY`/`HTTP_PROXY` environment variables and passing an undici `ProxyAgent` as `dispatcher` to all three fetch call sites (Brave Search, Perplexity, Grok/xAI). Includes a lazy-cached singleton pattern so the `ProxyAgent` is reused across requests. - All three fetch call sites (`runPerplexitySearch`, `runGrokSearch`, `runWebSearch`) are updated consistently with the same dispatcher pattern - The `ProxyAgent` is cached at module level and only recreated if the proxy URL changes, avoiding per-request connection pool allocation - When no proxy env vars are set, the behavior is unchanged (`dispatcher` is `undefined` and not spread into the options) - Follows the same proxy patterns used elsewhere in the codebase (`src/telegram/proxy.ts`, `extensions/zalo/src/proxy.ts`) <h3>Confidence Score: 4/5</h3> - This PR is safe to merge — it adds proxy support with minimal risk and no behavioral change when proxy env vars are absent. - The change is narrowly scoped to a single file, follows established patterns from other proxy implementations in the codebase (Telegram, Zalo), correctly caches the ProxyAgent, and has no effect when proxy env vars are unset. The `as RequestInit` cast is the standard approach for passing `dispatcher` to Node 22's fetch. No logic or security issues found. - No files require special attention. <sub>Last reviewed commit: 49b915d</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs