clockworklabs / clockworklabs/SpacetimeDB

Codegen silently ignores explicit enum discriminant values

Open
#4,618 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
25.2k
Forks
1.1k
Avg merge
2d 7h
Merged PRs (30d)
46

Description

Problem

When a Rust module defines an enum with explicit discriminant values:

#[derive(SpacetimeType)]
enum MyEnum {
    A = 1,
    B = 2,
    C = 3,
}

SATS encoding assigns variant tags by declaration order (0, 1, 2), completely ignoring the Rust discriminant values (1, 2, 3). Client-side codegen then generates enums with the SATS tag order, resulting in a mismatch between server and client enum values.

This means the server thinks A = 1 but the client thinks A = 0, silently corrupting data when enum values are used for anything beyond pattern matching.

Expected Behavior

The derive macro should emit a compile error when explicit discriminant values are used, since they cannot be preserved through the SATS encoding.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the SpacetimeType derive macro and the SATS enum encoding path described in the issue. Trace how explicit Rust discriminants are handled, then add coverage showing that such enums produce a compile error rather than declaration-order tags; done means the server and client cannot silently disagree on these values.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend-api-design, database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.