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

Closed
tharun-37 wants to merge 2 commits from upstream-pr/2009 into main
tharun-37 commented 2026-11-25 02:51:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by tharun-37 on 2026-11-25T02:51:51Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6596089840 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2009). Originally posted by [tharun-37](https://github.com/tharun-37) on 2026-11-25T02:51:51Z. --- 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.
catminou4 commented 2026-11-25 04:06:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T03:33:12Z.

Review: COMMENTED


Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Copy-back writes only changed bytes + pages marked current (#721/#722) — part of a three-way split of #2000 (which fixed #721/#722/#726 in one PR): #2009 covers copy-back, #2010 covers #726's v_med3 NaN fix (shader, macOS-tested separately). Maintainer should compare #2000 vs #2009+#2010 and pick.

<!-- greyfinch-sync:Marvisak/VIctory:review:6051461325 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2009#pullrequestreview-6051461325). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T03:33:12Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Copy-back writes only changed bytes + pages marked current (#721/#722) — **part of a three-way split of #2000** (which fixed #721/#722/#726 in one PR): #2009 covers copy-back, #2010 covers #726's v_med3 NaN fix (shader, macOS-tested separately). Maintainer should compare #2000 vs #2009+#2010 and pick.
upipibi commented 2026-11-25 04:06:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-25T03:20:47Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7151827676 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2009#issuecomment-7151827676). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-25T03:20:47Z. --- 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).
jeremygold02 commented 2026-11-25 04:06:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-25T03:08:05Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7151622624 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2009#issuecomment-7151622624). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-25T03:08:05Z. --- **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://github.com/Marvisak/VIctory/pull/1024#issuecomment-7140468649) This verification was AI-assisted.
Marvisak commented 2026-11-25 10:07:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T09:17:01Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7158121745 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2009#issuecomment-7158121745). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T09:17:01Z. --- <!-- 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)_
ajsem1337 commented 2026-11-25 11:05:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ajsem1337 on 2026-11-25T10:48:27Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7160199061 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2009#issuecomment-7160199061). Originally posted by [ajsem1337](https://github.com/ajsem1337) on 2026-11-25T10:48:27Z. --- **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://github.com/Marvisak/VIctory/pull/2009#issuecomment-7151622624) · [Related earlier report](https://github.com/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).
ajsem1337 commented 2026-11-25 12:03:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ajsem1337 on 2026-11-25T11:55:32Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7161687129 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2009#issuecomment-7161687129). Originally posted by [ajsem1337](https://github.com/ajsem1337) on 2026-11-25T11:55:32Z. --- 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.
cloph-dsp commented 2026-11-25 17:05:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-25T16:26:25Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167982819 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2009#issuecomment-7167982819). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-25T16:26:25Z. --- 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).
upstream-sync closed this pull request 2026-11-26 04:05:03 +00:00
tharun-37 commented 2026-11-26 04:06:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by tharun-37 on 2026-11-26T03:26:31Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7181722253 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2009#issuecomment-7181722253). Originally posted by [tharun-37](https://github.com/tharun-37) on 2026-11-26T03:26:31Z. --- Closing to re-scope: taking on better-scoped issues instead.

Pull request closed

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
Marvisak/VIctory!2007
No description provided.