Skip to content

fix(embed): honor proxy env for non-loopback endpoints - #130

Open
spacemolt-molty wants to merge 1 commit into
mnemon-dev:masterfrom
spacemolt-molty:fix/embed-proxy-env
Open

fix(embed): honor proxy env for non-loopback endpoints#130
spacemolt-molty wants to merge 1 commit into
mnemon-dev:masterfrom
spacemolt-molty:fix/embed-proxy-env

Conversation

@spacemolt-molty

Copy link
Copy Markdown
Contributor

What

The embedding client's http.Transport now resolves its proxy from the environment (HTTPS_PROXY/HTTP_PROXY/NO_PROXY) for non-loopback endpoints, and never uses a proxy for loopback endpoints.

Why

NewClientWithModel set Proxy: nil on the transport. The comment said "Bypass system proxy for localhost connections" — but Proxy: nil disables proxy env for every endpoint, not just localhost. Two consequences:

  1. Behind a credential gateway that injects auth at the proxy boundary (a transparent HTTPS_PROXY, as used by e.g. OneCLI-style agent gateways), remote OpenAI-compatible embedding providers become unreachable: the client bypasses the gateway and hits the provider directly, then fails with 401 because the API key only exists gateway-side.
  2. Local Ollama keeps working either way, so nothing caught this in local testing.

Routing by endpoint fixes both: loopback never proxied, remote endpoints follow standard env resolution (so gateways work), and corporate proxies stop breaking local setups in the opposite direction.

One subtlety: the loopback branch returns an explicit no-proxy resolver (func(*http.Request) (*url.URL, error) { return nil, nil }) rather than nil, because a nil Transport.Proxy panics when invoked.

Follow-up to #127 (same area, found while wiring up a Voyage AI backend behind a credential gateway).

Checklist

  • Deterministic tests pass (make test)
  • Relevant E2E/process/Docker boundaries pass (make test-integration, when affected)
  • New/changed behavior is covered by tests
  • Documentation updated (USAGE.md, DESIGN.md, or README) if applicable
  • User-facing release-note impact described in this PR, if applicable

The embedding client set Proxy: nil on its http.Transport — intended to
keep local Ollama instances off corporate proxies, but it also disabled
proxy env for every remote endpoint. Behind credential gateways that
inject auth at the proxy boundary (a transparent HTTPS_PROXY), remote
OpenAI-compatible providers became unreachable: the client bypassed the
gateway, then failed with 401 because the key only exists gateway-side.

Route by endpoint instead: loopback (localhost / 127.0.0.0/8 / ::1)
never uses a proxy; everything else resolves through the standard
HTTPS_PROXY/HTTP_PROXY/NO_PROXY environment. The loopback branch returns
an explicit no-proxy resolver rather than nil, which panics when the
Transport invokes it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant