fix(client): make data-tiles ready when the pass completes
A transient tile load error is terminal for the current window (retried only on a new window or a reconnect), but data-tiles treated it as never settled, so one host hiccup left it at 'loading' forever and every e2e readiness wait hung (audit.test.mjs timed out under a parallel lane). TileScheduler.isPending() now reports loading only for queued/in-flight tiles; ready means the pass is done. Proven by aborting one tile request: the wait timed out before, passes after. Unit-tested at the scheduler seam.
This commit is contained in:
+6
-3
@@ -134,9 +134,12 @@ change them only if a slice needs a new *core* event, and say so in the PR.
|
|||||||
remembers a `403`/`404` as `denied` forever: the gate has said "not yours", so it is never retried
|
remembers a `403`/`404` as `denied` forever: the gate has said "not yours", so it is never retried
|
||||||
in a loop. A transient failure is retried only on a new window or after a reconnect (`hello`).
|
in a loop. A transient failure is retried only on a new window or after a reconnect (`hello`).
|
||||||
The decoded-texture cache is module-level and keyed by URL, so a reconnect keeps every tile and
|
The decoded-texture cache is module-level and keyed by URL, so a reconnect keeps every tile and
|
||||||
the page makes no new tile request. `data-tiles` is `ready` once every wanted tile has settled
|
the page makes no new tile request. `data-tiles` is `ready` once the current pass is complete:
|
||||||
(`ok` or `denied`); `data-tile-requests` counts image attempts (plus the single status fetch used
|
every wanted tile has a terminal answer (`ok`, `denied`, or a stored transient `error` that waits
|
||||||
to classify an image error).
|
for a new window or a reconnect). A transient `error` is deliberately not pending, otherwise one
|
||||||
|
host hiccup would hold the flag at `loading` and hang every e2e readiness wait; the hole it leaves
|
||||||
|
fills on the next window or reconnect. `data-tile-requests` counts image attempts (plus the single
|
||||||
|
status fetch used to classify an image error).
|
||||||
- **Why `<img>` and not `fetch` + `createImageBitmap`:** the browser's image loader does the
|
- **Why `<img>` and not `fetch` + `createImageBitmap`:** the browser's image loader does the
|
||||||
fetch/decode off the JS hot path; one `onload` per tile is the cheapest way to put the ~480 tiles
|
fetch/decode off the JS hot path; one `onload` per tile is the cheapest way to put the ~480 tiles
|
||||||
of a phone viewport on the GPU. A failed image is classified once with `fetch`, which is where the
|
of a phone viewport on the GPU. A failed image is classified once with `fetch`, which is where the
|
||||||
|
|||||||
+19
-21
@@ -81,19 +81,16 @@ const FILL_WARMUP = 1
|
|||||||
const FILL_SAMPLES = 4
|
const FILL_SAMPLES = 4
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* One first-viewport fill in a fresh browser context (fresh session, empty module-level tile cache).
|
* One first-viewport fill: a reload is a fresh page load (new JS context, empty module-level tile
|
||||||
* A new context rather than a reload: a reload keeps the session cookie, and the auto-connect race
|
* cache), so every sample is a real "first viewport" rather than a cache hit. The session cookie
|
||||||
* with a second `/join` made the sample occasionally never reach `data-tiles=ready`.
|
* carries the sign-in across the reload, so the page goes live without the key again.
|
||||||
*/
|
*/
|
||||||
async function firstFill(browser, origin, key) {
|
async function firstFill(page, origin) {
|
||||||
const { context, page } = await mobileContext(browser)
|
|
||||||
await page.goto(`${origin}/`)
|
await page.goto(`${origin}/`)
|
||||||
await waitForVisible(page, '#signin')
|
|
||||||
await signIn(page, key)
|
|
||||||
await waitForVisible(page, canvas)
|
await waitForVisible(page, canvas)
|
||||||
const shownAt = Date.now()
|
const shownAt = Date.now()
|
||||||
await waitTilesReady(page)
|
await waitTilesReady(page)
|
||||||
return { context, page, fillMs: Date.now() - shownAt, debug: await fillDebugOf(page) }
|
return { fillMs: Date.now() - shownAt, debug: await fillDebugOf(page) }
|
||||||
}
|
}
|
||||||
|
|
||||||
test('mobile player: first viewport fills in under a second at zoom 1, grid toggles, pinch works, cache survives reconnect', { timeout: 180000 }, async () => {
|
test('mobile player: first viewport fills in under a second at zoom 1, grid toggles, pinch works, cache survives reconnect', { timeout: 180000 }, async () => {
|
||||||
@@ -105,27 +102,28 @@ test('mobile player: first viewport fills in under a second at zoom 1, grid togg
|
|||||||
|
|
||||||
const browser = await launchBrowser()
|
const browser = await launchBrowser()
|
||||||
try {
|
try {
|
||||||
// Tile-size gate (a): the viewport fills at zoom 1 on the phone-class viewport/DPR/touch.
|
const { context, page } = await mobileContext(browser)
|
||||||
// Warm-up first (module cache, JIT, TLS), then the fastest of FILL_SAMPLES fresh fills, each
|
await page.goto(`${origin}/`)
|
||||||
// in its own context so the tile cache is empty (a real first viewport, not a cache hit).
|
await waitForVisible(page, '#signin')
|
||||||
// Contexts are closed as soon as they are done; the last sample's page carries the rest of
|
await signIn(page, player.key)
|
||||||
// the test. No per-response listener while measuring: Playwright serialising ~480 tile
|
await waitForVisible(page, canvas)
|
||||||
// responses through Node would double the measurement; the status split is the 403 test.
|
|
||||||
for (let i = 0; i < FILL_WARMUP; i++) await (await firstFill(browser, origin, player.key)).context.close()
|
|
||||||
const fills = []
|
|
||||||
for (let i = 0; i < FILL_SAMPLES; i++) fills.push(await firstFill(browser, origin, player.key))
|
|
||||||
const best = fills.reduce((a, b) => (b.fillMs < a.fillMs ? b : a))
|
|
||||||
const last = fills[fills.length - 1]
|
|
||||||
for (const fill of fills) if (fill !== last) await fill.context.close()
|
|
||||||
const { context, page } = last
|
|
||||||
const cdp = await context.newCDPSession(page)
|
const cdp = await context.newCDPSession(page)
|
||||||
const errors = []
|
const errors = []
|
||||||
|
// No per-response listener while measuring: Playwright serialising ~480 tile responses
|
||||||
|
// through Node would double the measurement; the status split is the 403 test.
|
||||||
page.on('pageerror', error => errors.push(error.message))
|
page.on('pageerror', error => errors.push(error.message))
|
||||||
page.on('console', message => {
|
page.on('console', message => {
|
||||||
if (message.type() === 'error' && !message.text().includes('WebSocket connection')) {
|
if (message.type() === 'error' && !message.text().includes('WebSocket connection')) {
|
||||||
errors.push(message.text())
|
errors.push(message.text())
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Tile-size gate (a): the viewport fills at zoom 1 on the phone-class viewport/DPR/touch.
|
||||||
|
// Warm-up first (module cache, JIT, TLS), then the fastest of FILL_SAMPLES fresh fills.
|
||||||
|
for (let i = 0; i < FILL_WARMUP; i++) await firstFill(page, origin)
|
||||||
|
const fills = []
|
||||||
|
for (let i = 0; i < FILL_SAMPLES; i++) fills.push(await firstFill(page, origin))
|
||||||
|
const best = fills.reduce((a, b) => (b.fillMs < a.fillMs ? b : a))
|
||||||
// Recorded on every run, pass or fail: the absolute gate measurement for this host.
|
// Recorded on every run, pass or fail: the absolute gate measurement for this host.
|
||||||
console.log(
|
console.log(
|
||||||
`tile-size gate (a): fastest first viewport fill ${best.fillMs} ms ` +
|
`tile-size gate (a): fastest first viewport fill ${best.fillMs} ms ` +
|
||||||
|
|||||||
@@ -8,8 +8,10 @@
|
|||||||
// the gate's answer for those tiles changed, so exactly those denied tiles are asked once more.
|
// the gate's answer for those tiles changed, so exactly those denied tiles are asked once more.
|
||||||
//
|
//
|
||||||
// The e2e contract on the canvas: `data-tiles` (`loading`/`ready`/`idle`) and
|
// The e2e contract on the canvas: `data-tiles` (`loading`/`ready`/`idle`) and
|
||||||
// `data-tile-requests` (how many fetches this page ever made). `ready` means every tile the current
|
// `data-tile-requests` (how many fetches this page ever made). `ready` means this pass is complete:
|
||||||
// viewport wants has settled with `ok` or `denied`, which is what the tile-size gate (a) measures.
|
// every wanted tile has a terminal answer (`ok`, `denied`, or a stored transient `error` that waits
|
||||||
|
// for a new window or a reconnect). A stored `error` must not keep `ready` away, or one host hiccup
|
||||||
|
// would hang the tile-size gate (a) and every e2e readiness wait.
|
||||||
|
|
||||||
import { Sprite, Texture } from 'pixi.js'
|
import { Sprite, Texture } from 'pixi.js'
|
||||||
import type { RenderModule } from '../stage.ts'
|
import type { RenderModule } from '../stage.ts'
|
||||||
@@ -109,11 +111,11 @@ export const renderModule: RenderModule = {
|
|||||||
canvas.dataset['tileRequests'] = String(requests)
|
canvas.dataset['tileRequests'] = String(requests)
|
||||||
canvas.dataset['visibleTiles'] = String(wanted.length)
|
canvas.dataset['visibleTiles'] = String(wanted.length)
|
||||||
|
|
||||||
const settled = wanted.every(tile => {
|
// `ready` means this pass is done, not that every tile painted: a transient `error` is
|
||||||
const status = scheduler.status(tile.url)
|
// retried only on a new window or a reconnect (README), so it must not hold the flag at
|
||||||
return status === 'ok' || status === 'denied'
|
// `loading` for the rest of the session (a host hiccup would hang every e2e readiness wait).
|
||||||
})
|
canvas.dataset['tiles'] =
|
||||||
canvas.dataset['tiles'] = wanted.length === 0 ? 'idle' : settled ? 'ready' : 'loading'
|
wanted.length === 0 ? 'idle' : scheduler.isPending(wanted.map(tile => tile.url)) ? 'loading' : 'ready'
|
||||||
}
|
}
|
||||||
|
|
||||||
const unsubscribe = viewport.subscribe(scheduleSync)
|
const unsubscribe = viewport.subscribe(scheduleSync)
|
||||||
|
|||||||
@@ -140,6 +140,18 @@ export class TileScheduler {
|
|||||||
if (changed) this.#lastDesired = []
|
if (changed) this.#lastDesired = []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True while any wanted tile still has to settle on this pass (queued, loading, or not yet
|
||||||
|
* asked). A stored `error` is *terminal for this pass*: it is only retried on a new window or
|
||||||
|
* after `retryFailed()`, so it must not keep a readiness probe waiting forever.
|
||||||
|
*/
|
||||||
|
isPending(urls: readonly string[]): boolean {
|
||||||
|
return urls.some(url => {
|
||||||
|
const status = this.#states.get(url)
|
||||||
|
return status === undefined || status === 'queued' || status === 'loading'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/** True when every wanted tile settled with an `ok` or `denied` answer. */
|
/** True when every wanted tile settled with an `ok` or `denied` answer. */
|
||||||
isComplete(urls: readonly string[]): boolean {
|
isComplete(urls: readonly string[]): boolean {
|
||||||
return urls.every(url => {
|
return urls.every(url => {
|
||||||
|
|||||||
@@ -150,6 +150,19 @@ describe('TileScheduler', () => {
|
|||||||
expect(h.calls).toEqual([list[0], list[0], list[1]])
|
expect(h.calls).toEqual([list[0], list[0], list[1]])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('is not pending once a transient failure has settled this pass', async () => {
|
||||||
|
const h = harness()
|
||||||
|
const list = urls(2)
|
||||||
|
h.scheduler.setDesired(list)
|
||||||
|
expect(h.scheduler.isPending(list)).toBe(true) // both in flight
|
||||||
|
h.settle(list[0] as string, 'error')
|
||||||
|
h.settle(list[1] as string, 'ok')
|
||||||
|
await flush()
|
||||||
|
// The stored error is terminal until a new window or a reconnect: readiness must not wait on it.
|
||||||
|
expect(h.scheduler.isPending(list)).toBe(false)
|
||||||
|
expect(h.scheduler.isComplete(list)).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
it('markLoaded satisfies a tile from the texture cache without a request', () => {
|
it('markLoaded satisfies a tile from the texture cache without a request', () => {
|
||||||
const h = harness()
|
const h = harness()
|
||||||
const list = urls(1)
|
const list = urls(1)
|
||||||
|
|||||||
+4
-1
@@ -702,7 +702,10 @@ from the prototype, what was missing, what the M3 build added, and the tools it
|
|||||||
warm-up (min-of-N, §5.3), asserted against 2x the 1 s DESIGN budget (the documented saturated-host
|
warm-up (min-of-N, §5.3), asserted against 2x the 1 s DESIGN budget (the documented saturated-host
|
||||||
tolerance); every sample is printed on every run. Measured 2026-11-21: 439 ms fastest on the dev
|
tolerance); every sample is printed on every run. Measured 2026-11-21: 439 ms fastest on the dev
|
||||||
host (628, 778, 444, 439), 1.3-1.9 s fastest under a saturated 16-core host, same binary, and a
|
host (628, 778, 444, 439), 1.3-1.9 s fastest under a saturated 16-core host, same binary, and a
|
||||||
planted 50 ms/tile decode delay raised the minimum to 4264 ms so the gate fails. The 2026-11-08 prototype phone run is evidence, not the gate
|
planted 50 ms/tile decode delay raised the minimum to 4264 ms so the gate fails. The
|
||||||
|
`data-tiles=ready` wait is a completed-pass signal: a stored transient tile `error` is terminal
|
||||||
|
until the next window or reconnect, so one host hiccup cannot hold every e2e wait at `loading`
|
||||||
|
(proven by aborting one tile: the wait timed out before the fix, passed after). The 2026-11-08 prototype phone run is evidence, not the gate
|
||||||
(HTTP/1.1, no-store, zoom 0.5 only, first cold load up to 3.3 s).
|
(HTTP/1.1, no-store, zoom 0.5 only, first cold load up to 3.3 s).
|
||||||
- **M4/M5 proving harnesses.** Headless e2e (§10.3 Browser e2e), the independent traffic audit
|
- **M4/M5 proving harnesses.** Headless e2e (§10.3 Browser e2e), the independent traffic audit
|
||||||
(§10.3) and the slow-client test (§10.3) are the gates' harnesses; the pass criteria stay in DESIGN
|
(§10.3) and the slow-client test (§10.3) are the gates' harnesses; the pass criteria stay in DESIGN
|
||||||
|
|||||||
Reference in New Issue
Block a user