fix(client): tile loading: centre-out, one request per tile, 404 recovery (#86)
The GM survey view asked row-major, at most 8 at a time, rebuilt the whole wanted window on every settle, and paid two requests for every failed tile (image error, then a fetch to learn the status). A 404/5xx was stored as permanent `denied`, so a tile imported after page load stayed black until a page reload, and `viewport.setScene` swallowed a same-id art_version change so the old textures were never dropped. - TILE_CONCURRENCY 8 -> 32, the measured knee on a Full HD scene (min-of-3 headless: GM fit + player 0.5, tile 32/64; 64 is inside the noise). - orderTilesCentreOut: nearest the viewport centre first. - Settle path is incremental (one settle = one tile sprite/flag update); the window is rebuilt only on camera/scene changes. - fetch + createImageBitmap: status from the same response, decode off the main thread, so a failure costs one request. - 403 stays permanent (retried only on fog.fresh); 404/5xx/network retry with 250/500 ms backoff up to 3 loads, and `hello`/reconnect or a scene/art_version change resets the budget. A failure that lands after a reconnect is a fresh first attempt; a failure that leaves the window does not spend the budget. - setScene emits for a same-id scene; a new art_version drops the texture cache and reschedules. Tiles are `Cache-Control: private, max-age=1y, immutable` (still gated), so a reload reuses them; DESIGN 3.3/11.1 and client/README updated. Tests: vitest for ordering, incremental invariants, retry budget/backoff, reconnect epoch and art_version invalidation; e2e for a GM survey fill (one request per succeeded tile) and a 404 tile recovering after the file appears and a real reconnect. Before -> after (min-of-3, saturated host, Full HD): GM fit 32px 910->843 ms, player 0.5 32px 972->862 ms, GM fit 64px 320->249 ms, player 0.5 64px 332->368 ms (noise). Part of #63. Blocks #77.
This commit is contained in:
+13
-10
@@ -307,8 +307,11 @@ Notes:
|
||||
- Tile URLs include the scene's `art_version` so that re-imported art does not hit stale caches
|
||||
[FIXED, owner decision 2026-11-14, #7]: from M3 on, always `1` in M3. The gate reads
|
||||
`<state>/tiles/<scene>/v<art_version>/` (layout fixed in M3; writing versions is the import CLI of
|
||||
11.1, pulled forward to M4 by #79; cleanup remains M6). Response `Cache-Control: private` [FIXED,
|
||||
owner decision 2026-11-14, #7], not the prototype's `no-store`.
|
||||
11.1, pulled forward to M4 by #79; cleanup remains M6). Response `Cache-Control: private,
|
||||
max-age=31536000, immutable` [FIXED, owner decision 2026-11-14, #7; immutable cache, #86,
|
||||
2026-11-21]: the URL carries the version, so a tile never changes under its URL, and a reload may
|
||||
reuse every tile from the browser cache instead of revalidating tens of thousands of requests;
|
||||
`private` keeps gated bytes out of shared caches.
|
||||
- **URL grammar and status split [FIXED (owner-delegated), 2026-11-15, #24].** Every numeric
|
||||
component is canonical decimal: digits only, no sign, no space, **no leading zero** (`0` alone is
|
||||
the only zero), bounded at 9 digits for `<scene>` and `<art_version>` (`v` + digits) and 5 digits
|
||||
@@ -323,9 +326,9 @@ Notes:
|
||||
explored set under the global lock; a player with no sight state has explored nothing.
|
||||
`X-Accel-Redirect` is built only from the parsed integers
|
||||
(`/_tiles/<scene>/v<art_version>/<x>_<y>.png`), never from request text, so no path shape can
|
||||
steer it. `Cache-Control: private` is set by the Nim gate and rides through nginx's internal
|
||||
redirect unchanged; nginx adds nothing of its own there (the test vhost records this, TESTING
|
||||
§11.1). Nim sends no body and no `Content-Type`.
|
||||
steer it. `Cache-Control: private, max-age=31536000, immutable` is set by the Nim gate and rides
|
||||
through nginx's internal redirect unchanged; nginx adds nothing of its own there (the test vhost
|
||||
records this, TESTING §11.1). Nim sends no body and no `Content-Type`.
|
||||
|
||||
### 3.4 Threat list
|
||||
|
||||
@@ -2251,11 +2254,11 @@ See TESTING §10.4 (Node 26 black-box harnesses, built-ins only, `devbox run tes
|
||||
off`. The map must be declared at `http{}` level.
|
||||
- `location = /join` -> proxy, **`access_log off`**, `add_header Referrer-Policy no-referrer`.
|
||||
- `location /tiles/` -> proxy (Nim decides, returns `X-Accel-Redirect`).
|
||||
- `location /_tiles/` -> `internal; alias <state dir>/tiles/;` `Cache-Control private`. Must be
|
||||
readable by the nginx user (group read on the tiles dir) [INFERRED NixOS gotcha]; do not expose
|
||||
the state dir otherwise. [FIXED (owner-delegated), #24] The `Cache-Control: private` on a served
|
||||
tile comes from the Nim gate (3.3) and nginx passes it through the internal redirect; the
|
||||
location adds no header of its own, so the header is not duplicated.
|
||||
- `location /_tiles/` -> `internal; alias <state dir>/tiles/;` `Cache-Control: private,
|
||||
max-age=31536000, immutable`. Must be readable by the nginx user (group read on the tiles dir)
|
||||
[INFERRED NixOS gotcha]; do not expose the state dir otherwise. [FIXED (owner-delegated), #24]
|
||||
The `Cache-Control` on a served tile comes from the Nim gate (3.3) and nginx passes it through
|
||||
the internal redirect; the location adds no header of its own, so the header is not duplicated.
|
||||
- Test nginx [FIXED (owner-delegated), #24]: a devbox `nginx` in front of the harness mirrors this
|
||||
vhost shape; details in TESTING §11.1.
|
||||
- Response headers: HSTS, CSP (no inline scripts, `connect-src 'self'` wss),
|
||||
|
||||
Reference in New Issue
Block a user