Skip to content

Inconsistent state after client reconnect due to missed or duplicated subscription updates #4944

@Shiven0504

Description

@Shiven0504

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

  1. Start a local SpacetimeDB instance
  2. Deploy the module shown below
  3. Run the writer client (continuous updates)
  4. Run the reader client (subscription + forced reconnect)
  5. 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

  1. After reconnecting and resubscribing, the client should receive a consistent state
  2. No updates should be lost or duplicated
  3. State should match both:
  • other continuously connected clients
  • a fresh query snapshot

Actual Behavior

  1. Missed updates, value jumps unexpectedly
  2. Duplicate or out-of-order updates (state regression)
  3. Subscription state diverges from actual database state

Example output:

Missed updates detected { current: 1050, lastValue: 1032 }
State regression detected { current: 1035, lastValue: 1050 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions