Skip to content

Pipeline cache: verify content when accepting a racing publication - #2828

Open
andrewpozdnakov7-jpg wants to merge 3 commits into
Marvisak:mainfrom
andrewpozdnakov7-jpg:codex1/concurrent-cache-publication
Open

andrewpozdnakov7-jpg wants to merge 3 commits into
Marvisak:mainfrom
andrewpozdnakov7-jpg:codex1/concurrent-cache-publication

Conversation

@andrewpozdnakov7-jpg

@andrewpozdnakov7-jpg andrewpozdnakov7-jpg commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

#1324 landed as a73d59e and covers the case where another writer publishes the correct cache entry before Windows rejects the rename. This branch keeps that behavior and checks that the existing file contains the converted bytes before accepting it.

The comparison uses bounded chunks on the failure path. An unreadable entry, a different length, or different content leaves the original publishing error available to the caller. The upstream handling of staging write failures is preserved.

  • Same Windows fixture on f3578e3: the identical entry is reused, then an existing XYZ file is incorrectly accepted for output ABC.
  • On 2dacec0: the identical file is reused, and the same-length and longer mismatches return an error. The recorded file is unchanged and staging files are cleaned up.
  • Six paired runs. All eight pipeline tests, crate formatting, strict Clippy, and asset policy passed.

Coordination claim · Windows file sharing rules

Please retain my Git author if moving the follow-up. If you fold the comparison or test extension into another commit, please add the following trailer.

Co-authored-by: andrewpozdnakov7-jpg andrewpozdnakov7-jpg@users.noreply.github.com

AI-assisted with Codex. Synthetic Windows file test.

Review follow-up

The same Windows fixture on 2dacec0 fails because a second lookup returns the existing XYZ. With b80763c198d6b13ca97e7aa0ee354a6721cf43b0, a separately opened cache declines both mismatches while the reader blocks replacement, then publishes ABC after the reader closes. The next lookup hits ABC; the identical-output control still hits without conversion. An empty companion marker adds a file-presence check to hits. Byte comparison is confined to failed rename attempts.

Six successful runs, all eight pipeline tests and four GPU shader-cache tests passed, plus formatting, strict pipeline Clippy, and policy.

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Verified f8302c39 on Windows 11:

  • cargo xtask policy: 184 files ok; cargo clippy --locked -p victory-pipeline --all-targets -- -D warnings: 0 warnings.
  • cargo test --locked -p victory-pipeline: 8/8 passed (including an_open_concurrent_cache_entry_wins_only_if_identical).
  • Streaming 8 KiB chunk + length + EOF comparison in same_output cleanly handles concurrent publication without full-file copies and removes &tmp on collision. Clean git merge-tree against origin/main and Loader: accept identical destination when concurrent publish rename fails #2797 (complementary across victory-pipeline and victory-loader).

@kotekompotek kotekompotek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct concurrency handling: on Windows the rename can fail only because a reader holds the published file — treating that as success iff the published bytes are identical is sound (the output is content-addressed work). Length check first, chunked compare, trailing-byte check — and unwrap_or(false) keeps genuine failures propagating. The paused-converter test exercises the real race. LGTM.

@andrewpozdnakov7-jpg andrewpozdnakov7-jpg changed the title Pipeline cache: accept identical output after a concurrent publication Pipeline cache: verify content when accepting a racing publication Nov 25, 2026
@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor Author

I resolved the conflict after #1324 landed. 2dacec0 keeps the upstream staging-write behavior and adds the byte check on rename failure.

The same synthetic test on main f3578e3 accepts XYZ where ABC was converted. The update reuses the identical file and rejects both mismatch controls. Six paired runs, eight pipeline tests, strict Clippy, formatting, and asset policy passed. The prior verified commit stays in the branch history.

Please preserve Git authorship if moving the comparison or test extension. If squashing it into another commit, please add this trailer.

Co-authored-by: andrewpozdnakov7-jpg andrewpozdnakov7-jpg@users.noreply.github.com

@AwsAli05 AwsAli05 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first call now reports the publication mismatch. The next call can still report the wrong entry as a cache hit. I extended the Windows race fixture at 2dacec0 to call get_or_convert a second time after the error. The retry returned Ok(path) and read the original XYZ bytes for the conversion that produces ABC. The longer mismatch behaved the same way.

Can this rare path mark the mismatched entry unusable to subsequent lookups, or can the error explicitly tell the caller to invalidate it? A retry assertion would pin the expected behavior without adding any byte comparison to normal cache hits.

AI-assisted review and test using synthetic bytes.

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor Author

Follow-up to the retry review in b80763c.

The same Windows fixture on 2dacec0 fails because a second lookup returns the existing XYZ. With b80763c198d6b13ca97e7aa0ee354a6721cf43b0, a separately opened cache declines both mismatches while the reader blocks replacement, then publishes ABC after the reader closes. The next lookup hits ABC; the identical-output control still hits without conversion. An empty companion marker adds a file-presence check to hits. Byte comparison is confined to failed rename attempts.

Six successful runs, all eight pipeline tests and four GPU shader-cache tests passed, plus formatting, strict pipeline Clippy, and policy.

Please preserve the Git author if cherry-picking the fix or test. If folding either into another commit, please include Co-authored-by: andrewpozdnakov7-jpg <andrewpozdnakov7-jpg@users.noreply.github.com>.

Marvisak commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Verdict: proposed close (was needs work). Thanks for checking the production caller and for the candid answer. As you found, the shader cache keys entries by translator source, encoding, loop limit and container bytes, and on a publication error it already returns the in-memory translation (#2055). There is no known case where two writers publish different bytes for the same key, so the byte comparison and the .invalid marker in Cache::get_or_convert (crates/victory-pipeline/src/cache.rs) guard a case that does not occur, at the cost of an extra try_exists() on every hit. #1324's behaviour in main stays as is, which matches your own suggestion to defer.

This will be closed in 48 hours unless you push a change (for example, with a real case where the contents differ) or a maintainer removes the label.

CI: passing (check).


Generated by Claude Code

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor Author

Thanks for flagging the hot-path cost. I checked the production caller on 63bcca4: the shader cache keys entries by the translator source, encoding, loop limit, and container bytes. On a publication error it already returns the in-memory translation. The Windows test creates a mismatched entry deliberately while a reader holds it open. I have no production case where two conversions with that same key produce different bytes.

The two reviews identify a trade-off. The failure-only comparison in 2dacec0 has no extra I/O on hits, but the same test then returns the mismatched file on a second lookup. b80763c covers that retry at the cost of the marker check on each hit. With no observed production case, I'd leave #1324 as the current behavior and defer this follow-up until there's evidence that the retry case matters.

If you use the comparison or the Windows fixture later, please retain the original Git author. For a combined commit, please use:

Co-authored-by: andrewpozdnakov7-jpg andrewpozdnakov7-jpg@users.noreply.github.com

AI-assisted with Codex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants