Skip to content

Design: read it bounded — one response-read contract for mcpx's outbound calls #4375

Open
4 of 4 issues completed

Description

@dezren39

Design doc: files/designs/code-mcpx-bounded-response-reads.md in the keep-the-four-repos-healthy goal workspace. Audit at origin/main f93e6dc5b — every defect below re-verified present at the cited lines this pass (2026-11-02).

Summary

mcpx reads responses from endpoints it does not control — third-party MCP servers, configured model providers, remote embeddings services — with no byte bound in four places. A client timeout bounds duration, never bytes: a fast endpoint can deliver gigabytes inside the timeout. Each filing re-derived the same missing rule in a different package:

The conforming embodiments already agree: error bodies are read via io.LimitReader(resp.Body, defaults.HTTPErrorBodyLimit) (4 KB, upstream.errorBodyLimit) in mcpclient/http.go:167 and sse.go:76,225,228; the SSE reader has a max line size; every daemon inbound body is bounded by http.MaxBytesReader / named defaults limits. The inbound side has a contract; the outbound side has exceptions.

The contract

Every byte mcpx reads from a peer it does not operate is bounded, and the bound's shape depends on what the bytes are for: an error body is an excerpt, a buffered success body is refused past its cap, a retained copy is truncated while the delivered stream is not, and every call carries a deadline as well as a byte bound — a timeout bounds duration, never bytes.

Recorded decisions (full reasoning, alternatives and risks in the design doc):

  1. Error bodies are excerpts, everywhere, at the existing limit — any non-2xx body embedded in an error/record/log is read at most defaults.HTTPErrorBodyLimit (4 KB). No new limit, no exceptions.
  2. A success body mcpx buffers whole is refused past its cap, never silently truncated — read cap+1; over → error naming the surface and the cap (truncated JSON fails parsing with a misleading error). Caps are named defaults.json entries: model + scripting providers 16 MiB; the mcpclient non-JSON fallback 1 MiB (aligned with http.bodyLimit), pinning mcpx(mcpclient): a non-JSON 200 reply is buffered whole with no size cap — Send's fallback io.ReadAll is unbounded while the error path in the same function caps at 4 KB #4282's open choice to refuse — over the cap, Send errors and pushes nothing (a truncated non-JSON body would manufacture a partial "message" out of a body that is definitionally not a protocol message). Under the cap, hand-on-whole behaviour is unchanged.
  3. A retained copy is truncated; the delivered stream never is — the proxy's feedback record is capped with the truncation visible in the record; the client receives the full response. PR mcpx(daemon): bound chat proxy upstream calls (#2114) #3380 (for mcpx(daemon): chat-completions proxy has no upstream timeout and buffers the whole upstream response in memory — proxyToUpstream uses http.DefaultClient and an uncapped TeeReader buffer #2114) already implements this shape and is adopted as the embodiment.
  4. Deadline and byte bound are both required — providers, embeddings and mcpclient already carry client deadlines; the proxy's proxy.timeout (PR mcpx(daemon): bound chat proxy upstream calls (#2114) #3380) closes the exception. A future outbound site is conforming only when both are present.

Phased breakdown

Phases adopt the three filed origins as sub-issues (no parallels); Phase 4 is a new closing-audit issue, gated on Phases 1–3.

Open questions (in the design doc, not filed)

A per-message byte bound for the mcpclient JSON decoder path; the 16 MiB provider cap revisited on Phase 1's real completion sizes; a decoded-value (max-dimension) bound for embeddings — a schema contract, not a byte contract.

Related

Design doc (full problem/evidence/alternatives/risks): files/designs/code-mcpx-bounded-response-reads.md (goal workspace). Origins: #2114, #4282, #4354. Neighbours, not this design: #2082 (closed — daemon request bodies), openchamber #1127 (the same contract stated for that repo's codebase), #3068 (parsed-shape validation — what a value's shape may be, not how many bytes may be read).

Filed by the design architect (pass 38, 2026-11-02): design issue for the mcpx bounded response-read contract. The three origin issues are adopted as its phases — triage of each origin should record the phase structure and the decisions above rather than re-filing or re-scoping. Phase 4's closing audit is filed separately and gated on Phases 1–3.

Acceptance criteria

  • One bounded response-read contract for mcpx outbound calls is stated in the design and adopted: every byte read from a peer mcpx does not operate is bounded, with the bound's shape matched to the bytes' purpose.
  • Each of the four named unbounded sites (daemon proxy routes_proxy.go:244, MCP client fallback http.go:218, both OpenAI-compatible providers, and the embeddings error path at embeddings.go:101) is dispositioned by a phase of this design — fixed under the contract or explicitly excepted with reasoning.
  • The conforming embodiments (4 KB HTTPErrorBodyLimit error reads, SSE max line size, bounded inbound bodies) are named as the contract's reference implementations.
  • Child/phase issues (including Phase 4 (audit) of #4375 — closing response-read inventory + contract statement for mcpx #4376 Phase 4) carry the implementation work; this design issue closes when the contract is adopted and all phases are filed/landed or excepted.

Activity

  1. added
    app/mcpxPackage/app: mcpx (pkgs/ or apps/ in this repo)
    epicMeta-issue grouping multiple items (org Project Type=Epic)
    kind/designA design proposal (design-architect): multi-step, phased, decision-bearing
    on Nov 2, 2026
  2. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    Design architect, pass 38 (2026-11-02): this issue is the design of record for the mcpx bounded response-read contract. The three origin issues are adopted as its phases and linked as sub-issues: Phase 1 = #4354 (providers: success cap + error excerpt), Phase 2 = #4282 (mcpclient fallback: bounded, refuse past cap), Phase 3 = #2114 (daemon proxy: deadline + retained-copy cap; in flight as PR #3380), Phase 4 = #4376 (closing response-read inventory + contract statement, gated on Phases 1–3, status/blocked).

    The four recorded decisions are in the issue body and the design doc (files/designs/code-mcpx-bounded-response-reads.md, goal workspace). Triage of any origin should record the phase structure and those decisions rather than re-filing, re-scoping or splitting the origin. Register entry added to files/potential-projects.md (status: proposed). No user/review: every origin carries explicit acceptance with verified probes, and the open rulings (excerpt limit, per-surface caps, refuse-vs-truncate, copy-vs-stream) are the architect's recorded decisions in the doc.

  3. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    Intake review

    Design epic filed 2026-11-02 by the design-architect pass, audited against origin/main f93e6dc with every defect re-verified at cited lines this same day. Related: #2114 (daemon proxy buffering, implementation PR #3380 in flight), #4282 (MCP fallback), #4354 (provider error bodies), #4376 (Phase 4 audit, already filed and gated). Risks: four separate filings had already re-derived the same missing rule — without one contract the fifth and sixth instances will keep appearing. Suggested approach: adopt the contract as written, then land phases in dependency order; the monitor has added priority/effort only — the design's own status/needs-triage stands.

    — fleet monitor intake enrichment (protocol §5), 2026-11-02 run. Original body preserved verbatim above the appended acceptance-criteria section.

  4. added
    priority/normalOrdinary priority (the default)
    effort/lLarge: multi-day or open-ended; expect staged check-ins
    meta/enrichedIntake review done: acceptance criteria, links, and normalized labels added
    on Nov 2, 2026
  5. 26 remaining items

  6. added
    queue/claimedQueue worker lifecycle state
    and removed
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    on Nov 8, 2026
  7. added a commit that references this issue on Nov 9, 2026
  8. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    state: done
    task: 13050
    lane: code-b (direct, #8187)
    issue: #4375
    pr: #8273

    Phase 4 closing evidence (#4376 audit, 2026-11-10, lane code-b)

    Origins verified closed/fixed: #4354 CLOSED (Phase 1), #4282 CLOSED (Phase 2), #2114 CLOSED with PR #3380 MERGED (Phase 3). The gate on #4376 is fully landed.

    Contract statement landed: PR #8273 writes the four decisions into pkgs/mcpx/internal/defaults/defaults.go beside HTTPErrorBodyLimit, with an audit summary. The same PR makes the audit's one allowed behaviour change: the remote embeddings error read in internal/catalog/embeddings.go was io.ReadAll(resp.Body) unbounded — now an excerpt at defaults.HTTPErrorBodyLimit (decision 1), the disposition #4376 named for it.

    Read inventory — every production resp.Body read / buffered peer-response copy in pkgs/mcpx (51 candidate sites audited; test code excluded):

    Conforms:

    • internal/model/openai.go:124 (error excerpt at the limit), :128 (success buffered, cap+1 refuse pattern) — Phase 1.
    • internal/scripting/provider.go:123, :127 — same pair.
    • internal/mcpclient/sse.go:77, :227; internal/mcpclient/http.go:248 — error excerpts at the limit.
    • internal/mcpclient/http.go:297, :309 — decoder over a TeeReader with a capped retained head + LimitReader room (decision 3) — Phase 3.
    • internal/daemon/routes_proxy.go:292, :301 — peer response relayed whole to the client; the retained feedback copy passes through cappedFeedbackBuffer{proxyFeedbackCaptureLimit} (decision 3).
    • internal/mcpauth/failover.go:458 — error read capped at 1<<20. Bounded excerpt, conforms in effect; the cap is a literal rather than the named constant (recorded, not changed — outside the audit's one-fix allowance).

    Decoder-streamed success paths (streaming conforms; the bound on the decoded value itself remains this issue's standing open question — recorded per path, not silently settled):

    • internal/catalog/embeddings.go:111 (remote embeddings Decode), internal/preflight/resolve.go:433 (npm registry; the client carries a Timeout, decision 4), internal/registry/registry.go:305 (operator-configured BaseURL — joins the contract for the decoded-value question; its error path reads no body), internal/mcpclient/http.go:297 (JSON decoder path), and the daemon-local Decode sites below.

    Deliberately local — internal/cli reads of mcpx's own daemon (endpoint from c.Endpoint, the local daemon by construction; not operator-configured beyond it):

    • internal/cli/embeddings.go:52 (Decode), :102 (error ReadAll, export), :112/:119 (io.Copy streamed delivery to file/stdout — delivered, not retained), :154 (error ReadAll, import), :161 (Decode).
    • internal/cli/client.go:494 (ReadAll), :926 (Decode), :1278 (Scanner, streamed).
    • internal/cli/opcmd.go:552 (ReadAll), :556 (Scanner, streamed).
    • internal/cli/feedback.go:85, :149 (ReadAll), :153, :243 (Decode) — all via c.Endpoint.
    • internal/cli/exec.go:225 (Scanner, streamed), :425, :518, :708 (ReadAll).
      The two unbounded daemon-local error excerpts (cli/embeddings.go:102, :154) are recorded here rather than fixed: the audit's acceptance allows exactly one slip fix, and the peer-contract slip (catalog) is the one it named.

    Filed as a named follow-up:

    Out of scope, per the audit's ruling (not peer bytes): stdin reads at internal/cli/consumer.go:247, opcmd.go:471, logs.go:390, exec.go:650, secrets_cmd.go:145; file reads at internal/artifacts/artifacts.go:682 and internal/mcpclient/stdio.go:196 (stderr copy).

    Inbound request bodies (separate surface; audited, all capped at their handlers): daemon/routes_proxy.go:74 (MaxBytesReader, HTTPCallBodyLimit), daemon/server.go:1798, :1833 (LimitReader, http.bodyLimit), daemon/upgrade.go:108 (MaxBytesReader, HTTPControlBodyLimit), daemon/routes_proto.go:915 (MaxBytesReader), mcpserver/server.go:1985, :2039 (LimitReader, 64<<20).

    Side finding, filed separately: TestNoPackageRedeclaresADefault is red on clean main (proven with the audit's changes stashed) — filed as #8270 (same class as closed #3085; tracker #2534).

    With PR #8273 merged, Phase 4 closes: all four phases of this design are landed, the contract is written where the next call site will find it, and the only open threads are the named follow-ups #8271 and this issue's decoded-value open question.

  9. added a commit that references this issue on Nov 10, 2026
  10. dezren39 commented on Nov 12, 2026

    @dezren39
    MemberAuthor

    Program tending — epic completion (tracking: #1352)

    • Child progress: 8 of 8 children closed (0 open).
    • Last movement: 2026-11-12T07:04:23Z.
    • All recorded children are closed. Proposing closure of this epic: if more work belongs here, reopen a child or say what remains and this stays open.
  11. dezren39 commented on Nov 17, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · triaged

    • Agent: repo queue worker (repo-worker-code), lane code-i (openchamber-scheduled-lane)
    • Session / ID: task 18281 (triage)
    • Found via: scheduled queue claim; fresh GitHub state
    • Verdict: all 8 child issues are closed (per the 2026-11-12 program-tending note) and the design contract landed in PR docs(mcpx): #4375 response-read contract + bounded embeddings error excerpt (#4376) #8273 (MERGED). The epic is ready for owner closure. No code remainder is found here and no packet is created. The owner should close the epic or name what remains.
  12. dezren39 commented on Nov 19, 2026

    @dezren39
    MemberAuthor

    Program tending — epic completion (tracking: #1352)

    • Child progress: 8 of 8 children closed (0 open).
    • Last movement: 2026-11-17T02:43:54Z.
    • All recorded children are closed. Proposing closure of this epic: if more work belongs here, reopen a child or say what remains and this stays open.
  13. removed their assignment
    on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/mcpxPackage/app: mcpx (pkgs/ or apps/ in this repo)effort/lLarge: multi-day or open-ended; expect staged check-insepicMeta-issue grouping multiple items (org Project Type=Epic)epic/mcpx-platformReprioritization program epic (2026-11-12)kind/designA design proposal (design-architect): multi-step, phased, decision-bearingmeta/enrichedIntake review done: acceptance criteria, links, and normalized labels addedpriority/normalOrdinary priority (the default)source/design-architectFiled by the repo design architect jobstatus/triagedTriaged and routed (see agent note)task/triageQueue packet kind: verify, reproduce, and route this item

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions