Skip to content

Disconnect with intent - #5782

Open
onx2 wants to merge 5 commits into
clockworklabs:masterfrom
onx2:disconnect-with-intent
Open

Disconnect with intent#5782
onx2 wants to merge 5 commits into
clockworklabs:masterfrom
onx2:disconnect-with-intent

Conversation

@onx2

@onx2 onx2 commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Description of Changes

Adds a new DisconnectIntent API to the Rust SDK. Consumers can use on_disconnect_with_intent to distinguish client-requested disconnects, lost connections, and SDK errors. The existing on_disconnect API remains unchanged for compatibility.

Use case

Automatic reconnect should apply only to unexpected disconnects, and application-requested disconnects are distinct. For example, when a game player logs out or switches accounts, the client intentionally calls disconnect(). If the reconnect system treats that event like a network failure, it may reconnect with the cached credentials, restore subscriptions, and make the player appear online again—or reconnect to the wrong account or database (depending on user's implementation).

Exposing whether a disconnect was intentional lets integrations such as bevy_stdb reconnect after network/server failures while remaining disconnected after explicit application shutdown or logout using internal SDK semantics.

API and ABI breaking changes

This is additive and does not break the existing API or ABI, but I think in v3 the on_disconnect should be replaced by this version.

Expected complexity level and risk

1/5

This adds disconnect intent information without changing existing behavior for current consumers.

Testing

  • cargo check -p spacetimedb-sdk
  • cargo test -p spacetimedb-sdk --lib
  • Unit tests for requested, lost, and errored disconnects.
  • Verify the new callback with a live server disconnect and reconnect.

Local(PendingMutation<M>),
}

fn disconnect_result(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Making this a function might be a little overkill 🤷🏻

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