Skip to content

The gateway passes a worker's framing headers through to the caller #546

Closed

Description

@V3RON

What happens

The gateway copies every header from a worker's relay head onto the response it sends the caller (src/gateway/relay.ts, around line 252). Framing headers such as content-length and transfer-encoding from a worker can reach the caller.

What should happen

Both sides drop hop-by-hop and framing headers, as the spec of #514 says; the gateway sets its own framing for the response it streams.

Context

A review note on #528 (task #514). Feature #511.

Written by an agent.

Activity

  1. added
    bug:new
    and removed
    bug:new
    on Oct 14, 2026
  2. self-assigned this
    on Oct 16, 2026
  3. added a commit that references this issue on Oct 16, 2026
  4. V3RON commented on Oct 16, 2026

    @V3RON
    ContributorAuthor

    Confirmed: a defect on main, reproduced by a failing gateway unit test on bug/546-repro.

    Reproduction

    Branch bug/546-repro (commit de704f9d, test only), src/gateway/relay.test.ts:

    drops every hop-by-hop and framing header of a worker's relay head, in any case, and keeps an ordinary header, on the response it hands the caller

    pnpm exec vitest run --project unit src/gateway/relay.test.ts

    The test drives GatewayRelay over the scripted connection with a relay-head push carrying all nine framing/hop-by-hop names the contract lists (three in mixed case, the case edge) plus x-kept, and asserts the caller's response headers equal exactly [["x-kept","yes"]]. It fails on that deep-equality assertion with all nine present:

    AssertionError: expected [ [ 'connection', 'close' ], …(9) ] to deeply equal [ [ 'x-kept', 'yes' ] ]
    +  "content-length", "5"   +  "transfer-encoding", …   +  "te", "trailers, custom-checksum"
    

    The unit level is where this can fail for the right reason: the existing e2e (relay-gateway.e2e.test.ts:650) shows content-length gone only because the worker strips it in #respond; a same-version worker's head never carries a framing header, so nothing above the gateway's own head handling can force one. Verified as reading the code plus Node's Headers (v24): it accepts all nine names on a Response — none is guarded — so a head that carries them hands them to the caller.

    Root cause

    Defect. src/gateway/relay.ts:207 — #onHead copies every [name, value] pair of the worker's head straight onto the Response: for (const [name, value] of headers) responseHeaders.append(name, value). relayHeadersSchema bounds the shape of a header, not which header arrives, and the wire is a claim, not a fact (safety rule 10), so the gateway must apply #514's own rule — "both sides drop the framing and hop-by-hop headers, which the relay re-creates" — when it parses the head. It does not. The other two header paths of the relay do drop them through relayHeaderPairs (request side, relay.ts:136; worker's response side, src/daemon/relay.ts:253); the gateway's head handling is the one path missing the drop. Present since the relay landed (#528).

    Simplest fix

    In #onHead's append loop, skip pairs the contract already knows: if (isRelayFramingHeader(name)) continue; (src/contract/relay.ts:47, exported, case-insensitive, the one place the nine names are listed). No wire or protocol change. Verified locally: with that one guard the new test passes and all 36 tests in the file pass.

    Alternatives rejected

    • Drop them in src/daemon/relay.ts #respond instead — already done there; the missing drop is the gateway not trusting wire input, which the worker cannot fix for it.
    • Delete framing names from responseHeaders after the loop — same size, but splits the drop across two mechanisms when the predicate exists to be used at the boundary.
    • Refuse framing names in relayHeadersSchema — a contract-shape change (protocol bump) that kills the whole relay over one stray header instead of ignoring it.

    Risk

    • A relayed download now reaches the HTTP caller without the worker's content-length (chunked framing) — that is feat(fleet): a gateway relays an HTTP exchange to a worker module over the uplink #514's intent, but check gateway-front.test.ts "downloads over 2 GiB" (the 413 cap is enforced worker-side in host.ts, so it should stay green).
    • src/stream reads only its own simlock-stream-* headers off a relayed response; confirm nothing else in it or the agent-device front depends on a dropped name.
    • Keep #onHead's existing Headers-refusal path (#invalid) working: the skip must not turn a refused value into a silently dropped one.

    Written by an agent.

  5. removed their assignment
    on Oct 16, 2026
  6. added
    bug:ready
    and removed on Oct 16, 2026
  7. self-assigned this
    on Oct 16, 2026
  8. added a commit that references this issue on Oct 16, 2026
    8e45a99
  9. V3RON commented on Oct 16, 2026

    @V3RON
    ContributorAuthor

    Delivery run

    Merged: #643 (#546)
    Parked: none
    Waiting: none
    Decided: none

    Round 1 of the reviews passed with no findings (spec, code, claims: F0). The gate merged at 8e45a994. No slow-lane check was needed.

    Written by an agent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug:ready

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions