Skip to content

Conversation

@gefjon
Copy link
Contributor

@gefjon gefjon commented Oct 9, 2025

Description of Changes

API and ABI breaking changes

Expected complexity level and risk

Testing

gefjon and others added 30 commits July 23, 2025 17:19
Discussion in other forums has yielded a better design,
where procedure code can programmatically register `on_abort` handlers at runtime.
I even called some myself to try it!
No implementation; linking will fail.
At this stage, changes are not integrated, so build is broken.
But these are never supposed to block, so use a custom "executor" which only calls `poll` once.
This reverts commit b26d447.

These changes are now in a separate branch, `phoebe/skippable-tests`.
Co-authored-by: Mazdak Farrokhzad <[email protected]>
Co-authored-by: joshua-spacetime <[email protected]>
Signed-off-by: Phoebe Goldman <[email protected]>
So that we can determine whether we should be running this on the database core or not
And fix typo that mis-categorized `Module::Js` as `ModuleType::Wasm`.
It's not used in private either, and no one knew what it was for, so I'm cutting it.
and resolve just a whole boatload of merge conflicts
I successfully called this:

```bash
[phoebe@phoebe-desktop:~/clockworklabs/SpacetimeDB/modules/module-test]$ curl -H "Content-Type:application/json" -X POST -d '[]' http://localhost:3000/v1/database/module-test/procedure/this_procedure_sleeps
"Started at 2025-10-02T14:46:22.288936+00:00, requested to sleep until 2025-10-02T14:46:23.288936+00:00, woke at 2025-10-02T14:46:23.290299+00:00"
```
Prior to this commit, when shutting down SpacetimeDB-standalone via C-c / SIGINT,
the process would print a panic message and backtrace (if enabled)
due to dropping nested Tokio runtimes.
This commit avoids doing so in SpacetimeDB-standalone,
and adds a note to `JobCores` instructing how to avoid it in other uses.
github-merge-queue bot pushed a commit that referenced this pull request Oct 24, 2025
# Description of Changes

This commit adds a macro attribute `#[procedure]` which applies to
functions, and various in-WASM machinery for defining, calling and
running procedures.

A simple example of a procedure, included in `modules/module-test`:

```rust
fn sleep_one_second(ctx: &mut ProcedureContext) {
    let prev_time = ctx.timestamp;
    let target = prev_time + Duration::from_secs(1);
    ctx.sleep_until(target);
    let new_time = ctx.timestamp;
    let actual_delta = new_time.duration_since(prev_time).unwrap();
    log::info!("Slept from {prev_time} to {new_time}, a total of {actual_delta:?}");
}
```

We intend eventually to make procedures be `async` functions (with the
trivial `now_or_never` executor from `future-util`), but I found that
making the types work for this was giving me a lot of trouble, and
decided to put it off in the interest of unblocking more parallelizable
work.

Host-side infrastructure for executing procedures is not included in
this commit. I have a prototype working, but cleaning it up for review
and merge will come a bit later.

One item of complexity in this PR is enabling scheduled tables to
specify either reducers or procedures, while still providing
compile-time diagnostics for ill-typed scheduled functions (as opposed
to publish-time). I had to rewrite the previous
`schedule_reducer_typecheck` into a more complex `schedule_typecheck`
with a trait `ExportFunctionForScheduledTable`, which takes a "tacit
trait parameter" encoding reducer-ness or procedure-ness, as described
in https://willcrichton.net/notes/defeating-coherence-rust/ .

The trait name `ExportFunctionForScheduledTable` is user-facing in the
sense that it will appear in compiler diagnostics in ill-typed modules.
As such, I am open to bikeshedding.

# API and ABI breaking changes

Adds a new user-facing API, which we intend to change before releasing.

# Expected complexity level and risk

2? Mostly pretty mechanical changes to macros and bindings.

# Testing

- [x] Added a procedure definition to `module-test`, saw that it
typechecks.
- [x] Executed same procedure definition using #3390 , the prototype
implementation this PR draws from.
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.

2 participants