name.reveal writes the actual name into every player's encountered row #27

Closed
opened 2026-11-15 13:18:29 +01:00 by SirStone · 1 comment
Owner

Summary

name.reveal reveals a subject's actual name to one player, but its SQLite snapshot write updates the encountered row of every player who has met that subject. The in-memory snapshot update is correctly per player, so the bug is invisible until a restart reloads encountered from disk. Afterwards every other player's encountered list carries the subject's actual name, which they were never given: the descriptive name / actual name split and the encountered-list rule ("under the name that player knows") both break.

Where

  • server/main.nim:1667-1669 — the reveal path calls revealEncountered / revealEncounteredToken with no player id.
  • server/characters.nim:282-286 — UPDATE encountered SET actual_name = ? WHERE character_id = ? and ... WHERE entity_id = ?: the row is selected by subject only, never by player.
  • server/main.nim:1670-1674 — the in-memory path, which is correctly keyed by player. The two paths disagree, and the leaking one persists.
  • server/main.nim:1682+ — name.reveal_all shares the same helpers, so the fix must keep its all-players semantics.

Failure scenario

Reproduced on the real binary: Bob's encountered list shows "a cloaked figure". The GM runs name.reveal for Alice only. Both live views are correct (Alice: "Lady Vex", Bob: "a cloaked figure"). After a server restart, Bob's encountered entry reads "Lady Vex". Restarting again does not undo it. Bob never triggered anything; the leak is persistent and silent.

Missed by tests because tools/leakcheck.nim only inspects the live transcript, and the restart group has a single named player, so no second encountered list exists to be wrong.

Confidence

High — reproduces deterministically on the real binary; the SQL has no player predicate.

Fix direction

The persisted reveal must be scoped to the revealing player: the encountered write takes the player id as well as the subject, or the DB update is derived from the already-correct in-memory per-player snapshot instead of recomputing from the subject alone. Keep a separate all-players write for name.reveal_all so neither call silently inherits the other's scope.

Acceptance

  • After name.reveal to one player and a restart, that player's encountered entry shows the actual name and every other player's entry still shows the descriptive name.
  • name.reveal_all still reveals to every player who has an entry, before and after a restart.
  • With three players who have met the same token, exactly one encountered row changes (asserted directly against the DB, and via restart).
  • Regression test: extend tools/restart.test.mjs (and the leak-test restart group) so at least two named players meet the same character or plain token, one player is revealed to, then the server restarts and both players' encountered lists are compared. Extend tools/leakcheck.nim so a restart group with more than one player compares each subject's encountered names against truth.

Related

  • #23 (slice 8: characters and names), where reveal landed.
  • #2 (M3 planning map).
## Summary `name.reveal` reveals a subject's actual name to **one** player, but its SQLite snapshot write updates the `encountered` row of **every** player who has met that subject. The in-memory snapshot update is correctly per player, so the bug is invisible until a restart reloads `encountered` from disk. Afterwards every other player's encountered list carries the subject's actual name, which they were never given: the descriptive name / actual name split and the encountered-list rule ("under the name that player knows") both break. ## Where - `server/main.nim:1667-1669` — the reveal path calls `revealEncountered` / `revealEncounteredToken` with no player id. - `server/characters.nim:282-286` — `UPDATE encountered SET actual_name = ? WHERE character_id = ?` and `... WHERE entity_id = ?`: the row is selected by subject only, never by player. - `server/main.nim:1670-1674` — the in-memory path, which *is* correctly keyed by `player`. The two paths disagree, and the leaking one persists. - `server/main.nim:1682+` — `name.reveal_all` shares the same helpers, so the fix must keep its all-players semantics. ## Failure scenario Reproduced on the real binary: Bob's encountered list shows "a cloaked figure". The GM runs `name.reveal` for Alice only. Both live views are correct (Alice: "Lady Vex", Bob: "a cloaked figure"). After a server restart, Bob's encountered entry reads "Lady Vex". Restarting again does not undo it. Bob never triggered anything; the leak is persistent and silent. Missed by tests because `tools/leakcheck.nim` only inspects the live transcript, and the restart group has a single named player, so no second encountered list exists to be wrong. ## Confidence High — reproduces deterministically on the real binary; the SQL has no player predicate. ## Fix direction The persisted reveal must be scoped to the revealing player: the encountered write takes the player id as well as the subject, or the DB update is derived from the already-correct in-memory per-player snapshot instead of recomputing from the subject alone. Keep a separate all-players write for `name.reveal_all` so neither call silently inherits the other's scope. ## Acceptance - After `name.reveal` to one player and a restart, that player's encountered entry shows the actual name and every other player's entry still shows the descriptive name. - `name.reveal_all` still reveals to every player who has an entry, before and after a restart. - With three players who have met the same token, exactly one `encountered` row changes (asserted directly against the DB, and via restart). - Regression test: extend `tools/restart.test.mjs` (and the leak-test restart group) so at least two named players meet the same character or plain token, one player is revealed to, then the server restarts and both players' encountered lists are compared. Extend `tools/leakcheck.nim` so a restart group with more than one player compares each subject's encountered names against truth. ## Related - #23 (slice 8: characters and names), where reveal landed. - #2 (M3 planning map).
SirStone added the ready-for-agent label 2026-11-15 13:18:29 +01:00
Author
Owner

Fixed and pushed on main.

Fix — server/characters.nim: rewriteEncountered is now the single path that keeps an encountered snapshot in step with its subject. It takes the subject's SubjectNames plus the reveal set, applies the 8 name rule per player, and rewrites the SQLite row and the in-memory entry together; onlyPlayer scopes the whole rewrite, so name.reveal writes exactly one player's row and name.reveal_all every player's. server/main.nim: name.reveal calls it with onlyPlayer = player inside one lock hold; name.reveal_all keeps all-players scope. The old subject-only revealEncountered* SQL is gone.

Regression test (red -> green) — tools/restart.test.mjs now builds three named players who all meet the same monster and the same character-linked token, reveals the character's actual name to Alice only and the monster's to Bob only, and asserts directly against the DB while the server runs:

AssertionError: 'Grib' !== ''   // Alice's encountered row for the monster, OLD code

After the fix the three rows are bob=Grib, alice='', carol='' (and the mirrored character case). Every player's whole 6.3 resync is then compared over SIGTERM and SIGKILL against both the pre-restart value and an independent expected-name oracle, so a leak cannot hide behind two equally wrong snapshots. tools/leakcheck.nim gained STALE_NAME (an entry must carry the name that player knows) and tools/leak.mjs now walks a second player into the room so two encountered lists are checked per transcript.

Commits — 8e045b0 names: per-player reveal, one encountered write path, link by update (#27, #29, #30); b4bddf1 design: record the #27-#31 rules (6.1/4.3/10.3/14); e13fa90 results: rerun the gates.

Gates — devbox run test: all Nim suites + 107 node tests pass. devbox run mutation: exit 0, control and every mutation pass (new e1 pins the per-player knowledge scope, e2 the live snapshot write, plus repointed b2).

Fixed and pushed on `main`. **Fix** — `server/characters.nim`: `rewriteEncountered` is now the single path that keeps an `encountered` snapshot in step with its subject. It takes the subject's `SubjectNames` plus the reveal set, applies the 8 name rule per player, and rewrites the SQLite row **and** the in-memory entry together; `onlyPlayer` scopes the whole rewrite, so `name.reveal` writes exactly one player's row and `name.reveal_all` every player's. `server/main.nim`: `name.reveal` calls it with `onlyPlayer = player` inside one lock hold; `name.reveal_all` keeps all-players scope. The old subject-only `revealEncountered*` SQL is gone. **Regression test (red -> green)** — `tools/restart.test.mjs` now builds **three named players** who all meet the same monster and the same character-linked token, reveals the character's actual name to Alice only and the monster's to Bob only, and asserts directly against the DB while the server runs: ``` AssertionError: 'Grib' !== '' // Alice's encountered row for the monster, OLD code ``` After the fix the three rows are `bob=Grib`, `alice=''`, `carol=''` (and the mirrored character case). Every player's whole 6.3 resync is then compared over SIGTERM and SIGKILL against both the pre-restart value and an independent expected-name oracle, so a leak cannot hide behind two equally wrong snapshots. `tools/leakcheck.nim` gained `STALE_NAME` (an entry must carry the name that player knows) and `tools/leak.mjs` now walks a second player into the room so two encountered lists are checked per transcript. **Commits** — `8e045b0` names: per-player reveal, one encountered write path, link by update (#27, #29, #30); `b4bddf1` design: record the #27-#31 rules (6.1/4.3/10.3/14); `e13fa90` results: rerun the gates. **Gates** — `devbox run test`: all Nim suites + 107 node tests pass. `devbox run mutation`: exit 0, control and every mutation pass (new `e1` pins the per-player knowledge scope, `e2` the live snapshot write, plus repointed `b2`).
Sign in to join this conversation.