design: record the closing message and the protocol-shell decisions (#18)

Owner decision (#18), option A: mummy 0.4.8 cannot send an application close code
(close(ws) -> an empty close frame -> the browser sees 1005), and mummy is not forked
for it. Every server-initiated close now sends one closing {reason, code} message and
then the close frame; the client reads the reason from that last message. Amends 3.2
(the OPEN note is FIXED) and 6.5, and adds the message to the 6.1 catalogue (server
messages 14 -> 15) with the reason/code table.

Also recorded FIXED: proto is a required query parameter (400 when absent, 4003 on a
mismatch, no hello); the server Ping interval (20 s, plus one right after hello, lag
enforcement stays M5); the n rule (server frames only, no number for Ping/Pong); the
explicit 64 KB maxMessageLen; and the slice-3 rollout note that catalogue intents
whose slice has not landed answer unknown-type. 10.3 lists the protocol test group.
This commit is contained in:
2026-11-15 08:33:16 +01:00
parent 951f37c3fb
commit db22b33567
+21 -11
View File
@@ -1,6 +1,6 @@
# FFF_vtt design
Status: draft v0.14, 2026-11-14 (owner decisions recorded in section 14; v0.4 records Q4 (tile_size 32 px), the outbox lock invariant (4.2, 4.3), and the follow-ups in 3.4, 8, 11.1, 12, 13; v0.5 records the M2 move-rule decisions in 5.5 and updates 3.4, 4.2, 5.1, 5.4, 6.1, 7.4, 8, 10.3, 12, 13; v0.6 records #14 (characters and player data) in 3.1, 3.4, 4.1, 4.4, 6.1, 8, 9, 10.3, 13, 14; v0.7 records #6 (players and invites) in 3.1, 3.2, 3.4, 4.4, 6.1, 8, 12, 13, 14; v0.8 records #7 (map tiles) in 3.3, 3.4, 11.1, 13, 14; v0.9 records #9 (test tools) in 2, 10.4, 13, 14; v0.10 records #12 (what M3 done means) in 13, 14; v0.11 records #15 (M3 limits) in 4.3, 6.4, 10.1, 13, 14; v0.12 records #11 (M3 message list) in 3.1, 3.2, 3.4, 4.2, 4.3, 5.5, 5.6, 6, 7.5, 13, 14; v0.13 records the owner review of #11 flags in 1, 3.1, 5.5, 6.1, 8, 14; v0.14 records #17 (getting in: keys, sessions, the auth slice) in 3.2, 4.4, 6.5, 6.6, 8, 11.1, 13, 14. All of Q1-Q24 are RESOLVED or DEFERRED; none OPEN). Audience: the owner and coding agents.
Status: draft v0.15, 2026-11-15 (owner decisions recorded in section 14; v0.4 records Q4 (tile_size 32 px), the outbox lock invariant (4.2, 4.3), and the follow-ups in 3.4, 8, 11.1, 12, 13; v0.5 records the M2 move-rule decisions in 5.5 and updates 3.4, 4.2, 5.1, 5.4, 6.1, 7.4, 8, 10.3, 12, 13; v0.6 records #14 (characters and player data) in 3.1, 3.4, 4.1, 4.4, 6.1, 8, 9, 10.3, 13, 14; v0.7 records #6 (players and invites) in 3.1, 3.2, 3.4, 4.4, 6.1, 8, 12, 13, 14; v0.8 records #7 (map tiles) in 3.3, 3.4, 11.1, 13, 14; v0.9 records #9 (test tools) in 2, 10.4, 13, 14; v0.10 records #12 (what M3 done means) in 13, 14; v0.11 records #15 (M3 limits) in 4.3, 6.4, 10.1, 13, 14; v0.12 records #11 (M3 message list) in 3.1, 3.2, 3.4, 4.2, 4.3, 5.5, 5.6, 6, 7.5, 13, 14; v0.13 records the owner review of #11 flags in 1, 3.1, 5.5, 6.1, 8, 14; v0.14 records #17 (getting in: keys, sessions, the auth slice) in 3.2, 4.4, 6.5, 6.6, 8, 11.1, 13, 14; v0.15 records #18 (talking safely: the protocol shell and the `closing` close-reason message) in 3.2, 4.3, 6, 6.1, 6.2, 6.4, 6.5, 10.3, 13, 14. All of Q1-Q24 are RESOLVED or DEFERRED; none OPEN). Audience: the owner and coding agents.
Legend:
- **[FIXED]** owner decision, not up for debate here.
@@ -139,7 +139,7 @@ Notes:
- Rejected: env/config seed (secret leaks via config, repo, backups); auto-print at startup (secrets in logs); first visitor claims GM (takeover); rotate on every lookup (logs out GM devices); live rotation while the server runs (needs an admin channel to the running server).
- **Key and session formats [FIXED (owner-delegated, 2026-11-14, #17)].** Player and GM keys are 20 symbols in 5 groups of 4 separated by dashes (24 characters shown), alphabet `ABCDEFGHJKMNPQRSTUVWXYZ23456789` (no `0/O`, `1/I/L`), drawn from the OS CSPRNG (`std/sysrand`, `getrandom`): ~99 bits. Comparison normalizes ASCII case, dashes and spaces and is length-independent (no early exit); at most 7 stored keys are compared. A session token is 32 CSPRNG bytes as lowercase hex (64 characters); only `sha256(token)` is stored. SHA-256 is a small in-repo implementation (`server/crypto.nim`, FIPS known-answer tested) because the pinned Nim stdlib has no SHA-2 and this adds no dependency. The cookie is `fff_session` (6.6).
- **`fff-vtt gm-key` wiring [FIXED (owner-delegated, 2026-11-14, #17)].** `fff-vtt gm-key [--new] [config flags]` opens (and migrates) the DB with the normal config keys, creates the GM (role `gm`, name `GM`) when absent, and prints one line `GM key: <key>`; re-runs print the same key. `--new` rotates, revokes all GM sessions, and prints `GM key (new): <key>`. The server holds an exclusive `fcntl(F_SETLK)` write lock on `<stateDir>/instance.lock` for its lifetime (also refusing a second server); `--new` tries the same lock and exits **3** without touching the DB while it is held. The read-only print takes no lock and works while the server runs. Other exit codes: 0 ok, 1 DB/state-dir error, 2 config error.
- **Application close codes at the mummy pin [OPEN, found in #17].** Mummy 0.4.8 exposes only `close(ws)`, which sends an empty close frame (a browser reports **1005**); the app codes 4001/4002/4003 of 6.5 cannot be sent without patching or forking mummy. Slice 2 closes revoked and evicted connections this way and tests the close, not the code. Slice 3 (#18) must choose: accept 1005 and amend 6.5, or take the fork fallback (4.3).
- **Application close codes at the mummy pin [FIXED, owner decision #18, 2026-11-15: option A, accept 1005 plus a reason message].** Mummy 0.4.8 exposes only `close(ws)`, which sends an empty close frame (a browser reports **1005**), so the app codes of 6.5 cannot ride the close frame; mummy is not forked or patched for this. The server therefore sends one final application message, `closing {reason, code}` (6.1), immediately before every server-initiated close, and then closes. A client reads the reason from that last message and 1005 from the close event; the numeric `code` keeps the 6.5 table's mapping (`revoked` 4001, `evicted` 4002, `proto-mismatch` 4003, `malformed-flood` 1008). Slice 2's revocation and eviction paths already send it. Consequence: a server-initiated close is always two steps (message, then close), and the message is the last app frame that connection ever sees.
### 3.3 Tiles
- Browser asks `GET /tiles/<scene>/v<art_version>/<x>_<y>.png` (Nim path). Nim parses strictly (digits only, length-bounded, range-checked against scene size; malformed or out-of-range -> `404`), checks the session's explored grid (the explored-area logic of 5.1), and answers `200` with `X-Accel-Redirect: /_tiles/<scene>/v<art_version>/<x>_<y>.png`, or `403` if unexplored [FIXED, owner decision 2026-11-14, #7]. nginx serves the bytes from an `internal` location; direct hits on `/_tiles/` give 404 [MEASURED: `prototype-server-vision/results/smoke.log`, README "Phase 2a"].
@@ -214,7 +214,7 @@ Second limitation [INFERRED]: a fast drag sampled at ~50 ms can produce a straig
- Worker threads: prototype uses 8; one table needs 2-4 [INFERRED].
- **Slow client [FIXED (owner decision), 2026-11-08, Q13 option A]**. mummy's send queue is one unbounded deque and per-socket backlog is invisible to app code (no forced close, no depth API at this pin). No mummy patch. Research: `docs/research/q13-mummy-slow-clients.md`.
- **Bounded outbox per connection** (keyed by app `connId`), with byte and message caps. State messages (vision, token, explored, wall) are **latest-state-wins coalesced per key** (MQTT-retained-like). The diff against `known` is computed at **flush time**, not enqueue time, so a dropped intermediate state cannot desynchronise the client.
- **Ack by Ping/Pong**: server sends WS `Ping(seq)` (payload <= 125 B) on a timer; the client's Pong echoes `seq` (RFC 6455 §5.5.2-5.5.3; browsers answer without JS). Acks give bytes in flight and lag per connection.
- **Ack by Ping/Pong**: server sends WS `Ping(seq)` (payload <= 125 B) on a timer; the client's Pong echoes `seq` (RFC 6455 §5.5.2-5.5.3; browsers answer without JS). Acks give bytes in flight and lag per connection. Interval [FIXED (owner-delegated), #18]: every 20 s, plus one Ping immediately after `hello` on each connection. Slice 3 sends the Ping and records the Pong per connection (`Conn.pongSeq`, `Conn.lastPongMs`); the lag measurement itself, the stop-feeding rule and the forced close of a silent peer stay M5. A Ping/Pong is a control frame and carries no `n` (6).
- **Lagging client** (outbox over cap, or no Pong within a bound): stop feeding it, keep the connection. On recovery, full resync (6.3).
- **Dead or stuck peers**: closed by nginx proxy timeouts [PROPOSED mechanism; verify in M5 that `/ws` goes through nginx and which directive fires, `send_timeout` is the candidate]. `close(ws)` cannot force-close at this pin (it queues behind the backlog).
- Connection limits [FIXED (owner-delegated, 2026-11-14, #15)]: 4 connections per player (a 5th closes that player's oldest); 16 total (1 GM + 6 players x ~2 devices + headroom); the 17th is refused. Replaces the PROPOSED cap of 8. Enforced in `websocketHandler` (mummy's inbound queue is unbounded). Frame and intent limits: 6.4.
@@ -350,7 +350,7 @@ Notation: token centre `c`, radius `r` (entity `radius` if set, else scene `toke
Transport: one WebSocket per client at `/ws`, JSON text frames (a binary frame counts as malformed, 6.5). Envelope: `{t: string, ...fields}`; every server frame adds a per-connection counter `n` (starts at 1 on the connection's first frame; replaces the global `gseq` for everyone, section 3.1).
The whole of 6 is [FIXED (owner-delegated, 2026-11-14, #11)] unless a line says otherwise: the owner delegated the wire shapes and accepted the set. It is the complete M3 wire catalogue (29 intents, 14 server messages); nothing outside it exists in M3.
The whole of 6 is [FIXED (owner-delegated, 2026-11-14, #11)] unless a line says otherwise: the owner delegated the wire shapes and accepted the set. It is the complete M3 wire catalogue (29 intents, 15 server messages); nothing outside it exists in M3.
Conventions:
- **Naming.** Client -> server `t` is `<noun>.<verb>`: lowercase ASCII, exactly one dot. Nouns follow GLOSSARY.md: `token` (the map figure; the word "entity" never appears on the wire), `character`, `player`, `key` (a player key), `status`, `name`, `encountered`, plus `wall`, `door`, `scene`, `prop`, `conn`, `act`. Server -> client `t` is a bare state or event noun, snake_case, **no dot** (`token`, `token_gone`). A server `t` therefore never equals a client `t`.
@@ -360,6 +360,7 @@ Conventions:
- **Effects.** An intent's effects reach clients only as state messages, each built per recipient (3.1, 8) and sent only when that recipient's view changed (T11). "GM" below = every GM connection; "player X" = every connection of player X; "visible" = per the view rules in 3.1.
- **Roles.** Sender column: P = player, G = GM. A P-sender intent from a connection whose player has no name yet is refused `not-allowed`, except `conn.ping` and `player.setname`.
- **Not in M3:** `act.do` is reserved (v1 answers `no-rules`); server -> client `event` is reserved (9); GM `view.player` (7.3) is later; none is built in M3. Wire changes for M4/M5/M6 are limited to what 6.5 marks.
- **Slice-3 rollout note [FIXED (owner-delegated), #18].** The catalogue below is the contract; the handlers land slice by slice. Until a slice lands, its intents still get exactly one `ack` with the static code `unknown-type` and no state, so a half-built server never lies about having applied anything. Slice 3 builds the envelope, `hello`, `error`, `closing`, `conn.ping`, `act.do` (`no-rules`), and the three auth intents of slice 2 (`key.create`, `key.replace`, `player.remove`).
### 6.1 Catalogue
@@ -447,13 +448,14 @@ All are built per recipient at egress (single egress rule, 2). "Sent" always mea
| `character` | GM: `id, owner, descriptive_name, actual_name, reveal_all, revealed:[player ids], props:{public,owner,gm}`. Owner (P): `id, descriptive_name, actual_name, props:{public,owner}`; the owner is never sent `reveal_all` or `revealed` | GM: every character; player: only the characters they own. No other player ever gets a character record (no browsable list, T16) |
| `character_gone` | `id` | GM; and the previous owner on reassign |
| `encountered` | `full:bool, set:[{id:<token id>, name, grey:bool}], del:[id]`; `full:true` replaces the whole list (on connect, resync); (GM) adds `player:<id>` | player: own list only; GM: one message per player and list. `name` = the name that recipient's player knows (8); `grey` = no longer in that player's view ("met before, whereabouts unknown"); no position, no `character_id` for players |
| `closing` | `reason` (one of the static strings of 6.5: `revoked`, `evicted`, `proto-mismatch`, `malformed-flood`) and `code` (the 6.5 close code: 4001, 4002, 4003, 1008) | sender connection only; the last frame a server-initiated close sends, immediately before the close frame (FIXED #18, 6.5). No other frame follows it |
Count: 14 server messages. Reserved, not built: `event` (9).
Count: 15 server messages. Reserved, not built: `event` (9).
Leak notes (R5 review, #11): (1) `kind` is GM-only because a value like `npc` would tell a player what a visible token is; the client names tokens from `name` and `props`. (2) `character_id` goes only to the character's owner and the GM; showing it to others would link two tokens of one character and mark a token as "a character, not a monster". (3) `cprops` is public bucket only and always present (even empty) for non-owners so presence does not mark a token as character-linked. (4) The roster omits unnamed players for players so an unused key (or the number of keys) is not visible. (5) `hello` carries `vision_radius_default` so the client can respect the step cap (5.5); it states a distance only, no wall fact. (6) `statuses[].source` goes to the GM only (amends #4, 2026-11-14): viewers see the status, not its cause, so a player does not learn that a wall or GM action caused it. Open: a `walls`-sourced status still tells a viewer that some blocking wall touches the token; #4 argued LOS covers that, owner to confirm. (7) `encountered.grey` flipping and `token`/`token_gone` carry the same fact (the token left view), so deletion and moving away look identical to the player.
### 6.2 Versioning [PROPOSED]
- `proto` is an integer compiled into both client and server; M3 ships `proto = 1`. The client announces it in the upgrade request (`/ws?proto=N`). Any mismatch, older or newer, is refused (6.5): the upgrade completes and the server closes with WS code 4003, because a browser `WebSocket` cannot read an HTTP status, only a close code. The client then shows "reload" (assets are content-hashed by Vite, so a reload fetches the matching client). `hello.proto` is checked again on receipt as a backstop.
- `proto` is an integer compiled into both client and server; M3 ships `proto = 1`. The client announces it in the upgrade request (`/ws?proto=N`), and the parameter is required: absent or not a plain integer is HTTP 400, no upgrade (6.5 row 3). Any mismatch, older or newer, is refused (6.5 row 5): the upgrade completes and the server sends `closing {reason:"proto-mismatch", code:4003}` and closes, because a browser `WebSocket` cannot read an HTTP status, only a close code (and the code itself cannot be sent at the mummy pin, 3.2). The client then shows "reload" (assets are content-hashed by Vite, so a reload fetches the matching client). No `hello` and no state are sent on a mismatch. `hello.proto` is checked again on receipt as a backstop.
- Within one proto version: additive only (new optional fields, new message types). The client ignores unknown server message types and unknown fields; the server ignores unknown fields in intents and answers an unknown `t` with `ack {ok:false, code:"unknown-type"}` (or `error {code:"malformed"}` if there is no `reqId`).
- Breaking change -> bump `proto`, document in `docs/` changelog.
@@ -468,7 +470,9 @@ Leak notes (R5 review, #11): (1) `kind` is GM-only because a value like `npc` wo
- Bytes [MEASURED, `results/concurrency-final1-server.log`]: monster move 145 B to a seeing player, 244 B to GM; player move: mover 3359-3653 B (worst 4.9 KB, dominated by the full `vision` polygon + `explored` diff), GM 145 B; door toggle 45 B (prototype `door` message; the M3 `wall` upsert is a little larger).
- v1 decisions [FIXED, Q16]: full vision polygon, integer px (halves the text size [INFERRED]), owner only, sent only on change; deltas/binary post-v1. Explored on connect as run-length rows, later diffs as cell lists [PROPOSED].
- Move rate [FIXED (owner-delegated, 2026-11-14, #15)]: client sends at most ~20 Hz while dragging (prototype 50 ms) plus a final position. Server: token bucket per connection, 30 intents/s sustained, burst 100, same for GM and players. Excess intents are refused with `ack {ok:false, code:"rate-limited"}`; no rollback: each intent is atomic (accepted ones stay, rejected ones are never applied); the connection stays open. Reconciling refused optimistic edits is client behaviour (M4).
- Max inbound WS message [FIXED (owner-delegated, 2026-11-14, #15)]: 64 KB = mummy 0.4.8 default `maxMessageLen` (inbound only, cumulative across fragments). Over the limit mummy closes TCP without a close frame (mummy.nim :658-660). No config; outbound unaffected.
- Max inbound WS message [FIXED (owner-delegated, 2026-11-14, #15)]: 64 KB = mummy 0.4.8 default `maxMessageLen` (inbound only, cumulative across fragments). The server passes it explicitly (`protocol.MaxInboundBytes`), so a mummy default change cannot move the limit silently. Over the limit mummy closes TCP without a close frame (mummy.nim :658-660). No config; outbound unaffected.
- Per-connection `n` counts **server frames only**, starting at 1 with `hello`; a Ping/Pong (4.3) is a control frame and does not consume a number. There is no global counter on the wire (H25).
- Server Ping [FIXED (owner-delegated), #18]: one immediately after `hello`, then one every 20 s on every connection (`protocol.PingIntervalMs`); payload = the sequence number the client echoes in its Pong. Sending, recording and the interval are slice 3; lag measurement and the stop-feeding rule are M5 (4.3).
### 6.5 Refusals, errors and connection outcomes [FIXED (owner-delegated, 2026-11-14, #11)]
@@ -516,7 +520,11 @@ Player name text: trimmed, NFC, 1 to 32 code points, no control characters. Char
| 9 | inbound message over 64 KB, bad opcode/rsv, unmasked or oversized control frame | mummy closes TCP with **no close frame** (client sees 1006); not catchable by app code | open |
| 10 | server shutdown (SIGTERM) | WS **1001** (going away) [M5, 4.4 handler] | M5 |
WS close reasons are the static strings in bold above. Close codes 4001-4003 are the app's range; 1008 and 1001 are the RFC 6455 standard codes. Lagging clients (M5, 4.3) get no close and no frame: they are not fed until resync, and nginx closes dead peers (M5). At the mummy 0.4.8 pin the application codes 4001-4003 cannot be sent: `close(ws)` emits an empty close frame (1005). Slice 2 closes on revocation and eviction without a code; the choice between accepting 1005 (amending this table) and the fork fallback is OPEN for slice 3 (3.2).
**How the outcome reaches the client [FIXED, owner decision #18, 2026-11-15: option A].** At the mummy 0.4.8 pin `close(ws)` emits an **empty** close frame, so a browser reports **1005** and none of the codes above can be sent; mummy is neither patched nor forked. Instead, every server-initiated close (rows 5-8) is sent as **two frames**: one final application message `closing {reason, code}` (6.1 `closing`), then the close frame. `reason` is the bold static string of the row; `code` is the row's numeric code (4001, 4002, 4003, 1008); `closing` also carries the connection's `n`. The client's rule: on 1005, the reason is the `reason` field of the last message it received. A close with no preceding `closing` is a transport failure (row 9 or a dead peer), not an application outcome. Rows 1-4 refuse before the upgrade, so they are plain HTTP statuses with no frame; row 10 (M5) is the same two-step shape with `reason:"server-shutdown"`, `code:1001`, and is not built yet.
Why not the alternatives: patching/forking mummy is fallback only (4.3), and a client-side heuristic on 1005 alone cannot tell eviction from revocation from a proto mismatch. Consequence for tests: every close assertion is "the last message is `closing` with this reason and code, then the close event reports 1005".
WS close reasons are the static strings in bold above. Close codes 4001-4003 are the app's range; 1008 and 1001 are the RFC 6455 standard codes. Lagging clients (M5, 4.3) get no close and no frame: they are not fed until resync, and nginx closes dead peers (M5).
### 6.6 HTTP surface in M3
- `POST /join` (the sign-in page; HTTP, not WS; 3.2). Body `application/x-www-form-urlencoded`, one field `key`, at most 1 KB (the server answers `400` above that; mummy closes far above it). Key comparison ignores case, dashes and spaces and is constant-time. Valid key (player or GM): `303` to `/` with `Set-Cookie: fff_session=<random>; HttpOnly; Secure; SameSite=Strict; Path=/` and `Referrer-Policy: no-referrer`; the session token is a fresh 32-byte hex value and only its SHA-256 is stored (3.2). Invalid key: `401`, no body detail, no cookie. Wrong method `405`; missing `key` or wrong content type `400`. No rate limit (owner, #6). The body is never logged (T6). Cookie name `fff_session` [FIXED (owner-delegated, 2026-11-14, #17)].
@@ -639,7 +647,7 @@ Principles carried from the prototype: the checker must be independent of the co
- **Characters and names (#14)**: tests for reveal per player and reveal to all; owner sees own actual name; character owner change leaves token controllers unchanged; encountered entries survive token removal and scene change and are removed only by the GM; `gm_only` tokens never enter an encountered list. Fault classes: `ACTUAL_NAME` = unrevealed actual name sent to a player; `CHAR_LIST` = another player's character or encountered entry sent; `CONTROLLER_CHANGE` = owner change altering controllers; `CHAR_OWNER_PROP` = character owner-bucket prop sent to a non-owner.
- **Probing test (T8)**: M2, in-process against the move-rules module (5.5): arbitrary far moves; assertion: facts about walls/doors beyond LOS recoverable from replies <= a bounded amount (step cap), and uniform nack shape. M3: same test over WS with a hostile client (moved from M2).
- **Auth tests**: key replace (old key invalid, sessions revoked, live connections closed), remove player (key invalid, characters and tokens pass to GM), one key reused on several devices (Q10 FIXED), Origin mismatch rejected, cookie flags present.
- **Protocol tests**: proto mismatch, unknown message type both directions, oversized frame, malformed JSON flood, rate limit.
- **Protocol tests** (#18, `tools/protocol.test.mjs`): proto missing/non-integer (HTTP 400) and mismatch (`closing` 4003, no `hello`); unknown intent type (`unknown-type`) with unknown fields ignored; exactly one `ack` per `reqId` (reqId 0 and 2^31-1 included); `hello` first with `n = 1` and a per-connection `n` thereafter; `error malformed` for unreadable frames; the malformed flood (nine tolerated, the tenth closes 1008); the intent bucket (burst then `rate-limited`, connection stays open, a refused intent applies nothing, `error rate-limited` for an unreadable frame on an empty bucket); the 64 KB inbound boundary (exactly 64 KB is a message, 64 KB + 1 drops the TCP connection with no close frame); unmasked and bad-opcode frames; the server Ping and the Pong answer to a client Ping; the connection cap (503 + `Retry-After: 5`); and every server-initiated close as `closing` then 1005.
- **Persistence**: migration tests (old DB -> new), chunked explored round trip, restart test extended to wall CRUD and entity props.
- **Slow client** (Q13, 4.3): a client that stops reading; outbox stays under cap, no further state is queued to it, RSS flat, full resync on recovery equals a fresh connection; nginx closes the dead `/ws` socket within its configured timeout.
- **Browser e2e (new, none in prototype)**: headless Chromium via playwright-core (the perf prototype already drives devbox chromium, `prototype-pixi-perf/bench.mjs`; SwiftShader is fine for correctness, not for perf). Checks: join -> canvas renders; pixel probe shows unexplored area black, visible area map-coloured, dimmed explored area; GM sees walls, player DOM/network contains none; reconnect restores view; drag moves token and rollback works.
@@ -742,7 +750,7 @@ Each is small, ends with a green gate, and no milestone depends on browser UI be
- Scope: scanline `cellsTouched`, differential + independent explored oracle tests, radius-bbox wall cull (spatial grid only if the 5k bench misses), capsule/swept move check and token-on-wall escape (5.5), step cap = effective vision radius (5.5), `blocked` flag with circle-overlap trigger and Set/Keep/Clear policy (5.5), GM moves ignore walls and step cap (and set/clear `blocked`), bench harness incl. 5k-wall scene, pure in-process move-rules module with unit tests. The WS/hostile-client harness is M3, not M2.
- Accept: `visibilityPolygon` and `cellsTouched` equal the old implementation on the corpus (5.5); `moveBlocked` excluded (its results change on purpose); polygon+cells bench <= prototype (0.451 ms) on the prototype scene and polygon < 1 ms on the 5k-wall scene [targets PROPOSED]; in-process probing test passes; escape and capsule positive and negative unit tests pass; door-push tests pass (each side, centre on the line uses the previous side, other-side fallback for a blocking wall and for out of bounds, both invalid -> blocked and opening frees it, GM-owned token pushed, wall add still sticks); `blocked` tests pass (every Set/Keep/Clear rule of 5.5: overlap trigger, doorway, two overlapping walls, GM drop/move sets and clears, GM clear then escape, unrelated change does not re-block); mutations k (no Keep), l (GM moves do not set blocked), m (push to the wrong side), n (push skips the validity check) and o (previous side ignored) each fail >= 1 test; over-cap move gives the same nack as a blocked move; thresholds documented in the module header; oracle tolerance 0.5 px. The KNOWN LIMITATION test and the Q14 pin test are replaced with positive assertions and `blocked`-policy tests.
- **M3 - Server core.**
- Scope: entities with bucketed props, characters with names, name reveal and encountered list (8, #14), players, player keys/sessions, scenes, chunked explored persistence, typed per-recipient views and single egress, per-connection counters, proto versioning, the wire catalogue of 6 (29 intents, 14 server messages), wall/token/character CRUD intents, Origin check, plaintext player keys and non-expiring sessions (Q10, Q11), SQLite schema + migrations. Tile gate `/tiles/` (3.3), fixture tiles at 32 px generated at test time by a helper (not committed), minimal local test nginx with internal `/_tiles/` (production vhost and tile import CLI stay M6) [FIXED, owner decision 2026-11-14, #7]. Black-box harnesses ported to `tools/` on Node 26; `devbox run test` runs Nim then Node (10.4) [FIXED, owner decision 2026-11-14, #9].
- Scope: entities with bucketed props, characters with names, name reveal and encountered list (8, #14), players, player keys/sessions, scenes, chunked explored persistence, typed per-recipient views and single egress, per-connection counters, proto versioning, the wire catalogue of 6 (29 intents, 15 server messages), wall/token/character CRUD intents, Origin check, plaintext player keys and non-expiring sessions (Q10, Q11), SQLite schema + migrations. Tile gate `/tiles/` (3.3), fixture tiles at 32 px generated at test time by a helper (not committed), minimal local test nginx with internal `/_tiles/` (production vhost and tile import CLI stay M6) [FIXED, owner decision 2026-11-14, #7]. Black-box harnesses ported to `tools/` on Node 26; `devbox run test` runs Nim then Node (10.4) [FIXED, owner decision 2026-11-14, #9].
- Accept: `devbox run test` green on a clean checkout, and that run includes the nine named groups below; details live at the § refs, not here. Out of M3 accept: concurrency (M5), 127.0.0.1 bind check (M6 deploy) [FIXED, owner decision 2026-11-14, #12].
1. **leak+fault**: ported leak test A and B; fault test catches every class with exact class sets, incl. characters and names; clean build passes (10.1, 10.3).
2. **tiles**: Tile gate: leak test (d) and smoke tile-steal checks pass through the test nginx; gate decisions match the independent explored oracle (10.2); direct `/_tiles/` fetch -> 404; malformed or out-of-range path -> 404; unexplored -> 403 [FIXED, owner decision 2026-11-14, #7].
@@ -815,10 +823,12 @@ Owner also decided 2026-11-14 [FIXED (owner decision), #12]: what M3 done means.
Owner also decided 2026-11-14 [FIXED (owner-delegated, 2026-11-14, #15)]: M3 limits. The owner delegated the numbers to the agent and accepted the set. Max inbound WS message 64 KB (mummy default; inbound only; no config). Intent rate: token bucket per connection, 30/s sustained, burst 100, same for GM and players; excess refused with `rate limited`, no rollback (each intent atomic), connection stays open. Connections: 4 per player (a 5th closes the oldest), 16 total (the 17th is refused); replaces the PROPOSED cap of 8. Consequence: the M5 concurrency port spreads load across connections (10.1). See 4.3, 6.4, 10.1, 13.
Owner also decided 2026-11-14 [FIXED (owner-delegated, 2026-11-14, #11)]: M3 message list. The owner delegated the wire shapes; the set is the complete M3 catalogue in 6 (29 client intents, 14 server messages). Client `t` is `<noun>.<verb>` (GLOSSARY nouns: `token`, never "entity"), server `t` is a dotless state noun, so they never collide. Every intent carries `reqId` and gets exactly one `ack` (`ok`, new `id`, `pos` for moves); a refused player move stays the uniform nack (old position, no code), every other refusal has a static code (`rate-limited`, `not-allowed`, `not-found`, `invalid`, `name-taken`, `cap-reached`, `in-use`, `no-rules`, `unknown-type`); frames without a readable `reqId` get `error` (`malformed`, `rate-limited`). `invite.*`, `gmClearBlocked` and `blocked` are retired: `key.*`/`player.*` for player keys and players, `status.set`/`status.clear` and `token.resize` for #4. Connection outcomes: HTTP 403 (Origin), 401 (no session), 400, 503 (17th connection); WS close 4001 revoked, 4002 evicted (5th connection), 4003 proto mismatch, 1008 malformed flood; oversize closes TCP with no frame. `POST /join` is HTTP (6.6). Server `door` is folded into `wall`; `presence` into `roster`; `pong` into the ping `ack`. See 3.1, 3.2, 3.4, 4.2, 4.3, 5.5, 5.6, 6, 7.5, 13.
Owner also decided 2026-11-14 [FIXED (owner-delegated, 2026-11-14, #11)]: M3 message list. The owner delegated the wire shapes; the set is the complete M3 catalogue in 6 (29 client intents, 14 server messages, 15 with #18's `closing`). Client `t` is `<noun>.<verb>` (GLOSSARY nouns: `token`, never "entity"), server `t` is a dotless state noun, so they never collide. Every intent carries `reqId` and gets exactly one `ack` (`ok`, new `id`, `pos` for moves); a refused player move stays the uniform nack (old position, no code), every other refusal has a static code (`rate-limited`, `not-allowed`, `not-found`, `invalid`, `name-taken`, `cap-reached`, `in-use`, `no-rules`, `unknown-type`); frames without a readable `reqId` get `error` (`malformed`, `rate-limited`). `invite.*`, `gmClearBlocked` and `blocked` are retired: `key.*`/`player.*` for player keys and players, `status.set`/`status.clear` and `token.resize` for #4. Connection outcomes: HTTP 403 (Origin), 401 (no session), 400, 503 (17th connection); WS close 4001 revoked, 4002 evicted (5th connection), 4003 proto mismatch, 1008 malformed flood; oversize closes TCP with no frame. `POST /join` is HTTP (6.6). Server `door` is folded into `wall`; `presence` into `roster`; `pong` into the ping `ack`. See 3.1, 3.2, 3.4, 4.2, 4.3, 5.5, 5.6, 6, 7.5, 13.
Owner also decided 2026-11-14 (review of #11 flags) [FIXED (owner decision)]: (1) players cannot create or edit characters or props in v1 (GM only); opening that later is a permission change on the existing intents, not a redesign (1). (2) A revealed name cannot be un-revealed: no un-reveal intent (8, 6.1). (3) `character.remove` is refused with `in-use` while tokens link the character (6.1, 6.5). (4) Encountered stays encountered: a `gm_only` flip leaves the entry, greyed (8, 6.1). (5) Status markers do not reveal their cause to non-GM viewers: `statuses[].source` goes to the GM only (3.1, 5.5, 6.1; amends #4). The controlling owner is not given `source` either, as the doc has no owner-view rule for statuses; revisit if wanted.
Owner also decided 2026-11-14 [FIXED (owner-delegated, 2026-11-14, #17)]: M3 slice 2 ("getting in"). Storage is migration step 2 (`auth`): `player`, `player_key`, `session`, a single-GM partial unique index, cascading deletes (4.4). Players/keys/sessions: 3.2 and 8. Cookie `fff_session`, `POST /join` as in 6.6. `fff-vtt gm-key [--new]` and the `<stateDir>/instance.lock` fcntl lock with exit 3 are recorded in 3.2/11.1. Slice 2 implements only the three GM intents auth needs (`key.create`, `key.replace`, `player.remove`) with the 6.1 ack shape; the rest of the envelope, error frames, rate limits and unknown-type answers stay slice 3 (#18). The application close codes of 6.5 are not expressible at the mummy pin (3.2); slice 3 decides. See 3.2, 4.4, 6.5, 6.6, 8, 11.1, 13.
Owner also decided 2026-11-15 [FIXED (owner decision), #18]: close codes at the mummy pin, option A. Mummy 0.4.8 cannot send an application close code (`close(ws)` -> an empty close frame -> the browser sees 1005); mummy is not forked or patched for it. Every server-initiated close is preceded by exactly one `closing {reason, code}` message carrying the reason of 6.5, then the close frame; a client treats 1005 plus that last message as the reason. `closing` is a catalogue message (server -> client, dotless noun) and the catalogue count is 15. Slice 2's eviction and revocation paths send it. Also recorded FIXED here: the server Ping interval (20 s, plus one right after `hello`; lag enforcement stays M5), the per-connection `n` rule (server frames only, no number for Ping/Pong, no global counter), the own `maxMessageLen` (64 KB) rather than mummy's default, and the slice-3 rollout note that catalogue intents whose slice has not landed answer `unknown-type`. See 3.2, 4.3, 6, 6.1, 6.2, 6.4, 6.5, 10.3.
Owner also decided 2026-11-14 [FIXED (owner-delegated, 2026-11-14, #16)]: M3 slice 1 groundwork ("bare server"). Config keys, defaults, precedence and the canonical origin: 11.1. Migration history DDL, the agreement/contiguity rule and one-transaction-per-step: 4.4. Secret redaction (value registry plus sensitive field names, minimum secret length 8): 11.3. `GET /healthz` answers `200 {"status":"ok"}` from slice 1; the lock-bounded health check stays M5: 6.6, 11.3. `devbox run test` runs `nimble test` first and only then `node --test tools/*.test.mjs` (10.4); both logs land in `results/`. The server's listen address is the constant `config.BindAddress` = `127.0.0.1`, not a config key (T15). Dependencies: `fff_vtt.nimble` requires `mummy == 0.4.8` and `db_connector == 0.1.0`; devbox adds nodejs 26 and sqlite (`out`+`bin`, with `LD_LIBRARY_PATH=$DEVBOX_PACKAGES_DIR/lib` for the dlopen). Node 26 `{headers}` re-check: 10.4.