design: record slice 1 decisions (#16)
This commit is contained in:
+9
-5
@@ -49,7 +49,7 @@ A browser virtual tabletop for one table (1 GM + up to 6 players [FIXED, Q1]), s
|
||||
- Client: TypeScript + PixiJS v8 + Vite; plain HTML/DOM overlay for UI (no UI framework). Agents use the official pixijs-skills (already in `.agents/skills/pixijs*`).
|
||||
- Server: Nim 2.x; `mummy` pinned to tag `0.4.8` (commit `77a7563e`; `src/` identical to the former pin `01deb1ff694988635c7bf0f24f6088a0bdf6db5d`) [FIXED (owner decision), 2026-11-08; tags 0.4.6-0.4.8 exist]. `prototype-server-vision/servervision.nimble` still pins the commit until ported; `db_connector/db_sqlite`, WAL. No Nim in the browser.
|
||||
- nginx (existing, HTTPS) in front: static client, reverse proxy for `/ws`, `/join`, `/tiles/`; internal location for tile bytes.
|
||||
- Dev env: NixOS, devbox per project for toolchains, nothing global. Node 26 (devbox) runs the black-box test harnesses only; in-process tests stay Nim [FIXED, owner decision 2026-11-14, #9] (10.4).
|
||||
- Dev env: NixOS, devbox per project for toolchains, nothing global. Node 26 (devbox) runs the black-box test harnesses only; in-process tests stay Nim [FIXED, owner decision 2026-11-14, #9] (10.4). devbox also carries `sqlite` (output `out` + `bin`): `db_connector` dlopens `libsqlite3.so`, so the devbox env sets `LD_LIBRARY_PATH=$DEVBOX_PACKAGES_DIR/lib`.
|
||||
|
||||
### Component diagram
|
||||
```
|
||||
@@ -222,7 +222,7 @@ Second limitation [INFERRED]: a fast drag sampled at ~50 ms can produce a straig
|
||||
- 583 ms intent->ack outlier: **not reproduced**, cause undetermined (host stall or node harness pause; not proven either way, `results/spike/investigation.md`). Production logging (section 11) must make a recurrence diagnosable (SLOW lines with breakdown).
|
||||
|
||||
### 4.4 Persistence
|
||||
Engine: SQLite via `db_connector/db_sqlite`, `journal_mode=WAL`, one connection used under the global lock.
|
||||
Engine: SQLite via `db_connector/db_sqlite`, `journal_mode=WAL`, one connection used under the global lock. Also `busy_timeout=5000` and `foreign_keys=ON` at open [FIXED (owner-delegated, 2026-11-14, #16)].
|
||||
|
||||
**synchronous choice [FIXED, Q12]: `NORMAL`; `FULL` around GM authoring transactions.**
|
||||
- [MEASURED] avg commit 0.60 -> 0.17 ms, server total avg 1.16 -> 0.74 ms; tail unchanged (~20 ms worst) (`results/spike/investigation.md`).
|
||||
@@ -253,7 +253,7 @@ explored_chunk(player_id, scene_id, cx, cy, bits BLOB, PRIMARY KEY(player_id, sc
|
||||
- Exactly one scene in v1 (Q3): `scene_id` keys stay in the schema.
|
||||
- Prototype stores one row per explored cell (`exp(role, c)`, one INSERT per new cell, `HANDOFF.md`); real build stores **chunked bitmaps**: a chunk is e.g. 64x64 cells = 512 B; dirty chunks upserted per mutation [PROPOSED]. Sizes [INFERRED]: 4096 px map / 32 px cell = 16 384 cells = 2 KB bitmap; 16384 px map = 262 144 cells = 32 KB.
|
||||
- Entity move = one UPSERT of x,y (prototype: `INSERT OR REPLACE INTO tok`).
|
||||
- Migrations: `PRAGMA user_version` + forward-only migration list; startup refuses to run on a newer DB [PROPOSED].
|
||||
- Migrations: `PRAGMA user_version` + forward-only migration list; startup refuses to run on a newer DB [PROPOSED]. Detail [FIXED (owner-delegated, 2026-11-14, #16)]: `schema_migration(version INTEGER PRIMARY KEY, name TEXT NOT NULL, applied_at TEXT NOT NULL)` is the history; `user_version` carries the same latest version, and startup refuses when the two disagree or the history is not contiguous from 1. One transaction per step (DDL + history row + `user_version`); a failing step rolls back completely, and an up-to-date DB is not written at all (re-open is a no-op). Step 1 (M3 slice 1) creates `meta(k TEXT PRIMARY KEY, v TEXT NOT NULL)`.
|
||||
- Startup: load everything into memory, recompute vision for all players (prototype does, in one transaction) so `vision` is never stale vs walls.
|
||||
- Shutdown: install a SIGTERM handler [prototype has only SIGINT, `HANDOFF.md`]: stop accepting, close sockets, final `wal_checkpoint(TRUNCATE)`, exit. Durability does not depend on it (WAL commit before ack).
|
||||
|
||||
@@ -519,7 +519,7 @@ WS close reasons are the static strings in bold above. Close codes 4001-4003 are
|
||||
- `POST /join` (the sign-in page; HTTP, not WS; 3.2). Body `application/x-www-form-urlencoded`, one field `key`, at most 1 KB (mummy closes the connection above its limit). 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=/` [name PROPOSED]. 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).
|
||||
- `GET /ws`: 6.5 (rows 1-4).
|
||||
- `GET /tiles/<scene>/v<art_version>/<x>_<y>.png`: 3.3 (`200` with `X-Accel-Redirect`, `403` unexplored, `404` malformed/out of range).
|
||||
- `GET /healthz`: M5 (11.3).
|
||||
- `GET /healthz`: 200 `{"status":"ok"}` from M3 slice 1 [FIXED (owner-delegated, 2026-11-14, #16)]; M5 makes it report whether the global lock can be acquired within a bound (11.3).
|
||||
|
||||
---
|
||||
|
||||
@@ -647,7 +647,7 @@ Principles carried from the prototype: the checker must be independent of the co
|
||||
|
||||
### 10.4 Test tools [FIXED, owner decision 2026-11-14, #9]
|
||||
- Black-box (outside) WS/HTTP harnesses: Node 26 only, repo-root `tools/`, ported from `prototype-server-vision/tools/` (`smoke.mjs`, `leak.mjs`, `restart.mjs`, `concurrency.mjs`, `lib.mjs`, `withserver.sh` incl. the M3 test nginx). No Nim rewrite. Reason: Node is already required for the client (Vite/TS, playwright-core e2e, reducer tests); a harness in another language from the server cannot share its protocol bugs; zero deps; already measured. Fix the stale "Node 22" note in `lib.mjs` on port.
|
||||
- Harness tooling: built-ins only, no npm deps. Global `WebSocket` with `{headers}` for Cookie/Origin; `node:net` for raw and malformed frames (oversize, bad opcode/rsv, unmasked, flood); `node:test` as runner. Node 26 header behaviour is not yet verified (#8 verified v24 only): the first harness re-verifies it.
|
||||
- Harness tooling: built-ins only, no npm deps. Global `WebSocket` with `{headers}` for Cookie/Origin; `node:net` for raw and malformed frames (oversize, bad opcode/rsv, unmasked, flood); `node:test` as runner. Node 26 header behaviour [MEASURED, 2026-11-14, #16, node v26.11.1]: `{headers}` still puts `Cookie` and `Origin` on the wire, and without `{headers}` no `Origin` is sent; pinned by `tools/wsheaders.test.mjs` so a Node upgrade that drops the option fails loudly (#8 had verified v24 only; the prototype's "Node 22" note is stale).
|
||||
- Root `devbox.json` pins `nodejs` 26 (port step).
|
||||
- `devbox run test` = Nim tests first, then Node harnesses.
|
||||
- In-process tests stay Nim (`nimble test`, unchanged).
|
||||
@@ -659,6 +659,7 @@ Principles carried from the prototype: the checker must be independent of the co
|
||||
|
||||
### 11.1 Deployment on NixOS [PROPOSED]
|
||||
- **Service** [FIXED, Q20; research: `docs/research/q20-nix-packaging.md`]: NixOS module `services.fffVtt` in `nix/module.nix`, defining: package from `nix/package.nix` (`buildNimPackage`; dependencies from committed `nix/lock.json` generated by `nim_lk`; mummy tag `0.4.8`; nixpkgs input pinned to match devbox Nim 2.2.12; fallback: vendored deps via `nimFlags --path:`), a systemd unit, state dir, options for `publicOrigin`, `port`. Imported from the owner's server NixOS config, like `foundryvtt.nix`.
|
||||
- Config keys [FIXED (owner-delegated, 2026-11-14, #16)]: `--public-origin` / `FFF_VTT_PUBLIC_ORIGIN`, `--port` / `FFF_VTT_PORT`, `--state-dir` / `FFF_VTT_STATE_DIR`. Flag wins over env wins over default; defaults `http://localhost:8080`, `9000`, `run`. The origin is canonicalised (lowercase scheme/host, no trailing slash) because it is compared byte for byte with the browser's `Origin` (3.2). The listen address is not a key: the binary always binds `127.0.0.1`.
|
||||
- Unit hardening: `DynamicUser` or dedicated user, `StateDirectory=fff-vtt`, `ProtectSystem=strict`, `ProtectHome`, `NoNewPrivileges`, `PrivateTmp`, `RestrictAddressFamilies=AF_INET AF_INET6`, `MemoryMax`. Add `AF_UNIX` only if the FFF sidecar (section 9, option b) is chosen; revisit at Q19. Listen on `127.0.0.1:<port>` only [MEASURED prototype binds 127.0.0.1].
|
||||
- `fff-vtt gm-key` (3.2) must run as the service user (e.g. `sudo -u <service user> fff-vtt gm-key`, or a wrapper in the module), so the DB and its WAL files stay owned by that user; with `DynamicUser` the module needs a fixed user name or a wrapper. [FIXED, owner-delegated, 2026-11-14, #13]
|
||||
- `Restart=on-failure`; `TimeoutStopSec` short; SIGTERM handler flushes (4.4).
|
||||
@@ -685,6 +686,7 @@ Principles carried from the prototype: the checker must be independent of the co
|
||||
- Real: under the lock only O(1) updates: a fixed-size ring buffer or fixed-bucket histogram per metric (lock_wait, vision, sqlite, send, total) and atomic counters (mutations, errors, nacks, connections, bytes). A separate timer thread (not holding the lock) snapshots and computes percentiles every N s and logs one line.
|
||||
- Keep the `SLOW` line (total > `SLOW_MS`, default 50) with breakdown `lock_wait / vision / sqlite / send / other` and intent type: it is what diagnosed the SQLite COMMIT tail [MEASURED, `results/spike/investigation.md`]. Formatting of the line happens after releasing the lock; at most O(1) rate-limited lines per second.
|
||||
- Log to stdout -> journald; levels; never log player key/session secrets, token positions of hidden entities are fine in server logs (server is trusted) but logs are GM-readable only (file perms).
|
||||
- Redaction mechanism [FIXED (owner-delegated, 2026-11-14, #16)]: the logger (`server/eventlog.nim`) keeps a registry of secret *values* (`addSecret`, refuses anything shorter than 8 chars) and replaces each occurrence with `[redacted]` on every line, wherever it appears; independently, a field whose *name* is in the sensitive set (`key`, `player_key`, `gm_key`, `secret`, `session`, `session_token`, `cookie`, `set-cookie`, `token_hash`, `authorization`) is masked even when its value was never registered. Call sites still must not pass secrets; the registry is the safety net behind them.
|
||||
- Metrics exposure: journald lines only in v1, no `/metrics` endpoint (Q22 FIXED).
|
||||
- Health: `GET /healthz` internal-only returning 200 when the lock can be acquired within a bound. `/healthz` stays (Q22 FIXED).
|
||||
|
||||
@@ -812,3 +814,5 @@ Owner also decided 2026-11-14 [FIXED (owner-delegated, 2026-11-14, #15)]: M3 lim
|
||||
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 (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, #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.
|
||||
|
||||
Reference in New Issue
Block a user