Skip to content

Stream wire contract v2 (WE MR C1) ​

This guide covers the release in which every Helix SSE surface (the CF Durable Object's /sse, the StreamServer DO's /sse, agent-server's /sse, core's ResumableStreamHandler) speaks one protocol, encoded and decoded by core, and a stream that ends without a terminal frame is a typed, retryable failure instead of a clean end. It is a major release of @helix-agents/runtime-cloudflare, @helix-agents/agent-server and @helix-agents/ai-sdk, and a minor (0.x) release of @helix-agents/core and @helix-agents/store-cloudflare. Nothing is deprecated: there is no back-compat.

Protocol reference: Stream wire. The user's rulings: a–c (2026-10-09), D-4 (2026-10-11).

Deploy writers and readers together ​

A v1 producer and a v2 consumer (or the reverse) do not interoperate: a v2 reader ignores the v1 error frame and then reads the body's end as a drop (StreamDropError, retried); a v1 reader does not know truncated, rewound or caught-up and treats a v2 end without its old fields as before. Roll out the packages that write a stream (runtime-cloudflare, store-cloudflare, agent-server, core's ResumableStreamHandler) and the ones that read it (runtime-cloudflare's clients and transports, store-cloudflare's DurableObjectStreamManager, core's HttpRemoteAgentTransport, ai-sdk's chat transport) in one deploy. For cross-service remote agents, upgrade the producer and the consumer services together.

Frame renames ​

v1v2
event: error { error, errorDetail?, recoverable? }event: fail { error, errorDetail?, recoverable }
fail / error with code: 'TRUNCATED', floorevent: truncated { floor, errorDetail } (terminal)
non-terminal truncated { truncatedAtStep, … }event: rewound { atStep, atSequence?, minSequence? }
the DO's : connected commentevent: caught-up { head }
StreamServer end { finalOutput }end { status, output?, state?, usage? }
ResumableStreamHandler end { streamId }, errorend { status } / fail; chunk data { sequence, chunk }

A hand-written SSE client should decode with core's createSSEFrameDecoder + decodeStreamFrame (or iterate parseSSEFrames) and classify the end with classifyStreamTerminal. ResumableStreamHandler keeps a caller-set eventName / serializeChunk for its chunk frames; its terminal frames are always the protocol's.

A cut stream is a drop, never a clean end (ruling a) ​

Every reader now throws the retryable StreamDropError when a body ends with no terminal frame (an eviction, a proxy dropping the connection, a crash), unless its own caller aborted the read (CP-102). Before, these readers ended cleanly and a consumer could not tell a drop from a finished run.

ReaderBeforeNow
DOStreamManagerClient.createResumableReaderdonethrows StreamDropError (re-attach)
DOFrontendExecutor handle stream()donethrows StreamDropError
DurableObjectStreamManager readersdonethrows StreamDropError
HttpRemoteAgentTransport / DOStubTransport.streamthe iterator endedthrows StreamDropError
ai-sdk createHelixChatTransport (since removed: upgrade guide)a clean finishthe UI stream errors with StreamDropError
agent-server streamAgent on an active streama synthesized end{completed}a recoverable transport_stream_drop fail

Retry by re-attaching from your cursor (fromSequence / the snapshot's streamSequence); never re-send the request that started the run. A rewound frame (a cleanup while you were attached, or, first on a re-open, one that removed a chunk you hold, CP-200) that leaves the reader behind the head throws StreamTruncatedError, as the in-process readers always did.

The Durable Object readers re-open before they throw (C2a, C2b) ​

DOStreamManagerClient.createResumableReader (the DO chat route's resume / attach), the DO run handle's stream() (a DO chat send) and the DurableObjectStreamManager readers (the CF Workflows chat route) now re-open their /sse connection themselves on a drop: an EOF with no terminal frame, or a body read that fails (an eviction, a DO restarted from storage). They re-open from the highest stored sequence they took in, so every chunk arrives once: both stream DOs number chunks from one persisted counter that is never rewound, so a sequence survives a restart. A run that ended or failed while the reader was detached still ends with its real terminal. StreamDropError is thrown only when a re-open cannot help:

  • a second drop with no new chunk since the last re-open (core StreamReopenBudget; no wall clock is involved);
  • more than MAX_STREAM_REOPENS (8) counted re-opens for one reader;
  • a re-open that fails or answers 404.

Two cases end with a typed subclass of StreamDropError (C2b), so a handler that only knows drops keeps its recovery:

  • After a re-open, a chunk of a NEWER run of the stream's own session (another run took the stream meanwhile) ends the read with StreamRunChangedError (transport_stream_run_changed, retryable): re-anchor from the snapshot. Before C2b this was a plain transport_stream_drop.
  • An eviction the reader cannot recover from ends with StreamEvictedError (transport_stream_evicted, retryable, cause = the eviction reason). See the next section.

Each re-open is logged at info, and the cap at warn.

An evicted connection is told why: the evicted frame (C2b) ​

Both Durable Object /sse routes (the agent DO's and store-cloudflare's StreamDurableObject) now end a connection they evict with one last frame, evicted{resumeFrom, reason}, then EOF. It is not a stream terminal: the stream goes on, and the reader re-opens.

reasonWhenCounts toward MAX_STREAM_REOPENS
slow_consumerthe connection passed its unread-byte budget (or the pending-write cap)no (still progress-gated)
stalenothing was read within the inactivity boundno (still progress-gated)
max_connectionsthe agent DO is at its connection cap (it used to answer a comment frame)yes
server_errorthe route failed to serve the connectionyes

resumeFrom is the highest chunk sequence the writer knows the client read. The readers re-open from their own cursor: a cursor below resumeFrom means a frame was lost on the way, so the read ends with StreamTruncatedError (re-anchor from the snapshot), never a re-open over a gap. A second eviction with no new chunk since the last re-open, or a counted re-open past the cap, ends the read with StreamEvictedError.

Changed error code. An evicted DO body's read that cannot be resumed ends with transport_stream_evicted. As of !397 (CP-26) it was a retryable transport_error. If you branch on errorDetail.code, add transport_stream_evicted and transport_stream_run_changed next to transport_stream_drop. A chat client receives either as the route's in-band error event, and useHelixChat / useReanchorOnError re-anchor on it as on any dropped send.

New core exports: EVICTION_REASONS, EvictionReason, EvictedFrame, SSEEviction, StreamEvictedError, StreamRunChangedError. If you write your own /sse route on SSEConnectionManager, record your replay with markRead(id, sequence) and pass the client's cursor to addConnection(…, { readThrough }), so resumeFrom is right.

Deploy order: any. A reader older than C2b decodes evicted as an unknown event and reads the EOF as a drop.

The frame format is in Stream wire contract › Evictions.

Both readers also bound their memory. Their buffer of unread chunks is capped by count and by bytes (READER_BUFFER_HIGH_WATER_BYTES, 8 MiB): past either, they stop reading until the consumer drains half of it. The backlog they read before returning (from the cursor to the route's caught-up frame) is capped at READER_BACKLOG_MAX_BYTES (32 MiB); past it, the reader ends with StreamTruncatedError, so re-anchor from the snapshot, whose cursor is a recent checkpoint. A rewind while the reader was detached is not replayed as a rewound frame; the rewinding entry's stream_resync chunk, above the cursor, is delivered instead. Your consumer code needs no change: a drop the reader recovered from never reaches it.

Reads that failed no longer read as "absent" ​

DOStreamManagerClient.getStreamInfo / getChunks* (CP-28) and DurableObjectStreamManager.createReader / createResumableReader / getChunks* return null / [] only when the stream does not exist (a 404, exists: false). Any other failure throws (DOPeerError / StreamConnectionError, retryable on a 5xx). DOStreamManager.getStreamInfo (the in-DO manager) returns null for a stream never created and for an id that is not the DO's own stream (RM-71).

Remote agents ​

  • TransportEvent's error variant is fail, and truncated{floor, errorDetail} is new. A RemoteAgentTransport you implement should decode with core decodeTransportEvents.
  • RemoteAgentFailedError carries the remote failure's errorDetail (new optional third argument), kept on every runtime's failed sub-agent result.
  • HttpRemoteAgentTransport and DOStubTransport send /start and /resume exactly once (CP-95, interim until D-2's idempotency key). A thrown request, or a 5xx that is not the host's typed retryable answer, rejects with the new non-retryable RemoteEntryOutcomeUnknownError (transport_remote_entry_outcome_unknown); check the remote session's status before acting. HttpTransportConfig.maxRetries now applies to the reads and stop requests only.
  • A remote dispatch re-attaches to a child it already started (any /status answer, or the sub-session ref's remote.streamId) and never re-POSTs /start (the D-2 guard); an interrupted child is a typed failure. A /start whose outcome is unknown is re-sent with its request key (D-2 MR 2, see request-key.md).

Chat replies end with finishReason: 'error' (D-4) ​

A reply that forwarded a run error now ends with { type: 'finish', finishReason: 'error' } after the error chunk (AISDKFinishEvent.finishReason). Every supported ai version (6.0.0 and later) accepts it. If you assert on the exact chunk sequence of an errored reply, expect the reason.

Removed ​

  • parseDOSSEStream and its ParsedStreamChunk / ParsedStreamEnd / ParsedStreamFail / ParsedStreamTruncated / ParsedSSEItem / ParseDOSSEStreamOptions types and isParsed* guards (@helix-agents/ai-sdk/cloudflare): decode with core decodeStreamFrame.
  • Core parseNamedSSEEvent: use decodeStreamFrame.

Released under the MIT License.