stream:open/close/error carry no requestId, so a stream cannot be joined to the request that opened it #84

Closed
opened 2026-09-01 16:53:09 +00:00 by chrnx · 0 comments
Owner

src/http/core.ts states the design as:

request:end fires when the handler returns, not when a stream it produced finishes: a
route that returns an AsyncIterable is done here in milliseconds while its connection may
live for hours […] stream:open/stream:close already describe the connection, and now
carry the same requestId
.

They do not. All three emitters send { name } and nothing else:

  • src/http/stream.ts:41,79,86 — the Node adapter
  • src/http/ws-core.ts:120,132,135 — the WebSocket path
  • src/http/web.ts — the Fetch adapter (added in #83, mirroring the two above)

Bus.emit (src/bus.ts:179) forwards the payload verbatim and adds nothing ambient, so there is
no other place the field could be arriving from.

Why the gap matters

The split of responsibilities is right: a request span that ended in 2ms and a connection that
lived for six hours must not share a latency distribution. But the split only works if the two
can be joined, and requestId is the join key — it is what EventPayload documents itself
as ("Correlates every event of one request").

Without it:

  • an exporter cannot attribute a stream to the route, tenant or trace that opened it, because
    name is the only field and it is just the pattern;
  • traceId, which is carried verbatim precisely so an exporter can hand it to OTLP, never
    reaches the events describing the longest-lived thing the server does;
  • "which request opened the SSE connection that is still holding a slot" is unanswerable, which
    is the question stream gauges exist to answer.

Scope

Thread Correlation to the three emitters the same way emitShedPair already receives it, and
spread it into the payload:

bus?.emit('stream:open', { name, ...correlation });

pipeStream and asReadableStream both already take bus and name; this is one more argument
on each, and the callers (src/http/server.ts:181, outcomeToResponse in src/http/web.ts)
have correlation in hand at the call site. ws-core needs checking separately — an upgrade
correlates differently and may not have one to give.

Then fix or delete the claim in core.ts, which is currently the only place the intended
behaviour is written down.

Related

Found while implementing #83. Pre-existing: the field has never been emitted, so the comment
described an intent that was not carried out rather than a regression.

`src/http/core.ts` states the design as: > `request:end` fires when the handler returns, **not** when a stream it produced finishes: a > route that returns an `AsyncIterable` is done here in milliseconds while its connection may > live for hours […] `stream:open`/`stream:close` already describe the connection, **and now > carry the same `requestId`**. They do not. All three emitters send `{ name }` and nothing else: - `src/http/stream.ts:41,79,86` — the Node adapter - `src/http/ws-core.ts:120,132,135` — the WebSocket path - `src/http/web.ts` — the Fetch adapter (added in #83, mirroring the two above) `Bus.emit` (`src/bus.ts:179`) forwards the payload verbatim and adds nothing ambient, so there is no other place the field could be arriving from. ## Why the gap matters The split of responsibilities is right: a request span that ended in 2ms and a connection that lived for six hours must not share a latency distribution. But the split only works if the two can be **joined**, and `requestId` is the join key — it is what `EventPayload` documents itself as ("Correlates every event of one request"). Without it: - an exporter cannot attribute a stream to the route, tenant or trace that opened it, because `name` is the only field and it is just the pattern; - `traceId`, which is carried verbatim precisely so an exporter can hand it to OTLP, never reaches the events describing the longest-lived thing the server does; - "which request opened the SSE connection that is still holding a slot" is unanswerable, which is the question stream gauges exist to answer. ## Scope Thread `Correlation` to the three emitters the same way `emitShedPair` already receives it, and spread it into the payload: ```ts bus?.emit('stream:open', { name, ...correlation }); ``` `pipeStream` and `asReadableStream` both already take `bus` and `name`; this is one more argument on each, and the callers (`src/http/server.ts:181`, `outcomeToResponse` in `src/http/web.ts`) have `correlation` in hand at the call site. `ws-core` needs checking separately — an upgrade correlates differently and may not have one to give. Then fix or delete the claim in `core.ts`, which is currently the only place the intended behaviour is written down. ## Related Found while implementing #83. Pre-existing: the field has never been emitted, so the comment described an intent that was not carried out rather than a regression.
chrnx closed this issue 2026-09-04 13:32:30 +00:00
Sign in to join this conversation.