Pipeline: delimit converter id in cache keys #922

Closed
github-bot wants to merge 1 commit from gh-pr/922/head into gh-pr/922/base
Owner

@⁠enzoduarte1 on GitHub · 2026-11-24 14:12 UTC · original
enzoduarte1:pipeline/cache-key-delimiter → main · +31 −2 · 1 files · 1 commits · closed without merging

What

CacheKey::new fed the converter id, a single 0x00 separator, the 4-byte version and the input straight into BLAKE3. A &'static str may contain NUL, so the separator was ambiguous: id = "a\0", version = 1 and id = "a", version = 256 produced the same byte stream and therefore the same cache key. With two converters sharing a cache, whichever ran first could serve its output to the other.

The id is now length-prefixed with a u64, which makes every field boundary unambiguous while keeping the key stable for existing valid ids. A regression test asserts that the colliding pair and a differing-input pair produce distinct keys.

Tested

  • Windows 11, Rust 1.98.1, x86_64-pc-windows-gnu (no MSVC linker on this machine).
  • cargo test -p victory-pipeline --lib: 4 passed.
  • git diff --check and rustfmt --check on the changed file: clean.
  • cargo xtask policy: 151 files ok. No game files or data taken from them were added.
  • Not tested: cargo test -p victory-loader --test load_probe; its fixture uses MSVC /DELAYLOAD, which MinGW rejects here (same failure on unmodified main).

Checklist

  • cargo fmt --all --check and cargo test --workspace pass — this workspace has pre-existing formatting diffs and the loader fixture limitation described above; the changed crate is clean.
  • cargo xtask policy passes. The change adds no game files or data taken from them (docs/asset-policy.md).
  • If an AI tool wrote part of this change, the description says so: an AI tool assisted with the code and test; I reviewed and ran them.
**@⁠enzoduarte1** on GitHub · 2026-11-24 14:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/922) `enzoduarte1:pipeline/cache-key-delimiter` → `main` · +31 −2 · 1 files · 1 commits · closed without merging ## What `CacheKey::new` fed the converter id, a single `0x00` separator, the 4-byte version and the input straight into BLAKE3. A `&'static str` may contain NUL, so the separator was ambiguous: `id = "a\0", version = 1` and `id = "a", version = 256` produced the same byte stream and therefore the same cache key. With two converters sharing a cache, whichever ran first could serve its output to the other. The id is now length-prefixed with a `u64`, which makes every field boundary unambiguous while keeping the key stable for existing valid ids. A regression test asserts that the colliding pair and a differing-input pair produce distinct keys. ## Tested - Windows 11, Rust 1.98.1, `x86_64-pc-windows-gnu` (no MSVC linker on this machine). - `cargo test -p victory-pipeline --lib`: 4 passed. - `git diff --check` and `rustfmt --check` on the changed file: clean. - `cargo xtask policy`: 151 files ok. No game files or data taken from them were added. - Not tested: `cargo test -p victory-loader --test load_probe`; its fixture uses MSVC `/DELAYLOAD`, which MinGW rejects here (same failure on unmodified `main`). ## Checklist - [ ] `cargo fmt --all --check` and `cargo test --workspace` pass — this workspace has pre-existing formatting diffs and the loader fixture limitation described above; the changed crate is clean. - [x] `cargo xtask policy` passes. The change adds no game files or data taken from them (`docs/asset-policy.md`). - [x] If an AI tool wrote part of this change, the description says so: an AI tool assisted with the code and test; I reviewed and ran them.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:14:11 +00:00
github-bot closed this pull request 2026-11-26 04:14:11 +00:00
Author
Owner

@⁠shortselow-byte on GitHub · 2026-11-24 14:21 UTC · original

Tested at head f7bce85 (base ffe310e) on Windows 11, Rust 1.98.1, x86_64-pc-windows-msvc:

  • cargo test --locked -p victory-pipeline: 5 passed.
  • cargo clippy --workspace --all-targets --locked -- -D warnings, and with --all-features: clean.
  • rustfmt --check on cache.rs: clean.

The fix itself looks right, but the regression test does not catch the bug. With main's key code (id, 0x00, version) put back, id_and_version_are_delimited still passes: "a\0"/1 and "a"/256 with the same empty input hash 7 bytes vs 6, so they never collided. The colliding pair needs the input to absorb the shifted byte:

// Old stream: "a\0" 00 | 01 00 00 00 | ""  ==  "a" 00 | 00 01 00 00 | "\0"
assert_ne!(
    CacheKey::new(&Keyed("a\0", 1), b""),
    CacheKey::new(&Keyed("a", 256), b"\0")
);

With the old key code this assertion fails (both keys 8502be22…ed13); with this PR it passes. Suggest using this pair in the test.

One nit on the description: the length prefix changes the hashed bytes for every id, so every existing cache key changes (existing caches miss once and rebuild). Probably fine, but "keeping the key stable for existing valid ids" isn't accurate.

**@⁠shortselow-byte** on GitHub · 2026-11-24 14:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/922#issuecomment-7134234342) Tested at head `f7bce85` (base `ffe310e`) on Windows 11, Rust 1.98.1, `x86_64-pc-windows-msvc`: - `cargo test --locked -p victory-pipeline`: 5 passed. - `cargo clippy --workspace --all-targets --locked -- -D warnings`, and with `--all-features`: clean. - `rustfmt --check` on `cache.rs`: clean. The fix itself looks right, but the regression test does not catch the bug. With `main`'s key code (`id`, `0x00`, version) put back, `id_and_version_are_delimited` still passes: `"a\0"`/1 and `"a"`/256 with the same empty input hash 7 bytes vs 6, so they never collided. The colliding pair needs the input to absorb the shifted byte: ```rust // Old stream: "a\0" 00 | 01 00 00 00 | "" == "a" 00 | 00 01 00 00 | "\0" assert_ne!( CacheKey::new(&Keyed("a\0", 1), b""), CacheKey::new(&Keyed("a", 256), b"\0") ); ``` With the old key code this assertion fails (both keys `8502be22…ed13`); with this PR it passes. Suggest using this pair in the test. One nit on the description: the length prefix changes the hashed bytes for every id, so every existing cache key changes (existing caches miss once and rebuild). Probably fine, but "keeping the key stable for existing valid ids" isn't accurate.
Author
Owner

@⁠MichaelSmithAI on GitHub · 2026-11-24 14:31 UTC · original

I checked the on-disk behavior behind the earlier review’s compatibility note. A Linux fixture prepopulated the old path for the ordinary converter ID test.upper, version 1, input abc, with output ABC. On f7bce85 the first lookup ran the converter and published ABC at a different path. The second lookup hit that new entry. The original file still contained ABC, and the converter ran exactly once across the two lookups. This measures a cold lookup for an existing input and no change in its converted bytes.

**@⁠MichaelSmithAI** on GitHub · 2026-11-24 14:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/922#issuecomment-7134506315) I checked the on-disk behavior behind the earlier review’s compatibility note. A Linux fixture prepopulated the old path for the ordinary converter ID `test.upper`, version 1, input `abc`, with output `ABC`. On f7bce85 the first lookup ran the converter and published `ABC` at a different path. The second lookup hit that new entry. The original file still contained `ABC`, and the converter ran exactly once across the two lookups. This measures a cold lookup for an existing input and no change in its converted bytes.
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 15:41 UTC · original

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at f7bce85: cargo test -p victory-pipeline passes, 5 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 15:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/922#issuecomment-7136437211) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at f7bce85: `cargo test -p victory-pipeline` passes, 5 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:28 UTC · original

Automated triage for the maintainers. Closing because it does not change behaviour the project needs (formatting, guards for cases that cannot occur, or notes and translations that cannot be kept current).

Length-prefixes the converter id in CacheKey against a collision that needs a NUL inside an id; ids are string literals in our code (only "shader.dxil" exists). Contrary to the body, the new byte stream changes every key, so the whole translated-shader cache misses once and the old entries stay orphaned in the same translator folder: a cost without a benefit.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

**@⁠Marvisak** on GitHub · 2026-11-25 00:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/922#issuecomment-7148541176) Automated triage for the maintainers. Closing because it does not change behaviour the project needs (formatting, guards for cases that cannot occur, or notes and translations that cannot be kept current). Length-prefixes the converter id in CacheKey against a collision that needs a NUL inside an id; ids are string literals in our code (only "shader.dxil" exists). Contrary to the body, the new byte stream changes every key, so the whole translated-shader cache misses once and the old entries stay orphaned in the same translator folder: a cost without a benefit. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!922
No description provided.