Fix #721, #722: copy-back writes only changed bytes; mark pages current conditionally #2009

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

@⁠tharun-37 on GitHub · 2026-11-25 02:51 UTC · original
tharun-37:fix/shadow-copyback → main · +52 −8 · 2 files · 2 commits · closed without merging

Split from #2000 per review feedback (gpu-only, Windows path). #721: copy_back now writes only changed bytes. #722: page marked current only if title still matches. Builds clean; shadow tests pass.

**@⁠tharun-37** on GitHub · 2026-11-25 02:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2009) `tharun-37:fix/shadow-copyback` → `main` · +52 −8 · 2 files · 2 commits · closed without merging Split from #2000 per review feedback (gpu-only, Windows path). #721: copy_back now writes only changed bytes. #722: page marked current only if title still matches. Builds clean; shadow tests pass.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:51:32 +00:00
github-bot closed this pull request 2026-11-26 04:51:32 +00:00
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-25 03:08 UTC · original · edited 2026-11-25 03:22 UTC

Triage verdict — Needs changes (57fdaea)

Evidence

  • The byte-run write in 57fdaea addresses the right invariant for #721. For #722, I would keep the PR in review until the final compare is tied to the page’s watch state. copy_back re-reads title bytes and compares them with the host copy, then separately calls Tracked::taken, which protects the page and clears its dirty entry. From the code, a title write between the compare and that clear can leave a stale copy marked current.
  • #1024 is an overlapping implementation, with separate regressions for concurrent writes and read-only pages.

Checks and limits

  • I did not reproduce that interleaving; the updated test assertions count bytes copied and do not schedule a write in this window.

Next step

  • I’d preserve those tests and add a controlled write between the compare and the clean-state transition. Also worth carrying forward its sparse-write cost check: this head makes one write_mapped call per changed run, so a passing dense or small test does not bound that cost. Prior sparse-write discussion

This verification was AI-assisted.

**@⁠jeremygold02** on GitHub · 2026-11-25 03:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/2009#issuecomment-7151622624) · edited 2026-11-25 03:22 UTC **Triage verdict — Needs changes** (`57fdaea`) **Evidence** - The byte-run write in `57fdaea` addresses the right invariant for #721. For #722, I would keep the PR in review until the final compare is tied to the page’s watch state. `copy_back` re-reads title bytes and compares them with the host copy, then separately calls `Tracked::taken`, which protects the page and clears its dirty entry. From the code, a title write between the compare and that clear can leave a stale copy marked current. - #1024 is an overlapping implementation, with separate regressions for concurrent writes and read-only pages. **Checks and limits** - I did not reproduce that interleaving; the updated test assertions count bytes copied and do not schedule a write in this window. **Next step** - I’d preserve those tests and add a controlled write between the compare and the clean-state transition. Also worth carrying forward its sparse-write cost check: this head makes one `write_mapped` call per changed run, so a passing dense or small test does not bound that cost. [Prior sparse-write discussion](https://git.gtahub.st/github/Marvisak--VIctory/pulls/1024) This verification was AI-assisted.
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 03:20 UTC · original

Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at 57fdaea. victory-gpu: 141 passed, 2 failed, 2 ignored. This PR adds no test of its own for #721 / #722, so this only shows the existing tests still pass. The 2 are #1744's NVIDIA failures on main (dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views, the heap-cap ones). Same as main on this hardware. Not run: a title.

AI-assisted (Claude Code).

**@⁠upipibi** on GitHub · 2026-11-25 03:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/2009#issuecomment-7151827676) Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at `57fdaea`. `victory-gpu`: 141 passed, 2 failed, 2 ignored. This PR adds no test of its own for #721 / #722, so this only shows the existing tests still pass. The 2 are #1744's NVIDIA failures on `main` (`dynamic_slots_are_held_until_released` and `lists_share_a_table_and_copies_keep_their_views`, the heap-cap ones). Same as `main` on this hardware. Not run: a title. AI-assisted (Claude Code).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 09:17 UTC · original · edited 2026-11-25 22:19 UTC

Automated triage for the maintainers.

Needs rebase. This PR no longer merges cleanly into main (conflicts in crates/victory-gpu/src/shadow.rs and crates/victory-gpu/src/watch.rs). It will be reviewed again once it is rebased.

From the earlier needs-work note, still open: regression tests in the PR for the #722 race and for #721, a bound or measurement for the per-run write_mapped cost, and the overlap with #1024.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 09:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/2009#issuecomment-7158121745) · edited 2026-11-25 22:19 UTC <!-- victory-triage v1 head=b9ecb1e295f18ebc3b5ad86e7a5b3774526fe8c5 verdict=needs-rebase at=2026-11-25T22:24:35Z --> Automated triage for the maintainers. **Needs rebase.** This PR no longer merges cleanly into `main` (conflicts in `crates/victory-gpu/src/shadow.rs` and `crates/victory-gpu/src/watch.rs`). It will be reviewed again once it is rebased. From the earlier needs-work note, still open: regression tests in the PR for the #722 race and for #721, a bound or measurement for the per-run `write_mapped` cost, and the overlap with #1024. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠ajsem1337 on GitHub · 2026-11-25 10:48 UTC · original

Deterministic reproduction of the guarded copy-back race

Following up on the race identified in review, a test simulates a GPU write by changing the host copy. During guarded snapshot copy-back, a test hook makes a second thread write to the tracked title page just before Tracked::taken.

Tested build Marker in title memory per seed Marker in host copy after two more submissions
main (940d32f) 32/32 0/32
main with #2009 (57fdaea) 32/32 0/32

Three seeds on main and two on the PR gave the same result. The other eight cases met their visibility deadlines on both builds.

On #2009 the write lands after the final comparison and before the page is re-protected. That write is marked as already copied. Marking the page current requires validating its bytes after re-protection and preserving later writes, including writes through aliases. Prior review · Related earlier report

Reproducer (test, test-only hook, and the one-line assertion change for this PR): https://gist.github.com/ajsem1337/551639fa596a63f63282956d42917b0c

Found with AI assistance (Codex wrote the original test, Claude Code ported it to main and ran it).

**@⁠ajsem1337** on GitHub · 2026-11-25 10:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/2009#issuecomment-7160199061) **Deterministic reproduction of the guarded copy-back race** Following up on the race identified in review, a test simulates a GPU write by changing the host copy. During guarded snapshot copy-back, a test hook makes a second thread write to the tracked title page just before `Tracked::taken`. | Tested build | Marker in title memory per seed | Marker in host copy after two more submissions | |---|---:|---:| | `main` (`940d32f`) | 32/32 | 0/32 | | `main` with #2009 (`57fdaea`) | 32/32 | 0/32 | Three seeds on main and two on the PR gave the same result. The other eight cases met their visibility deadlines on both builds. On #2009 the write lands after the final comparison and before the page is re-protected. That write is marked as already copied. Marking the page current requires validating its bytes after re-protection and preserving later writes, including writes through aliases. [Prior review](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2009) · [Related earlier report](https://git.gtahub.st/github/Marvisak--VIctory/issues/722) Reproducer (test, test-only hook, and the one-line assertion change for this PR): https://gist.github.com/ajsem1337/551639fa596a63f63282956d42917b0c Found with AI assistance (Codex wrote the original test, Claude Code ported it to `main` and ran it).
Author
Owner

@⁠ajsem1337 on GitHub · 2026-11-25 11:55 UTC · original

Re-ran the reproducer from the gist on b9ecb1e: the BeforeTaken case now passes for all three seeds (3913, 77, 1234567). The write made just before Tracked::taken reaches the host copy one submission later (lost: 0, deferred: 32, was lost: 32 on main and on 57fdaea), and the whole test passes.

Limits: the gist's 0001 no longer applies to the changed taken, so I put the same BEFORE_TAKEN hook in by hand at the same place (top of taken, before guards()), plus 0002. The test covers that window only, not a write landing inside the guarded section, and it ran under Proton on an RX 7900 GRE, not on Windows.

**@⁠ajsem1337** on GitHub · 2026-11-25 11:55 UTC · [original](https://github.com/Marvisak/VIctory/pull/2009#issuecomment-7161687129) Re-ran the reproducer from the gist on b9ecb1e: the `BeforeTaken` case now passes for all three seeds (3913, 77, 1234567). The write made just before `Tracked::taken` reaches the host copy one submission later (`lost: 0, deferred: 32`, was `lost: 32` on `main` and on 57fdaea), and the whole test passes. Limits: the gist's 0001 no longer applies to the changed `taken`, so I put the same `BEFORE_TAKEN` hook in by hand at the same place (top of `taken`, before `guards()`), plus 0002. The test covers that window only, not a write landing inside the guarded section, and it ran under Proton on an RX 7900 GRE, not on Windows.
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-25 16:26 UTC · original

Independent GPU validation for PR #2009 (Windows, Rust 1.100.0/MSVC, head b9ecb1e, no game data): cargo test --locked -p victory-gpu --lib shadow::tests with VICTORY_D3D12_WARP=0 on RTX 5060 Laptop (driver 621.24) -> 4 tests passed (title_writes_under_a_busy_range_are_copied, snapshots_cover_the_declared_ranges_and_writes_go_back_once, marked_pages_go_back_by_the_bytes_the_gpu_changed, mark_runs_are_reused_and_joined), 141 filtered, exit 0; with VICTORY_D3D12_WARP=1 --features diagnostics (WARP) -> same 4 tests passed, 144 filtered, exit 0. Explicit adapter selection used because the hybrid laptop may default to the 780M iGPU. No real title or game data used. AI-assisted (Hy4 flash). GPU/driver: RTX 5060 Laptop, driver 621.24, Vulkan 1.4.357 (WARP second data point).

**@⁠cloph-dsp** on GitHub · 2026-11-25 16:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2009#issuecomment-7167982819) Independent GPU validation for PR #2009 (Windows, Rust 1.100.0/MSVC, head b9ecb1e, no game data): `cargo test --locked -p victory-gpu --lib shadow::tests` with `VICTORY_D3D12_WARP=0` on RTX 5060 Laptop (driver 621.24) -> 4 tests passed (`title_writes_under_a_busy_range_are_copied`, `snapshots_cover_the_declared_ranges_and_writes_go_back_once`, `marked_pages_go_back_by_the_bytes_the_gpu_changed`, `mark_runs_are_reused_and_joined`), 141 filtered, exit 0; with `VICTORY_D3D12_WARP=1 --features diagnostics` (WARP) -> same 4 tests passed, 144 filtered, exit 0. Explicit adapter selection used because the hybrid laptop may default to the 780M iGPU. No real title or game data used. AI-assisted (Hy4 flash). GPU/driver: RTX 5060 Laptop, driver 621.24, Vulkan 1.4.357 (WARP second data point).
Author
Owner

@⁠tharun-37 on GitHub · 2026-11-26 03:26 UTC · original

Closing to re-scope: taking on better-scoped issues instead.

**@⁠tharun-37** on GitHub · 2026-11-26 03:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2009#issuecomment-7181722253) Closing to re-scope: taking on better-scoped issues instead.

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!2009
No description provided.