Skip to content

fix(codegen): support event streams in server SDK serde context#2175

Open
goelakash wants to merge 1 commit into
smithy-lang:mainfrom
goelakash:ssdk-event-stream-serde-context
Open

fix(codegen): support event streams in server SDK serde context#2175
goelakash wants to merge 1 commit into
smithy-lang:mainfrom
goelakash:ssdk-event-stream-serde-context

Conversation

@goelakash

@goelakash goelakash commented Jul 22, 2026

Copy link
Copy Markdown

The problem: make a Smithy model with an event stream, generate a server from it, and the code you get is broken. Two reasons:

  1. The response side of the stream is typed as any — which tells the compiler "don't check this." So that error was there, just hidden. (The request side was typed correctly, which is why the package as a whole already failed to compile.)
  2. The server is never handed the thing that actually encodes and decodes stream events (the marshaller). So even at runtime there's nothing to do the work.

Related to #959.

The fix — two small changes, both in the code generator. No npm packages touched:

  1. The generated response serializer now uses the real type, __EventStreamSerdeContext, instead of any. Now the compiler checks it for real. (The request side already used the right type.)
  2. The generated server now gets a marshaller, built with eventStreamSerdeProvider. All it needs is the utf8 helpers the server already had, so nothing new at runtime.

Who this affects: only servers generated from models that have event streams — and their code was already broken, so this is strictly an improvement. Everyone else gets byte-for-byte the same output as before. smithy-aws-typescript-codegen keeps compiling unchanged; restJson1 will need its own follow-up PR in aws-sdk-js-v3.

How it was tested: added the first-ever server event stream codegen tests, the full gradle build passes, and a sample of the new generated output compiles clean under tsc --strict. The old output fails that same check with eventStreamMarshaller is missing — exactly the error the any was hiding.

Not fixed here: the rpcv2Cbor-based test in this diff only exercises the handler wiring — that protocol's own server codegen is still stubbed. Stream validation is still skipped (events arrive after up-front validation runs, so supporting it needs a design decision). And there's no live end-to-end test yet — that needs a concrete protocol, which lives in aws-sdk-js-v3.

Why I'm doing this / where it's heading: I want to build Smithy services that stream to clients over Server-Sent Events (text/event-stream), which smithy-typescript has no story for today (smithy-java gained SSE handling for MCP; TypeScript has nothing). The marshaller is injected through the handler's serde context on purpose: all framing runs through that one object, so a protocol generator that wires in an SSE marshaller instead gets text/event-stream framing with the rest of the machinery unchanged. (To be precise: the plug-in point is the protocol-generator layer at codegen time, not a runtime hook in the emitted server.) I'm planning to prototype that as a third-party protocol generator and bring it back as an RFC — this PR is the first step, but it also stands on its own as a bugfix for #959.

Server SDK generation stubbed the event stream serde context type as
`& any` and never supplied an event stream marshaller, so generated
SSDK code for operations with event streams did not type-check.

Type the response serializer / request deserializer context with
__EventStreamSerdeContext, and wire the Node eventStreamSerdeProvider
into the handler's serde context base (it only needs utf8 encode/decode,
which the base already provides).

Adds server event stream codegen tests, which were previously absent.
@goelakash
goelakash marked this pull request as ready for review July 22, 2026 02:01
@goelakash
goelakash requested a review from a team as a code owner July 22, 2026 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant