Skip to content

Route Jetty Streams across multiple backends - #351

Closed
moetemp wants to merge 60 commits into
moe/brook/v4/p28-stream-resourcefrom
moe/jetty/v2/j1-backend-registry
Closed

moetemp wants to merge 60 commits into
moe/brook/v4/p28-stream-resourcefrom
moe/jetty/v2/j1-backend-registry

Conversation

@moetemp

@moetemp moetemp commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

This PR routes Stream calls through the backend in each handle. It supports multiple backends per Worker and combines their extension hooks.

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

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/contrib/streams/_plugin.py and _backend.py. Check that saved handles select the same backend and ambiguous defaults fail.
  2. Use tests/contrib/streams/test_backends.py to review selection errors and independent backends on one Worker.

…' into moe/jetty/v2/j1-backend-registry

# Conflicts:
#	temporalio/contrib/streams/_activity_stream.py
#	temporalio/contrib/streams/redis.py
#	temporalio/contrib/streams/workflow.py
…' into moe/jetty/v2/j1-backend-registry

# Conflicts:
#	temporalio/contrib/streams/redis.py
…/sdk-python into moe/jetty/v2/j1-backend-registry
# Conflicts:
#	temporalio/contrib/streams/redis.py
#	temporalio/contrib/streams/workflow.py
…y/v2/j1-backend-registry

# Conflicts:
#	temporalio/contrib/streams/workflow.py
The default backend is part of Workflow code, since a replayed create uses it, so it must not follow the order of the plugin list (S119).
`async with create_stream(...) as turn` reads better than `async with await`, and a missing `await` gave a confusing error. The exit rules stay those of the handle's own `async with` (S119).
A reader that added 1 to an offset itself got no resume point after the last item, and Topics outside the definition decoded as dicts (S113, S119).
One buffer over all Topics keeps the publish order across Topics. A full batch goes at once, and one write in flight bounds the writes. `await flush()` is the backpressure point (S119).
A burst of awaited publishes cost one marker for each await. The appends behind a write go as one Local Activity, and each call gets its own last offset, since a Store gives one batch consecutive offsets (S121).
Core keeps the extension with the Worker and calls nothing on it since the Workflow Task hooks went. Only the plugin calls it (S123 findings).
A lane that owns a Redis port runs the suite against it with TEMPORAL_STREAMS_REDIS_URL.
A Workflow that got a Stream as data could end it for every reader. The Store refuses it too, and the early error costs no Local Activity. The new errors map the stream_not_owner and seq_divergent reasons (S114, S117).
s21 refuses a close from a Producer that the Stream's owner doesn't allow, so an Activity can no longer close its Workflow's Stream. The test shows that refusal now (S114, S115, S116, S117).
A reader tells a cancelled or terminated owner from a failed one with no check of the failure's type. A CancelledError failure closes as canceled, from Workflow code, Activities and clients (S115).
A chat view shows the last few Records first, then follows. The first page comes from the Store's read of the last Records, and the read goes on after it (S116).
Pinned sdk-rust c7, which drops WorkerExtension, and crate s22, whose runtime is a plain object. The bridge builds one for each client of a plugin from its config, and the client's Workers share it (S123).
A server that made a handle per request kept one crate writer per handle. An opt-in producer(name, epoch) fences a writer's earlier incarnation, with the epoch from the caller (S120).
A plugin that writes for a run after its end must wait until the server accepted the run's completion, which only the eviction tells. The hook is generic, runs outside the sandbox and never in the Replayer (S121).
The close with the run went out before the completion, so a last Workflow Task that failed left a closed Stream, and its retry's writes failed the run. The Worker writes the close from the eviction that ends the run, as S72 says (S121, bug 6).
Only a Local Activity of the run chain may close a Workflow's Stream from an Activity, and a client may not close it at all. The Store refuses the others too, and the early error makes no call (S114).
…-client-objects

# Conflicts:
#	temporalio/contrib/streams/redis.py
# Conflicts:
#	temporalio/bridge/extension.py
#	temporalio/bridge/src/extension.rs
#	temporalio/bridge/src/lib.rs
#	temporalio/contrib/streams/__init__.py
#	temporalio/contrib/streams/redis.py
#	temporalio/contrib/streams/workflow.py
#	temporalio/worker/_extension.py
The write Local Activity ran the codec again on each attempt, so a codec with a random IV made a retry after a lost answer a different batch, which the Store refuses as seq_divergent. The bodies after the codec stay in the process until the append succeeds (S121, S117).
The merge capped its size before the codec, so a codec that grows payloads could pass the Store's 4 MiB batch limit and fail every merged call. The Local Activity checks the size after the codec and then sends each call as its own batch, and each call gets its own offset or error (S121).
The create sent no ref, so the Store kept no owner chain, and a Local Activity of another chain could close a Workflow's Stream. A close from a handle with only an id names the Activity's own chain, so the Store refuses it (S114).
…y/v2/j1-backend-registry

The merged Workflow append takes the backend from its ref, as the other write Local Activities do.
A Superseded item and the first Record of its batch have one offset, so a reader that stopped after the Superseded item and resumed past it lost that Record. A read from the item's offset gives it again, which withdraws nothing new (S113).
@moetemp moetemp changed the title [Jetty] Routed Stream calls to more than one backend per Worker. Route Jetty Streams across multiple backends 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.

1 participant