startup: scope zlib stream cache to queued continuation entries #1235

Closed
github-bot wants to merge 6 commits from gh-pr/1235/head into gh-pr/1235/base
Owner

@⁠lambirou on GitHub · 2026-11-24 04:48 UTC · original
lambirou:submit/pr-1214-cache-identity → main · +1121 −34 · 4 files · 6 commits · closed without merging

Change

This is stacked on #1214 at bb35f045. Review only the last commit, 0846d914; the earlier commits are #1214.

The queue-local stream cache still answered any aligned offset within the cached range when the file, compressed size and chunk size matched. A later independent request at a matching continuation offset could therefore receive the first stream's bytes.

  • Each queue entry now carries an id, and a cached stream records the exact ids of the following queued requests that form its continuation chain.
  • The cache lookup requires the current entry id to be in that chain. A later request with the same file, compressed size and offset gets a cache miss, decodes directly, and fails without touching its destination when the bytes are not a zlib stream.
  • The continuation scan skips status entries and stops at the first unrelated request, so a separate Submit cannot inherit a stale chain.
  • The source-built dstorage control now enqueues a valid chunked submission, then a separate Submit with a zlib-marked request at the exact matching offset. The request must fail and leave its 0xCC sentinel unchanged.

Verification

Windows 10.0.26300.10075, MSVC 19.44.35228.0, Ninja, Release.

ctest --preset release --no-tests=error -R '^startup_stubs$' -V
  • With this commit: startup_stubs passes 1/1.
  • Without the source change, the new control fails as expected: the independent request is answered with inflated (slice from stream cache) instead of failing.
  • git diff --check, tests/docs_links_check.py (16 files, 269 links) and tests/bidi_controls_check.py (1005 files) pass.

No game files, dumps or private logs were used. AI-assisted (Codex).

**@⁠lambirou** on GitHub · 2026-11-24 04:48 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1235) `lambirou:submit/pr-1214-cache-identity` → `main` · +1121 −34 · 4 files · 6 commits · closed without merging ## Change This is stacked on #1214 at `bb35f045`. Review only the last commit, `0846d914`; the earlier commits are #1214. The queue-local stream cache still answered any aligned offset within the cached range when the file, compressed size and chunk size matched. A later independent request at a matching continuation offset could therefore receive the first stream's bytes. - Each queue entry now carries an id, and a cached stream records the exact ids of the following queued requests that form its continuation chain. - The cache lookup requires the current entry id to be in that chain. A later request with the same file, compressed size and offset gets a cache miss, decodes directly, and fails without touching its destination when the bytes are not a zlib stream. - The continuation scan skips status entries and stops at the first unrelated request, so a separate `Submit` cannot inherit a stale chain. - The source-built `dstorage` control now enqueues a valid chunked submission, then a separate `Submit` with a zlib-marked request at the exact matching offset. The request must fail and leave its `0xCC` sentinel unchanged. ## Verification Windows 10.0.26300.10075, MSVC 19.44.35228.0, Ninja, Release. ```powershell ctest --preset release --no-tests=error -R '^startup_stubs$' -V ``` - With this commit: `startup_stubs` passes 1/1. - Without the source change, the new control fails as expected: the independent request is answered with `inflated (slice from stream cache)` instead of failing. - `git diff --check`, `tests/docs_links_check.py` (16 files, 269 links) and `tests/bidi_controls_check.py` (1005 files) pass. No game files, dumps or private logs were used. AI-assisted (Codex).
- Distinguish decode length from destination capacity in execute_request (Refs #1144).
- Bound queue_enqueue_request token array by destination_size to prevent out-of-bounds reads.
- Reject requests exceeding destination capacity or with missing/insufficient page grants with E_FAIL while leaving destination memory completely untouched.
- Add StreamCache and has_following_chunk to support chunked streaming reads where requests are stepped by destination size (Fixes #1136).
- Add multi-page, short-destination, missing-grant, linear-short, and 4-chunk streaming regression controls to startup_stub_consumer and startup_stub_check.
- In StreamCache::get_slice, check delta <= it->data.size() && need_bytes <= it->data.size() - delta to prevent integer overflow.
- In has_following_chunk, check e_offset > offset && e_offset - offset == destination_size.
- Add near-wrapping offset control (UINT64_MAX - 0x10000) verifying clean E_FAIL and untouched memory.
Track chunk_size from piece 0 in CachedStream so multi-piece continuation lookups step by chunk_size rather than the trailing piece's destination size. Allow short final destinations where destination_size <= available to receive their slice while rejecting requests that exceed remaining available uncompressed bytes.

Extend startup_stub_consumer dstorage scenario with source-built controls for a 100 KiB multi-piece stream targeting physical pages (64 KiB piece 0 + 36 KiB piece 1), verifying exact data, untouched guard bytes beyond 36 KiB in Page 1, and untouched neighboring page grants. Include negative control for invalid oversized decode failing cleanly with untouched destination memory. Refs #1144, #1214.
The queue cache now records the entry ids of the exact following requests that form the chunked continuation. A later standalone submission with the same file, compressed size and matching offset no longer receives cached bytes; it decodes directly or fails without touching its destination. Add a separate-Submit control for that case.

Verified on Windows Release: startup_stubs passes, and the new control fails against the previous head. docs_links and bidi_controls pass.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:51:09 +00:00
github-bot closed this pull request 2026-11-26 22:51:09 +00:00
Author
Owner

@⁠lambirou on GitHub · 2026-11-24 04:48 UTC · original

@⁠R0Y00 This is the remaining cache-identity case from #1214. It is stacked on #1214 at bb35f045; review only the last commit, 0846d914.

The queue cache now records the exact entry ids of the following queued requests that form the continuation chain, and a lookup requires the current entry id to be in that chain. The new source-built control does a valid chunked submission, then a separate Submit with a zlib-marked request at the exact matching offset; the request fails and its 0xCC sentinel stays unchanged. Against the previous head, the same control is answered by inflated (slice from stream cache).

Windows Release startup_stubs passes 1/1. Kept as a draft until #1214 lands. AI-assisted (Codex).

**@⁠lambirou** on GitHub · 2026-11-24 04:48 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1235#issuecomment-7122364274) @⁠R0Y00 This is the remaining cache-identity case from #1214. It is stacked on #1214 at `bb35f045`; review only the last commit, `0846d914`. The queue cache now records the exact entry ids of the following queued requests that form the continuation chain, and a lookup requires the current entry id to be in that chain. The new source-built control does a valid chunked submission, then a separate `Submit` with a zlib-marked request at the exact matching offset; the request fails and its `0xCC` sentinel stays unchanged. Against the previous head, the same control is answered by `inflated (slice from stream cache)`. Windows Release `startup_stubs` passes 1/1. Kept as a draft until #1214 lands. AI-assisted (Codex).
Author
Owner

@⁠lambirou on GitHub · 2026-11-24 04:51 UTC · original

CI is green on 0846d914: Windows checks run 3038 passed (Windows build/tests, Linux Python checks, gfx1013 fixtures). The PR is ready for review, still stacked on #1214 at bb35f045; review only the last commit.

Local Release startup_stubs passes 1/1, and the separate-Submit control fails against the previous head, so the regression is covered. AI-assisted (Codex).

**@⁠lambirou** on GitHub · 2026-11-24 04:51 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1235#issuecomment-7122397858) CI is green on `0846d914`: `Windows checks` run 3038 passed (Windows build/tests, Linux Python checks, gfx1013 fixtures). The PR is ready for review, still stacked on #1214 at `bb35f045`; review only the last commit. Local Release `startup_stubs` passes 1/1, and the separate-`Submit` control fails against the previous head, so the regression is covered. AI-assisted (Codex).
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 05:05 UTC · original

Tested on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at commit 0846d914:

  • Debug (--preset dev):
    • Build: cmake --preset dev && cmake --build out/build/dev -j 6 --target startup_stub_consumer startup_stub_acphal startup_stub_chad startup_stub_xapu startup_stub_xcrdapi startup_stub_xg_xs startup_stub_gameinput
    • Test: ctest --test-dir out/build/dev -R "^startup_stubs$" --output-on-failure -> 1/1 passed (0.49s, total 0.52s)
  • Release /O2 (--preset release):
    • Build: cmake --preset release && cmake --build out/build/release -j 6 --target startup_stub_consumer startup_stub_acphal startup_stub_chad startup_stub_xapu startup_stub_xcrdapi startup_stub_xg_xs startup_stub_gameinput
    • Test: ctest --test-dir out/build/release -R "^startup_stubs$" --output-on-failure -> 1/1 passed (0.54s, total 0.57s)
**@⁠tedin7** on GitHub · 2026-11-24 05:05 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1235#issuecomment-7122620904) Tested on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at commit `0846d914`: - **Debug (`--preset dev`)**: - Build: `cmake --preset dev && cmake --build out/build/dev -j 6 --target startup_stub_consumer startup_stub_acphal startup_stub_chad startup_stub_xapu startup_stub_xcrdapi startup_stub_xg_xs startup_stub_gameinput` - Test: `ctest --test-dir out/build/dev -R "^startup_stubs$" --output-on-failure` -> **1/1 passed** (`0.49s`, total `0.52s`) - **Release `/O2` (`--preset release`)**: - Build: `cmake --preset release && cmake --build out/build/release -j 6 --target startup_stub_consumer startup_stub_acphal startup_stub_chad startup_stub_xapu startup_stub_xcrdapi startup_stub_xg_xs startup_stub_gameinput` - Test: `ctest --test-dir out/build/release -R "^startup_stubs$" --output-on-failure` -> **1/1 passed** (`0.54s`, total `0.57s`)
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-24 05:22 UTC · original

The continuation-entry ID approach from this PR is on main through #1214 (0fa43ad6), with the original contribution credited. The merged version also verifies the submission ID and has an event-gated two-batch control. Thanks for supplying the original separate-Submit regression and independent verification.

**@⁠R0Y00** on GitHub · 2026-11-24 05:22 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1235#issuecomment-7122885107) The continuation-entry ID approach from this PR is on main through #1214 (0fa43ad6), with the original contribution credited. The merged version also verifies the submission ID and has an event-gated two-batch control. Thanks for supplying the original separate-Submit regression and independent verification.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 04:58 UTC · original · reviewed

Reviewed commit 0846d914 on Linux (Windows build/tests were not run locally).

Stacking & diff audit

  • Stacked on #1214 at bb35f045 (note #1214 is currently open at 9570cec4).
  • src/startup_stubs/xcrdapi.cpp:
    • Entry gains a monotonic u64 id assigned in push() under work.mutex (++work.next_entry_id).
    • following_chunk_ids() scans work.submitted (after the current entry has already been popped in the worker loop) and work.waiting, skipping status_entry items and stopping at any non-continuation or mismatched request. Unsigned overflow is guarded both on initial offset + destination_size (expected < offset) and per step (expected > UINT64_MAX - destination_size).
    • CachedStream stores continuation_ids, and cache lookup in execute_request() requires entry_id to be present in continuation_ids in addition to matching source, compressed_size, and aligned offset > base_offset.
  • tests/startup_stub_consumer.cpp: expands the temp file to 16 MiB and adds a separate-Submit control at the matching continuation offset (chunk_dest_size) verifying non-zero status and untouched destination (0xCC).
  • docs/startup-runtime.md: documents stream-cache identity. 100% title-neutral.

Linux checks (0846d914)

  • docs_links_check.py: passed (16 Markdown files, 269 links).
  • bidi_controls_check.py: passed (1005 files).
  • form_coverage_check.py: passed.
  • git diff --check: clean.
  • startup_stub_check.py / startup_stub_consumer.cpp: Windows-only executable checks, not run locally.
**@⁠tedin7** on GitHub · 2026-11-24 04:58 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1235#pullrequestreview-6033898857) · **reviewed** Reviewed commit `0846d914` on Linux (Windows build/tests were not run locally). ### Stacking & diff audit - Stacked on `#1214` at `bb35f045` (note `#1214` is currently open at `9570cec4`). - `src/startup_stubs/xcrdapi.cpp`: - `Entry` gains a monotonic `u64 id` assigned in `push()` under `work.mutex` (`++work.next_entry_id`). - `following_chunk_ids()` scans `work.submitted` (after the current entry has already been popped in the worker loop) and `work.waiting`, skipping `status_entry` items and stopping at any non-continuation or mismatched request. Unsigned overflow is guarded both on initial `offset + destination_size` (`expected < offset`) and per step (`expected > UINT64_MAX - destination_size`). - `CachedStream` stores `continuation_ids`, and cache lookup in `execute_request()` requires `entry_id` to be present in `continuation_ids` in addition to matching `source`, `compressed_size`, and aligned `offset > base_offset`. - `tests/startup_stub_consumer.cpp`: expands the temp file to 16 MiB and adds a separate-`Submit` control at the matching continuation offset (`chunk_dest_size`) verifying non-zero status and untouched destination (`0xCC`). - `docs/startup-runtime.md`: documents stream-cache identity. 100% title-neutral. ### Linux checks (`0846d914`) - `docs_links_check.py`: passed (16 Markdown files, 269 links). - `bidi_controls_check.py`: passed (1005 files). - `form_coverage_check.py`: passed. - `git diff --check`: clean. - `startup_stub_check.py` / `startup_stub_consumer.cpp`: Windows-only executable checks, not run locally.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.