Claude Code on opencode-go (set to "direct"), with Codex as the search
delegate and the proxy on Auto (system proxy 127.0.0.1:7890): every
WebSearch dialed chatgpt.com directly, to the addresses a poisoned DNS
gave, and failed with "no answer in 2m0s". Codex's own requests through
the same gateway went through the proxy.
Cause: attempt() puts the turn provider's proxy choice on the request
context (Provider.Via -> netproxy.With). The search runs inside that
context, and its sub-request to Codex calls Provider.Via again, but
netproxy.With(ctx, "") returned ctx unchanged, so a provider that
follows the global proxy inherited the outer provider's "direct".
- netproxy.With: "" now replaces a choice ctx already names, so any
request made for one provider while serving another (search delegate,
vision describer, classifier, Codex titles, all through attempt's
p.Via) takes its own provider's proxy or the global one.
- webSearch clears the turn's choice up front: the search APIs, which
have no proxy of their own, follow the global one.
- kimiSearch now applies the Kimi Code plan's own proxy (p.Via); it
had none and went the turn's way.
Verified:
- New TestSearchFollowsTheSearchersProxy: a fake CONNECT proxy on a free
port; the turn's provider is reachable only directly, the searcher, a
Kimi Code search service and a search API only through the proxy.
Cases: Settings' proxy, Auto (from the environment), a searcher's own
proxy with the global direct, a search API. On the old code it fails
with "dial tcp search.test:443: ... (dialed directly)", CONNECTs [];
with only the With fix the search API case fails; with the kimiSearch
change reverted the Kimi case fails. -race -count=5 passes.
- TestWith in netproxy gains With(With(ctx, outer), "") follows the
global proxy; fails on the old With.
- go test -tags nogui: gateway, netproxy, provider, plugin, update pass;
the full ./... suite under load ~180 passed except
internal/agent TestDshHomePickSurvivesSyncAndEffort, which passes alone
(-count=3) and touches no proxy code (not this change; not yet filed).
After rebasing onto 552c2244d (search MCP, also through webSearch) the
search, Kimi and proxy tests pass again. gofmt -l clean; go build;
GOOS=linux and GOOS=windows go vet -tags nogui on gateway and netproxy.
- docs/subsystems/gateway-routing.md: the one-try row says how a
sub-request picks its proxy; the test is in its run list.
- Not tried against the reporter's real proxy and DNS.
The reporter starts magpie at login with the proxy on "follow system
proxy". magpie comes up before the proxy app. With no system proxy set
yet, netproxy.For gives none, so magpie's own allowance reads went out
direct, from the user's real IP. That reading was then kept for up to
15s. A system proxy that is set but not listening fails the request
("proxyconnect ... connection refused"); it never falls back to direct.
Proxy freshness:
- netproxy.System re-reads a "none" reading after 2s (noneKeep) instead
of 15s (systemKeep, unchanged for a set proxy).
- The plugin host looks again every 2s while it has no proxy
(proxyLookNone), so a host started before the proxy app takes it soon.
- Catalog sync, the update check, plugin updates and token refresh all go
through netproxy.Func / Dispatch, so they use the current proxy too.
Settings -> Allowances -> "Allowance reads": Automatic (default, as
before) or When I ask (settings.QuotaReads = "asked",
POST /api/settings/quota-reads):
- These count as asking (provider.Asked): the Usage page opened or
refreshed (?asked=1), a card's refresh (RefreshUsage), magpie quota,
magpie accounts, magpie quota wait and the TUI's quotas.
- Every other read (quotaReading -> holdUnasked) carries netproxy.Hold.
netproxy.Func, Dispatch's choice proxies and the plugin host's calls
refuse a held request before it leaves.
- The readers return the last reading, dated (AsOf), or "not read yet".
That covers routing's Allowances / AwaitAllowance, the used-up switch,
the menu bar, alerts, Quotas/KeyBalances/PlanQuotas, Codex/Claude/
Cursor/Grok/Kiro usage and KeyAllowance.
- An account refused for its quota (StaleAllowance) or a key refused
(StaleKeyAllowance) is still read, once.
- Warm-up and check-in are unchanged.
- Strings are added in zh, zh-TW, ja and de. The docs are updated:
providers-accounts (Allowance row), provider-plugins (host proxy).
Run:
- go test -tags nogui ./... (sandbox HOME), gofmt -l, and go vet -tags
nogui on GOOS=linux/windows/darwin for ., netproxy, plugin, settings,
provider, gui and tui.
- New tests, each seen red by breaking the change by hand:
- TestSystemProxySetAfterStartIsTakenSoon and TestHeldRequestNeverLeaves
(netproxy).
- TestHostWithNoProxyLooksAgainSoon (plugin; red with 15s).
- TestAllowancesReadOnlyWhenAsked (red without the hold and without
markStaleRead), TestAllowancesReadByThemselvesByDefault and
TestKeyReadsOnlyWhenAsked (red without holdUnasked and without
unheld for a refused key).
- GUI quota-reads.test.cjs in Chromium and WebKit, at 900 and 360px, in
en/zh/zh-TW/ja/de.
- i18n-keys, gui-ja, gui-de, settings-sections, settings-groups,
currency, number-units and tray-bird.