Skip to content

chore: add the generated Stream API and binding helpers - #2128

Open
moetemp wants to merge 39 commits into
mainfrom
moe/streams-generated-code
Open

moetemp wants to merge 39 commits into
mainfrom
moe/streams-generated-code

Conversation

@moetemp

@moetemp moetemp commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

What was changed

The generator writes the Python Stream models and the client and Workflow APIs, and this PR adds the hand-written helpers that import and use them. The Core pin stays on Core main.

Why?

The Store and Worker PRs need typed requests and results that keep the Producer, the offsets and the create result exactly as the API defines them. Generating them from the API keeps the SDK in step with it.

CI and the local setup install nexgen 0.2.15, the first release with Nexgen #457. The generator script calls the installed tool.

Reviewer's guide

  1. Start with scripts/gen_nexus_system_api.py, its CI setup and the Core pin. Running the generator again must leave the bindings unchanged.
  2. Compare the Stream requests and resource methods with the API definitions: opaque offsets, the create result and the typed client hooks.
  3. Read temporalio/nexus/system/_support.py next to the generated wrappers. An empty page keeps after_offset, so the next read starts at the same place. A page with Records moves it to the last Record.
  4. Continue with #2186 for the Store contract.

Checklist

  • Check generator formatting.
  • Regenerate the bindings and check that they're unchanged.

@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 added this pull request to stack #2139 November 18, 2026 01:19
@moetemp
moetemp removed this pull request from stack #2139 November 22, 2026 21:24
@moetemp
moetemp added this pull request to stack #2156 November 22, 2026 21:24
@moetemp
moetemp force-pushed the moe/streams-generated-code branch from 293528d to 94fe3ec Compare November 23, 2026 21:22
@moetemp
moetemp force-pushed the moe/streams-generated-code branch from 94fe3ec to 932cbca Compare November 23, 2026 22:34
@moetemp moetemp added the skip-changelog PR changes do not require changelog updates label Nov 25, 2026
@moetemp
moetemp force-pushed the moe/streams-generated-code branch from 6535f48 to 523848f Compare November 26, 2026 03:34
@moetemp moetemp changed the title chore: add the generated code of the Streams API Generate the Python Stream API Nov 27, 2026
@moetemp moetemp changed the title Generate the Python Stream API Add the generated Stream API and binding helpers Nov 28, 2026
@moetemp
moetemp removed this pull request from stack #2156 December 1, 2026 20:16
@moetemp moetemp changed the title Add the generated Stream API and binding helpers chore: add the generated Stream API and binding helpers Dec 2, 2026
@moetemp
moetemp force-pushed the moe/streams-generated-code branch from 75cdfad to a5779b7 Compare December 2, 2026 08:37
moetemp and others added 26 commits December 4, 2026 15:54
Each request takes a ref, a create answers with the ref, and no request
has a request id, since the Nexus envelope has it. A Workflow's Activity
Producer has its scheduled event id. The code comes from the WIT that
Core `e4934879` vendors and from nexgen `74f8ce76`.
Core gives an Activity task the id of its scheduled event, keeps the
Stream calls of a Workflow Task in a ledger in place of a marker, and
gives each page of a Workflow read its last offset. The payload visitor
stays the same, since no Payload moved.
`gen_nexus_system_api.py` also generates the Stream service from
`stream-service.wit`, for Workflow and client code. It adds the Workflow
calls of that service to the exports of `temporalio.workflow`.
This is the output of `poe gen-protos` at the Core pin. The bridge
protos and the payload visitor have no Stream commands or jobs, because
this Core doesn't have them.
The Stream WIT refers to the SDK messages in
`temporal/api/sdk/v1/stream.proto`, so the descriptor set that nexgen
reads has that file too.
This is the output of `poe gen-protos` with nexgen at `74f8ce76`. The
Streams API has no close, no `done` and no `StreamStatus`, and its
requests have the ref of a Stream.
nexgen 0.2.14 is the first release that accepts the Stream WIT, so
check-protos can generate it. The code is the same as before, only the
version in each file header changes.
The generated read docstrings say the poll iterator keeps reading after
a page with no Record. The bridge lock adds the crates the new Core
asks for.
No released SDK has Streams, so no History holds a `None` create
result. The flag only kept the replay of such Histories.
Client interceptors need a typed hook for each Stream operation, so that
a Stream call of a client can skip 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.
Pin Core to the vendored API `main` and the generator to `4bf951e9`. API
`main` drops the Python output transform of the Stream create, so the
generated create builds the Stream from the create result. A create of
an existing Stream gives `created=False`. `stream_from_create` in
`_support.py` has no caller and goes.

The Core pin also brings the other API changes of Core `main`. The
`source_context` of `OnCompleteRequest` is optional, and the callback
tests check that it is set before they read it. The signal-with-start
operation names its storage target, so the generated registry now uses
`signal_with_start_workflow_storage_target`. A test covers each.
Both docstrings gave a reason and didn't say what the field holds.
The field of `activity.Info` is `_workflow_task`. A merge commit had this line, and the rebase of the branch onto main dropped it.
@moetemp
moetemp marked this pull request as ready for review December 5, 2026 00:27
@moetemp
moetemp force-pushed the moe/streams-generated-code branch from 64abde4 to 2d6d34a Compare December 5, 2026 00:53
Explain what the Producer helpers fill in and why, why Stream calls
convert models straight to protos, and why reads wait by default.
Only docstrings, comments and the README change.

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