Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c8cf017
Add the Stream read command, its result and the read marker data
moetemp Nov 25, 2026
b591893
Let Core read a Stream for Workflow code
moetemp Nov 25, 2026
b08d2f5
Test the Stream reads of Workflow code through a Worker
moetemp Nov 25, 2026
df69d1d
Test the Stream reads of Workflow code against a dev server
moetemp Nov 25, 2026
482990a
Force the next task for a read that the result budget holds
moetemp Nov 25, 2026
55d5ed9
Merge branch 'moe/streams-direct' into moe/streams-direct-read
moetemp Nov 25, 2026
5fa8448
Merge branch 'moe/streams-direct' into moe/streams-direct-read
moetemp Nov 26, 2026
b87c660
Merge branch 'moe/streams-direct' into moe/streams-direct-read
moetemp Nov 26, 2026
16ef11b
Turn the read and replay bounds into constants
moetemp Nov 26, 2026
44a01ec
Test the 1 MiB bound of the Stream read marker
moetemp Nov 26, 2026
4ecc661
Merge branch 'moe/streams-direct' into moe/streams-direct-read
moetemp Nov 26, 2026
903d109
Drop the removal of lang's ending commands at a Stream marker error
moetemp Nov 26, 2026
38124ca
Test that a read result goes before a Local Activity result
moetemp Nov 26, 2026
5548189
Wait for the read at the Store in the read tie test
moetemp Nov 26, 2026
d65b2a5
Merge branch 'moe/streams-direct' into moe/streams-direct-read
moetemp Nov 26, 2026
082de57
Merge branch 'moe/streams-direct' into moe/streams-direct-read
moetemp Nov 26, 2026
c471447
Say the JSON form of the read marker in place of the removed rules
moetemp Nov 26, 2026
01e02e0
Merge branch 'moe/streams-direct' into moe/streams-direct-read
moetemp Nov 26, 2026
5aff10b
Use the only Stream runtime for a read with no Store name
moetemp Nov 26, 2026
aa51821
Say when Core records a read marker with no entry
moetemp Nov 26, 2026
14e572d
Shorten the read entry of the CHANGELOG
moetemp Nov 26, 2026
ba5a742
Merge branch 'moe/streams-direct' into moe/streams-direct-read
moetemp Nov 26, 2026
b719270
Use the runtime under the empty name for a read with no Store name
moetemp Nov 26, 2026
2af2f1b
Merge branch 'moe/streams-direct' into moe/streams-direct-read
moetemp Nov 26, 2026
349dd4f
Bound Workflow reads and preserve recorded Producer values on replay
moetemp Nov 27, 2026
d0a4b39
Merge the updated Workflow append layer
moetemp Nov 27, 2026
972b330
Keep one changelog entry per Stream operation
moetemp Nov 27, 2026
1b0e5fc
Merge the revised Stream read contract
moetemp Nov 27, 2026
fb57242
Distinguish read admission from the task byte limit
moetemp Nov 27, 2026
4a5777f
Format the replay digest regression on the read layer
moetemp Nov 27, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions changelog/fixed/patient-page-turner.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Workflow replay skips timed-out tasks even when the task starts at the end of a History page.
18 changes: 17 additions & 1 deletion crates/protos/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"coresdk.external_data.LocalActivityMarkerData.backoff",
"#[serde(with = \"sdk_helpers::opt_duration\")]",
)
// A person reads a Stream marker's JSON in the web UI, so an offset is hex.
// A person reads a Stream marker's JSON in the web UI, so an offset or a digest is hex.
.field_attribute(
"coresdk.external_data.StreamAppendOffsets.first_offset",
"#[serde(with = \"sdk_helpers::hex_bytes\")]",
Expand All @@ -176,6 +176,18 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"coresdk.external_data.StreamAppendOffsets.last_offset",
"#[serde(with = \"sdk_helpers::hex_bytes\")]",
)
.field_attribute(
"coresdk.external_data.StreamReadResult.from_offset",
"#[serde(with = \"sdk_helpers::hex_bytes\")]",
)
.field_attribute(
"coresdk.external_data.StreamReadPage.digest",
"#[serde(with = \"sdk_helpers::hex_bytes\")]",
)
.field_attribute(
"coresdk.external_data.StreamReadPage.last_offset",
"#[serde(with = \"sdk_helpers::hex_bytes\")]",
)
.skip_debug(["temporal.api.common.v1.Payload"]);

for prefix in SERDE_DERIVE_PREFIXES {
Expand All @@ -187,6 +199,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"coresdk.external_data.StreamAppendResult.result",
"#[serde(rename_all = \"snake_case\")]",
);
builder = builder.type_attribute(
"coresdk.external_data.StreamReadResult.result",
"#[serde(rename_all = \"snake_case\")]",
);

#[cfg(feature = "vendored-protox")]
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,44 @@ message StreamFailure {
// The message of the failure, of at most 4096 bytes.
string message = 2;
}

// The data of a `core_stream_read` marker. Core records one in each activation in which Workflow
// code got the page of a read. An empty marker keeps a task with an open read and no open append
// apart from the next task when chunking is on. The marker keeps the offsets, the count and a
// digest of each page, never its Records. A replay reads the Records from the Store again. Its
// JSON has `bytes` fields in lower-case hex, as for appends.
message StreamReadMarkerData {
repeated StreamReadResult reads = 1;
}

message StreamReadResult {
uint32 seq = 1;
string stream_id = 2;
// The name of the Store that the read used. For a ref with no Store name, it is the empty name
// if the Worker has a Stream runtime under it, else the name of its only runtime.
string store = 3;
// The index of the activation, within its Workflow Task, in which Workflow code got the result.
uint64 activation_index = 4;
// The `from_offset` of the read. A replay reads the Records of the page after it.
bytes from_offset = 5;
oneof result {
StreamReadPage page = 6;
StreamFailure failure = 7;
}
}

// A page that a read gave Workflow code, without its Records.
message StreamReadPage {
uint32 record_count = 1;
// The first 16 bytes of SHA-256 over the Records in a Core-owned encoding. New markers prefix
// these bytes with version 1. Original markers contain just the legacy hash. Empty for no Records.
bytes digest = 2;
// The size of the Records, as the `max_bytes` of a read measures it. A replay asks the Store for
// this much.
uint64 record_bytes = 3;
// The `last_offset` that Workflow code got. A replay gives the same value, since another read of
// the Store can end at another offset.
bytes last_offset = 4;
// The `wait_cut` that Workflow code got with the page.
bool wait_cut = 5;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import "temporal/api/update/v1/message.proto";
import "temporal/api/common/v1/message.proto";
import "temporal/api/enums/v1/failed_cause.proto";
import "temporal/api/enums/v1/workflow.proto";
import "temporal/api/stream/v1/message.proto";
import "temporal/sdk/core/activity_result/activity_result.proto";
import "temporal/sdk/core/child_workflow/child_workflow.proto";
import "temporal/sdk/core/common/common.proto";
Expand Down Expand Up @@ -49,13 +50,14 @@ import "temporal/sdk/core/nexus/nexus.proto";
// this to ensure the LA resolution happens after that cancel (or whatever else it may be) as it
// normally would have when executing.
// * Stream results go with the local activity resolutions, for the same reason. Core records a
// Stream result in a `core_stream_append` marker, which History has after the
// `WorkflowTaskCompleted` event of its task. A replay must give the result before it reaches
// Stream result in a `core_stream_append` or `core_stream_read` marker, which History has after
// the `WorkflowTaskCompleted` event of its task. A replay must give the result before it reaches
// that event, so it scans ahead in History for the marker, as for a local activity marker. Each
// result in the marker has the index of the activation that got it, so the replay gives it in
// that same activation. In one activation, the Stream results go first, in `seq` order, and then
// the local activity resolutions. A replay with workflow task chunking on can give several
// activations of the first run as one. Then the results go in the order of those activations.
// that same activation. In one activation, the Stream results go first, appends before reads,
// each in `seq` order, and then the local activity resolutions. A replay with workflow task
// chunking on can give several activations of the first run as one. Then the results go in the
// order of those activations.
// * Queries always go last (and, in fact, always come in their own activation)
// * Evictions also always come in their own activation
//
Expand Down Expand Up @@ -157,6 +159,8 @@ message WorkflowActivationJob {
ResolveNexusOperation resolve_nexus_operation = 16;
// An append to a Stream finished.
ResolveStreamAppend resolve_stream_append = 17;
// A read of a Stream finished.
ResolveStreamRead resolve_stream_read = 18;
// Remove the workflow identified by the [WorkflowActivation] containing this job from the
// cache after performing the activation. It is guaranteed that this will be the only job
// in the activation if present.
Expand Down Expand Up @@ -462,3 +466,29 @@ message StreamAppended {
bytes first_offset = 1;
bytes last_offset = 2;
}

// The result of a `ReadStream`. Each read gets exactly one, unless Core drops the read (see
// `ReadStream`). The activation rules of `ResolveStreamAppend` apply to it too, with the
// `core_stream_read` marker in place of the `core_stream_append` one.
message ResolveStreamRead {
// The `seq` of the `ReadStream`.
uint32 seq = 1;
oneof status {
StreamPage page = 2;
// The failure of the read. It has the parts of the `failed` of a `ResolveStreamAppend`.
temporal.api.failure.v1.Failure failed = 3;
}
}

message StreamPage {
// The Records of the page, in the order of the Stream. It's empty if no Record came while the
// read waited.
repeated temporal.api.stream.v1.StreamRecord records = 1;
// The offset where the page ends, also for a page with no Record. The next read can pass it as
// its `from_offset`.
bytes last_offset = 2;
// True if the page has no Record because the read time of the Workflow Task ended the wait
// before the `wait` of the read. A reader that waits for a Record can read again from
// `last_offset`. It's false for a page that ends a whole wait.
bool wait_cut = 3;
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ message WorkflowCommand {
ScheduleNexusOperation schedule_nexus_operation = 21;
RequestCancelNexusOperation request_cancel_nexus_operation = 22;
AppendToStream append_to_stream = 23;
ReadStream read_stream = 24;
}
}

Expand Down Expand Up @@ -439,3 +440,48 @@ message AppendToStream {
temporal.api.sdk.v1.StreamRef stream = 2;
repeated temporal.api.common.v1.Payload bodies = 3;
}

// Reads one page after from_offset. A reader continues from the page's last_offset until an
// application Record tells it to stop. ResolveStreamRead follows the ordering of ResolveStreamAppend.
//
// A page returns as soon as Records are available. For an empty page Core polls from the Store's
// returned offset at most once per 100 ms until wait expires or the task reaches its read time.
// StreamSettings.read_time defaults to half the task timeout and starts when replay ends.
// An empty page reports wait_cut when the task read time shortens the wait.
//
// Before completing a task, Core checks unanswered reads with a nonblocking Store call and a
// one-second deadline. If the task has a command or a server message, it waits only for this check.
// Core carries available Records into the next task when a command must go first. An empty
// blocking read resumes on a later task. An idle Stream alone does not request another task.
// A nonblocking read can return an empty page in the current task, even after the read deadline.
//
// Each task delivers at most 16 MiB of encoded Records. After 256 read results, new reads wait
// for the next task. Reads already running can finish. A single Record over 16 MiB gives a failed
// job with stream_unsupported. A Store outage or an unanswered check fails the Workflow Task with
// StreamStoreUnavailable. Lang must accept results it no longer awaits. The terminal Workflow
// command drops unresolved reads.
//
// Replay matches seq, Stream and from_offset. It rereads the recorded range and verifies the
// Record count and digest. Retention must cover Workflow replay and later queries. Missing or
// changed Records give a StreamReplay error. A missing runtime or unavailable Store fails the
// Workflow Task, or the legacy query. Replay loads History in parts. The Store selection rules
// are the same as for AppendToStream.
//
// Negative limits or wait, an offset over 1024 bytes, or an invalid seq or Stream reference
// fail the Workflow Task.
message ReadStream {
// Lang's incremental sequence number for reads, starting at 1.
uint32 seq = 1;
temporal.api.sdk.v1.StreamRef stream = 2;
// The page has the Records after this offset. If it's empty, the page starts at the beginning
// of the Stream.
bytes from_offset = 3;
// How long the read waits for a Record if the Stream has none after `from_offset`. If it's
// unset, the read doesn't wait.
google.protobuf.Duration wait = 4;
// The maximum number of Records in the page, which is 256 if this is zero.
int32 max_records = 5;
// Page size in encoded Record bytes. Zero selects 4 MiB. A single Record may exceed this
// request limit up to the Workflow Task limit of 16 MiB.
int64 max_bytes = 6;
}
3 changes: 3 additions & 0 deletions crates/protos/src/protos/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ pub const LOCAL_ACTIVITY_MARKER_NAME: &str = "core_local_activity";

/// Used as `marker_name` field when recording the results of Stream appends
pub const STREAM_APPEND_MARKER_NAME: &str = "core_stream_append";

/// Used as `marker_name` field when recording the pages of Stream reads
pub const STREAM_READ_MARKER_NAME: &str = "core_stream_read";
9 changes: 9 additions & 0 deletions crates/protos/src/protos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,9 @@ pub mod coresdk {
workflow_activation_job::Variant::ResolveNexusOperation(_) => {
write!(f, "ResolveNexusOperation")
}
workflow_activation_job::Variant::ResolveStreamRead(r) => {
write!(f, "ResolveStreamRead({})", r.seq)
}
workflow_activation_job::Variant::ResolveStreamAppend(r) => {
write!(f, "ResolveStreamAppend({})", r.seq)
}
Expand Down Expand Up @@ -1655,6 +1658,12 @@ pub mod coresdk {
}
}

impl Display for ReadStream {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "ReadStream({})", self.seq)
}
}

impl Display for AppendToStream {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "AppendToStream({})", self.seq)
Expand Down
8 changes: 8 additions & 0 deletions crates/sdk-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,16 @@ relevant information.
An outage at the task heartbeat fails the Workflow Task with `StreamStoreUnavailable:`.
* [lang-internal] The experimental `temporalio-streams` crate provides the `StreamStore` trait,
a validating `StreamRuntime` and `StoreLimits` for checking batches before dispatch.
* [lang-internal] `ReadStream` returns one Store page in a `ResolveStreamRead` job.
`StreamSettings::read_time` bounds the wait in one Workflow Task. Read markers store offsets,
the Record count and a digest. Replay reads those Records again and verifies the digest.

### Fixed
* A Workflow Stream read returns an unsupported-read error for a single Record over 16 MiB.
New read markers preserve the Producer's optional timestamps and signed values during replay.
Workers can still replay the original marker format, including previously delivered oversized
Records. Older Workers cannot interpret the new digest format.
* Workflow replay now skips timed-out tasks consistently when a History page ends at the task start.
* Replayed Local Activity timeouts now report an Activity failure with the timeout as its cause,
matching live execution.

Expand Down
1 change: 1 addition & 0 deletions crates/sdk-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ reqwest = { version = "0.13", features = [
], default-features = false, optional = true }
serde = "1.0"
serde_json = { workspace = true }
sha2 = "0.11"
siphasher = "1.0"
slotmap = "1.0"
sysinfo = { version = "0.38", default-features = false, features = ["system"] }
Expand Down
Loading
Loading