Skip to content

feat: add Stream Stores - #2186

Draft
moetemp wants to merge 14 commits into
moe/streams-generated-codefrom
moe/streams-stores
Draft

moetemp wants to merge 14 commits into
moe/streams-generated-codefrom
moe/streams-stores

Conversation

@moetemp

@moetemp moetemp commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

What was changed

temporalio.streams gets the Store contract, and the SDK gets an in-memory Store, Producer helpers and a buffered appender.

Why?

Anyone can write a Store, so the contract spells out what the SDK relies on: safe concurrent calls, all-or-nothing batches, offsets that only grow, and how long to keep Records for replay. Each Store picks its retention and decides whether to fence older attempts. A Store that remembers a resend answers it with the first offsets, so a retry never writes the Records twice.

The contract uses the protobuf requests and responses. Whether to generate the Store interface is still open.

Reviewer's guide

Review after #2128.

  1. Read temporalio/streams.py for the contract and what each method must do.
  2. Check temporalio/testing/_stream_store.py against it. One instance serves one event loop.
  3. Read temporalio/contrib/streams/_appender.py for how it flushes and fails, then the Producer helpers.

Checklist

  • Run Python lint and the Store and appender tests.
  • Keep one changelog fragment.

@moetemp
moetemp added this pull request to stack #2189 December 2, 2026 22:49
@moetemp moetemp added the skip-changelog PR changes do not require changelog updates label Dec 2, 2026
@moetemp
moetemp marked this pull request as ready for review December 2, 2026 22:59
@moetemp
moetemp requested a review from a team as a code owner December 2, 2026 22:59
@moetemp
moetemp force-pushed the moe/streams-stores branch from bf635e6 to bba27f4 Compare December 3, 2026 08:49
@moetemp
moetemp removed this pull request from stack #2189 December 3, 2026 09:00
@moetemp
moetemp added this pull request to stack #2202 December 3, 2026 09:00
@moetemp
moetemp force-pushed the moe/streams-stores branch 2 times, most recently from 953a9d8 to 779ab52 Compare December 3, 2026 16:59
Comment thread temporalio/client/_stream_store.py Outdated
data in an activation must fit within 1 MiB. Keep messages short to avoid
failing the Workflow Task with ``StreamMarkerTooLarge``.

Calls can run concurrently on the event loop. Cancellation can follow a

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Express just the thing the user needs: their methods should be concurrency safe.

Comment thread temporalio/client/_stream_store.py Outdated
Calls can run concurrently on the event loop. Cancellation can follow a
timeout, eviction or Worker shutdown. A cancelled call may have taken effect.
The Store must remain usable, and overlapping retries must not duplicate a
batch.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This paragraph doesn't seem to get the point across: your methods may be called multiple times with the same batch so it should be idempotent, I don't think cancel is really relevant.

Comment thread temporalio/client/_stream_store.py Outdated
@@ -0,0 +1,257 @@
"""Stream Stores and the Stream config of a client."""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably makes sense to have its own module. temporalio.streams

Comment thread temporalio/client/_stream_store.py Outdated
Methods use request and response messages from
:py:mod:`temporalio.api.streamservice.v1`. Requests contain a Stream id.
The SDK routes each ``StreamRef`` to its registered Store and sets the Store
name on refs returned by create. Stores don't read or set ``StreamRef.store``.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why mention streamref at all?

Comment thread temporalio/client/_stream_store.py Outdated

Retention:

* Retention starts at create and restarts after an append that writes a batch.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"The retention timer" perhaps?

Comment thread temporalio/client/_stream_store.py Outdated
Retention:

* Retention starts at create and restarts after an append that writes a batch.
Retries and reads don't extend it. The Store sets the retention period.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retries? Of what? A retried write doesn't?

Comment thread temporalio/client/_stream_store.py Outdated
Retention:

* Retention starts at create and restarts after an append that writes a batch.
Retries and reads don't extend it. The Store sets the retention period.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the store setting a retention period, what does that mean?

Comment thread temporalio/client/_stream_store.py Outdated
The Store must remain usable, and overlapping retries must not duplicate a
batch.

SDK Core validates and retries Workflow appends and reads during outages.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't mention sdk core by name

@tconley1428 tconley1428 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments.

@moetemp
moetemp force-pushed the moe/streams-stores branch from 779ab52 to 0f600a2 Compare December 4, 2026 00:26
@moetemp
moetemp force-pushed the moe/streams-stores branch from b4e3098 to 8661820 Compare December 5, 2026 00:53
@moetemp
moetemp marked this pull request as draft December 5, 2026 01:00
`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.
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.
Store names are required to stay stable. A second registry is not
needed to protect against changing them.
The docstrings say the same in fewer words. No code changes.
Explain Stores, Producers, attempts, request ids, fencing and offsets
once in the temporalio.streams module docs, so the Store rules can say
why each rule exists. Rewrite the appender, Producer and memory Store
docs in active voice. Only docstrings, comments and the README change.
@moetemp
moetemp force-pushed the moe/streams-stores branch from 8b27ffe to 9ec5040 Compare December 6, 2026 10:14

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

skip-changelog PR changes do not require changelog updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants