Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
167d0f8
Added the memory Store and the shared Store suite.
moetemp Oct 27, 2026
a757ea0
Merged K3 into K4.
moetemp Oct 30, 2026
b58d89c
Gated the memory Store's test hooks behind test-support.
moetemp Oct 30, 2026
d3e547b
Merged K3 into K4.
moetemp Oct 30, 2026
0ec602b
Merged K3 into K4.
moetemp Oct 30, 2026
1ea93b2
Gave a batch with no sequence the next one in the memory Store.
moetemp Oct 30, 2026
9f72a8c
Merged K3 into K4.
moetemp Oct 31, 2026
2e78972
Renamed Supersession to Superseded, and StreamRef to StreamHandle.
moetemp Oct 31, 2026
cea64a5
Merged K3 into K4.
moetemp Nov 1, 2026
0d90e6c
Merged K3 into K4.
moetemp Nov 1, 2026
dda1580
Kept the memory Store's meta fields as bytes.
moetemp Nov 4, 2026
9bddeef
Merged K3 into K4.
moetemp Nov 4, 2026
cef053b
Kept one meta field per Producer.
moetemp Nov 4, 2026
baf64da
Merged K3 into K4.
moetemp Nov 5, 2026
e39f395
Applied the strict create and the close rule to the memory Store.
moetemp Nov 5, 2026
6fcbfc7
Merged K3 into K4.
moetemp Nov 5, 2026
ba26a57
Merged K3 into K4.
moetemp Nov 5, 2026
81c4964
Made the memory Store's close write no entry and wake the reads.
moetemp Nov 5, 2026
9797dc0
Merged K3 into K4.
moetemp Nov 5, 2026
1b38090
Called the memory Store's and the Store suite's Stream a ref.
moetemp Nov 5, 2026
d8689a3
Merged K3 into K4.
moetemp Nov 5, 2026
f47195a
Checked the format version before an append reads the Producer field.
moetemp Nov 5, 2026
085879a
Merged K3 into K4.
moetemp Nov 5, 2026
035f4bc
Built the Store suite's Superseded item from a StreamWriter.
moetemp Nov 5, 2026
1e2b8c0
Merged K3 into K4.
moetemp Nov 5, 2026
aceec09
Merged K3 into K4.
moetemp Nov 5, 2026
315e6ea
Put the Producer kind and the writer's withdrawal into variants.
moetemp Nov 7, 2026
b689c0f
Read the Producer kind through the oneof in the memory Store.
moetemp Nov 7, 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
102 changes: 63 additions & 39 deletions crates/protos/protos/api_upstream/temporal/api/stream/v1/message.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,6 @@ message StreamRef {
string backend = 3;
}

// Experimental. Might change in the future.
// The ordered attempt of a Producer. A higher epoch supersedes the Records of a lower epoch of the
// same Producer. The case is the kind of the Producer. It decides how the Store orders the epochs,
// and which earlier Records a higher epoch withdraws.
message ProducerEpoch {
oneof kind {
// A Workflow run, which writes in its Workflow Task. A higher epoch withdraws the Records
// of the run's Workflow Tasks that never completed, also those of their Local Activities.
WorkflowTaskEpoch workflow = 1;
// A Local Activity. A higher epoch withdraws the Producer's lower epochs.
LocalActivityEpoch local_activity = 2;
// An Activity of a Workflow. A higher epoch withdraws the Producer's lower epochs.
ActivityEpoch activity = 3;
// A Standalone Activity. A higher epoch withdraws the Producer's lower epochs.
ActivityEpoch standalone_activity = 4;
// A client. A higher epoch only fences the lower ones, since a restarted client's earlier
// Records are real messages, not the Records of a failed attempt.
ClientEpoch client = 5;
}
}

// Experimental. Might change in the future.
// One Workflow Task attempt of a run. It orders by started_event_id, then attempt, then
// started_time.
Expand Down Expand Up @@ -86,32 +65,78 @@ message ClientEpoch {
}

// Experimental. Might change in the future.
// The code that wrote a batch. Its id stays the same across attempts, and its epoch orders them.
// A Workflow run Producer. It writes in its Workflow Task. A higher epoch withdraws the Records of
// the run's Workflow Tasks that never completed, with those of their Local Activities.
message WorkflowProducer {
// The first execution run id of the run chain.
string run_id = 1;
WorkflowTaskEpoch epoch = 2;
}

// Experimental. Might change in the future.
// A Local Activity Producer. A higher epoch withdraws the Producer's lower epochs.
message LocalActivityProducer {
string run_id = 1;
LocalActivityEpoch epoch = 2;
}

// Experimental. Might change in the future.
// An Activity Producer, for an Activity of a Workflow or a Standalone Activity. A higher epoch
// withdraws the Producer's lower epochs.
message ActivityProducer {
string run_id = 1;
ActivityEpoch epoch = 2;
}

// Experimental. Might change in the future.
// A client Producer. A higher epoch only fences the lower ones, since a restarted client's earlier
// Records are real messages, not the Records of a failed attempt. A client has no run.
message ClientProducer {
ClientEpoch epoch = 1;
}

// Experimental. Might change in the future.
// The code that wrote a batch. Its id stays the same across attempts, and the kind's case orders
// its epochs and picks which earlier Records a higher epoch withdraws. A run-based kind carries its
// run, so a client can't.
message Producer {
// Stable across attempts, such as `wf:<run id>` for the Workflow Producer of a run.
string id = 1;
// Required. Its case gives the kind of the Producer.
ProducerEpoch epoch = 2;
// The run of the Producer, so nobody parses the id. Empty for a client.
string run_id = 3;
// Required. The case is the kind of the Producer.
oneof kind {
WorkflowProducer workflow = 2;
LocalActivityProducer local_activity = 3;
ActivityProducer activity = 4;
ActivityProducer standalone_activity = 5;
ClientProducer client = 6;
}
}

// Experimental. Might change in the future.
// The Producer of a write, and which earlier Records the write withdraws. An append, a close and
// a writer carry the same fields, so the Store orders and withdraws each write the same way.
message StreamWriter {
// Required on a write. Its epoch's case picks the withdrawal rule.
// Required on a write. Its Producer's kind picks the withdrawal rule.
Producer producer = 1;
// Workflow and Local Activity only. The run's last completed Workflow Task, from a Local
// Activity's start. Its started_event_id is 0 before the first. The write withdraws the run's
// Local Activity Records whose Workflow Task never completed.
WorkflowTaskEpoch previous_completed_task = 2;
// Workflow and Local Activity only. The started event ids of the run's failed or timed out
// Workflow Tasks. The write withdraws the run's Local Activity Records of these tasks.
repeated int64 failed_tasks = 3;
// Retry run only. The previous run, on the retry run's first write. Every Record whose
// Producer carries it is withdrawn.
string withdraw_run = 4;
// Set only by a Workflow or Local Activity write, since only a run withdraws orphaned Local
// Activity Records or a previous run. Unset for an Activity or client write.
RunWithdrawal withdrawal = 2;
}

// Experimental. Might change in the future.
// What a Workflow or Local Activity write withdraws from its run. One write can carry both the task
// facts and a run to withdraw, so these are fields of one message and not a oneof.
message RunWithdrawal {
// The run's last completed Workflow Task, from a Local Activity's start. Its started_event_id
// is 0 before the first. The write withdraws the run's Local Activity Records whose Workflow
// Task never completed.
WorkflowTaskEpoch previous_completed_task = 1;
// The started event ids of the run's failed or timed out Workflow Tasks. The write withdraws
// the run's Local Activity Records of these tasks.
repeated int64 failed_tasks = 2;
// Retry run only. The previous run, on the retry run's first write. Every Record whose Producer
// carries it is withdrawn.
string withdraw_run = 3;
}

// Experimental. Might change in the future.
Expand All @@ -125,8 +150,7 @@ message AppendRecord {
// batch of a higher epoch, or for a retry run's first write, and a read builds a Superseded item
// from them. A reader drops the earlier Records that the facts match.
message StreamSuperseded {
// The writer of the batch that withdraws. Its Producer's epoch is empty when only
// withdraw_run applies.
// The writer of the batch that withdraws, with its withdrawal facts.
StreamWriter writer = 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ message AppendRecordsRequest {
int64 sequence = 4;
repeated temporal.api.stream.v1.AppendRecord records = 5;
// Only read by the server, on a Workflow Producer's batch. The batch withdraws no Workflow
// Task and keeps no task facts, but the writer's withdraw_run still applies.
// Task and keeps no task facts, but the writer's withdrawal withdraw_run still applies.
bool defer_withdrawal = 6;
// Only read by the server. The server checks the Producer against the Activity's current
// attempt, so nobody else writes as that Activity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import "temporal/api/stream/v1/message.proto";
message OpenWriterRequest {
string namespace = 1;
temporal.api.stream.v1.StreamRef ref = 2;
// Each batch sends it as AppendRecords does. For a Local Activity it has the run's task facts,
// so the writes withdraw the run's orphaned Local Activity Records. Its withdraw_run must be
// empty, since only a retry run's first append withdraws a run, and a writer sends many.
// Each batch sends it as AppendRecords does. For a Local Activity its withdrawal has the run's
// task facts, so the writes withdraw the run's orphaned Local Activity Records. The withdrawal's
// withdraw_run must be empty, since only a retry run's first append withdraws a run, and a
// writer sends many.
temporal.api.stream.v1.StreamWriter writer = 3;
// A write sends at most this many Records in one batch. Zero is 1000.
int32 max_batch_size = 4;
Expand Down
9 changes: 7 additions & 2 deletions crates/streams/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ keywords = ["temporal", "workflow", "streams"]
categories = ["development-tools"]

[features]
# The test helpers, for the crates of other Stores.
test-support = []
# The shared suites, for the crates of other Stores.
test-support = ["dep:futures-util", "dep:serde_json"]

[dependencies]
async-trait = "0.1"
futures-util = { version = "0.3", default-features = false, features = ["std"], optional = true }
parking_lot = "0.12"
prost = { workspace = true }
prost-types = { workspace = true }
serde_json = { workspace = true, optional = true }
sha2 = "0.10"
thiserror = { workspace = true }
tokio = { version = "1.47", default-features = false, features = ["rt", "sync", "time"] }
Expand All @@ -30,7 +33,9 @@ version = "~1.1.0"
default-features = false

[dev-dependencies]
futures-util = { version = "0.3", default-features = false, features = ["std"] }
serde_json = { workspace = true }
tokio = { version = "1.47", features = ["macros", "rt-multi-thread", "time"] }

[lints]
workspace = true
13 changes: 11 additions & 2 deletions crates/streams/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,14 @@ re-exports them, so a value needs no conversion between the crates.
- `testdata/*.json` are the shared vectors. They cover Stream ids, Producer ids, Store keys and
meta fields, offsets, epoch keys, the withdrawal rule and the batch digest of a dedupe entry.
`testdata/gen_vectors.py` writes them from a second implementation, and the crate's tests read
each file. The Python SDK also reads `ids.json` and `withdrawals.json`. `digests.json` is the
golden of the crate's batch digest.
each file. The Python SDK also reads `ids.json` and `withdrawals.json`. Each Store reads
`fields.json` through the shared Store suite. `digests.json` is the golden of the crate's batch
digest.

## Stores and the shared suites

The memory Store is for tests. It keeps the key layout of the Redis Store and applies the same rules
in the same order. The `test-support` feature exports the shared suites in `testing`. A Store crate
implements `testing::TestBackend` for its Store and runs each suite with `testing::run`, so that
every Store keeps one set of rules. This crate runs them on the memory Store in its unit tests.

Loading
Loading