viewer: reset chunk download deadline while body bytes stream (VIEWER-CHUNK-IDLE-TIMEOUT) #651

Merged
kirigayakazima merged 1 commit from upstream-pr/651 into main 2026-11-29 02:16:03 +00:00
kirigayakazima commented 2026-11-24 10:59:07 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-24T10:59:07Z.


Claimed in the coordination issue as: VIEWER-CHUNK-IDLE-TIMEOUT (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7129434586)

What and why

Follows up on @slauko's finding in #14 (comment 7128949696), where valid multi-hundred-megabyte clay chunks (up to 773 MB) hit CHUNK_DOWNLOAD_TIMEOUT_MS (30 s) on a cold read because the timer bounded the entire download wall-clock duration rather than idle stalls.

  • viewer/index.html: add parseContentLength / readChunkBytes so loadChunk streams chunks via response.body.getReader() and resets the 30 s deadline whenever non-empty body bytes arrive:
    • Headers alone and zero-byte chunks do not reset the deadline.
    • Preallocates a single Uint8Array (capped at 1 GiB) when an uncompressed Content-Length is valid, spilling gracefully if more bytes arrive or slicing if the stream ends early; omits preallocation when Content-Encoding is set.
    • Cancels the stream reader on AbortSignal abort and releases the lock in finally.
    • Falls back to response.arrayBuffer() when response.body?.getReader is absent.
  • tests/test_viewer_streaming.cjs: extend the mock fetch/GLTFLoader fixture with streamHeaders and parses and add 5 unit test groups covering sliding idle timeouts (with and without Content-Length), headers-only stalls, empty-chunk stalls, Content-Length mismatches / Content-Encoding, and mid-transfer cancellation/drop cleanup.

Tested

On Windows 11 x64 (Node v24.19.0, Python 3.14.7) at $sha, synthetic fixtures only (no game data):

  • node --test tests/test_viewer_streaming.cjs — 67 passed, 0 failed (includes 5 new streamed-timeout / assembly tests)
  • node --test tests/test_viewer_studio.cjs — 11 passed, 0 failed
  • python -I tests/test_viewer_cdn_integrity.py — 10 ran, OK
  • python -I tests/test_viewer_serve.py — 39 ran, OK (1 skipped)
  • python -I tests/test_ci_registration.py — 15 ran, OK
  • python -I tests/test_text_write_line_endings.py — 3 ran, OK
  • python -I tests/test_check_no_game_data.py & python -I scripts/check_no_game_data.py — exit 0
  • python -m compileall -q make_game.py tools tests — exit 0

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main (21625bca) and merges cleanly (a conflicting pull request is labeled
    eeds rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a — viewer streaming only)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5470849654 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/651). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-24T10:59:07Z. --- Claimed in the coordination issue as: VIEWER-CHUNK-IDLE-TIMEOUT (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7129434586) ### What and why Follows up on @slauko's finding in [#14 (comment 7128949696)](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7128949696), where valid multi-hundred-megabyte clay chunks (up to 773 MB) hit `CHUNK_DOWNLOAD_TIMEOUT_MS` (30 s) on a cold read because the timer bounded the entire download wall-clock duration rather than idle stalls. - `viewer/index.html`: add `parseContentLength` / `readChunkBytes` so `loadChunk` streams chunks via `response.body.getReader()` and resets the 30 s deadline whenever non-empty body bytes arrive: - Headers alone and zero-byte chunks do not reset the deadline. - Preallocates a single `Uint8Array` (capped at 1 GiB) when an uncompressed `Content-Length` is valid, spilling gracefully if more bytes arrive or slicing if the stream ends early; omits preallocation when `Content-Encoding` is set. - Cancels the stream reader on `AbortSignal` abort and releases the lock in `finally`. - Falls back to `response.arrayBuffer()` when `response.body?.getReader` is absent. - `tests/test_viewer_streaming.cjs`: extend the mock `fetch`/`GLTFLoader` fixture with `streamHeaders` and `parses` and add 5 unit test groups covering sliding idle timeouts (with and without `Content-Length`), headers-only stalls, empty-chunk stalls, `Content-Length` mismatches / `Content-Encoding`, and mid-transfer cancellation/drop cleanup. ### Tested On Windows 11 x64 (Node v24.19.0, Python 3.14.7) at $sha, synthetic fixtures only (no game data): - `node --test tests/test_viewer_streaming.cjs` — 67 passed, 0 failed (includes 5 new streamed-timeout / assembly tests) - `node --test tests/test_viewer_studio.cjs` — 11 passed, 0 failed - `python -I tests/test_viewer_cdn_integrity.py` — 10 ran, OK - `python -I tests/test_viewer_serve.py` — 39 ran, OK (1 skipped) - `python -I tests/test_ci_registration.py` — 15 ran, OK - `python -I tests/test_text_write_line_endings.py` — 3 ran, OK - `python -I tests/test_check_no_game_data.py` & `python -I scripts/check_no_game_data.py` — exit 0 - `python -m compileall -q make_game.py tools tests` — exit 0 GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current main (21625bca) and merges cleanly (a conflicting pull request is labeled eeds rebase). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a — viewer streaming only)
lixonik commented 2026-11-24 11:27:35 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-24T11:27:35Z.

Review: COMMENTED


Independent verification at 5e19f489: all 67 viewer streaming tests and 11 viewer studio tests passed. I also exercised the downloader over loopback HTTP with a shortened deadline and synthetic bytes. With nonempty body fragments arriving within each idle interval but taking longer than one interval in total, the base aborted and the PR returned the complete byte sequence. Both revisions still aborted a stalled response.

AI-assisted testing.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6038376930 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/651#pullrequestreview-6038376930). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-24T11:27:35Z. **Review:** COMMENTED --- Independent verification at `5e19f489`: all 67 viewer streaming tests and 11 viewer studio tests passed. I also exercised the downloader over loopback HTTP with a shortened deadline and synthetic bytes. With nonempty body fragments arriving within each idle interval but taking longer than one interval in total, the base aborted and the PR returned the complete byte sequence. Both revisions still aborted a stalled response. AI-assisted testing.
zmasi commented 2026-11-28 22:01:48 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T22:01:48Z.


#651 | head 5e19f48910 (merged cleanly with main a8465211fb) | node --test tests/test_viewer_streaming.cjs | red on main: pass 57, fail 10 (loadChunk set a single CHUNK_DOWNLOAD_TIMEOUT_MS timer across fetch + response.arrayBuffer() without resetting on streaming progress, aborting active multi-chunk transfers after 30 s) | green on PR+main: pass 67 / 67, fail 0 (duration_ms 284.5) | Windows 11 (10.0.26200.9974), Node.js v24.16.0 | AI-assisted: yes

Audited viewer/index.html and tests/test_viewer_streaming.cjs on Windows 11: readChunkBytes resets the idle deadline only on non-empty body chunks (never on headers alone or zero-byte chunks), handles Content-Length mismatches and Content-Encoding bodies safely (MAX_PREALLOC_BYTES cap), and cancels/releases the ReadableStream reader lock on timeout or drop(). Note: touches viewer/index.html and tests/test_viewer_streaming.cjs in disjoint sections from #918 (loadWorld vs loadChunk). Also verified tests/test_ci_registration.py and scripts/check_no_game_data.py.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246445373 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/651#issuecomment-7246445373). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T22:01:48Z. --- #651 | head 5e19f4891003d45d27467604c49d865ebf61a4cc (merged cleanly with main a8465211fb) | `node --test tests/test_viewer_streaming.cjs` | red on main: `pass 57, fail 10` (`loadChunk` set a single `CHUNK_DOWNLOAD_TIMEOUT_MS` timer across `fetch` + `response.arrayBuffer()` without resetting on streaming progress, aborting active multi-chunk transfers after 30 s) | green on PR+main: `pass 67 / 67, fail 0` (`duration_ms 284.5`) | Windows 11 (`10.0.26200.9974`), Node.js v24.16.0 | AI-assisted: yes Audited `viewer/index.html` and `tests/test_viewer_streaming.cjs` on Windows 11: `readChunkBytes` resets the idle deadline only on non-empty body chunks (never on headers alone or zero-byte chunks), handles `Content-Length` mismatches and `Content-Encoding` bodies safely (`MAX_PREALLOC_BYTES` cap), and cancels/releases the `ReadableStream` reader lock on timeout or `drop()`. Note: touches `viewer/index.html` and `tests/test_viewer_streaming.cjs` in disjoint sections from `#918` (`loadWorld` vs `loadChunk`). Also verified `tests/test_ci_registration.py` and `scripts/check_no_game_data.py`.
OreoFR commented 2026-11-29 01:58:22 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T01:58:22Z.


Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Node v26.7.0, main 59e65849b, PR head 5e19f4891 : red 10 failures / green 67 OK

node --test tests/test_viewer_streaming.cjs:

  • Red (main + only this PR's test file): 67 tests (incl. subtests), 10 failed cases in 5 top-level tests:
    • streamed chunk downloads reset the idle deadline on each non-empty body chunk (with and without Content-Length)
    • streamed chunk headers alone do not reset the download deadline
    • empty body chunks do not reset the streamed download deadline
    • streamed chunk assembly handles Content-Length mismatches and encoded bodies (3 subtests)
    • dropping a streamed chunk mid-transfer cancels its reader and releases the lock
  • Green (main + merge): 67/67 OK.
  • (MEASURED n=3) each failing test rerun alone 3 times: red 3/3 fail, green 3/3 pass.
  • Skipped: none (skip 0, todo 0). No npm dependencies (CI runs node --test tests/test_*.cjs).
  • Merge: clean (git merge --no-ff onto main). The PR's test file is not older than main's, so the red run is the plain one.

Verdict: READY

AI-assisted: Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7249129883 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/651#issuecomment-7249129883). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T01:58:22Z. --- Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Node v26.7.0, main 59e65849b, PR head 5e19f4891 : red 10 failures / green 67 OK `node --test tests/test_viewer_streaming.cjs`: - **Red** (main + only this PR's test file): 67 tests (incl. subtests), 10 failed cases in 5 top-level tests: - `streamed chunk downloads reset the idle deadline on each non-empty body chunk (with and without Content-Length)` - `streamed chunk headers alone do not reset the download deadline` - `empty body chunks do not reset the streamed download deadline` - `streamed chunk assembly handles Content-Length mismatches and encoded bodies (3 subtests)` - `dropping a streamed chunk mid-transfer cancels its reader and releases the lock` - **Green** (main + merge): 67/67 OK. - (MEASURED n=3) each failing test rerun alone 3 times: red 3/3 fail, green 3/3 pass. - Skipped: none (skip 0, todo 0). No npm dependencies (CI runs `node --test tests/test_*.cjs`). - Merge: clean (`git merge --no-ff` onto main). The PR's test file is not older than main's, so the red run is the plain one. **Verdict: READY** AI-assisted: Claude Code
MoonEyes commented 2026-11-29 02:16:05 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T02:16:05Z.


Merged after OreoFR's red/green check (check) (macOS 27.2.1, Apple M5) and a local re-check here. Merged after local re-verification: this PR merged onto main ed72a793f without conflict, and its test file(s) (tests/test_viewer_streaming.cjs) pass there. Earlier today the same tests failed on main without the PR (red/green) and a bundle with other open PRs showed no new failures. check_no_game_data.py is clean. Windows 11, Python 3.14; no GPU needed for these tests.

AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7249318188 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/651#issuecomment-7249318188). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T02:16:05Z. --- Merged after **OreoFR**'s red/green check ([check](https://github.com/ProjectLeonida/mandy/pull/651#issuecomment-7249129883)) (macOS 27.2.1, Apple M5) and a local re-check here. Merged after local re-verification: this PR merged onto `main` ed72a793f without conflict, and its test file(s) (`tests/test_viewer_streaming.cjs`) pass there. Earlier today the same tests failed on `main` without the PR (red/green) and a bundle with other open PRs showed no new failures. `check_no_game_data.py` is clean. Windows 11, Python 3.14; no GPU needed for these tests. _AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes._
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!651
No description provided.