Skip to content

Intercept Stream client calls by operation - #2180

Draft
tconley1428 wants to merge 13 commits into
moe/streams-apifrom
tconley/stream-client-interceptors
Draft

tconley1428 wants to merge 13 commits into
moe/streams-apifrom
tconley/stream-client-interceptors

Conversation

@tconley1428

@tconley1428 tconley1428 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Wire generated operation-specific Stream start hooks into client outbound interception, accepting typed Nexus input envelopes and returning operation handles while bypassing generic Nexus start/result hooks. Keep request IDs, result types, and all call options on the original envelope; default type arguments preserve existing unparameterized input annotations.

Cover envelope identity and options, client/Activity Store routing, handle-based response overrides, short-circuiting, unknown operations, and retries after lost Store responses.

Stacked on #2129. Paired with temporalio/nexgen#457; the generation script pins its generator commit, and the nexgen draft pins this SDK revision for runtime validation.

@tconley1428
tconley1428 force-pushed the tconley/stream-client-interceptors branch from 66c3418 to 6e0f0ea Compare December 1, 2026 17:35
@moetemp
moetemp force-pushed the moe/streams-api branch 3 times, most recently from 214106d to 02d8ff0 Compare December 2, 2026 03:42
This Core has the Workflow commands and activation jobs of Stream
appends and reads. A codec gets each Stream body alone and with no
serialization context, and the passes of external storage skip Stream
bodies, since any writer can make a body.
A Store is the service that keeps the Records of a Stream. The contract
says what client, Activity and Workflow calls need from a Store, and
`StreamConfig` registers the Stores of a client and its Workers.
Tests and local runs need a Store with no other service. The memory
Store keeps its Streams in plain Python data and applies the rules of
`StreamStore` in their order, so it also shows what a Store does.
An Activity that appends each model token pays one Store call for each
token. The appender batches them with one write in flight, and stops at
the first failed batch so that a reader sees no gap. `current_producer`
and `as_producer` let resumed Activity work write as its first Producer.
The client passes each Stream call of the generated API through the
typed interceptor hooks that nexgen generates, to the Store that its ref
or the selector picks, with the codec and a request id that retries
keep. It checks each request with the rules of SDK Core and the limits
of the Stream config, so that client and Workflow calls refuse the same
requests. An Activity writes as the Producer of its schedule, from the
info that Core gives.
Workflow code can't call a Store itself, since a replay must get the
same answers. Core runs each append on the Python Store through the
bridge and records its result in History, and a create or a describe
runs in a Local Activity of the SDK. In this commit a Workflow read
reaches that Local Activity, which refuses it, so the Workflow Task
fails.
A Stream create or describe runs as a Local Activity, and a Workflow
Task that waits for one can complete with no command. Chunking merges
such tasks in a replay, so Workflow code can get a result in another
activation than in the first run. Core records the choice in the first
completed Workflow Task, so a Workflow that started earlier keeps it.
Core runs each read and records the offset, the count and the digest of
its page, so a replay reads the Records from the Store again and checks
them. `stream_read_time` bounds how long reads keep a Workflow Task
open, and `StreamReplayError` lets a Workflow fail when Records changed.
A ref in Workflow or Activity input must keep its body type, since a
read converts each body to it. Only `StreamRef` takes the two new
decoding paths, since a change for any other type would alter the
replay of existing Workflow Histories.
Client interceptors need a typed hook for each Stream operation, since a
Stream call of a client doesn't go through the generic Nexus chain. The
hooks type `StartNexusOperationInput` by its argument and result. The
generator is pinned to a nexgen commit that is not on main yet.
`datetime.fromtimestamp(0)` reads the local time zone, so on a host west
of UTC the default times of `ActivityEnvironment` fall before 1970. SDK
Core and the client both refuse a Stream append whose Producer has an
attempt time before 1970.
@moetemp
moetemp force-pushed the tconley/stream-client-interceptors branch from 6e0f0ea to aa4068a Compare December 2, 2026 07:43

This branch has not been deployed

No deployments
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.

2 participants