Skip to content

compile_dxil: invalidate a published manifest when sidecar content changes with an older timestamp - #3137

Closed
lambirou wants to merge 2 commits into
R0Y00:codex/native-shader-modulesfrom
lambirou:native/stale-manifest-mtime
Closed

lambirou wants to merge 2 commits into
R0Y00:codex/native-shader-modulesfrom
lambirou:native/stale-manifest-mtime

Conversation

@lambirou

@lambirou lambirou commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Change

A watched pixel-input sidecar could change content while keeping a preserved or older timestamp. is_watch_request_pending compared only the sidecar mtime against the manifest, so the request stayed a cache hit and the stale accepted manifest kept being served.

The published manifest now records an FNV-1a digest of the sidecar bytes (<key>.psinh, over the .psin/.ps57in extension, length and content). The watch path writes it before the manifest, the batch graphics path writes the same file, and the watcher withdraws the manifest when the digest differs. Unchanged bytes stay a cache hit. Existing manifests without a digest are retranslated once.

Refs #3133. Refs #3091. Targets codex/native-shader-modules while #3091 is open.

Verification

Windows 10 Pro 26H2 build 26300.10075, MSVC 19.51, Windows SDK and DXC 10.0.26100.0. These checks are CPU-only.

Commit 2ce9f112 in native/stale-manifest-mtime.

cmake --build --preset dev --target compile_dxil
python -B tests/native_startup_request_cache_check.py controls out/build/dev/compile_dxil.exe "C:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.26100.0\\x64"
python -B tests/native_compile_dxil_watch_check.py out/build/dev/compile_dxil.exe "C:\\Program Files (x86)\\Windows Kits\\10\\bin\\10.0.26100.0\\x64"
  • native_startup_request_cache controls: passed, including the new regressions:
    • unchanged .psin -> cache hit, manifest not rewritten;
    • contradictory .ps57in with an mtime older than the manifest -> manifest withdrawn, conflicting stream and slot-57 pixel entry records;
    • the same bytes with a newer mtime from a fresh publication -> same withdrawal and identical .fail content;
    • changed .psin with a preserved mtime -> manifest withdrawn (invalid pixel input description).
  • native_compile_dxil_watch: passed (--once controls, resume/recheck, live watch retry/skip/recovery, CLI negative controls).

Evidence and follow-up

The digest covers the sidecar extension, its length and its bytes, so moving bytes between .psin and .ps57in changes it. No public fixture or asset is added. The watch and batch paths share the same digest writer, so a cache built by either path is interoperable with the watcher.

Review update (2026-11-27, 13c7cfab)

Both R0Y00/pigalot findings are addressed.

  • pixel_sidecar_hash now resolves an .rtv marker to its base .psin path, the same path graphics_psin_path uses for the mtime check, and hashes the base .psin/.ps57in pair. A base sidecar change with an older or preserved mtime now withdraws the variant as well as the base.
  • The watch and batch paths hash the sidecars before translation and again before publishing. A change during compilation throws pixel input sidecar changed during compilation; no manifest or stage is published from the mismatched snapshot.
  • native_startup_request_cache_check.py now publishes a base plus req_<base>.rtv, then checks unchanged hits, an older-mtime conflicting .ps57in, a newer-mtime conflict, and a preserved-mtime .psin change. Both base and variant manifests must be withdrawn or restored together.

Verification at 13c7cfab, dev and release: native_compile_dxil_watch, native_startup_request_cache_controls and native_rtv_variant_controls pass 3/3. docs_links_check and bidi_controls_check pass. This PR keeps the .psinh identity; #3138 is the alternative .psdep implementation. CI is not triggered for this branch target; the local receipt is above.

… mtime

The watcher treated a pixel-input sidecar as current whenever its timestamp
was not newer than the manifest, so a content change with a preserved or
older mtime kept a stale accepted manifest. Publish an FNV-1a digest of the
.psin/.ps57in bytes next to the manifest and compare it before a cache hit;
the batch graphics path writes the same digest.

Regression: native_startup_request_cache_check.py now covers an unchanged
cache hit, a contradictory .ps57in both older and newer than the manifest,
and a changed .psin with a preserved mtime.

Refs R0Y00#3133. Refs R0Y00#3091.
@lambirou

Copy link
Copy Markdown
Contributor Author

Note: the Windows checks workflow triggers only for pull requests to main and cpp-migration, so this branch-targeted PR has no CI run. The complete local receipt is in the description.

@lambirou

Copy link
Copy Markdown
Contributor Author

CI-equivalent smoke receipt for this branch-targeted PR. The pr preset used by the Windows workflow for pull requests to main was built and run locally on native/stale-manifest-mtime (2ce9f112) with the change applied.

cmake --preset dev
cmake --build --preset pr
ctest --preset pr --no-tests=error

41/41 passed, 0 failed (20.4 s). The 12 spirv_*_warp tests are capability skips because SPIR-V tools are not installed on this host; they are skipped, not failed. Windows build 10.0.26300.10075, WARP. The two targeted watch checks remain as described in the PR.

@lambirou

Copy link
Copy Markdown
Contributor Author

Migration impact measured on the reference rev-29 cache, to answer the expected review question.

The cache at out/startup/shader_cache holds 520 published manifests, 0 .psin/.ps57in sidecars and 0 .psdep files. With this change, pixel_sidecar_hash returns false for those entries, sidecar_changed stays false, and the original mtime path applies unchanged: every published entry with both stage blobs stays a cache hit. Nothing is retranslated on that cache.

A manifest that does have a sidecar and no <key>.psinh is retranslated once (the conservative case for a pre-fix entry), after which the digest is published and unchanged inputs hit.

Note for context: that cache also carries 5,365 .fail files; --once retries failed requests by design (skip_failed is only set in continuous mode), which is unrelated to this change.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Two paths still allow a stale manifest by code inspection. In is_watch_request_pending, graphics_psin_path(req.marker) correctly resolves an .rtv request to the base sidecar for the mtime check, but pixel_sidecar_hash(req.marker, ...) hashes paths beside the variant marker itself. An older or preserved-mtime change on the base .psin/.ps57in can therefore keep an RTV variant as a cache hit. Please run the same invalidation control for both the base and a published .rtv variant.

The watch and batch writers also hash fresh filesystem reads after compiling from input.pixel_entry. If a sidecar changes during compilation, a digest of the new bytes can be published next to DXIL made from the old bytes. Persist an identity from the same snapshot that was validated and compiled, or verify that the new read matches that snapshot before publishing. #3138 uses the existing .psdep from the parsed request and has a base-plus-RTV control. Please coordinate so the shared watcher fix lands once while preserving both contributors’ test evidence.

@pigalot pigalot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I reviewed 2ce9f112 merged over current codex/native-shader-modules a48d39dc, the PR's base. The merge is clean and git diff --cached --check is clean. #3138 fixes the same issue (#3133) by comparing against .psdep, so I ran each PR's new regressions against the other's build.

What I ran. I built compile_dxil native_compute_pack_check native_frozen_request_check native_pixel_ir_dump native_compute_ir_dump in dev, then ran

ctest --test-dir out/build/dev --no-tests=error -j 1 -R '^(native_compile_dxil_watch|native_startup_request_cache_controls|native_rtv_variant_controls|native_direct_container|native_frozen_request)$'

5/5 pass.

Blocking: an RTV variant keeps a stale manifest. I ran #3138's tests/native_compile_dxil_watch_check.py against this build, and it fails in its RTV case:

  1. Publish a base req_<b>.a and an RTV variant req_<v>.rtv (put_graphics_request and put_variant), then run --once.
  2. Add a contradictory req_<b>.ps57in whose mtime is 60 s older than both manifests.
  3. Run --once again. The base is withdrawn (refused: conflicting stream and slot-57 pixel entry records), but <v>.txt is still served. The assert names variant.

The cause is that pixel_sidecar_hash(req.marker, ...) replaces the marker's own extension. For an .rtv marker that gives req_<v>.psin / req_<v>.ps57in, which never exist, so the digest step is skipped. A variant's sidecars are its base's, which is what graphics_psin_path resolves (and what the existing mtime check already uses). Hashing *graphics_psin_path(req.marker) in the pending check, and in compile_watch_item for variants, should close it. A variant case in native_startup_request_cache_check.py would pin it.

Cross-check the other way. #3138 also passes this PR's native_startup_request_cache_check.py regressions once the .psinh-file existence assert is removed (native_startup_request_cache_controls passes on #3138's build).

Non-blocking (not measured). The digest is computed from the sidecar on disk when the manifest is published, not from the bytes the compile read. If a sidecar is rewritten while a compile is running, the digest records the new bytes next to a manifest built from the old ones, and the stale manifest stays a cache hit. #3138 avoids this by comparing against .psdep, which is written from the description that was compiled.

Verdict: changes requested on 2ce9f112, for the RTV variant case. Since #3138 also passes this PR's four regressions, the branch owner may want to pick one of the two.

Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; DXC 1.9.2602.17; Python 3.12.10. These are CPU-only checks.

This reply was AI-assisted.

…le snapshot

An .rtv variant hashed paths beside its own marker, so a base .psin/.ps57in
change with an older or preserved mtime kept the variant manifest. Resolve
the base sidecars for the digest, like the mtime check, and add a variant
regression to native_startup_request_cache_check.

Also hash the sidecars before and after translation; a change during the
compile refuses the publish instead of pairing new bytes with old DXIL.
@lambirou

Copy link
Copy Markdown
Contributor Author

Review update (2026-11-27, 13c7cfab)

Both R0Y00/pigalot findings are addressed.

  • pixel_sidecar_hash now resolves an .rtv marker to its base .psin path, the same path graphics_psin_path uses for the mtime check, and hashes the base .psin/.ps57in pair. A base sidecar change with an older or preserved mtime now withdraws the variant as well as the base.
  • The watch and batch paths hash the sidecars before translation and again before publishing. A change during compilation throws pixel input sidecar changed during compilation; no manifest or stage is published from the mismatched snapshot.
  • native_startup_request_cache_check.py now publishes a base plus req_<base>.rtv, then checks unchanged hits, an older-mtime conflicting .ps57in, a newer-mtime conflict, and a preserved-mtime .psin change. Both base and variant manifests must be withdrawn or restored together.

Verification at 13c7cfab, dev and release: native_compile_dxil_watch, native_startup_request_cache_controls and native_rtv_variant_controls pass 3/3. docs_links_check and bidi_controls_check pass. This PR keeps the .psinh identity; #3138 is the alternative .psdep implementation. CI is not triggered for this branch target; the local receipt is above.

@lambirou

Copy link
Copy Markdown
Contributor Author

@R0Y00 @pigalot the base-sidecar digest for .rtv variants and the pre/post-compile snapshot check are on 13c7cfab; the request-cache control now covers the variant. Could you re-review?

@lambirou

Copy link
Copy Markdown
Contributor Author

#3138 is now approved by both reviewers and covers the same base-plus-.rtv invalidation using .psdep. This branch carries the equivalent fix and variant regression on 13c7cfab, but it is the duplicate implementation. I am leaving it open for R0Y00 to choose which one lands; no further code changes are needed here.

@pigalot pigalot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-reviewed 13c7cfab merged over current codex/native-shader-modules a48d39dc, the PR's base. The merge is clean and git diff --cached --check is clean.

The blocking finding from my review of 2ce9f112 is fixed. For an .rtv marker, pixel_sidecar_hash now hashes the base's sidecars through graphics_psin_path. The request-cache control has a variant case.

The non-blocking note is addressed too. Both the watch path (compile_watch_item) and the batch path now hash the sidecars before reading the request and again after both compiles. If the two hashes differ, the step throws and no manifest is published (the watch path also removes the stale one). The digest written to .psinh is the one taken before the read.

What I ran. I built compile_dxil native_compute_pack_check native_frozen_request_check native_pixel_ir_dump native_compute_ir_dump in dev, then ran

ctest --test-dir out/build/dev --no-tests=error -j 1 -R '^(native_compile_dxil_watch|native_startup_request_cache_controls|native_rtv_variant_controls|native_direct_container|native_frozen_request)$'

5/5 pass.

Cross-check. #3138's tests/native_compile_dxil_watch_check.py (the RTV case that failed on 2ce9f112) now passes against this build. With the cross-check the other way from my first review, each PR's regressions pass on the other's build.

Mutants in tools/startup/compile_dxil.cpp. For each, I rebuilt compile_dxil in dev and ran the same 5 tests:

Mutant Result
.rtv marker hashes its own (missing) sidecars again killed (native_startup_request_cache_controls)
watch path skips the before/after comparison survives
watch path publishes the after-compile digest survives, equivalent while the comparison stands (the two digests are equal)

Restored and rebuilt afterwards; git diff --quiet is clean.

Non-blocking. The before/after comparison isn't pinned, because no test rewrites a sidecar while a compile is running. That's hard to do deterministically, and the code is small and reads correctly. I'm only noting it as unmeasured.

Verdict: approve on 13c7cfab. This PR and #3138 now both fix #3133, so as lambirou says, it's for R0Y00 to pick which one lands. R0Y00's changes request on 2ce9f112 still stands, and the base is a codex/* branch, so this is review only.

Environment: Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; DXC 1.9.2602.17; Python 3.12.10. These are CPU-only checks.

This reply was AI-assisted.

@lambirou

Copy link
Copy Markdown
Contributor Author

@R0Y00 pigalot approved 13c7cfab at 22:30:26, and #3138 is also approved by both of you. Both now pass each other's RTV/base-sidecar regressions. Which implementation do you want to land? If #3138 is the choice, I can close this duplicate; if #3137 is the choice, the pending CHANGES_REQUESTED can be cleared.

@KelboLive

Copy link
Copy Markdown
Contributor

Agree with both APPROVED reviews: FNV-1a sidecar digest in .psinh is a clean approach — the watch path and batch path share the same writer, so cache built by either path is interoperable. RTV variant case fixed (hashes base's sidecars through graphics_psin_path). Before/after comparison during compilation addresses stale-during-compile edge case.

@JohnConnorNPC

Copy link
Copy Markdown
Collaborator

Thank you for this work, and for offering to close it if #3138 was the choice. #3138 fixes the same stale-manifest case on the same base and merged at 2026-11-28T06:15Z, so I'm closing this as its duplicate.

One part is still worth having on the base: section 7's check that an unchanged RTV variant stays a cache hit (assert variant_manifest.stat().st_mtime_ns == variant_ns). The base test has no equivalent (grep -c variant_ns → 0). A small follow-up that ports it would be very welcome.

This comment was AI-assisted.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants