Repository navigation
Description
Problem
The mcpx daemon's chat-completions reverse proxy (proxyToUpstream, pkgs/mcpx/internal/daemon/routes_proxy.go:215) has no bound on either direction of its upstream call:
1. No upstream timeout. routes_proxy.go:237 calls http.DefaultClient.Do(upReq). http.DefaultClient has no Timeout, and the client sets no ResponseHeaderTimeout — the only cancellation is the inbound request's context, i.e. the downstream client disconnecting. The daemon's own HTTP servers set only ReadHeaderTimeout (internal/daemon/server.go:309,361) — no write/response deadline rescues a stuck handler. An upstream that accepts the connection and never answers (or trickles forever) holds the handler, its goroutine and the downstream connection indefinitely. This is reachable per-request: handleChatCompletions takes the upstream URL from the X-Upstream-Url request header when present (routes_proxy.go, step 4, ~:150), so any local client can aim the daemon at a slow-loris endpoint.
2. The whole upstream response is buffered in memory, uncapped. routes_proxy.go:245-262: the response body is streamed through an io.TeeReader into a bytes.Buffer, then buf.String() is stored as the feedback interaction record after io.Copy finishes. The copy itself streams, but the buffer defeats it — memory grows with the full response size, with no cap. A streamed request makes this worst-case: chatCompletionReq.Stream (routes_proxy.go:38) is marshalled straight into the proxied payload (:227) and handleChatCompletions proxies unconditionally (:164), so a long SSE stream accumulates in the buffer for its entire life.
Verified on main 42796be5bbe8824545df570f3b239d23d4ef93ac by reading the code this run.
The house pattern this misses
Every other outbound HTTP call in mcpx pins a timeout or a body bound:
internal/catalog/embeddings.go:52—&http.Client{Timeout: defaults.EmbeddingsRemoteTimeout}internal/mcpclient/sse.go:58—&http.Client{Timeout: timeout}; error bodies read viaio.LimitReader(..., defaults.HTTPErrorBodyLimit)(sse.go:76,225)internal/cli/client.go:118-162— all daemon clients built with explicit timeoutsinternal/daemon/ops.go:285— registry calls usecs.Duration("registry.timeout")
routes_proxy.go:237 is the only http.DefaultClient use in internal/daemon.
Why it matters
The daemon is the process every other tool call depends on. One hung upstream (a crashed provider gateway, a misconfigured proxy.upstreamUrl, a header-aimed slow endpoint) leaks a handler + connection pair forever per request, and one large or streamed response can grow daemon memory without limit — the daemon-side mirror of the inbound body-cap gap in #2082 (request bodies), on the response path #2082 does not cover. Distinct from #2097/#2100/#2102: those are the standalone proxy packages; this is mcpx's own daemon proxy route.
Acceptance criteria
-
proxyToUpstreamuses a client with a configured timeout (aproxy.*setting with a sane default, in the style ofregistry.timeout/defaults.EmbeddingsRemoteTimeout), covering at least time-to-headers and total response time; a timed-out upstream yields a clean 502 to the downstream client. - The feedback-record copy of the upstream response is capped (e.g.
io.LimitReaderat a named constant, in the spirit ofdefaults.HTTPErrorBodyLimit); over-cap responses are still proxied in full to the client, only the recorded copy is truncated, and the truncation is visible in the record. - Tests: a stub upstream that accepts and never responds makes the handler return within the configured timeout; a stub upstream returning an over-cap (or streamed) response is proxied completely while daemon-side buffering stays bounded.
- Existing daemon test suites pass unchanged.
Activity
developing-today commentedon Oct 29, 2026
CODE-1017
dezren39 commentedon Oct 29, 2026
🤖 Agent note · filed
55 remaining items
dezren39 commentedon Nov 3, 2026
🤖 Agent note · parked
Merge pull request #3380 from developing-today/queue/3088-2114-proxy-…
dezren39 commentedon Nov 3, 2026
🤖 Agent note · done