Skip to content

feat: let Core read a Stream for Workflow code - #1819

Draft
moetemp wants to merge 24 commits into
moe/streams-directfrom
moe/streams-direct-read
Draft

moetemp wants to merge 24 commits into
moe/streams-directfrom
moe/streams-direct-read

Conversation

@moetemp

@moetemp moetemp commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What was changed

This PR lets Core read a Stream for Workflow code. Its base is #1801.

  • ReadStream is a command for Core. A read gives one page, which is one answer of the Store, in a ResolveStreamRead job. The page has the Records that the Store has at once.
  • A read with no Record waits up to its wait, but at most to the read limit of its task. Then it gives a page with no Record, and wait_cut says if the limit cut the wait. StreamSettings::read_time sets the limit, half the Workflow Task timeout by default, counted from the end of a replay.
  • Before a task completes, each read with no answer gets one Store call with no wait, within 1 s. Its Records come in the task, or first in the next task if the task has a command. With no Record, a read with a wait starts again in the next task. So an idle Stream makes no new task.
  • Core asks for a new task only for a page that Core holds for the next task, a page that a limit cut before the end of the Stream, or a read that the result limit of a task holds back. That read starts in the new task. So a read loop forces at most one task per 256 results.
  • A Store outage at a read fails the Workflow Task with a message that starts with StreamStoreUnavailable:, as for an append.
  • A task gives at most 16 MiB of Records, and starts no new read after 256 results.
  • Each activation that gives pages records their offsets, their count and a digest of their Records in a core_stream_read marker. A replay reads the Records from the Store again. If they are gone or differ, it fails the task, or the Workflow with WorkflowErrorType::StreamReplay. A replay reads 8 entries at a time, for at most 4 runs of the Worker at a time, and tries a Store in an outage for at most 3 s.
  • The check deadline, the result limit of a task and the replay bounds are constants, not settings. StreamSettings::read_time is the one setting that reads add.
  • A core_stream_read marker has the same 1 MiB bound on its data as an append marker. An activation whose read marker has more fails its task with a message that starts with StreamMarkerTooLarge:.

Why?

A library that iterates a Stream in Workflow code needs each Record while its Producer still runs. With a Local Activity, each page costs one marker and one Workflow Task. With this PR, the pages of one activation share one marker, which keeps no Records, and an idle Stream makes no Workflow Task.

This point is open.

  • A replay reads every Record again. So the Retention of a Stream must cover the life of each Workflow that reads it, and the time in which that Workflow gets queries.

Reviewer's guide

More than half of the ~8,800 added lines are tests.

  1. ReadStream and ResolveStreamRead in the protos, and StreamReadResult in external_data.proto, for the rules of a read and what its marker keeps.
  2. streams/calls.rs and ReadLimit in streams/mod.rs, for the read limit, the call before a completion, and when Core asks for a new task. streams/read.rs makes the marker entry and the page.
  3. streams/replay.rs and streams/digest.rs, for how a replay reads the Records again and compares them with the marker.
  4. managed_run.rs, workflow_stream.rs, wft_extraction.rs and history_update.rs, which every Workflow runs. A replay reads its Records in a stage next to the History fetch, and a completion can wait for its calls to the Store.
  5. workflow_machines.rs, for the look-ahead of a read marker. A read result goes before a Local Activity result of the same activation, as an append result does in feat: let Core append to a Stream for Workflow code #1801.

Checklist

  1. How was this tested: unit tests over generated Store answers (a model of the read calls, and a replay property), and core_tests/streams/reads.rs with a mock server that writes History as a server does and a test Store. Tests against a dev server (tests/integ_tests/workflow_tests/streams.rs) show a paged replay, held pages, the call before a completion, a drain past the read limit, and an outage.
  2. Any docs updates needed? No.

@moetemp
moetemp added this pull request to stack #1820 November 19, 2026 05:46
@moetemp
moetemp removed this pull request from stack #1820 November 19, 2026 07:29
@moetemp
moetemp added this pull request to stack #1821 November 19, 2026 19:08
@moetemp
moetemp removed this pull request from stack #1821 November 19, 2026 21:28
@moetemp
moetemp force-pushed the moe/streams-direct-read branch from f858a1b to 4029b4b Compare November 19, 2026 22:55
@moetemp
moetemp force-pushed the moe/streams-direct-read branch from 4029b4b to d8db906 Compare November 20, 2026 03:21
@moetemp
moetemp force-pushed the moe/streams-direct-read branch from d8db906 to 41befdd Compare November 20, 2026 05:01
@moetemp
moetemp force-pushed the moe/streams-direct-read branch from 41befdd to ed7da9b Compare November 20, 2026 06:38
@moetemp
moetemp force-pushed the moe/streams-direct-read branch from ed7da9b to 83c6ee9 Compare November 20, 2026 16:28
@moetemp
moetemp force-pushed the moe/streams-direct-read branch from 83c6ee9 to f961aa4 Compare November 22, 2026 01:11
@moetemp
moetemp force-pushed the moe/streams-direct-read branch from f961aa4 to 3816a12 Compare November 22, 2026 02:13
@moetemp
moetemp force-pushed the moe/streams-direct-read branch from 3816a12 to 1897538 Compare November 22, 2026 07:11
@moetemp
moetemp force-pushed the moe/streams-direct-read branch from 1897538 to a97c149 Compare November 22, 2026 11:16
@moetemp
moetemp force-pushed the moe/streams-direct-read branch from 15db19f to 5420da8 Compare November 24, 2026 21:28
@moetemp
moetemp removed this pull request from stack #1828 November 25, 2026 18:59
Lang sends a ReadStream and gets a ResolveStreamRead with the page. The
core_stream_read marker keeps the offsets, the count and a digest of a
page. Core refuses the command until it runs reads.
A read gives one Store answer as its page, and a core_stream_read
marker records its offsets, count and digest. Before a completion each
read with no answer gets one check, a Store outage fails the task, and
a replay reads the Records again in bounded parts.
The tests drive a Worker on a mock server that writes History as a
server does, with properties for replays and focused tests for the
checks, the outages, the budgets and the forced tasks.
The dev server writes and pages the History, so the tests show a paged
replay, held pages, checks, a drain over the read limit and an outage.
@moetemp
moetemp added this pull request to stack #1842 November 25, 2026 20:57
@moetemp
moetemp force-pushed the moe/streams-direct-read branch from fc07aab to df69d1d Compare November 25, 2026 21:20
A read that max_task_read_results holds back now makes Core ask for
the next task, as a held page does. So a Workflow whose only open work
is such a read no longer waits for another event.
The read job and command move to 18 and 24, after the append numbers.
The settings test now checks each setting that can't be zero.
moetemp added a commit that referenced this pull request Nov 25, 2026
The new read design of #1819 wins in each conflict. The metric hooks of
this branch move to the new append, read and replay read code paths.
The check deadline, the read result budget of a task and the three
replay bounds are no longer Stream settings. Tests still set them
through fields that exist only in test builds.
The read marker goes through the same size check as the append marker.
A boundary test covers both kinds, and a Worker test fails a task with
1,200 failed reads in its markers.
The filter of replayed commands at a forced failure keeps only the fail
command, so Core doesn't need to remove lang's commands here. A test
shows that a Stream marker with no call sends one fail command.
At one activation index a read result goes first, as an append result
does, in the first run and in a replay with chunking on and off.
The test lets the read pass the gate only once the read is at the Store,
so the order of the spawned calls can't stall it. A doc says what the
check of a failing completion skips.
The JSON rules of the append marker doc are removed, so the read marker
doc says its own JSON form.
A read whose ref has no Store name runs on the Store of the Worker's
only Stream runtime, as an append does. Its marker records that name,
and a replay compares it with History.
The doc pointed to the rule of the append marker, which names only an
open append.
The entry keeps the command, the job, the read limit, the marker and the
replay, in the style of the append entry. The proto docs have the rest.
A read picks its Store as an append does. The docs of ReadStream and
StreamReadResult.store say so, and two tests cover it, live and in a
replay.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant