Skip to content

build: native_file vanishes under zccache snapshot restore on Windows #3048

Closed

Description

@zackees

Symptoms

bash test --cpp (and --clean) intermittently fail on Windows. The error surfaced by Ninja regenerate is:

FileNotFoundError: [Errno 2] No such file or directory: '...\.build\meson-quick\meson_native.txt'

The wrapper's own log shows the file IS written successfully, then a moment later it is gone:

2.08 [MESON] Regenerated native file: ...\.build\meson-quick\meson_native.txt
3.48 [zccache-meson] warning: cache restore failed (...os error 32...); falling back to fresh setup
4.16 ERROR: Cannot find specified native file

Root cause (suspected)

The zccache snapshot restore captures the whole .build/meson-quick/ (zackees/zccache#710). On Windows, the restore:

  1. Partially restores cached files (overwriting our just-written native_file).
  2. Hits a file-lock race (os error 32) and fails partway through.
  3. Reports "falling back to fresh setup" but the native_file is already nuked.

The existing _purge_restored_pch_artifacts defensive cleanup in ci/meson/meson_setup_execute.py covers PCH artifacts but not the native_file.

Proposed fix

Extend the zccache-snapshot recovery in ci/meson/meson_setup_execute.py to rewrite the native_file unconditionally after a failed snapshot restore. The file is small and is derived from CompilerDetection, so re-emission is free. Pattern: detect the cache restore failed outcome and call write_meson_native_file() again before handing control back to the build orchestrator.

Acceptance

  • Three back-to-back bash test --cpp invocations on Windows pass without manual intervention.
  • Self-healing path fires at least once during those runs (verifies the recovery exercises).

Decisions

🤖 Filed via Claude Code after multiple hits on this issue during a long session.

Activity

  1. zackees commented on Jun 14, 2026

    @zackees
    MemberAuthor

    Investigated. Root cause is in zccache, not FastLED — filed upstream as zackees/zccache#749.

    TL;DR: zccache meson configure's restore path (restore_from_cache in crates/zccache/src/cli/commands/meson_cache.rs:515) does an unconditional remove_dir_all(build_dir) before extracting the cached payload. That has two distinct bugs:

    1. Destructive wipe nukes user-owned files even on success. v3's allowlist only captures is_configure_output() paths, so the FastLED wrapper's pre-meson meson_native.txt is never in the snapshot — and is deleted by the wipe with no way to come back.
    2. remove_dir_all is not atomic on Windows. A single mid-loop ERROR_SHARING_VIOLATION (os error 32) — Defender, Search Indexer, etc. holding a transient lock — aborts the wipe partway through. The destination is left half-deleted; the "falling back to fresh setup" recovery doesn't restore the deleted files.

    The FastLED-side rewrite-on-restore-failure workaround in ci/meson/meson_setup_execute.py is still worth landing as a P2 defensive layer, but the durable fix is upstream. zccache#749 proposes a targeted wipe (only allowlisted paths, leave user-owned files alone) + extract-then-swap for atomicity.

  2. zackees commented on Jun 15, 2026

    @zackees
    MemberAuthor

    Fixed upstream in zccache 1.12.5 via zackees/zccache#750 (closes #749).

    zccache meson configure's restore path now uses extract-then-swap: it stages the cached entries into a sibling tempdir, then per-file renames each into place. The destination is never wiped, so user-owned files like meson_native.txt survive both successful and failed restores. Mid-extract failures (e.g. the Windows os error 32 sharing-violation race that triggered this report) now leave the build dir untouched so the wrapper's "fall back to fresh setup" recovery can actually rely on the pre-restore state.

    To pick up the fix:

    • via PyPI: uv pip install --upgrade 'zccache>=1.12.5'
    • via fbuild's managed install: bump MANAGED_ZCCACHE_VERSION to "1.12.5" in crates/fbuild-build/src/managed_zccache.rs (same shape as PR chore(deps): bump managed zccache 1.12.3 -> 1.12.4 fbuild#582). The download path verifies SHA256 against the GitHub release, so no SHA edits needed.

    The FastLED-side rewrite-on-restore-failure defensive layer mentioned in the issue is still worth landing as belt-and-suspenders, but it's no longer strictly required.

  3. moved this from Triage to Done in FastLED Trackeron Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions