Skip to content

[Brook K9] Added writers for Activities and clients. - #219

Closed
moetemp wants to merge 33 commits into
moe/brook/review/streams-k7-withdrawalsfrom
moe/brook/review/streams-k9-writers
Closed

moetemp wants to merge 33 commits into
moe/brook/review/streams-k7-withdrawalsfrom
moe/brook/review/streams-k9-writers

Conversation

@moetemp

@moetemp moetemp commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

What changed?

This PR adds writers for Activities and clients, served through the runtime's writer calls.

  • A writer keeps one Producer epoch and one sequence order. WriteRecords returns the offsets, and resends the same batch after a Store failure, so the Store writes it once.
  • A Local Activity's writer, and an Activity retry's writer, first sends an empty batch, which withdraws the earlier epoch's Records.
  • A writer retries only an unavailable Store. If the Store stays unavailable, only that write fails, and the next write takes a higher sequence. Corrupt Store data fails the writer with no retry. A refusal, such as on a closed Stream or a newer epoch, still fails the writer.
  • free_writer needs no Store and no async runtime, so a bridge can call it from a finalizer.

Depends on #218 (K7), for the Local Activity task facts. Review lane is the Rust reviewers.
Part of the Brook review series.

Why?

Writers are the client and Activity side of the runtime, and nothing else in the crate uses them.

How did you test it?

cargo fmt, cargo clippy -- -D warnings (with and without features), cargo test -p temporalio-streams --all-features and cargo doc pass at this commit. The writer suite runs on the memory Store here, and on Redis in R3 (temporal-community/sdk-streams#3).

@moetemp
moetemp force-pushed the moe/brook/review/streams-k7-withdrawals branch from d21bc6e to e12bbce Compare October 27, 2026 07:35
@moetemp
moetemp force-pushed the moe/brook/review/streams-k9-writers branch 2 times, most recently from 26765fa to d18c6dc Compare October 27, 2026 08:17
@moetemp
moetemp force-pushed the moe/brook/review/streams-k7-withdrawals branch from e12bbce to 855fbbc Compare October 27, 2026 08:17
@moetemp moetemp added the skip-changelog Changelog entry rides another PR label Oct 27, 2026
@moetemp
moetemp force-pushed the moe/brook/review/streams-k7-withdrawals branch from 855fbbc to 1228850 Compare October 27, 2026 16:55
@moetemp
moetemp force-pushed the moe/brook/review/streams-k9-writers branch 2 times, most recently from 018e21d to be4d7ae Compare October 27, 2026 23:46
@moetemp
moetemp force-pushed the moe/brook/review/streams-k7-withdrawals branch from 1228850 to 8601859 Compare October 27, 2026 23:46
@moetemp
moetemp force-pushed the moe/brook/review/streams-k9-writers branch from be4d7ae to 95ed97c Compare October 28, 2026 08:55
@moetemp
moetemp force-pushed the moe/brook/review/streams-k7-withdrawals branch 2 times, most recently from 70da9b2 to 7363e49 Compare October 29, 2026 04:06
@moetemp
moetemp force-pushed the moe/brook/review/streams-k9-writers branch from 95ed97c to 0922872 Compare October 29, 2026 04:06
@moetemp
moetemp force-pushed the moe/brook/review/streams-k7-withdrawals branch from 7363e49 to eb4a41f Compare October 29, 2026 08:37
@moetemp
moetemp force-pushed the moe/brook/review/streams-k9-writers branch from 0922872 to b163ba2 Compare October 29, 2026 08:37
@moetemp
moetemp force-pushed the moe/brook/review/streams-k7-withdrawals branch from eb4a41f to 9416b54 Compare October 29, 2026 09:17
@moetemp
moetemp force-pushed the moe/brook/review/streams-k9-writers branch from b163ba2 to 83b33d1 Compare October 29, 2026 09:17
A writer keeps one Producer epoch and one `sequence` order, so a retry after a
Store failure writes a batch only once. The handles of one Producer epoch on
one Stream share one writer. The writer suite runs on every Store.
@moetemp
moetemp force-pushed the moe/brook/review/streams-k7-withdrawals branch from 9416b54 to 64c31e5 Compare October 29, 2026 10:03
@moetemp
moetemp force-pushed the moe/brook/review/streams-k9-writers branch from 83b33d1 to 56fd065 Compare October 29, 2026 10:03
The Store now refuses an append of more than 1000 Records, so a larger max_batch_size would fail every full batch.
The case also gives an Activity's attempt, so the rule reads one field. The writer suite builds its Producers and creates from the new shapes.
Corrupt Store data reads the same on a retry, so the write fails at once and the writer fails. The writer suite checks it on a Store that refuses one append as corrupt.
An open carries its StreamRef in ref, and the writer keeps it as stream_ref.
OpenWriterRequest carries the Producer and the task facts in one StreamWriter, and each batch sends it as AppendRecords does.
Only a retry run's first append withdraws a run, and a writer sends many batches. The writer suite checks the refusal.
The review asked to stop representing invalid states. The Producer kind is now a oneof with run_id only in the run-based variants, so a client can't carry a run. A write's task facts and withdraw_run move into RunWithdrawal, which only a run writer sets.
The protos moved these into variants. The crate reads them through helpers on Producer and StreamWriter, so the stored format, the epoch keys and the test vectors stay the same.
@moetemp

moetemp commented Nov 10, 2026

Copy link
Copy Markdown
Owner Author

Closed in favor of #228, the combined branch, which has this change.

@moetemp moetemp closed this Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changelog Changelog entry rides another PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant