Skip to content

Conversation

gefjon
Copy link
Contributor

@gefjon gefjon commented Sep 25, 2025

Description of Changes

Each reducer gets its arguments through an ArgSource, a Unix-file-like abstraction for streams of bytes. Prior to this commit, we had an ABI designed as if it could support other args sources, but it actually hardcoded the ID of the reducer args source, and errored elsewhere.

This commit extends the BytesSource infrastructure to support other bytes sources. This will be useful for exposing JWT payloads and HTTP responses. No other BytesSource uses are actually included in this commit, only the infrastructure.

This commit also defines a new host call, bytes_source_remaining_length. This is intended to allow callers to pre-allocate a buffer correctly sized to read the entire BytesSource all at once. The new host function is added to a new ABI minor version, 10.1, so that old SpacetimeDB hosts can detect and reject too-new compiled modules. I have added uses of this new function to __call_reducer__ in both Rust and C#, even though it's not strictly necessary,
and I haven't removed the loop which repeatedly calls bytes_source_read and grows the buffer.

API and ABI breaking changes

Adds a new ABI minor version, spacetime_10.1. This means that old SpacetimeDB hosts will reject new compiled modules.

Expected complexity level and risk

2-ish? WASM ABI code is always fiddly, but this is a pretty simple case.

Testing

  • New behavior and new host function are both hit through existing tests that instantiate modules and call reducers against them, so I believe automated testing is sufficient.

Each reducer gets its arguments through an `ArgSource`,
a Unix-file-like abstraction for streams of bytes.
Prior to this commit, we had an ABI designed as if it could support other args sources,
but it actually hardcoded the ID of the reducer args source,
and errored elsewhere.

This commit extends the `BytesSource` infrastructure to support other bytes sources.
This will be useful for exposing JWT payloads and HTTP responses.
No other `BytesSource` uses are actually included in this commit, only the infrastructure.

This commit also defines a new host call, `bytes_source_remaining_length`.
This is intended to allow callers to pre-allocate a buffer
correctly sized to read the entire `BytesSource` all at once.
The new host function is added to a new ABI minor version, 10.1,
so that old SpacetimeDB hosts can detect and reject too-new compiled modules.
I have added uses of this new function to `__call_reducer__` in both Rust and C#,
even though it's not strictly necessary,
and I haven't removed the loop which repeatedly calls `bytes_source_read` and grows the buffer.
As @jsdt points out, `bytes::Bytes` is already a view over an underlying buffer,
so keeping an additional cursor as a slice into it is silly.
@Centril Centril self-requested a review September 25, 2025 18:12
gefjon and others added 2 commits September 25, 2025 16:22
Co-authored-by: rekhoff <[email protected]>
Signed-off-by: Phoebe Goldman <[email protected]>
@gefjon gefjon requested a review from jsdt September 25, 2025 22:10
gefjon and others added 2 commits September 26, 2025 10:37
Co-authored-by: Mazdak Farrokhzad <[email protected]>
Signed-off-by: Phoebe Goldman <[email protected]>
@bfops bfops added the release-any To be landed in any release window label Sep 29, 2025
@cloutiertyler
Copy link
Contributor

Force merging for reasons discussed internally.

@cloutiertyler cloutiertyler merged commit 351af50 into master Sep 29, 2025
22 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-any To be landed in any release window
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants