#16897: fix(tools): route web_search requests through HTTP proxy env vars
channel: telegram
agents
size: S
Cluster:
Web Search Provider Enhancements
## 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
#15923: feat: add proxy support for web_search tool
by Shuai-DaiDai · 2026-02-14
82.8%
#16144: fix: respect HTTP_PROXY/HTTPS_PROXY in SSRF-protected fetch (#2102)
by battman21 · 2026-02-14
80.2%
#8571: fix: support system proxy in web_fetch SSRF dispatcher
by Asura-2010 · 2026-02-04
79.6%
#19660: fix: respect HTTP_PROXY/HTTPS_PROXY env vars for undici fetch
by 88plug · 2026-02-18
77.2%
#20578: feat(browser): add proxy configuration option
by illusivejosiah · 2026-02-19
74.2%
#13637: fix(discord): add proxy support for media attachment downloads
by ayanesakura · 2026-02-10
72.4%
#19042: Security: add URL allowlist for web_search and web_fetch
by smartprogrammer93 · 2026-02-17
72.0%
#13843: feat(web-search): allow overriding Brave Search base URL
by strelov1 · 2026-02-11
71.7%
#21132: fix: allow message(action='read') in isolated/cron sessions + add H...
by matt-bedda · 2026-02-19
71.6%
#22505: Feature/clean grok search base url
by vacuityv · 2026-02-21
71.5%