XGameRuntime: store over-long XGameSave container names in hashed folders #492

Open
github-bot wants to merge 2 commits from github-bot/gh-492 into main AGit
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 01:01 UTC · original
DavidM1911:gamesave-long-names → main · +143 −8 · 1 files · 2 commits · open

Fixes #326.

enc() expands every non-unreserved byte to %XX, so a GDK-legal container name (up to 256 chars, / allowed) can produce a folder name far past the 255-char path-component limit — create_dir_all then fails in apply() and every XGameSaveSubmitUpdate to that container returns E_FAIL.

What is in it

  • container_dir_name(): enc(name) while it fits (<= 200 chars — longer encodings cannot fit a Windows path component once the provider root is counted anyway), otherwise ~xcllong.<sip-hash>; ~ is percent-encoded by enc(), so no plain folder can collide with the prefix.
  • apply() writes the real container name to a name file inside hashed folders (atomic write, every update — self-healing if a previous update died mid-commit).
  • each_container resolves ~xcllong.* folders through that file, so enumeration, GetContainerInfo exact lookup, EnumerateContainerInfoByName and DeleteContainer all keep working by the real name.
  • XGameSaveCreateContainer / delete_path use the same mapping; Update carries the container name for apply.

Names that fit keep their enc() folder, so existing saves are untouched.

Tested

  • Windows 11, Ryzen 9 7900X (Radeon iGPU + NVIDIA RTX 3060 Ti 8 GB, driver 610.88), Rust 1.100.0 x86_64-pc-windows-msvc:
    • cargo test -p xcl --lib gamesave: 11 passed, 0 failed (new long_container_names_round_trip_through_a_hashed_folder covers a 256-char name and an "a/"-heavy name through create → submit → enumerate → exact lookup → delete)
    • cargo test --workspace -- --test-threads=4: 677 passed, 0 failed, 41 ignored
  • Regression run on the retail title (1.0.2.1, own copy), RTX 3060 Ti, scripts/smoke.ps1 -Seconds 60, cargo build --release -p xcl:

main a6f5f7a (upstream/main is now 2997c9a, a docs-only commit on top):

xcl-smoke v1
commit: a6f5f7a74cc620c1f88a9e3669a633d10c3c8212
gpu: NVIDIA GeForce RTX 3060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1503 (PresentX 1503)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14437 MB

this PR's head 560368c:

xcl-smoke v1
commit: 560368c4c9bd03de8ae504df4b82785636ad6dec
gpu: NVIDIA GeForce RTX 3060 Ti
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1500 (PresentX 1500)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14447 MB

Not tested

  • Linux/macOS (crate is Windows-only); a title that actually uses over-long container names
  • A container created before this change with an enc() name of 200–255 chars would now get a hashed folder on its next update — judged unreachable in practice since the full path already exceeded MAX_PATH there

AI use

  • Devin (SWE-2 Flash Medium): implemented the change and test, ran the suites and smoke runs.
**@⁠DavidM1911** on GitHub · 2026-11-24 01:01 UTC · [original](https://github.com/xcl-dev/xcl/pull/492) `DavidM1911:gamesave-long-names` → `main` · +143 −8 · 1 files · 2 commits · open Fixes #326. `enc()` expands every non-unreserved byte to `%XX`, so a GDK-legal container name (up to 256 chars, `/` allowed) can produce a folder name far past the 255-char path-component limit — `create_dir_all` then fails in `apply()` and every `XGameSaveSubmitUpdate` to that container returns `E_FAIL`. **What is in it** - `container_dir_name()`: `enc(name)` while it fits (`<= 200` chars — longer encodings cannot fit a Windows path component once the provider root is counted anyway), otherwise `~xcllong.<sip-hash>`; `~` is percent-encoded by `enc()`, so no plain folder can collide with the prefix. - `apply()` writes the real container name to a `name` file inside hashed folders (atomic write, every update — self-healing if a previous update died mid-commit). - `each_container` resolves `~xcllong.*` folders through that file, so enumeration, `GetContainerInfo` exact lookup, `EnumerateContainerInfoByName` and `DeleteContainer` all keep working by the real name. - `XGameSaveCreateContainer` / `delete_path` use the same mapping; `Update` carries the container name for `apply`. Names that fit keep their `enc()` folder, so existing saves are untouched. **Tested** - Windows 11, Ryzen 9 7900X (Radeon iGPU + NVIDIA RTX 3060 Ti 8 GB, driver 610.88), Rust 1.100.0 `x86_64-pc-windows-msvc`: - `cargo test -p xcl --lib gamesave`: 11 passed, 0 failed (new `long_container_names_round_trip_through_a_hashed_folder` covers a 256-char name and an `"a/"`-heavy name through create → submit → enumerate → exact lookup → delete) - `cargo test --workspace -- --test-threads=4`: 677 passed, 0 failed, 41 ignored - Regression run on the retail title (1.0.2.1, own copy), RTX 3060 Ti, `scripts/smoke.ps1 -Seconds 60`, `cargo build --release -p xcl`: main `a6f5f7a` (upstream/main is now `2997c9a`, a docs-only commit on top): ``` xcl-smoke v1 commit: a6f5f7a74cc620c1f88a9e3669a633d10c3c8212 gpu: NVIDIA GeForce RTX 3060 Ti title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1503 (PresentX 1503) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14437 MB ``` this PR's head `560368c`: ``` xcl-smoke v1 commit: 560368c4c9bd03de8ae504df4b82785636ad6dec gpu: NVIDIA GeForce RTX 3060 Ti title: 3c290c16 seconds: 60 exit: 0x0 frames shown: 1500 (PresentX 1500) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14447 MB ``` **Not tested** - Linux/macOS (crate is Windows-only); a title that actually uses over-long container names - A container created before this change with an `enc()` name of 200–255 chars would now get a hashed folder on its next update — judged unreachable in practice since the full path already exceeded MAX_PATH there **AI use** - Devin (SWE-2 Flash Medium): implemented the change and test, ran the suites and smoke runs.
enc() can expand a GDK-legal 256-char container name past the 255-char path-component limit, so create_dir_all failed in apply() and every update to that container returned E_FAIL. container_dir_name() keeps enc() while it fits and otherwise uses ~xcllong.<hash> (the '~' cannot appear in enc() output); apply() writes the real name to a 'name' file in the folder and each_container reads it back, so enumeration, exact lookup and delete keep working by the real name.
Review follow-ups: DefaultHasher is not stable across Rust releases, so the on-disk folder name now uses the crate's fnv64 over the lowercased name (case-insensitive like every other container folder on NTFS; the name file keeps the original case). An enc() folder that already exists on disk keeps being used, so saves written before hashed folders stay reachable.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:23:27 +00:00
Author
Owner

@⁠SM-dev123 on GitHub · 2026-11-24 01:09 UTC · original

Human here :

Thank you for wanting to contribute but please read CONTRIBUTING.md, it explicitly states that contributions must be provided by a Frontier Model,

Devin SWE 2 Flash (on Medium Thinking) is not a frontier model and can introduce alot of slop into the project

**@⁠SM-dev123** on GitHub · 2026-11-24 01:09 UTC · [original](https://github.com/xcl-dev/xcl/pull/492#issuecomment-7118822921) Human here : Thank you for wanting to contribute but please read CONTRIBUTING.md, it explicitly states that contributions must be provided by a **Frontier Model**, Devin SWE 2 Flash (on Medium Thinking) is not a frontier model and can introduce alot of slop into the project
Author
Owner

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

Test run of 560368c4c9bd03de8ae504df4b82785636ad6dec on AMD RDNA4. I merged it onto current main e50836b locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 705 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 664 passed, 0 failed, 21 ignored
  • 0 SKIPPED; long_container_names_round_trip_through_a_hashed_folder passes.

Review: Duplicate of #481 (open), which also stores over-long container names in hashed folders for #326. Only one should land, and its folder naming must then stay fixed, or existing saves would no longer be found.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

**@⁠MesshM** on GitHub · 2026-11-24 05:28 UTC · [original](https://github.com/xcl-dev/xcl/pull/492#issuecomment-7122986209) Test run of `560368c4c9bd03de8ae504df4b82785636ad6dec` on AMD RDNA4. I merged it onto current `main` `e50836b` locally (clean merge) and tested that tree. **Tested** - AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 `stable-x86_64-pc-windows-msvc`, debug - `cargo build --workspace` + `cargo test --workspace -- --test-threads=4` on the merge: **705 passed, 0 failed, 41 ignored**, exit code 0; `xcl` lib tests 664 passed, 0 failed, 21 ignored - **0 `SKIPPED`**; `long_container_names_round_trip_through_a_hashed_folder` passes. **Review:** **Duplicate of #481** (open), which also stores over-long container names in hashed folders for #326. Only one should land, and its folder naming must then stay fixed, or existing saves would no longer be found. **Not tested:** no retail title or regression run (I have no unpacked game), no `XCL_SAMPLE_*` tests, release build; the PR's head on its old base was not run, only its merge onto `main`. Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 08:59 UTC · original

All three points addressed in 7bf139f:

  1. Stable hash: container_dir_name now uses the crate's fnv64 (same FNV-1a as #481) instead of DefaultHasher.
  2. Case-insensitivity: the hash is over name.to_ascii_lowercase(), so "A"*256 and "a"*256 share one folder; the name file keeps the original case for enumeration. The new test creates+submits with the upper-case name, looks up and deletes with the lower-case one, and asserts enumeration is empty afterwards.
  3. Existing saves: container_dir_name returns the enc() folder whenever root.join(enc(name)).is_dir(), so a 201–255-char enc() folder written before this change keeps being used (the test builds exactly that layout by hand: enc() = 201 chars, plain folder, no name file).

cargo test -p xcl --lib gamesave: 11 passed, 0 failed.

**@⁠DavidM1911** on GitHub · 2026-11-24 08:59 UTC · [original](https://github.com/xcl-dev/xcl/pull/492#issuecomment-7126817030) All three points addressed in `7bf139f`: 1. **Stable hash**: `container_dir_name` now uses the crate's `fnv64` (same FNV-1a as #481) instead of `DefaultHasher`. 2. **Case-insensitivity**: the hash is over `name.to_ascii_lowercase()`, so `"A"*256` and `"a"*256` share one folder; the `name` file keeps the original case for enumeration. The new test creates+submits with the upper-case name, looks up and deletes with the lower-case one, and asserts enumeration is empty afterwards. 3. **Existing saves**: `container_dir_name` returns the `enc()` folder whenever `root.join(enc(name)).is_dir()`, so a 201–255-char `enc()` folder written before this change keeps being used (the test builds exactly that layout by hand: `enc()` = 201 chars, plain folder, no `name` file). `cargo test -p xcl --lib gamesave`: 11 passed, 0 failed.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-24 08:59 UTC · original

Fresh regression smoke on the new head 7bf139f (review fixes: FNV-1a hash, case-insensitive folder, existing enc() folders kept). RTX 3060 Ti, GTA VI 1.0.2.1, 60 s:

xcl-smoke v1
commit: 7bf139f92c3053c3467c565a0a43d3a220f7c1f1
gpu: NVIDIA GeForce RTX 3060 Ti
title: GTA6.Xbox.v1.0.2.1-CYBERLEEK
seconds: 60
exit: 0x0
frames shown: 1498 (PresentX 1499)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14446 MB

cargo test --workspace -- --test-threads=4: 677 passed, 0 failed, 41 ignored.

**@⁠DavidM1911** on GitHub · 2026-11-24 08:59 UTC · [original](https://github.com/xcl-dev/xcl/pull/492#issuecomment-7126822000) Fresh regression smoke on the new head `7bf139f` (review fixes: FNV-1a hash, case-insensitive folder, existing `enc()` folders kept). RTX 3060 Ti, GTA VI 1.0.2.1, 60 s: ``` xcl-smoke v1 commit: 7bf139f92c3053c3467c565a0a43d3a220f7c1f1 gpu: NVIDIA GeForce RTX 3060 Ti title: GTA6.Xbox.v1.0.2.1-CYBERLEEK seconds: 60 exit: 0x0 frames shown: 1498 (PresentX 1499) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14446 MB ``` `cargo test --workspace -- --test-threads=4`: 677 passed, 0 failed, 41 ignored.
Author
Owner

@⁠upipibi on GitHub · 2026-11-24 14:07 UTC · original

This and #481 (opened 5 minutes earlier) both fix #326. They are not interchangeable, because each writes its own on-disk layout for a long container, and the one that lands fixes the layout of players' saves:

#481 this PR
folder for a name whose encoding is over 200 chars ~xclc. + FNV-1a 64 of the name ~xcllong. + fnv64 of the name lowercased
where the real name is kept a container_name file, read back for every folder (falls back to decoding the folder name) a name file written when an update is submitted; enumeration reads it only for ~xcllong. folders and skips one without it
an existing folder with the long encoded name not looked for kept (root.join(&e).is_dir())

The lowercasing makes two names that differ only in case share one folder. That matches how the short encoded names behave on a case-insensitive NTFS volume, which #481 does not do for long names. Read from the diffs only; I have not run either.

AI-assisted (Claude Code).

**@⁠upipibi** on GitHub · 2026-11-24 14:07 UTC · [original](https://github.com/xcl-dev/xcl/pull/492#issuecomment-7133871690) This and #481 (opened 5 minutes earlier) both fix #326. They are not interchangeable, because each writes its own on-disk layout for a long container, and the one that lands fixes the layout of players' saves: | | #481 | this PR | |---|---|---| | folder for a name whose encoding is over 200 chars | `~xclc.` + FNV-1a 64 of the name | `~xcllong.` + `fnv64` of the name **lowercased** | | where the real name is kept | a `container_name` file, read back for every folder (falls back to decoding the folder name) | a `name` file written when an update is submitted; enumeration reads it only for `~xcllong.` folders and skips one without it | | an existing folder with the long encoded name | not looked for | kept (`root.join(&e).is_dir()`) | The lowercasing makes two names that differ only in case share one folder. That matches how the short encoded names behave on a case-insensitive NTFS volume, which #481 does not do for long names. Read from the diffs only; I have not run either. AI-assisted (Claude Code).
Author
Owner

@⁠Snorps37 on GitHub · 2026-11-24 01:17 UTC · original · reviewed

Three problems with the folder mapping, found by reading the diff against main (2997c9a). I have not run the tests: I'm on Linux, and XCL builds on Windows only.

1. DefaultHasher is not stable across Rust releases. container_dir_name names the folder with DefaultHasher::new(). The std docs say its algorithm "should not be relied upon over releases", and the repo does not pin a toolchain. The folder name is stored on disk. After a Rust update, XGameSaveCreateContainer and XGameSaveDeleteContainer would point a long-named container at a new, empty folder. Enumeration would still list the old one through its name file. The next update would then create a second container with the same name. A fixed hash avoids this, for example FNV-1a, which #481 uses.

2. Hashed names are case-sensitive; every other name is case-insensitive. Lookups use eq_ignore_ascii_case. enc() keeps letter case, so on NTFS Slot1 and slot1 share one folder. The hash is taken over the exact bytes, so "A".repeat(256) and "a".repeat(256) get two folders:

  • XGameSaveDeleteContainer with the other case removes a folder that does not exist and returns S_OK. The container is still listed.
  • XGameSaveCreateContainer plus a submit with the other case makes a second container. XGameSaveGetContainerInfo then reports two matches for one name.

Hashing name.to_ascii_lowercase() keeps it consistent; the name file can keep the original case.

3. Existing saves with a 201–255 character folder name move. On main, a name whose enc() is 201–255 characters long saves fine. With this PR the same name maps to ~xcllong.<hash>, so opening it by name finds an empty container, while enumeration still lists the old folder. The same was raised on #481. Checking for the enc() folder first and using it when it exists would keep those saves, without any migration.

A test that covers both fixes: create and submit with one case, then delete with the other case, and check that enumeration is empty. Plus a container whose enc() folder is 201–255 characters long, created with the old layout.

AI use: Claude Code (Claude Opus 5.5) helped read the diff and draft this. I checked each point against the code myself.

**@⁠Snorps37** on GitHub · 2026-11-24 01:17 UTC · [original](https://github.com/xcl-dev/xcl/pull/492#pullrequestreview-6032170018) · **reviewed** Three problems with the folder mapping, found by reading the diff against `main` (`2997c9a`). I have not run the tests: I'm on Linux, and XCL builds on Windows only. **1. `DefaultHasher` is not stable across Rust releases.** `container_dir_name` names the folder with `DefaultHasher::new()`. The std docs say its algorithm "should not be relied upon over releases", and the repo does not pin a toolchain. The folder name is stored on disk. After a Rust update, `XGameSaveCreateContainer` and `XGameSaveDeleteContainer` would point a long-named container at a new, empty folder. Enumeration would still list the old one through its `name` file. The next update would then create a second container with the same name. A fixed hash avoids this, for example FNV-1a, which #481 uses. **2. Hashed names are case-sensitive; every other name is case-insensitive.** Lookups use `eq_ignore_ascii_case`. `enc()` keeps letter case, so on NTFS `Slot1` and `slot1` share one folder. The hash is taken over the exact bytes, so `"A".repeat(256)` and `"a".repeat(256)` get two folders: - `XGameSaveDeleteContainer` with the other case removes a folder that does not exist and returns `S_OK`. The container is still listed. - `XGameSaveCreateContainer` plus a submit with the other case makes a second container. `XGameSaveGetContainerInfo` then reports two matches for one name. Hashing `name.to_ascii_lowercase()` keeps it consistent; the `name` file can keep the original case. **3. Existing saves with a 201–255 character folder name move.** On `main`, a name whose `enc()` is 201–255 characters long saves fine. With this PR the same name maps to `~xcllong.<hash>`, so opening it by name finds an empty container, while enumeration still lists the old folder. The same was raised on #481. Checking for the `enc()` folder first and using it when it exists would keep those saves, without any migration. A test that covers both fixes: create and submit with one case, then delete with the other case, and check that enumeration is empty. Plus a container whose `enc()` folder is 201–255 characters long, created with the old layout. AI use: Claude Code (Claude Opus 5.5) helped read the diff and draft this. I checked each point against the code myself.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/492/head:github-bot/gh-492'
git switch 'github-bot/gh-492'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-492'
git switch 'github-bot/gh-492'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-492'
git switch 'github-bot/gh-492'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-492'
git switch 'main'
git merge --squash 'github-bot/gh-492'
git switch 'main'
git merge --ff-only 'github-bot/gh-492'
git switch 'main'
git merge 'github-bot/gh-492'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.