diff --git a/prototype-server-vision/HANDOFF.md b/prototype-server-vision/HANDOFF.md index f8dc500..f3e6395 100644 --- a/prototype-server-vision/HANDOFF.md +++ b/prototype-server-vision/HANDOFF.md @@ -5,6 +5,11 @@ Each item verified against code at the commit named in README. Pointers = where ## Port as-is - Vision/geometry: `src/geometry.nim` (visibilityPolygon, cellsTouched, inside, moveBlocked) + `tests/tgeometry.nim` (corner tests, run `nimble test`; mutation check `devbox run mutation`, `tools/mutation.sh`). Leak harness (`tools/leak.mjs`, `tools/leakcheck.nim`, `tools/faulttest.sh`) is the acceptance test for any port. - Limits: token exactly on a wall cannot move off it (`moveBlocked`, inclusive `segsCross`, `geometry.nim:59-85`); vision is O(rays x walls) per token, bbox cull only (`geometry.nim` visibilityPolygon); cellsTouched ~12x the polygon cost (`results/bench.log`). +- Test gap: "shared endpoint: no leak at the vertex" (`tests/tgeometry.nim:29`) still passes with the horizontal arm removed (verified); shared-vertex coverage is only indirect via `hasVertex`. Port a test that fails if either arm is missing. + +## Caveats +- All timings are single machine, loopback, power-save CPU; no real network, no client render. Not production numbers (`results/bench.log`, `results/concurrency-final*.log`). +- Boundary epsilon (`RayEps` 1e-4 rad, `geometry.nim:12`; inclusive tests): a token exactly on a vision boundary is ambiguous. Leak checker uses a 0.5 px neighbourhood (`tools/leakcheck.nim:17-20`). ## Leaks / security - Tile leak: a revealed tile exposes all 256 px, not just explored cells; door changes never affect tiles (static art). `src/server.nim` tile handler, `data/tiles/`. @@ -18,7 +23,8 @@ Each item verified against code at the commit named in README. Pointers = where ## Ops / robustness - No SIGTERM handler: only `setControlCHook` (SIGINT) prints stats (`server.nim:359`); shutdown = hard kill. Durability rests on WAL commit before ack (`results/final-restart.log`). -- `PRAGMA synchronous=NORMAL` (`server.nim:331`): process kill loses nothing, OS crash/power loss may drop last commits (never corrupts). Tail (~20 ms server worst) unchanged by it: `results/spike/investigation.md`. +- `PRAGMA synchronous=NORMAL` (`server.nim:331`): process kill loses nothing, OS crash/power loss may drop last commits (never corrupts). Tail (~20 ms server worst) unchanged by it: `results/spike/investigation.md`. Real project must choose NORMAL vs FULL deliberately (NORMAL cut avg commit 0.60 -> 0.17 ms, bought no tail). +- Timing instrumentation in `server.nim` (`tm` samples L52, appended per mutation L178; `printStats` L69-80 copies+sorts all samples, called at L174 inside `finish` under the global `lk`) is prototype-only: DO NOT PORT. Real build needs bounded metrics (histogram/ring buffer) computed outside the lock. - 583 ms intent->ack spike: not reproduced (base worst 73.1/21.8/18.1 ms, fixed 21.3/20.8/21.0), cause undetermined (host-wide stall or node harness pause; original run was ~3.5x slower on average). Server tail >50 ms = SQLite COMMIT stall + lock_wait queued behind it. `results/spike/investigation.md`. - mummy: send queue is one unbounded server-wide deque, no backpressure for slow clients; `WebSocket` keyed in `conns` by its raw bytes (no hash/==) (`server.nim` Conn/conns, README "mummy suitability"). diff --git a/prototype-server-vision/README.md b/prototype-server-vision/README.md index 4c42106..65dd73a 100644 --- a/prototype-server-vision/README.md +++ b/prototype-server-vision/README.md @@ -23,7 +23,7 @@ Browser rendering was NOT verified (no browser in the build environment): only H | `devbox run smoke` | fresh DB, server+nginx, auth/cookie/tile/steal/garbage checks | | `devbox run leaktest` | runs twice (SUBJECT=A, SUBJECT=B), fresh DB each; subject walks ~240 steps through rooms, corridor, open/closed doors while GM + B act; Nim checker (`tools/leakcheck.nim`) replays the transcript. Output per subject: `results/leak-A.log`, `results/leak-B.log` (committed), transcripts `results/leak-{A,B}.jsonl` (1.1-1.3 MB each, 2.4 MB total, committed) | | `devbox run faulttest` | deliberate leaks: builds the server with `-d:leakfault` (hook absent from the normal build, asserted by grepping the clean binary for `LEAK_FAULT`), injects 8 faults one at a time (`LEAK_FAULT=`): hidden token sent (`hidden`), wall data to player (`walls`), unexplored tile 200 (`tile`), visible token withheld (`withhold`), B's vision / explored / ownership sent to A (`other-vision`, `other-explored`, `other-owner`), missing `remove` (`noremove`). Passes only if the checker fails each with exactly the expected failure-class set (classes: HIDDEN_TOKEN WALLDATA TILE WITHHELD OTHER_PLAYER NO_REMOVE, plus collateral OWN_VIEW / EXPLORED) and the clean build still passes. Details in `results/faults.log` (committed), summary `results/final-faulttest.log` | -| `devbox run restart` | isolated server, moves A/B/monsters, toggles doors, A explores a new area; stops with SIGTERM then (second round of changes) SIGKILL, restarts on the same DB; asserts invite secrets, token positions, doors, vision, explored grids per role and the full hello+state a reconnecting client receives are identical (gseq excluded: in-memory). Note: the server has no SIGTERM handler, so SIGTERM is as abrupt as SIGKILL; durability rests on the SQLite WAL commit before ack (`synchronous=NORMAL`: survives process kill, may lose the last commits on OS crash/power loss; see `results/spike-investigation.md`) | +| `devbox run restart` | isolated server, moves A/B/monsters, toggles doors, A explores a new area; stops with SIGTERM then (second round of changes) SIGKILL, restarts on the same DB; asserts invite secrets, token positions, doors, vision, explored grids per role and the full hello+state a reconnecting client receives are identical (gseq excluded: in-memory). Note: the server has no SIGTERM handler, so SIGTERM is as abrupt as SIGKILL; durability rests on the SQLite WAL commit before ack (`synchronous=NORMAL`: survives process kill, may lose the last commits on OS crash/power loss; see `results/spike/investigation.md`) | | `devbox run concurrency` | 60 s (`DUR=` secs) A, B, GM(6 monsters + doors) at 20-50 ms per token; logs `results/concurrency-.log` + `...-server.log` (server STATS; TAG defaults to `s`; final runs use `TAG=final1..3`) | | `devbox run mutation` | geometry mutation check on a temp copy (`tools/mutation.sh`): (a) no ±RayEps rays, (b) upper segment end exclusive, (c) lower end exclusive; control must pass, each mutation must fail a corner test. Logs `results/mutation-{a,b,c}.log` | | `devbox run bench` | vision microbench, log `results/bench.log` | diff --git a/prototype-server-vision/results/spike/investigation.md b/prototype-server-vision/results/spike/investigation.md index e3d3582..2ca2e0c 100644 --- a/prototype-server-vision/results/spike/investigation.md +++ b/prototype-server-vision/results/spike/investigation.md @@ -19,7 +19,7 @@ Client p99 added to `tools/concurrency.mjs`. Logs: `results/spike/base{1,2,3}[-s (base runs' sqlite worst: run 2 file shows 21.2, run 3 file 9.6; table taken per file.) -## Slowest mutations (baseline; only one exceeded 50 ms in 3 runs, `SLOW` lines in `spike/*-server.log`) +## Slowest mutations (baseline; three exceeded 50 ms, all in base run 1 (gseq 136, 138, 152), `SLOW` lines in `spike/base1-server.log`; none in base 2/3 or fixed runs) - run1 gseq=136 move-player total=63.8: sqlite=62.9 (COMMIT), vision 0.7, send 0.1, lock_wait 0. - run1 gseq=138 move-monster total=56.6: lock_wait=55.9 (queued behind gseq=136's commit). - run1 gseq=152 move-player total=72.9: lock_wait=71.7 (queued behind another stalled holder), rest < 1. diff --git a/prototype-server-vision/tests/tgeometry.nim b/prototype-server-vision/tests/tgeometry.nim index fda0318..64d3fbe 100644 --- a/prototype-server-vision/tests/tgeometry.nim +++ b/prototype-server-vision/tests/tgeometry.nim @@ -32,10 +32,10 @@ suite "visibility": # viewer on the diagonal through the shared vertex: the ray touches both arms' endpoint let v: Vec = (0.0, -25.0) check visibilityPolygon(v, w, 500).hasVertex((50.0, 0.0)) - check not sees(w, v, (70.0, 9.0)) # just above the ray through the vertex: vertical arm shadows it - check sees(w, v, (70.0, 11.0)) # just below the ray: past the vertex, the corner is not a crack - # token on the line of the horizontal arm: a point just below the line is visible past the arm's end-on - # edge, just above it is shadowed by the vertical arm + check not sees(w, v, (70.0, 9.0)) # just below the ray through the vertex (y=10 at x=70): vertical arm shadows it + check sees(w, v, (70.0, 11.0)) # just above the ray: past the vertex, the corner is not a crack + # token on the line of the horizontal arm: a point just above the line is visible past the arm's end-on + # edge, just below it is shadowed by the vertical arm check sees(w, (0.0, 0.0), (70.0, 5.0)) check not sees(w, (0.0, 0.0), (70.0, -5.0))