Skip to content

A game id in the protocol before the first store release

Context and problem

The server serves one game, Canasta, and its protocol named no game: docs/architecture.md listed a game id as “future work, once a second game exists”. Once the iPhone and Android apps ship, every installed build is a client the server must keep serving, so any field added later has to be optional for years. Today only the web client, deployed with the server, speaks the protocol. The architecture review of 2026-11-25 asked whether to add the id now or with game two.

Options considered

  1. Add it with the second game. No work now, but the first store builds would not send or read it, and the server would have to guess the game for every request from them.
  2. Add it now, before the store release. A small change while only the web reads the protocol; old clients never exist without it.
  3. Put the game in the URL (/canasta/table/ID). It changes every invite link already sent, and the server still needs the id on its tables.

Decision

We chose option 2. From #254:

  • tables.game is a column, canasta by default, so every existing table is Canasta.
  • POST /tables takes an optional game; an id that is not on the server’s fixed list (rust/canasta-server/src/games.rs) is refused with unknownGame (400, kind table).
  • The table message, GET /me/tables, the invite answer and every redeem or request answer that names a table carry its game.
  • The server never loads a table whose game it does not run: the hello is refused with a final unknownGame (4403), which clients do not retry. The web client opens a table only as the game its redeem, request, list or table answer names (gameForTable in web/src/games.ts, strict: no id counts as unknown), and says to update the app otherwise.

Choosing the rules engine, the snapshots and the WebSocket messages by the id stays for game two. Together with #233, which puts client and the protocol version in the hello, this freezes protocol v1 before the stores (decision 0013).

Consequences

Good

  • A second game is an additive change: a new id on the list, a new engine, no field to retrofit.
  • Store builds can refuse a game they do not have instead of misreading it.

Bad

  • Every client must read and check one more field now, for one game.
  • The URLs still carry no game, so a /table page opened cold starts with Canasta (openingTableGame) until the server answers; game two must look the game up first (docs/architecture.md “Web routes”).

More information

  • Issue #254; hello versioning #233.
  • Protocol: spec/protocol/server.md “The table”, “Create a table”, “Your tables”, “Redeem a code”.