Skip to content

feat: Add module lifecycle reducer#5487

Open
ritankarsaha wants to merge 1 commit into
clockworklabs:masterfrom
ritankarsaha:feat/stop-lifecycle-reducer
Open

feat: Add module lifecycle reducer#5487
ritankarsaha wants to merge 1 commit into
clockworklabs:masterfrom
ritankarsaha:feat/stop-lifecycle-reducer

Conversation

@ritankarsaha

@ritankarsaha ritankarsaha commented Jul 6, 2026

Copy link
Copy Markdown

Description of Changes

Fixes #5480

Adds a stop module lifecycle reducer, the symmetric counterpart to init, invoked exactly once immediately before a database is permanently destroyed via spacetime delete or a reset. It does not fire on an ordinary module update/hot-reload or on replica scale-down, since the database's data survives both, and it's best-effort: a failing, trapping, or slowstop reducer is logged but never blocks the deletion it precedes.

Implemented via #[reducer(stop)] (Rust), ReducerKind.Stop (C#), and spacetime.stop() (TypeScript). Core changes: new Lifecycle::Stop variant, ModuleHost::call_module_stop (wired through both the WASM and V8/JS instance paths), and a new is_final_teardown flag on HostController::exit_module_host, set only by the standalone control plane's delete_database/reset_database paths (not replica scale-down/decommission).

Adds a module-test-stop fixture module and an integration test verifying stop fires exactly once on deletion and not on update.

API and ABI breaking changes

None. This is a purely additive change: a new Lifecycle enum variant and a new reducer-kind/attribute surface in each binding. No existing behavior changes for modules that don't declare a stop reducer.

Expected complexity level and risk

2.5 - touches the module lifecycle/shutdown path in crates/core/src/host The main risk surface is the is_final_teardown threading through crates/standalone/src/lib.rs's four delete_replica call sites — getting one of those wrong could either misfire stop on routine replica scale-down or silently skip it on real deletion.

Testing

  • cargo test -p spacetimedb-schema — new duplicate-lifecycle tests for Stop (v9 + v10)
  • cargo fmt --check and cargo clippy -D warnings clean on spacetimedb-lib, spacetimedb-schema, spacetimedb-core, spacetimedb-standalone, spacetimedb-bindings-macro, spacetimedb, spacetimedb-testing
  • New integration test test_stop_reducer_fires_only_on_deletion against a real compiled module, confirming stop does not fire on update and fires exactly once on deletion
  • TypeScript: tsc --noEmit, eslint, and prettier --check all clean; full vitest suite (232/232) passes
  • Manual: publish a module with stop, confirm no fire across spacetime publish, exactly one fire on spacetime delete, and rejection on a direct spacetime call <module> stop

@bfops

bfops commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Hi @ritankarsaha, what's the motivation for adding this reducer?

@ritankarsaha

ritankarsaha commented Jul 7, 2026

Copy link
Copy Markdown
Author

Hi @ritankarsaha, what's the motivation for adding this reducer?

This is in context to an issue #5480 which mentions for a similar reducer during teardown.

@ritankarsaha

ritankarsaha commented Jul 7, 2026

Copy link
Copy Markdown
Author

Hi @ritankarsaha, what's the motivation for adding this reducer?

Could you point me to more issues requiring attention?
I would like to contribute to the project more.

Do you guys have any community meet? @bfops

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.

Module Deinit reducer

2 participants