Description
When a client disconnects and reconnects to SpacetimeDB, the state received after resubscribing can become inconsistent with the actual database state. Specifically some updates appear to be either missed or duplicated and thus leading to divergence between clients.
This seems related to how subscription state is restored after reconnect. I've added a minimal reproducible example below demonstrating the issue under high-frequency updates with a forced reconnect.
Steps to Reproduce
- Start a local SpacetimeDB instance
- Deploy the module shown below
- Run the writer client (continuous updates)
- Run the reader client (subscription + forced reconnect)
- Observe console logs after reconnect
Reproducible Example
Module (Rust)
use spacetimedb::{table, reducer};
#[table]
pub struct Counter {
#[primary_key]
id: u32,
value: u64,
}
#[reducer]
pub fn increment(ctx: &spacetimedb::ReducerContext) {
let mut counter = ctx.db.counter().id().find(1).unwrap();
counter.value += 1;
ctx.db.counter().id().update(counter);
}
Expected Behavior
- After reconnecting and resubscribing, the client should receive a consistent state
- No updates should be lost or duplicated
- State should match both:
- other continuously connected clients
- a fresh query snapshot
Actual Behavior
- Missed updates, value jumps unexpectedly
- Duplicate or out-of-order updates (state regression)
- Subscription state diverges from actual database state
Example output:
Missed updates detected { current: 1050, lastValue: 1032 }
State regression detected { current: 1035, lastValue: 1050 }
Description
When a client disconnects and reconnects to SpacetimeDB, the state received after resubscribing can become inconsistent with the actual database state. Specifically some updates appear to be either missed or duplicated and thus leading to divergence between clients.
This seems related to how subscription state is restored after reconnect. I've added a minimal reproducible example below demonstrating the issue under high-frequency updates with a forced reconnect.
Steps to Reproduce
Reproducible Example
Module (Rust)
Expected Behavior
Actual Behavior
Example output: