loader,pipeline(cache): coalesce concurrent cache misses and handle publish rename races #92

Merged
Androtim merged 1 commit from upstream-pr/92 into main 2026-11-29 10:05:05 +00:00
Androtim commented 2026-11-29 09:23:26 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-11-29T09:23:26Z.


Summary

Adapted from upstream VIctory-NVIDIA (86d5539a and 78c71e5c, GPL-3.0), extracted cleanly on origin/main (5d40f8b) with zero overlap against any open PR:

  • Per-key cache miss coalescing (crates/victory-pipeline/src/cache.rs): Adds a lightweight Flight/gates (Weak<Mutex<()>>) registry keyed by canonicalized output path so concurrent identical misses in Cache::get_or_convert() share one conversion, re-check path.is_file() after acquiring the gate, and clean up dead registry entries atomically in Drop while cache hits remain lock-free.
  • Publish rename-race hardening (crates/victory-loader/src/publish.rs, crates/victory-pipeline/src/cache.rs): Extracts publish_staging() so Windows rename races against another publisher succeed when expected output exists (destination.is_file() in cache, exact matching bytes in loader publication) without masking unrelated rename errors, preserving PR #83's concurrent publication behavior.

Verification

  • cargo xtask policy: asset policy: 303 files ok
  • cargo test -p victory-pipeline -p victory-loader --lib --locked:
    • victory-loader: 52 passed; 0 failed (including 3 new publish::tests::* rename-race tests)
    • victory-pipeline: 13 passed; 0 failed (including concurrent_identical_misses_share_one_conversion, independent_keys_do_not_share_a_gate_and_registry_drains, failed_conversion_releases_gate_for_retry, rename_race_returns_the_other_publishers_file, failed_rename_without_a_destination_returns_the_error, and existing accepts_entry_published_concurrently_while_open)
  • cargo clippy --workspace --all-targets --locked -- -D warnings: 0 warnings
  • cargo clippy --workspace --all-targets --features diagnostics --locked -- -D warnings: 0 warnings
<!-- greyfinch-sync:Androtim/MiniVI:issue:5549379391 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/92). Originally posted by [Androtim](https://github.com/Androtim) on 2026-11-29T09:23:26Z. --- ## Summary Adapted from upstream `VIctory-NVIDIA` (`86d5539a` and `78c71e5c`, GPL-3.0), extracted cleanly on `origin/main` (`5d40f8b`) with zero overlap against any open PR: - **Per-key cache miss coalescing (`crates/victory-pipeline/src/cache.rs`):** Adds a lightweight `Flight`/`gates` (`Weak<Mutex<()>>`) registry keyed by canonicalized output path so concurrent identical misses in `Cache::get_or_convert()` share one conversion, re-check `path.is_file()` after acquiring the gate, and clean up dead registry entries atomically in `Drop` while cache hits remain lock-free. - **Publish rename-race hardening (`crates/victory-loader/src/publish.rs`, `crates/victory-pipeline/src/cache.rs`):** Extracts `publish_staging()` so Windows rename races against another publisher succeed when expected output exists (`destination.is_file()` in cache, exact matching bytes in loader publication) without masking unrelated rename errors, preserving PR #83's concurrent publication behavior. ## Verification - `cargo xtask policy`: `asset policy: 303 files ok` - `cargo test -p victory-pipeline -p victory-loader --lib --locked`: - `victory-loader`: **52 passed; 0 failed** (including 3 new `publish::tests::*` rename-race tests) - `victory-pipeline`: **13 passed; 0 failed** (including `concurrent_identical_misses_share_one_conversion`, `independent_keys_do_not_share_a_gate_and_registry_drains`, `failed_conversion_releases_gate_for_retry`, `rename_race_returns_the_other_publishers_file`, `failed_rename_without_a_destination_returns_the_error`, and existing `accepts_entry_published_concurrently_while_open`) - `cargo clippy --workspace --all-targets --locked -- -D warnings`: **0 warnings** - `cargo clippy --workspace --all-targets --features diagnostics --locked -- -D warnings`: **0 warnings**
Androtim commented 2026-11-29 10:02:59 +00:00 (Migrated from github.com)

Imported from Androtim/MiniVI. Originally posted by Androtim on 2026-11-29T10:02:59Z.


Automated triage for the maintainers (not an approval).

Verdict: merge-candidate · CI (check): passing

Review Summary

Clean, well-scoped change with passing CI and thorough unit tests covering both concurrency and rename-race paths.

Verified Changes

  • crates/victory-loader/src/publish.rs (write_if_changed, publish_staging):
    • Extracts publish_staging() so a rename failure (e.g., Windows PermissionDenied / sharing violation when a concurrent publisher wins the race) removes the staging file and succeeds only if destination already contains the exact expected bytes; otherwise the original rename error is propagated.
    • Covered by 3 new unit tests (rename_race_accepts_destination_with_expected_bytes, rename_race_rejects_unexpected_destination_bytes, failed_rename_without_destination_returns_the_error).
  • crates/victory-pipeline/src/cache.rs (Flight, gates, Cache::get_or_convert, Cache::publish, publish_staging):
    • Adds a process-wide OnceLock<Mutex<HashMap<PathBuf, Weak<Mutex<()>>>>> registry keyed by canonicalized root + relative cache key path (gate_path) so concurrent misses for the same key coalesce into a single conversion while cache hits remain lock-free and the returned path is unchanged.
    • Lock ordering is safe: gates() is never held across conversion/I/O or while acquiring a per-key Gate, and Flight::drop drops self.gate while holding gates() so strong_count() == 0 cleanup cannot race with another final drop or Weak::upgrade. Mutex poisoning is handled via unwrap_or_else(|e| e.into_inner()) so a panicked converter does not wedge waiters.
    • Extracts publish_staging() preserving destination.is_file() race acceptance for content-addressed cache entries without masking unrelated rename errors.
    • Covered by 5 new unit tests (concurrent_identical_misses_share_one_conversion, independent_keys_do_not_share_a_gate_and_registry_drains, failed_conversion_releases_gate_for_retry, rename_race_returns_the_other_publishers_file, failed_rename_without_a_destination_returns_the_error).

Verdict

merge-candidate — logic, concurrency/drop semantics, and tests look solid, CI is passing, no overlap with other open PRs, and no GPU-specific paths are touched. (Automated triage review; not a formal maintainer approval.)


Generated with Antigravity CLI (agy).

<!-- greyfinch-sync:Androtim/MiniVI:comment:7254172222 --> Imported from [Androtim/MiniVI](https://github.com/Androtim/MiniVI/pull/92#issuecomment-7254172222). Originally posted by [Androtim](https://github.com/Androtim) on 2026-11-29T10:02:59Z. --- <!-- minivi-triage v1 head=baf607b09013e2c4fbd187ac3b5161ac10c2998d verdict=merge-candidate ci=passing at=2026-11-29T10:03:32Z --> Automated triage for the maintainers (not an approval). **Verdict:** `merge-candidate` · **CI (`check`):** `passing` ### Review Summary Clean, well-scoped change with passing CI and thorough unit tests covering both concurrency and rename-race paths. #### Verified Changes - **`crates/victory-loader/src/publish.rs` (`write_if_changed`, `publish_staging`)**: - Extracts `publish_staging()` so a rename failure (e.g., Windows `PermissionDenied` / sharing violation when a concurrent publisher wins the race) removes the staging file and succeeds **only** if `destination` already contains the exact expected `bytes`; otherwise the original rename error is propagated. - Covered by 3 new unit tests (`rename_race_accepts_destination_with_expected_bytes`, `rename_race_rejects_unexpected_destination_bytes`, `failed_rename_without_destination_returns_the_error`). - **`crates/victory-pipeline/src/cache.rs` (`Flight`, `gates`, `Cache::get_or_convert`, `Cache::publish`, `publish_staging`)**: - Adds a process-wide `OnceLock<Mutex<HashMap<PathBuf, Weak<Mutex<()>>>>>` registry keyed by canonicalized root + relative cache key path (`gate_path`) so concurrent misses for the same key coalesce into a single conversion while cache hits remain lock-free and the returned `path` is unchanged. - Lock ordering is safe: `gates()` is never held across conversion/I/O or while acquiring a per-key `Gate`, and `Flight::drop` drops `self.gate` while holding `gates()` so `strong_count() == 0` cleanup cannot race with another final drop or `Weak::upgrade`. Mutex poisoning is handled via `unwrap_or_else(|e| e.into_inner())` so a panicked converter does not wedge waiters. - Extracts `publish_staging()` preserving `destination.is_file()` race acceptance for content-addressed cache entries without masking unrelated rename errors. - Covered by 5 new unit tests (`concurrent_identical_misses_share_one_conversion`, `independent_keys_do_not_share_a_gate_and_registry_drains`, `failed_conversion_releases_gate_for_retry`, `rename_race_returns_the_other_publishers_file`, `failed_rename_without_a_destination_returns_the_error`). #### Verdict `merge-candidate` — logic, concurrency/drop semantics, and tests look solid, CI is passing, no overlap with other open PRs, and no GPU-specific paths are touched. (Automated triage review; not a formal maintainer approval.) --- _Generated with Antigravity CLI (`agy`)._
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
Androtim/MiniVI!92
No description provided.