The durable write and registry update stay put; the ack is enqueued
between the commit and the first effect, then hello, the full resync and
roster follow in their existing order. The failure paths are unchanged.
Frame-order test pins ack first on the renaming connection.
A readable intent that fails in handling now always gets exactly one ack:
the new static internal code, unless the handler's own ack was already
enqueued. Both transaction helpers roll back on every unwind path,
Defect included, so the shared SQLite connection never keeps an open
transaction. Test-only dispfault build covers catchable/defect/after-ack;
DESIGN 6.5 records internal as an owner decision and 6.2 names refusal
codes as additive.
A wall cause change (endpoint move, thickness/position, player_marker off,
no longer window) committed the wall row in the FULL transaction while its
marker_seen deletes rode the later NORMAL derived-memory transaction. A crash
between them left the stale row, and restart restored the marker with the
anchor recomputed from the NEW geometry, revealing a position the player never
saw (DESIGN 5.8).
updateWall now deletes the affected rows in the same FULL transaction as the
replaced row, exactly as the composite FK cascade already does for wall.remove.
The live del frames are unchanged and marker inserts stay in the derived
transaction: wall+deletes commit, derived inserts, then ack.
The marker cause signature moves to world.markerSig so the write-time delete
and the online retraction cannot drift.
Proof: a leakfault-only markerCrash hook quits between the wall commit and
the derived write; tools/markers.test.mjs covers all four causes and restarts
on a clean build, asserting no marker for the changed wall (no new anchor) and
restoring the untouched window's marker as the positive control.
Ref #60
Retract a player marker when the GM removes the wall, clears
player_marker, makes the wall stop deriving window, or moves its
geometry (a/b, thickness, position). Retraction emits del only and
never the new anchor; a re-earned marker gets a fresh id. The
marker_seen deletes ride the same derived-memory NORMAL transaction as
the explored chunks, after the wall row commits and before the ack.
Replace the leak checker's aggregate MARKER class with MARKER_EARLY,
MARKER_EXTRA and MARKER_OFF, add their leakfault hooks and exact-class
fault tests, and extend the leak scenario with an unseen marked window
and a marked solid wall as the negative controls. WS black-box tests
cover all four causes, fresh re-earns, no untouched re-send, no
set/del for one id in a frame, no explored write from a retraction,
and delete/cascade durability across a restart.
A wall that is player_marker:true and derives window sends a player one
anchor (the drawn midpoint, integer px) and an opaque per-player 12-char id
once any point of its segment enters that player's vision polygon. Markers
live in PlayerVision like explored, persist to marker_seen in the same
derived-memory transaction, load before the first connection and resync as a
full set after explored; the GM and other players never receive one.
- markers.nim: emission gate, visible-extent test, id mint, anchor, marker_seen I/O.
- views/main: PlayerView markers + full/diff frames, refresh sync, startup load.
- markers.test.mjs: window preset, switch off, solid wall, any-part anchor,
walk-away/door/lost sight, full-after-explored, per-player privacy, GM none.
- leakcheck: marker allowed type + independent visible-extent oracle with a
positive control (a marked window the subject sees).
- restart: marked window in the fixture; marker set and marker_seen rows
identical before/after SIGTERM and SIGKILL.
- protocol/tviews: catalogue and frame order pin the 16th message.
Retraction, re-earning and MARKER_* faults are #60.
Ref #59
- geometry.Wall carries the stored blocks_sight/blocks_movement switches; sight asks
blocksSight, movement and the status rules ask blocks (open door passes both).
- worldmap translates both switches; moverules only pushes on a movement barrier.
- leakcheck and the tile oracle read blocks_sight independently.
- Walls/token-details/tiles groups prove both forms, sight-through, stuck, push and
the locked-window open refusal; existing scenes stay byte-identical.
Ref #57
# Conflicts:
# server/geometry.nim
# server/world.nim
# server/worldmap.nim
# tools/leakcheck.nim
The vision fan blocks a sight-blocking one-way wall only for a viewer on
its blind side (sight_dir names it; left is the (-dy,dx) normal of a->b),
one sign test inline after the radius cull, so the hoisted wall list stays
viewer-independent. Movement never reads the direction: one-way walls block
both ways. Explored and tiles therefore differ by side and only ever grow.
- geometry: WallDir + Wall.sightDir + blindTo, filter in visibilityPolygon.
- worldmap: sight_dir mapping (movement mapping unchanged).
- vision: the ONEWAY leak-fault build drops sight_dir player-side.
- leakcheck: own side test for the fan and the clear-segment oracle; ONEWAY
class detected against the sight_dir-dropped fan.
- leak scenario gains a one-way wall the subject sees across; fault test
asserts exactly ONEWAY.
- oneway.test.mjs: both sides, tile sweep with its own oracle, flip with
fixed endpoints, monotone explored/tiles, restart, two-way movement.
- docs: DESIGN 5.8 mechanism sentence corrected; TESTING #58 markers built.
- nginx harness: temp dirs created recursively (restart on one state dir).
- door.set: opening a secret or locked door is invalid; closing either is
allowed; a fixed window/non-door still has no open state.
- new tools/doors.test.mjs: two fresh servers, one identical script, three
equivalence pairs (secret/wall, secret+locked/wall, locked/closed door),
canonicalised frame + full per-player tile sweeps, an open-door positive
control and a pinned zero-thickness close-push.
- secretgap fault hook (sight-only) makes the pair fail as exactly SECRETGAP;
the clean pair passes and the shipped binary carries no fault hook.
- docs/TESTING.md T2/T17 and the door-equivalence/10.3 sections: built.
Ref #56
wall.add/wall.update now take a preset or raw switches, never both:
resolveWall expands the four 5.8 presets to switches before validating, so
a preset never touches geometry and preset+switch or preset+open is invalid.
A raw create starts from the wall defaults; a raw update patches only the
switches it names and {door:false} closes and de-secrets.
The switch-set invariants are enforced by that one path for add and update:
open/secret/locked without a door, a secret door that is open/one-way/not
opaque, open with secret or locked, and a direction with no sight to block
are all invalid. The DB gains the missing open+locked CHECK as the backstop,
and the now-redundant open/door parity test is gone from the server path.
A wall label is now the 6.5 text rule: trimmed, 1..64 code points, no control
characters, null clears, stored verbatim and GM-only. window/one_way presets
are accepted and expanded to their switch sets per DESIGN 5.8/6.1; their
player-facing behaviour stays with #57/#58.
Tests: WS black-box presets/patch semantics/every refusal/label round-trip;
Nim shape pins for expansion, invariants and the label rule.
Nim 385 / Node 117 green.
wall.add/wall.update take thickness, position, height and the eight raw
switches; kind is output-only and the GM wall frames echo the full typed
record. Geometry is stored but inert (0/full/centre behaviour), and the
legacy kind/open wire adapter is gone. proto is bumped to 2 with the
harness default, and BannedAlways gains every wall field name with a
WALLDATA positive control.
Tests: schema-7 migrated scene vs the same walls authored via raw switches
gives byte-identical player frames, refusals and per-tile statuses.
Nim 382 / Node 113 green.
Mummy runs websocket handlers on worker threads. Intents are parsed outside
the one global lock, while the world is walked under it; ORC refcounts are
not atomic, so any JsonNode or string payload reachable from both an intent
tree and the world can be freed or leaked by two threads at once.
- Add server/jsonbound.nim: detachedJson/detachedString/detachedProps copies
that share neither nodes nor string payloads (serialise+parse; std/json's
copy() would still alias JString payloads).
- Detach every intent value that enters world state: wall.add/wall.update
flags; token.create flags/props/names/kind/character_id; token.update
patch fields; prop.set key and value (token and character); character.create
props/names; scene.set name/extra. Use the world's own id in name.reveal.
- Build wall effects and create acks inside the mutation's critical section
(settleLocked/settleWorldLocked). Wall/token/character record copies and
frames no longer outlive the lock; only fresh scalars cross it.
- Move player.remove's in-memory follow-up under the lock (it mutated tokens,
characters, visions, reveals and encountered outside it).
- Cap mummy at 4 worker threads (default was 10x cores) for a seven-person table.
- Add tests/tdetach.nim: identity and string-payload checks for the boundary
helpers, plus the parseFlags-returns-the-caller's-node premise. A unit test
can prove the copy semantics, not the absence of a race.
scene.set reassigns app.scene under dbLock while the HTTP handlers read it with
no lock and no stable snapshot: tileGate read it three times (twice outside the
lock) and checkScene read the id unlocked, so a swap could hand a request two
records, or race ORC freeing the old walls seq. tileGate now takes one snapshot
under the lock and uses it for the URL parse, the explored check and the
X-Accel-Redirect; checkScene and scene.set read under the lock; the wall/door
handlers capture sceneId inside their lock for the post-lock log and effect
frame.
Tests: ttiles pins that one record gives one whole answer after a swap;
tiles.test.mjs pins the handler shape (one code read, after the lock) and
interleaves 20 scene.set plus wall edits with 200 tile fetches -- only whole
tiles, no crash.
views.Context held copies of scene, tokens, characters, reveals, encountered
and visions, so every mutation deep-copied each player's explored HashSet under
the global lock; playerView then copied its own PlayerVision again and greyFor
copied one per encountered entry. Context now holds six pointers
(contextOf/borrow), playerView/gmView read a ptr PlayerVision and a view builds
each player's visible-id set once per frame, so grey is a set test.
Measured on this build's types (debug, 6 players, 40 encountered entries, 40
world tokens, 16384 / 262144 explored cells): context construction 0.227 ms /
4.87 ms -> 0.008 us; one getOrDefault of a PlayerVision 28.8 us / 591 us -> gone;
GM egress pass 8.0 ms / 142.8 ms -> 0.79 ms / 0.80 ms; player pass 1.45 ms /
25.7 ms -> 0.32 ms. Behaviour is unchanged (leak/fault suites and tviews green);
tviews pins the borrow by identity, the six-pointer size and both sizes inside
the M5 7.5 ms budget.
name.reveal wrote the subject's actual name into the encountered row of every
player who had met it: the SQL had no player predicate, so the leak was silent
live and visible only after a restart. rewriteEncountered is now the one path
that keeps a snapshot in step with its subject: it rewrites the SQLite row and
the live in-memory entry together from the name rule, takes onlyPlayer for
name.reveal (every player for reveal_all), and also runs on a rename, a link
change and an owner change, so the wire and a post-restart reload cannot
disagree (#30). The DB-only renameEncountered*/revealEncountered* helpers are
gone, which is what let the two stores drift.
token.update {character_id} now drops the token's own two names as part of the
link patch (#29): a plain token can be linked, names supplied with a link stay
invalid and unlinking still needs both names.
Tests: tcharacters covers the per-player row, the DB/memory equality, the link
handover; restart.test.mjs builds three named players, reveals to one of them
and asserts the rows directly and the whole resync over SIGTERM/SIGKILL, plus a
mid-session rename; leak.mjs/leakcheck.nim pit two players on the same subject
and pin each entry's expected name (STALE_NAME). Mutations e1-e3 and the
repointed b2 pin the three rules.
`token.resize`, `status.set`, `status.clear`, `prop.set` and `prop.unset`
answer the 6.1 acks and codes; `token.create` now accepts `radius` and
`props` and computes the placement status before writing the row, so a token
dropped on a wall is born `stuck`. `token.update` keeps refusing the
character link and ignores `radius`/`props` (their intents own them).
Wall add/update/remove and door.set now run the pure rules on a snapshot
taken before the write and apply the outcome after it committed
(`applyRuleOutcome`: positions and walls-sourced statuses in one NORMAL
transaction, memory after COMMIT), which replaces the door-push-only helpers
and adds the 5.5 SET/KEEP/CLEAR rules and the squeeze of a failed push. A
value over the bucket cap is refused without touching the token (the clone
makes the cap check side-effect free). Prop keys are never logged.
The typed views carry the bucket filter: `PlayerTokenView` has `propsPublic`
always and `propsOwner` only when the recipient controls the token, and no
field for the `gm` bucket at all, so a later change to the frame builder
cannot leak one. Statuses are `StatusKind` values for a player (no `source`,
5.5/6.1 note 6) and full `(status, source)` entries for the GM.
Both negative controls for the new rules live behind `-d:leakfault` and in
the type, so the shipped binary has neither the fields nor the branches:
`gmProp` (the gm bucket reaches a player), `ownerProp` (the owner bucket
reaches a non-controller) and `statusSource` (a viewer learns the cause).
The `otherOwner` fault now carries the owner bucket too, so it stays one
class (the `mine` claim) instead of also tripping the bucket check.
moverules.nim replaces the M2 `blocked` bool with the 5.5 status model: the
rules own the `walls` source (`stuckWalls`, `squeezedWalls`) and take
`locked` (any entry, any source) as input, so a GM-sourced lock refuses a
player move without the rules ever knowing what caused it. Identity is kept
on KEEP, cleared on CLEAR, and only tokens the event touches change.
Every geometry path now uses the token's own radius (5.6): the overlap test,
the escape check, the capsule, the door push and the step cap's neighbour
rules. `resizeToken` implements 5.6: a shrink never pushes and clears the
walls entries only when the overlap ends, a grow that overlaps is displaced
by a deterministic greedy relaxation (radial off the first overlapped wall,
scene order, at most 16 rounds, one flipped-side pass) and a grow that cannot
be placed stays put and becomes squeezed(walls). A step whose centre path
would cross a wall ends the pass, so the relaxation never carries a token
through a wall.
worldmap.nim is the bridge: `ruleToken`/`ruleWall`/`moveScene` build the
rules' input from the records, `applyOutcome` copies the position, the
door-push history and the walls-sourced entries back, and `wallsStatuses`
does the same for a caller that writes its own row. All of them return fresh
sequences instead of mutating a shared one.
Migration step 6 ("token details") adds the three prop buckets to `entity`
and creates `entity_status`, the `(status, source)` set of 5.5. A token's
status rows are rewritten with its row, so a status change and the `token`
frame that reports it commit together.
server/props.nim owns the buckets, their caps (64 keys per bucket, a key of
1..64 code points, a value of at most 8 KB of serialized JSON) and the
property-schema registry: empty at start with a permissive fallback, because
DESIGN 8 says v1 never interprets props; a key the rules module registers is
enforced (kind and bucket). server/text.nim is the one copy of the 6.5 text
rule, shared by names and prop keys.
tokens.nim gains `props` and `statuses` on the record, the sorted-unique
entry helpers, `isLocked`, `parseRadius`/`parseStatusKind`/`parseStatusSource`,
the prop and status columns in insert/replace, and `loadStatuses` joined on
the scene. Every helper builds a fresh sequence: a copied record shares its
seq buffer, so an in-place edit would reach the authoritative list before
the transaction commits (4.2 step 6).
Startup restores each player's grid from its chunk rows (explored_loaded log) and every
mutation writes only the chunks its refresh dirtied, in the mutation's transaction: a move
keeps position and chunks in one NORMAL commit, a GM authoring write adds one NORMAL chunk
transaction under the same lock, before the ack. db.withTransaction is the shared seam.
Migration step 5 creates explored_chunk: one 512-byte bitmap per (player, scene, 64x64-cell
chunk), both FKs cascading. server/explored.nim owns the format (row-major, LSB-first bits),
dirty-chunk detection, the upsert and the startup restore. tests/texplored.nim pins the layout,
the whole-chunk encoding, the upsert replacement, the per-player keying, the restore and the
write cost (0.015 ms avg / 0.035 ms p99); tests/tdb.nim covers step 5 and a schema-4 fixture.
token.create/update/remove (GM) and token.move (controller, or GM) through
moverules: the uniform nack for locked/over-cap/collision and for an out-of-bounds
GM move, one not-allowed code for a player's unknown and not-yours targets, not-found
for the GM; accepted moves are persisted with NORMAL durability and the mover's
vision recomputed. token.update honours kind, both names, controller, gm_only,
flags and vision_radius, and refuses character_id until slice 8.
connect now sends hello, the GM walls snapshot and the 6.3 token half (vision,
explored full, tokens) under the global lock, so hello is always the first frame and
the resync is the diff base. Egress runs under the same lock, per mutation, so no two
threads touch a connection's known table and an unnamed player is never fed state.
door.set applies the 5.5 push: the move rules compute the new positions against the
pre-write state, the positions are persisted in one transaction, then memory and
vision follow (stuck/squeezed are slice 7). player.remove hands the controlled
tokens to the GM in memory as the FK already does in the DB.
server/views.nim is the only place where world state becomes bytes: a Recipient
builds a GmTokenView or a PlayerTokenView first, and only then a frame. Player
frames carry the public props bucket (plus owner for the controller), the
controller's vision_radius, and never kind, controller, gm_only, flags, radius_own
or either raw name; the GM gets all of it plus both names. The per-connection Known
table diffs on the built frame, so token/token_gone are exactly the changes and the
vision frame is re-sent only when the polygons move.
server/faults.nim compiles the negative-control hook only with -d:leakfault; the
shipped binary contains no LEAK_FAULT string and tools/fault.test.mjs asserts it.
hello gains the scene block (and extra for the GM); the protocol's implemented set
now names the four token intents.
server/vision.nim keeps one PlayerVision per player: a visibility polygon per
controlled token carrying the vision flag (range = the token's vision_radius or the
scene default), the explored set as the union of cellsTouched over history (only
grows, cells outside the world dropped), and the fresh cells of the current
mutation. The token-visibility rule of 3.1 (controlled always, otherwise inside own
LOS and not gm_only) exists exactly once there.
server/worldmap.nim translates the authoritative records into the inputs the pure
geometry and move-rule modules take, so those modules never see a wire field.
Migration step 4 ("tokens") creates the entity table: the token id, scene, kind,
both names, position, nullable radius/owner/vision_radius, gm_only and flags. A
NULL owner is GM-controlled, so player.remove hands that player's tokens to the GM
through the FK; radius, props and character_id stay out until slices 7-8.
server/tokens.nim holds the record, the 6.1 field rules (12 CSPRNG characters from
a 64-symbol alphabet, trimmed names, kind, positive vision_radius), the write-through
persistence (FULL for GM authoring, NORMAL for a move) and the loader. db_connector
quotes every argument, so the three nullable columns are emitted as numeric literals
while text still goes through ? arguments.
wall.add, wall.update, wall.remove and door.set leave the unknown-type rollout
list: field shapes and ranges per 6.1 (and the payload rules recorded FIXED in
4.4/6.1), lookup failures not-found, non-GM refused by the existing GM-only
gate. wall.add acks {id} from the scene's next_wall_id; wall.update patches
a/b/kind/flags only (open belongs to door.set); door.set is invalid on a plain
wall. Effects go to every GM connection only: wall / wall_gone, plus one walls
snapshot right after hello (the wall part of the 6.3 resync). Players receive
no wall data in any message (3.1, T2).
protocol.nim gains the wallObject/wallsFrame/wallFrame/wallGoneFrame builders
(no n: the sender stamps it per recipient) and the five wall intents in the
implemented set.
Migration step 3 ("world") creates scene and wall and seeds the single v1 scene
(id 1, 4096x4096, tile = cell 32, vision 400, token radius 20, art_version 1,
next_wall_id 1). server/world.nim holds the in-memory scene with SQLite as
write-through persistence: per-scene wall ids from next_wall_id (monotonic,
never reused, #3), 6.1 validation (a != b, in bounds, a wall is never open),
flags as an opaque JSON object, and one transaction with synchronous=FULL
around every GM authoring write (Q12); memory follows COMMIT, so a failed
write leaves both sides unchanged.
Tests: tests/tworld.nim (ids, reload, doors, validation, pragma, failed write),
tests/tdb.nim (version 3, history, a slice-2 DB migrating to slice 3).
The protocol shell over the socket, in DESIGN 6.5 order: spend a token, parse, then
unknown type / unnamed player / role / fields / lookup / semantics. Every readable
intent gets exactly one ack with a 6.5 code; an unreadable frame gets one error.
- hello {proto, role, me} as the first frame (n = 1); the scene block lands in slice 5
- /ws?proto=N is required: 400 when absent or not an integer, 101 + closing 4003 on
a mismatch (no hello, no state)
- intent bucket 30/s burst 100 and the 10-in-10-s malformed flood (closing 1008);
a rate-limited intent applies nothing and the connection stays open
- mummy maxMessageLen stated explicitly (64 KB) and mummy's own log lines routed
through the event log instead of stdout
- server Ping(seq) right after hello and every 20 s (lag enforcement stays M5);
inbound Pings are answered with a Pong, which mummy does not do itself
- close reasons: every server-initiated close sends closing {reason, code} then the
close frame, and slice 2's eviction/revocation paths do the same (FIXED, #18)
Conn now carries what DESIGN 6/6.4/6.5 need per connection, all under the one
registry lock: the outgoing n counter (starts at 1, server frames only), the intent
token bucket, the malformed-flood window, the player's named flag and the last Pong.
None of it is shared, so the n counter is not a global side channel (H25).
activate/revokePlayer now hand back the doomed Conn values instead of raw sockets:
the caller still has the frame count, so the final closing frame carries the right n
before the close. Tests cover per-connection counters, the bucket and the flood
window in isolation, and that a snapshot survives the lock.
Pure, mummy-free module for the protocol shell: the envelope rules of DESIGN 6.5
step 2 (UTF-8 text, JSON object, string t, integer reqId in 0..2^31-1), the frame
builders of 6.1 including closal/closing, the per-connection intent token bucket
(30/s, burst 100) and the malformed-flood window (10 in any 10 s), plus the FIXED
constants: proto 1, 64 KB inbound, close codes 4001/4002/4003/1008 and their reason
strings. The 29-intent catalogue and the GM-only set live here so 'unknown type'
and role checks have one definition.
Found while testing: std/json parseJson("") returns nil instead of raising, and
node{"t"} is nil for a missing key, so both are guarded (a bare {} would have
crashed the handler).
Control passes; a-d still caught (1,2,2,1,1 expected tests), new e-j each caught. Logs regenerated.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Pure in-process module (server/moverules.nim, plain data, no IO) per DESIGN 5.5. Replaces moveBlocked tests
(ported at r=0), the KNOWN LIMITATION pin and the Q14 pin with positive escape/capsule assertions and
blocked-policy tests. tests/tprobing.nim: in-process T8 probing test with a concrete bound (stepCap + r).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
cellsTouched is now a scanline over cell rows (prototype per-cell version kept test-only in
tests/refold.nim). Differential tests (random polygons, concave, grid-aligned) and a brute-force
explored oracle (0.5 px tolerance) cover it; regression corpus = prototype leak-run polygons.
moveBlocked leaves geometry.nim (replaced by server/moverules.nim next); geometry primitives exported.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Fixture tests/fixtures/scene.json copied from prototype data/; seed test no longer skips if missing.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>