Skip to content

feat: add Stream Stores and Workflow Stream calls - #2129

Draft
moetemp wants to merge 11 commits into
moe/streams-generated-codefrom
moe/streams-api
Draft

moetemp wants to merge 11 commits into
moe/streams-generated-codefrom
moe/streams-api

Conversation

@moetemp

@moetemp moetemp commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

What was changed

This PR adds Streams for Python clients, Activities and Workflows. StreamConfig registers the Stores and the append limits. Workflow appends and reads run in Core. A create and a describe run in a Local Activity.

Workflow reads remain a release stretch goal until notifications are available.

Why?

Records stay in the Store. History keeps the result of each call and a digest of each read, so a replay gets the same answers. A Store outage fails the Workflow Task. The Store must keep the Records for as long as the Workflow can replay.

Reviewer's guide

Review after the generated API. Merge both layers together. Read the 11 commits in order. Each one passes poe lint, the docs build and its Stream tests alone.

  1. Use UTC for the default times of ActivityEnvironment. A one-line fix. Core and the client refuse a Producer with an attempt time before 1970.
  2. Pin Core with the Stream runtime. The submodule, the generated protos and the payload visitor.
  3. Add the StreamStore contract, StreamConfig and StreamError. The public contract in temporalio/client/_stream_store.py.
  4. Add MemoryStreamStore. A plain Python Store for tests and local runs. It shows what a Store does.
  5. Add BufferedAppender, current_producer and as_producer. temporalio/contrib/streams.
  6. Send the Stream calls of client and Activity code to Stores. Store selection, the request checks of Core in Python, and the request ID that interceptor retries keep. Client gets create_stream and get_stream.
  7. Intercept Stream client calls by operation. By Tim Conley. Client interceptors get the typed hooks of the generated API, and Stream calls skip the generic Nexus chain.
  8. Let Workflow code create, describe and append to Streams. temporalio/worker/_workflow_streams.py, and the bridge code that lets Core call a Python Store. Alone, a Workflow read fails the Workflow Task (commit 10).
  9. Turn Workflow Task chunking off for new Workflows. It applies to all new runs, including runs without Streams. Existing Histories keep their recorded mode.
  10. Let Workflow code read a Stream. stream_read_time and StreamReplayError.
  11. Decode a StreamRef[T] in a dataclass, a list and an optional. Only StreamRef takes the new decoding paths.

Checklist

  • poe lint, the docs build and the Stream tests pass on each commit.
  • The whole test suite passes locally on the last commit.
  • The bridge build and poe bridge-lint pass with the Core pin.

@moetemp
moetemp added this pull request to stack #2130 November 14, 2026 01:00
@moetemp
moetemp removed this pull request from stack #2130 November 15, 2026 08:27
@moetemp
moetemp force-pushed the moe/streams-generated-code branch from 434ddd3 to d70f12d Compare November 15, 2026 18:51
@moetemp
moetemp force-pushed the moe/streams-generated-code branch from d70f12d to 6b44118 Compare November 15, 2026 20:23
@moetemp
moetemp force-pushed the moe/streams-generated-code branch from 6b44118 to f330b20 Compare November 16, 2026 17:14
@moetemp
moetemp force-pushed the moe/streams-generated-code branch from f330b20 to 31151f2 Compare November 16, 2026 17:33
@moetemp
moetemp force-pushed the moe/streams-generated-code branch from 31151f2 to e8898ec Compare November 16, 2026 19:42
@moetemp moetemp changed the title feat: add the Streams API, with Stream Stores on Redis and in memory feat: add the Streams API for Activity and client code, with Stores on Redis and in memory Nov 17, 2026
@moetemp
moetemp added this pull request to stack #2139 November 18, 2026 01:19
@moetemp moetemp changed the title feat: add the Streams API for Activity and client code, with Stores on Redis and in memory feat: add the Streams API for Activity and client code Nov 18, 2026
@moetemp moetemp changed the title feat: add the Streams API for Activity and client code feat: add the Streams API for client, Activity and Workflow code Nov 22, 2026
@moetemp
moetemp force-pushed the moe/streams-api branch 2 times, most recently from 4f48bab to 066b280 Compare November 22, 2026 03:31
moetemp and others added 11 commits December 2, 2026 01:36
`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.
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 sends each system Nexus call of the generated Stream API to
the Store that its ref or the selector picks, with the codec and a
request id that interceptor 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.
Each Stream operation of a client gets a typed hook on
`OutboundInterceptor`, so interceptors see Stream calls without the
generic Nexus chain. A hook that retries with the same input, or a copy,
keeps its request id, and a call with no result type gets the type of
its operation.
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.
@moetemp
moetemp force-pushed the moe/streams-generated-code branch from 75cdfad to a5779b7 Compare December 2, 2026 08:37

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