GPU: saturate COM AddRef at u32::MAX instead of wrapping #2059

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

@⁠fuzeofficlal on GitHub · 2026-11-25 04:17 UTC · original
fuzeofficlal:fix/gpu-addref-saturate-931 → main · +113 −5 · 1 files · 1 commits · closed without merging

Closes #931.

Summary

  • Update object::add_ref to increment refs via fetch_update + checked_add(1) so COM reference counts saturate at u32::MAX instead of wrapping to 0 in release builds (which could allow a subsequent Release to drop a still-referenced object), matching the existing CAS floor in object::release and object::release_boxed.

Testing

  • Added object::tests::add_ref_saturates_at_u32_max_without_wrapping covering both heap-allocated (hand_out + release_boxed) and static (Object + release) COM objects across u32::MAX - 1 -> u32::MAX saturation, decrement without premature drop, and final 1 -> 0 destruction.
  • cargo test -p victory-gpu (debug & release), cargo clippy --workspace --all-targets --all-features -- -D warnings, and cargo xtask policy.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 04:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/2059) `fuzeofficlal:fix/gpu-addref-saturate-931` → `main` · +113 −5 · 1 files · 1 commits · closed without merging Closes #931. ### Summary - Update `object::add_ref` to increment `refs` via `fetch_update` + `checked_add(1)` so COM reference counts saturate at `u32::MAX` instead of wrapping to `0` in release builds (which could allow a subsequent `Release` to drop a still-referenced object), matching the existing CAS floor in `object::release` and `object::release_boxed`. ### Testing - Added `object::tests::add_ref_saturates_at_u32_max_without_wrapping` covering both heap-allocated (`hand_out` + `release_boxed`) and static (`Object` + `release`) COM objects across `u32::MAX - 1 -> u32::MAX` saturation, decrement without premature drop, and final `1 -> 0` destruction. - `cargo test -p victory-gpu` (debug & release), `cargo clippy --workspace --all-targets --all-features -- -D warnings`, and `cargo xtask policy`.
Use `fetch_update` with `checked_add(1)` in `object::add_ref` so COM
reference counts saturate at `u32::MAX` rather than wrapping to zero and
allowing a premature release.

Closes #931.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:53:23 +00:00
github-bot closed this pull request 2026-11-26 04:53:23 +00:00
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-25 04:21 UTC · original

Triage verdict — Keep the overflow fix, define ownership at saturation (37e69e7)

Evidence

  • @⁠fuzeofficlal prevents the numeric wrap described in @⁠geiyiliyabumo’s #931. At the maximum count, an interface query can still hand out a reference while the stored count stays unchanged, and the release paths still decrement it. The implementation needs an explicit lifetime policy for that state. AddRef and interface handout · Boxed release

Checks and limits

  • This is source review. The new test establishes that the counter does not wrap. Its final drop assertion resets the count to one, so it covers ordinary destruction separately from the saturation policy. Regression test

Next step

  • Make saturation sticky through release, or retain a wider internal count and clamp only the reported value. Test the chosen policy. Preserve credit for #931 and track its broader object-test coverage separately if it stays outside this patch.

This verification was AI-assisted.

**@⁠jeremygold02** on GitHub · 2026-11-25 04:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2059#issuecomment-7152765185) **Triage verdict — Keep the overflow fix, define ownership at saturation** (`37e69e7`) **Evidence** - @⁠fuzeofficlal prevents the numeric wrap described in @⁠geiyiliyabumo’s #931. At the maximum count, an interface query can still hand out a reference while the stored count stays unchanged, and the release paths still decrement it. The implementation needs an explicit lifetime policy for that state. [AddRef and interface handout](https://github.com/Marvisak/VIctory/blob/37e69e79118fd8c34bf8ee21337804b4e741b854/crates/victory-gpu/src/object.rs#L69-L95) · [Boxed release](https://github.com/Marvisak/VIctory/blob/37e69e79118fd8c34bf8ee21337804b4e741b854/crates/victory-gpu/src/object.rs#L138-L153) **Checks and limits** - This is source review. The new test establishes that the counter does not wrap. Its final drop assertion resets the count to one, so it covers ordinary destruction separately from the saturation policy. [Regression test](https://github.com/Marvisak/VIctory/blob/37e69e79118fd8c34bf8ee21337804b4e741b854/crates/victory-gpu/src/object.rs#L570-L640) **Next step** - Make saturation sticky through release, or retain a wider internal count and clamp only the reported value. Test the chosen policy. Preserve credit for #931 and track its broader object-test coverage separately if it stays outside this patch. This verification was AI-assisted.
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 04:41 UTC · original

Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at 37e69e7. victory-gpu: 142 passed, 2 failed, 2 ignored; the new add_ref_saturates_at_u32_max_without_wrapping passes. The 2 failures are #1744's heap-cap failures on main. Same as main on this hardware. Not run: a title.

AI-assisted (Claude Code).

**@⁠upipibi** on GitHub · 2026-11-25 04:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/2059#issuecomment-7153078750) Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at `37e69e7`. `victory-gpu`: 142 passed, 2 failed, 2 ignored; the new `add_ref_saturates_at_u32_max_without_wrapping` passes. The 2 failures are #1744's heap-cap failures on `main`. Same as `main` on this hardware. Not run: a title. AI-assisted (Claude Code).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 05:00 UTC · original

Updated in 57535164 — thanks @⁠jeremygold02. Saturation at u32::MAX is now sticky across both object::release and object::release_boxed ((n != u32::MAX).then(|| n.checked_sub(1)).flatten()), so interface queries or AddRef calls at u32::MAX cannot be balanced down by later Release calls to drop a still-referenced object. Expanded the unit test to verify normal decrement at u32::MAX - 1, sticky saturation across answer + Release at u32::MAX, and ordinary 1 -> 0 destruction.

**@⁠fuzeofficlal** on GitHub · 2026-11-25 05:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/2059#issuecomment-7153356802) Updated in `57535164` — thanks @⁠jeremygold02. Saturation at `u32::MAX` is now sticky across both `object::release` and `object::release_boxed` (`(n != u32::MAX).then(|| n.checked_sub(1)).flatten()`), so interface queries or `AddRef` calls at `u32::MAX` cannot be balanced down by later `Release` calls to drop a still-referenced object. Expanded the unit test to verify normal decrement at `u32::MAX - 1`, sticky saturation across `answer` + `Release` at `u32::MAX`, and ordinary `1 -> 0` destruction.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 09:24 UTC · original

Automated triage for the maintainers.
Proposed close.

object::add_ref, object::release and object::release_boxed (crates/victory-gpu/src/object.rs) now stop the reference count at u32::MAX and then never drop the object. The count can only get there if a title holds about 4.29 billion references to one object at the same time. A title does not do that, so this is a guard for a case that cannot occur.

The guard also has a cost. Real COM lets the count wrap, so this differs from it. An object that did reach the limit would leak for good. The new test must free the saturated box by hand, which also skips the cleanup of the interface map in release_boxed. The same idea is already open in #1100 and #1105.

This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label. A reproduction showing a title, or a VIctory code path, that actually reaches this count would change the verdict.

CI: passing (check).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 09:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/2059#issuecomment-7158282838) <!-- victory-triage v1 head=5753516486cdf604bbfb82453f360b1abfbb8222 verdict=proposed-close at=2026-11-25T09:24:08Z --> Automated triage for the maintainers. **Proposed close.** `object::add_ref`, `object::release` and `object::release_boxed` (crates/victory-gpu/src/object.rs) now stop the reference count at `u32::MAX` and then never drop the object. The count can only get there if a title holds about 4.29 billion references to one object at the same time. A title does not do that, so this is a guard for a case that cannot occur. The guard also has a cost. Real COM lets the count wrap, so this differs from it. An object that did reach the limit would leak for good. The new test must free the saturated box by hand, which also skips the cleanup of the interface map in `release_boxed`. The same idea is already open in #1100 and #1105. This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label. A reproduction showing a title, or a VIctory code path, that actually reaches this count would change the verdict. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 10:17 UTC · original

Agreed with the triage analysis — u32::MAX simultaneous live references cannot occur in practice and pinning the count diverges from COM cleanup. Closing.

**@⁠fuzeofficlal** on GitHub · 2026-11-25 10:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/2059#issuecomment-7159503237) Agreed with the triage analysis — `u32::MAX` simultaneous live references cannot occur in practice and pinning the count diverges from COM cleanup. Closing.

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