Skip to content

Add the generated Stream API and binding helpers - #2128

Draft
moetemp wants to merge 26 commits into
moe/activity-workflow-task-infofrom
moe/streams-generated-code
Draft

moetemp wants to merge 26 commits into
moe/activity-workflow-task-infofrom
moe/streams-generated-code

Conversation

@moetemp

@moetemp moetemp commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

What was changed

This PR adds the generated Python Stream API and its binding helpers. The WIT and protobuf definitions come from Core #1733.

Why?

The pinned nexgen revision keeps client polls cancellable between pages. The create transform lets the SDK preserve historical Workflow results while reporting created=False when a Stream already exists.

This layer includes the helper functions it calls, so it passes standalone lint and import checks. The runtime PR connects the API to Stores and Workers.

Reviewer's guide

Review after the Activity info PR, together with the runtime layer.

  1. Start with scripts/gen_nexus_system_api.py, pyproject.toml and the Core pin. They must reproduce the generated files.
  2. Compare request types and resource methods with API #895. Check routing, opaque offsets and the create-result transform.
  3. Read _support.py and _workflow_context.py with the generated wrappers. Old Workflow histories must retain their cursor and None creation results. The runtime PR contains the replay tests.

Checklist

  • poe update-core refreshed the pin and bridge dependencies.
  • poe gen-protos passed using the pinned generator source.
  • Repeated generation left no diff.
  • Standalone poe format, poe lint, fresh-process imports and binding checks passed.
  • Runtime validation passed with the support layer.

@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
These are the files that `poe gen-protos` writes for the Stream service. They are in a PR of
their own, so that the hand-written change shows alone.
…eam.

The new Stream WIT gives the Workflow target `append` and `close`, so the generated Workflow `Stream` has them and `async with` closes it.
With nexgen commit 07b565b6, `read` yields Records, `read_pages` yields pages and `read_page`
sends one request. `PollIterator` moves to one `_poll.py` next to the models. The Workflow
interceptor terminal calls `_schedule_system_nexus_operation` and drops the generic hook, as
upstream nexgen does.
The API changes `epoch` to `attempt`, gives the Workflow `Stream` a read, passes the client to the default Producer of a client Stream, and drops `namespace` from the requests. This commit follows `temporalio/api` `7964b905` with nexgen 0.2.13.
The API takes a Stream id in each request and a request id on an append, and nexgen maps the ref of a request to its id with two helpers.
The API gives each kind of Producer a namespace and its own ids, and the Producer has no id string.
The API states the rules of a Store as the Stores keep them. Only docs change.
mypy fails on the code that nexgen generates, and the package of the Workflow service is left out for that already.
Core has Stream commands and jobs for Workflow code. Their generated
files are in this commit, so that the hand-written part of the Streams
API has no generated code. They come from the Core pointer and the
visitor generator of that part.
The SDK sets the Producer of Workflow code from the run and its
Workflow Task attempt, so the Workflow `append` and `close` have no
`producer`. The code comes from the WIT and the nexgen commit that the
API pins.
A Stream request takes a ref in place of a Stream id and has no request
id, a Workflow's Activity Producer has its scheduled event id, and the
task metadata has the Stream calls of Core. They come from the API that
Core `e4934879` vendors, which the hand-written part pins.
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.
@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

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.

1 participant