Skip to content

Use the native backend for the Jetty prototype - #366

Closed
moetemp wants to merge 88 commits into
moe/jetty/v2/j8-native-lanefrom
moe/jetty/v3/j9-reviewed-api
Closed

moetemp wants to merge 88 commits into
moe/jetty/v2/j8-native-lanefrom
moe/jetty/v3/j9-reviewed-api

Conversation

@moetemp

@moetemp moetemp commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

This PR uses the native backend by default and updates Jetty to its reviewed prototype API. It includes Workflow readers, Standalone Activity Streams and wake cancellation.

This is a frozen Jetty prototype. See the Brook design and Python implementation for current work.

Known limits remain.

  • Workflow readers skip codec decoding for Closed.failure payloads.
  • A replay digest mismatch fails the Workflow Task even when NondeterminismError is configured to fail the run.
  • Histories that ended with pending wakes on earlier prototype commits do not replay.
  • Cold replay reads native pages one at a time.
  • Redis execution timeout can leave an owned Stream without a close.

The November review inspected the source and existing test coverage. It did not rerun the frozen native server stack.

Reviewer's guide

This is a frozen prototype. Review current Streams behavior in the Python implementation.

  1. Start with temporalio/common/_streams/_native.py and _workflow_reader.py. Focus on failure payload decoding, replay digest errors, and pending wake cleanup.
  2. Review the known limits above before assessing the native default. Generated bindings and package renames do not validate compatibility with older prototype Histories.

The Streams API moves into temporalio.common.streams, so the module becomes a package with the same contents.
The first-class API lives next to the converter it registers with. The paths of the generators and the generated imports follow.
A Stream's lifecycle is its owner's to manage, so a run end closes nothing. drain() still lets unawaited writes finish before the run ends.
Only the run-end close on Redis used them, along with workflow.Info.execution_expiration_time.
Backends go in stream_backends= of Client.connect, a Worker takes its client's, and the Replayer and WorkflowEnvironment take them too. temporalio.workflow, Client.stream and WorkflowHandle.stream replace StreamClient, and Redis moves to temporalio.contrib.stream.
A read is stream-level only, so Topic objects lose subscribe and pass to the Stream's subscribe as topics. The proto field names stay.
The crate reserves the auto_close fields, so the pb2 and the system bindings lose them. The generators write into the new package.
s23 drops auto_close from the Stores and the protos, and c8 drops the cache-off eviction reason that only the run-end close used.
…iewed-api

The Brook layout, API and removals win. The native backend, the Workflow reads and the
Standalone Activity create move into temporalio.common.streams, and the crate and sdk-core
pins stay at j8's until they move to k3 and c10.
Every client, Worker and Replayer has it, and a registered NativeStreamBackend only
configures it. A client builds its native runtime at its first Stream call, and a Worker
loads Streams only when it has Workflows or Activities.
The server closes a native Stream when its run chain ends, and Redis ignores the field. The
owner check of an empty page is now the backend's, so the close-with-run flag goes.
A Standalone Activity owns its Stream on the native backend, which closes it when the
Activity ends. A client binds it from the Activity handle with no call.
k3 merges s23 into the native crate, and c10 merges c8 into the native sdk-rust. The vendored
protos and WIT already equal k3's, and the bindings regenerate with no change.
A replay reads each page of a native Workflow read again, and only the caller knows which
server keeps the Streams. The Replayer takes the client's backends when it has none.
The native lane registers nothing, and the examples follow the Jetty HLD. Examples that need
the native server run with Redis or a memory Store named redis in place of Redis.
A Worker with Workflows runs them, and they enable no polling of the task queue's
Activities and stay out of the errors about the user's Activities. So a Worker that uses no
Streams polls and fails as before.
read_spec takes any Topic object, so the base is no longer used in its own module, as
SyncTopicBase isn't. basedpyright and mypy are clean.
A Local Activity close outlived a Workflow Task that failed after it, so the retry's create failed the run. The block end now leaves the Stream open in a cron run and on a failure that a retry run follows.
A ClientStream kept a failed or cancelled Describe forever, and the handle map kept a failed one with its handle. A found id now stays as text, and a failed call goes.
A Replayer serves one backend as a Worker does, a Worker configures its backends after its plugins, and a generator of backends stays. A backend in plugins= fails before the connect, and the per-client calls are private.
A Worker serves one backend, so the backend-move recipe can't run. A continued run reads its Streams' backends after @workflow.init.
Redis keeps its regular Activity close, and a backend that closes another way overrides _close_in_workflow. Workers that share a task queue all register the Redis backend, since it polls Activities there.
The server carries out the close once the Workflow Task commits, so a task that fails after
the close leaves the Stream open for its retry. drain() awaits it as it awaits the writes.
…ure.

A cron chain writes on to the Stream in its next run, and so does a retry run after a failure
under a retry policy. An explicit close() still closes.
…iewed-api

p35's close hook and registration fixes win, and j9 keeps a Worker's many backends. The native
backend overrides the close hook with its System Nexus command, and only a Worker with a
Redis-kind backend registers the regular close Activity.
A Local Activity in the task of the close runs, the task fails, and the Stream stays open until
the retry closes it once, through the Activity on Redis and the command on native.
On native the close is a CloseStream operation in History, not an Activity, and the server
closes the Stream at the terminate. p35's block tests cover the cron and retry cases.
A plain TypeError ended the read with next_offset before the Record, so every resume failed on it again.
The close at the block end always raised StreamNotOwnerError and hid the block's own error.
An empty id failed only at the first call, with a bare AssertionError.
Nothing withdraws a client's Records, so a long UI read grew its withdrawal map with no end.
subscribe takes offset: int | End | None, and nothing in Brook or Jetty calls from_rpc_error.
The key is in History, so a run that never creates, binds or receives a Stream adds nothing there. A Local Activity keeps its key always, since its headers stay out of History.
Retention is a Record's age and trims open Streams, a trimmed offset raises StreamExpiredError, and aclose from another task raises.
The server keeps a Workflow reader's range of a client's Stream and refuses an append that the size cap would make drop it, so a reader no longer stops at half the Retention. StreamTooLargeError names that refusal.
The Brook crate and the Jetty server both answer a Record or a batch over the Store's limit with it, so both stacks raise one class.
The vendored extension.proto and stream-service.wit changed in comments only, so only their docstrings in the generated code moved.
The crate refuses a Local Activity's close of a Workflow's Stream, so a close by id from one is refused too. The vendored proto and WIT differ in comments only.
The code is in the private temporalio.common._streams, and temporalio.common loads its names on first use, since the Stream modules import temporalio.client and temporalio.workflow.
The model's converter keeps payloads raw for the Topic types, so the failure kept RawValue details, as p35 fixed for client reads.
Only that Activity closes it. As with a Workflow's Stream, the block end of async with would raise and hide the block's own error.
The native server finds a Workflow's Stream only by its owner fields, so the by-id case p35 added answers stream_not_found there.
The write takes its place in the Stream's order at the call, also with no await. An error that no caller gets raises at the run's end, as with publish_nowait.
@moetemp moetemp changed the title [Jetty] Merged Brook p35 and made native the default Stream backend. [Jetty] Merged Brook #365 and made native the default Stream backend. Oct 30, 2026
@moetemp moetemp changed the title [Jetty] Merged Brook #365 and made native the default Stream backend. Use the native backend for the Jetty prototype Nov 27, 2026
@moetemp moetemp closed this Nov 28, 2026
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