GPU/host: fix late_met overwrite/unsure handling and relay_land in_hand race #785

Open
AscilCH wants to merge 1 commit from upstream-pr/785 into main
AscilCH commented 2026-11-25 07:35:28 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-25T07:35:28Z.


Summary

Fix two ordering and freshness bugs in crates/victory-gpu/src/host.rs:

  1. late_met() scanned overlapping writes in forward order and returned on the first exact match, ignoring later overwrites and unsure flags.

    • Extract eval_late_met() to scan all overlapping writes in submission order:
      • Track unsure whenever line.written is already unsure, a write only partially overlaps the queried (at, size), or a write is Written::GpuTimestamp (value only known after GPU execution).
      • Keep the final exact-match write's value rather than returning on the first match, so a later overwrite or partial/timestamp clobber overrides an earlier match.
      • Return false if unsure is set.
    • Check !line.settling in late_met() alongside line.pending so queued late writes aren't treated as satisfied while settle() is draining them.
  2. relay_land() kept completed Late::Write entries in line.in_hand until after executing all writes.

    • Remove each Late::Write entry from line.in_hand immediately before executing what.write(...) so concurrent readers/overlap checks cannot observe a stale pending entry once the write begins landing.

Verification

  • cargo test -p victory-gpu --locked -- host::batch: 5 passed; 0 failed; 1 ignored (benchmark), including new unit test eval_late_met_uses_final_write_and_honors_unsure.
  • cargo clippy -p victory-gpu --all-targets --all-features --locked: 0 warnings in crates/victory-gpu/src/host.rs (only pre-existing 8dd30ab warnings in draw.rs and indirect.rs).
  • cargo xtask policy: 171 files ok.

(AI-assisted; synthetic unit tests only, no game data.)

<!-- greyfinch-sync:fxceless/victory-fork:issue:6599576480 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/785). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-25T07:35:28Z. --- ## Summary Fix two ordering and freshness bugs in `crates/victory-gpu/src/host.rs`: 1. **`late_met()` scanned overlapping writes in forward order and returned on the first exact match, ignoring later overwrites and `unsure` flags.** - Extract `eval_late_met()` to scan all overlapping writes in submission order: - Track `unsure` whenever `line.written` is already `unsure`, a write only partially overlaps the queried `(at, size)`, or a write is `Written::GpuTimestamp` (value only known after GPU execution). - Keep the **final** exact-match write's value rather than returning on the first match, so a later overwrite or partial/timestamp clobber overrides an earlier match. - Return `false` if `unsure` is set. - Check `!line.settling` in `late_met()` alongside `line.pending` so queued late writes aren't treated as satisfied while `settle()` is draining them. 2. **`relay_land()` kept completed `Late::Write` entries in `line.in_hand` until after executing all writes.** - Remove each `Late::Write` entry from `line.in_hand` immediately before executing `what.write(...)` so concurrent readers/overlap checks cannot observe a stale pending entry once the write begins landing. ## Verification - `cargo test -p victory-gpu --locked -- host::batch`: `5 passed; 0 failed; 1 ignored` (benchmark), including new unit test `eval_late_met_uses_final_write_and_honors_unsure`. - `cargo clippy -p victory-gpu --all-targets --all-features --locked`: 0 warnings in `crates/victory-gpu/src/host.rs` (only pre-existing `8dd30ab` warnings in `draw.rs` and `indirect.rs`). - `cargo xtask policy`: `171 files ok`. *(AI-assisted; synthetic unit tests only, no game data.)*
Pin0d1 commented 2026-11-25 09:08:52 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Pin0d1 on 2026-11-25T09:03:36Z.


@AscilCH, I reran the overwrite through the queue predicate on 67c6c89. With an equality wait for 1 and pending stores of 1 then 0, late_met returns false as expected. If the CPU word currently holds 0, queue::value_met also returns false. If the CPU word still holds 1, queue::value_met returns true through wait.met() before it consults the ordered writes.

The helper test passes. The queue-level case reproduced in two fresh Windows processes. Could the queue distinguish a pending write with a known final value from an address with no pending writer before using the current CPU word? Test patch and both controls.

Prepared with the help of Codex 6.2 Astra Max.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7157819532 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/785#issuecomment-7157819532). Originally posted by [Pin0d1](https://github.com/Pin0d1) on 2026-11-25T09:03:36Z. --- @AscilCH, I reran the overwrite through the queue predicate on 67c6c89. With an equality wait for 1 and pending stores of 1 then 0, late_met returns false as expected. If the CPU word currently holds 0, queue::value_met also returns false. If the CPU word still holds 1, queue::value_met returns true through wait.met() before it consults the ordered writes. The helper test passes. The queue-level case reproduced in two fresh Windows processes. Could the queue distinguish a pending write with a known final value from an address with no pending writer before using the current CPU word? [Test patch and both controls](https://github.com/Pin0d1/victory-fork/tree/b34a4cd06c4ef9cb5e79c51d1e4f79b8400610da/review-evidence/relay-followup). Prepared with the help of Codex 6.2 Astra Max.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/785:upstream-pr/785'
git switch 'upstream-pr/785'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/785'
git switch 'upstream-pr/785'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/785'
git switch 'upstream-pr/785'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/785'
git switch 'main'
git merge --squash 'upstream-pr/785'
git switch 'main'
git merge --ff-only 'upstream-pr/785'
git switch 'main'
git merge 'upstream-pr/785'
git push origin 'main'
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
fxceless/victory-fork!785
No description provided.