Skip to content

Conversation

@gefjon
Copy link
Contributor

@gefjon gefjon commented Oct 30, 2025

Description of Changes

This commit adds support to the Rust client SDK for calling procedures.

Similar to reducers, each DbContext implementor has a pub procedures: RemoteProcedures field, with methods provided by extension traits for each procedure.

Unlike reducers, the provided methods are invoke and invoke-then. Invoke-then takes a FnOnce callback to run
when the SDK is notified of the procedure's termination status, while invoke ignores that notification.
No mechanism is provided for observing procedures invoked by other clients.

Procedure callbacks are implemented by storing a map from request_id to ProcedureCallback, with the callback closure internally knowing how to deserialize the return value. It's mildly unfortunate to deserialize within the callback instead of on the preprocess background task, but it saves significant complexity.

This commit also adds a new sdk-test module, sdk-test-procedures, and a new Rust test client, procedure-client.
Together, these are used in two tests of invoking and observing procedures. I've left TODOs for other tests that we should write as we implement additional procedure features.

I also had to fix a few minor bugs in the Rust codegen which were not strictly related to procedures: we previously assumed that the sets of reducers and of tables were non-empty, which led to wonky invalid codegen on modules which did not define any reducers or which did not define any tables.

I'm sneaking a change to the Nix flake into this PR as well - when initially writing it I had included cargoArtifacts (the pre-built and cached dependencies of our actual builds) in its packages, but that was neither necessary or useful, and just made building the shell take a long time after dependency changes.

API and ABI breaking changes

Breaks the internal interface between the Rust client SDK and codegen, so users will have to re-run spacetime generate.

Expected complexity level and risk

2-ish? Pretty simple change to the Rust SDK overall.

Testing

  • Added new automated integration tests exercising the new functionality.

This commit adds support to the Rust client SDK for calling procedures.

Similar to reducers,
each `DbContext` implementor has a `pub procedures: RemoteProcedures` field,
with methods provided by extension traits for each procedure.

Unlike reducers, the provided methods are invoke and invoke-then.
Invoke-then takes a `FnOnce` callback to run
when the SDK is notified of the procedure's termination status,
while invoke ignores that notification.
No mechanism is provided for observing procedures invoked by other clients.

Procedure callbacks are implemented by storing a map from `request_id` to `ProcedureCallback`,
with the callback closure internally knowing how to deserialize the return value.
It's mildly unfortunate to deserialize within the callback
instead of on the preprocess background task, but it saves significant complexity.

This commit also adds a new sdk-test module, `sdk-test-procedures`,
and a new Rust test client, `procedure-client`.
Together, these are used in two tests of invoking and observing procedures.
I've left TODOs for other tests that we should write as we implement additional procedure features.
@gefjon
Copy link
Contributor Author

gefjon commented Oct 30, 2025

Closes #3513

@bfops bfops linked an issue Oct 30, 2025 that may be closed by this pull request
We're generating empty files for C# and TypeScript bindings for now,
which still appear in the snaps
Copy link
Contributor

@Centril Centril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just some minor things.

Copy link
Contributor

@cloutiertyler cloutiertyler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving my code owned files.

Copy link
Contributor

@JasonAtClockwork JasonAtClockwork left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, just adding into Unreal + C# now

I realize now that this wasn't necessary,
and it makes `nix develop` and direnv take much longer than they should.
@gefjon gefjon added this pull request to the merge queue Nov 10, 2025
Merged via the queue into master with commit 565e95b Nov 10, 2025
25 of 26 checks passed
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.

Procedures: Rust client SDK invocation interface

6 participants