Forget up-copy check entries for copies that are gone #412

Closed
github-bot wants to merge 661 commits from github-bot/gh-412 into main AGit
Owner

@⁠safesearch77 on GitHub · 2026-11-28 13:26 UTC · original
safesearch77:fix/upcheck-forget-gone → main · +60106 −5430 · 206 files · 661 commits · closed without merging

With VICTORY_UPCOPY_CHECK=1, KNOWN in host/upcheck.rs kept an entry for every copy that was ever declared or fetched. It's never pruned, so it grows for the whole session. The look at rest now keeps only the ids still in shadow::carded_copies(), before anything in the look can fail.

Why that's safe:

  • Copy ids come from a monotonic counter (shadow.rs NEXT) and are never reused.
  • CARDED only drops dead copies (card_dirty's retain keeps every live Weak). A live copy is never forgotten while it is temporarily without a card piece.
  • The look names the carded copies while holding KNOWN's own lock (carded_known), so nothing can be declared or fetched between naming them and pruning. (The first version said the submission lock covered this; it doesn't, because declared/fetched also run on the thread that lands flights. Fixed in the follow-up commit c15da1e.)

This is a diagnostics-only path, off by default, so it doesn't change the default behaviour.

Ported from trustno1-coder/VIctory-NVIDIA@8e9f11d (DiosET3RN0).

Verification (Linux, GE-Proton11-14 Wine runner, x86_64-pc-windows-msvc)

  • Scope of the Wine runs: CPU-side tests pass under Wine. GPU-backed tests return early because crate::host::host() is None (no D3D12 host in that harness). This PR's new test is a pure CPU test, so it runs and passes.
  • New test host::upcheck::tests::what_is_known_of_a_copy_that_is_gone_is_let_go: fails without forget_gone and passes with the fix.
  • cargo +1.98.1 test -p victory-gpu --lib (Wine): 523 passed; 5 failed (default) and 589 passed; 6 failed (--features diagnostics), matching untouched main (fe7c6e5); zero new failures.
  • cargo +1.98.1 clippy -p victory-gpu --all-targets -- -D warnings: clean, both default and --features diagnostics.
  • cargo +1.98.1 xtask policy: asset policy: 322 files ok.
**@⁠safesearch77** on GitHub · 2026-11-28 13:26 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/412) `safesearch77:fix/upcheck-forget-gone` → `main` · +60106 −5430 · 206 files · 661 commits · closed without merging With `VICTORY_UPCOPY_CHECK=1`, `KNOWN` in `host/upcheck.rs` kept an entry for every copy that was ever declared or fetched. It's never pruned, so it grows for the whole session. The look at rest now keeps only the ids still in `shadow::carded_copies()`, before anything in the look can fail. Why that's safe: - Copy ids come from a monotonic counter (`shadow.rs` `NEXT`) and are never reused. - `CARDED` only drops dead copies (`card_dirty`'s `retain` keeps every live `Weak`). A live copy is never forgotten while it is temporarily without a card piece. - The look names the carded copies while holding `KNOWN`'s own lock (`carded_known`), so nothing can be declared or fetched between naming them and pruning. (The first version said the submission lock covered this; it doesn't, because `declared`/`fetched` also run on the thread that lands flights. Fixed in the follow-up commit `c15da1e`.) This is a diagnostics-only path, off by default, so it doesn't change the default behaviour. Ported from `trustno1-coder/VIctory-NVIDIA@8e9f11d` (`DiosET3RN0`). ### Verification (Linux, `GE-Proton11-14` Wine runner, `x86_64-pc-windows-msvc`) - **Scope of the Wine runs:** CPU-side tests pass under Wine. GPU-backed tests return early because `crate::host::host()` is `None` (no D3D12 host in that harness). This PR's new test is a pure CPU test, so it runs and passes. - New test `host::upcheck::tests::what_is_known_of_a_copy_that_is_gone_is_let_go`: fails without `forget_gone` and passes with the fix. - `cargo +1.98.1 test -p victory-gpu --lib` (Wine): `523 passed; 5 failed` (default) and `589 passed; 6 failed` (`--features diagnostics`), matching untouched `main` (`fe7c6e5`); zero new failures. - `cargo +1.98.1 clippy -p victory-gpu --all-targets -- -D warnings`: clean, both default and `--features diagnostics`. - `cargo +1.98.1 xtask policy`: `asset policy: 322 files ok`.
With VICTORY_UPCOPY_CHECK=1, KNOWN kept an entry for every copy that was
ever declared or fetched, so the map grew for the whole session. The look
at rest now keeps only the ids still in carded_copies(), before anything
in it can fail. A copy's id is never reused, and nothing declares or
fetches while the look runs because the submission lock is held.

Ported from trustno1-coder/VIctory-NVIDIA 8e9f11d (DiosET3RN0).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 13:36:56 +00:00
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-29 11:35 UTC · original

Thanks for addressing the growing diagnostic map. Please check that pruning cannot discard a live copy's entry while it is being inspected, and that a retired or reused identifier doesn't inherit stale state.

**@⁠TaynanGT** on GitHub · 2026-11-29 11:35 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/412#issuecomment-7255219639) Thanks for addressing the growing diagnostic map. Please check that pruning cannot discard a live copy's entry while it is being inspected, and that a retired or reused identifier doesn't inherit stale state.
declared() and fetched() also run on the thread that lands flights,
which takes no submission lock. Naming the copies before taking KNOWN's
lock left a window where a copy made and declared in between would be
pruned while alive. Take KNOWN first (order KNOWN -> CARDED), and test
that a copy made again starts with nothing known.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Author
Owner

@⁠safesearch77 on GitHub · 2026-11-29 13:20 UTC · original

Thanks, both points checked. The first one turned up a gap, now closed.

Can pruning drop a live copy's entry while it is being inspected? Not the way it's used, but the PR's stated reason was wrong. Here's the reasoning:

  • KNOWN is read in two places. look() reads entries of the copies it just named (carded_copies()), and the prune keeps exactly those. Looks::read() (the check at each send) reads the copies card_dirty() handed to record(). Those were carded when recorded, and Looks holds an Arc to each. CARDED only drops a Weak that no longer upgrades (or the test tracker drops it), so a copy that's still held stays in carded_copies(), and its entry survives.
  • A Shadow gets or loses its card side only when it's built, so a copy never becomes carded later under the same id.
  • The gap: the commit message says nothing declares or fetches during the look "because the submission lock is held". That's not true. declared() and fetched() are called from relay_card_back, which runs on the thread that lands flights and is documented to take no submission lock. In practice at_rest only runs when flying() is false, and with the relay that includes flights still being landed. So I found no interleaving that hits it today. But the old code named the copies before taking KNOWN's lock, so a copy carded and declared in between would have been pruned while alive.
  • Fix: the copies are now named while KNOWN's lock is held (carded_known), so declared() and fetched() wait until the prune is done. That makes the guarantee local instead of depending on when at_rest runs. The lock order is KNOWN → CARDED. Nothing holds CARDED while asking for KNOWN: card_dirty, carded_copies, the counters and the push sites never call into upcheck, and Shadow::drop doesn't touch it.

Can a retired or reused id inherit stale state? No. Every Shadow gets its number from one process-wide AtomicU64 counter in Shadow::new, starting at 1 and incremented once per copy. Shadow::placed goes through new too. A number is never given twice. A new copy of the same title memory therefore starts with no KNOWN entry, so it doesn't inherit what was declared or fetched for the copy before it. KNOWN and NOTED are keyed only by that number.

Tests (CPU-only, using Shadow::unbacked):

  • copies_are_named_while_nothing_can_be_declared: the copies are named while the map's lock is held, and only the live copy's entry survives. It failed on the previous ordering ("the copies were named outside the lock") and passes now.
  • a_copy_made_again_knows_nothing_of_the_one_before: two copies of the same span get increasing ids. After the first is declared, the second still reads "no shader was declared to write the buffer".

Severity: this is diagnostics-only (VICTORY_UPCOPY_CHECK=1). The worst case before was a misleading "never declared" line in the log, not a rendering problem.

Verified under Wine: victory-gpu --lib passes 525 with 5 failures by default, and 591 with 6 failures with --features diagnostics. Those are the same failures that predate this PR on main (ambient::…indirect_hold…, host::readback_pool_tests::…, watch::… ×3, plus timeline::report::… with diagnostics). Under Wine host() is None, so only CPU-side results count. cargo clippy -p victory-gpu --all-targets -- -D warnings, with and without --features diagnostics, and cargo xtask policy (322 files ok) are clean.

AI-assisted: yes (Claude), reviewed locally before posting.

**@⁠safesearch77** on GitHub · 2026-11-29 13:20 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/412#issuecomment-7256460233) Thanks, both points checked. The first one turned up a gap, now closed. **Can pruning drop a live copy's entry while it is being inspected?** Not the way it's used, but the PR's stated reason was wrong. Here's the reasoning: - `KNOWN` is read in two places. `look()` reads entries of the copies it just named (`carded_copies()`), and the prune keeps exactly those. `Looks::read()` (the check at each send) reads the copies `card_dirty()` handed to `record()`. Those were carded when recorded, and `Looks` holds an `Arc` to each. `CARDED` only drops a `Weak` that no longer upgrades (or the test tracker drops it), so a copy that's still held stays in `carded_copies()`, and its entry survives. - A `Shadow` gets or loses its card side only when it's built, so a copy never becomes carded later under the same id. - The gap: the commit message says nothing declares or fetches during the look "because the submission lock is held". That's not true. `declared()` and `fetched()` are called from `relay_card_back`, which runs on the thread that lands flights and is documented to take no submission lock. In practice `at_rest` only runs when `flying()` is false, and with the relay that includes flights still being landed. So I found no interleaving that hits it today. But the old code named the copies before taking `KNOWN`'s lock, so a copy carded and declared in between would have been pruned while alive. - **Fix:** the copies are now named while `KNOWN`'s lock is held (`carded_known`), so `declared()` and `fetched()` wait until the prune is done. That makes the guarantee local instead of depending on when `at_rest` runs. The lock order is `KNOWN` → `CARDED`. Nothing holds `CARDED` while asking for `KNOWN`: `card_dirty`, `carded_copies`, the counters and the push sites never call into `upcheck`, and `Shadow::drop` doesn't touch it. **Can a retired or reused id inherit stale state?** No. Every `Shadow` gets its number from one process-wide `AtomicU64` counter in `Shadow::new`, starting at 1 and incremented once per copy. `Shadow::placed` goes through `new` too. A number is never given twice. A new copy of the same title memory therefore starts with no `KNOWN` entry, so it doesn't inherit what was declared or fetched for the copy before it. `KNOWN` and `NOTED` are keyed only by that number. **Tests** (CPU-only, using `Shadow::unbacked`): - `copies_are_named_while_nothing_can_be_declared`: the copies are named while the map's lock is held, and only the live copy's entry survives. It failed on the previous ordering ("the copies were named outside the lock") and passes now. - `a_copy_made_again_knows_nothing_of_the_one_before`: two copies of the same span get increasing ids. After the first is declared, the second still reads "no shader was declared to write the buffer". Severity: this is diagnostics-only (`VICTORY_UPCOPY_CHECK=1`). The worst case before was a misleading "never declared" line in the log, not a rendering problem. Verified under Wine: `victory-gpu --lib` passes 525 with 5 failures by default, and 591 with 6 failures with `--features diagnostics`. Those are the same failures that predate this PR on `main` (`ambient::…indirect_hold…`, `host::readback_pool_tests::…`, `watch::…` ×3, plus `timeline::report::…` with diagnostics). Under Wine `host()` is `None`, so only CPU-side results count. `cargo clippy -p victory-gpu --all-targets -- -D warnings`, with and without `--features diagnostics`, and `cargo xtask policy` (322 files ok) are clean. AI-assisted: yes (Claude), reviewed locally before posting.
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-29 14:39 UTC · original

Thanks for finding the gap in the original lock ordering. Naming the live copies under KNOWN and documenting the KNOWN-to-CARDED order is a stronger guarantee than relying on at_rest. The two focused tests are useful. I will retain the diagnostics-only scope and verify the restored implementation against the current tree.

**@⁠TaynanGT** on GitHub · 2026-11-29 14:39 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/412#issuecomment-7257468693) Thanks for finding the gap in the original lock ordering. Naming the live copies under KNOWN and documenting the KNOWN-to-CARDED order is a stronger guarantee than relying on at_rest. The two focused tests are useful. I will retain the diagnostics-only scope and verify the restored implementation against the current tree.
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-30 17:08 UTC · original

main has moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the current main and open a new PR; I'll review it there.

**@⁠TaynanGT** on GitHub · 2026-11-30 17:08 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/412#issuecomment-7285785799) `main` has moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the current `main` and open a new PR; I'll review it there.
github-bot closed this pull request 2026-11-30 17:14:27 +00:00

Pull request closed

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