Skip to content

build(meson): example-change detector forces a full reconfigure on a clean tree (missing cache == "changed") #3761

Closed

Description

@zackees

Symptom

Any bash test invocation that reaches meson setup pays a full reconfigure (~20-30s of "compiler probes") because of an example-change detector that reports a change on a clean tree.

The contradiction is visible inside a single run, with git status empty:

[MESON] ⚠️  Detected example file changes (files added/removed/modified)
[MESON] Reconfiguring build directory (example files changed): .build/meson-quick
...
Message: Using cached source file metadata (no changes detected)
Message: Using cached test metadata (no changes detected)
Message: Using cached example metadata (no changes detected)

The wrapper forces a reconfigure for "example file changes"; meson then reports there are none. Two caches, one run, opposite answers.

This is not the fingerprint layer misbehaving — that part works. On a warm cache with a clean tree the whole thing correctly short-circuits in 1.47s:

✓ Fingerprint cache valid - skipping C++ unit tests (no changes detected) [357/357 passed in 55.20s]

The cost only appears when meson setup actually runs, which is exactly when you least want an avoidable 20-30s.

Root cause

ci/meson/meson_setup_phases.py:530 detect_example_file_changes() gates on

.build/meson-quick/examples/example_metadata.cache

That file is currently absent. Verified directly, before and after runs.

With it absent the outcome is deterministic — there is no path to "unchanged":

step line behavior with cache missing
mtime fast-path :543-547 requires example_cache_file.exists(), so skip_example_hash stays False
read cached hash :557-564 file absent → cached_example_hash = ""
compare :566 current_example_hash != "" is always true
act :567-575 warn, unlink(), return True → reconfigure

So "cache missing" is conflated with "files changed."

It primes its own next false positive

:572 deletes the cache when it fires:

if current_example_hash != cached_example_hash:
    print_warning("[MESON] ⚠️  Detected example file changes ...")
    if example_cache_file.exists():
        example_cache_file.unlink()   # <-- removes the only evidence
    return True

Only meson rewrites it, via examples/meson.build:65-70 --update, and only on its cache-miss branch. So:

  1. detector fires → deletes cache → forces reconfigure
  2. meson runs → --check misses → discovery → --update rewrites cache
  3. but if the following runs are fully fingerprint-cached, meson never runs — the cache stays deleted
  4. next time setup does run, the missing cache guarantees another false "example files changed"

That is the state the repo is in right now: cache absent, primed to false-fire on the next setup.

Why it fires so readily: the hash is mtime-based

ci/meson/example_metadata_cache.py:83:

hash_input.append(f"{rel_path}:{stat.st_mtime:.6f}:{stat.st_size}")

Microsecond mtime, not content. Every git checkout, git worktree add, and branch switch rewrites example file mtimes with byte-identical content — and each one invalidates this hash. Sessions that move between branches (agent worktree workflows especially) will trip it constantly.

Reproduction

git status                      # clean
rm -f .build/meson-quick/examples/example_metadata.cache
touch src/fl/gfx/rgbw.cpp.hpp   # force meson setup to run
bash test fltest --cpp

Observe ⚠️ Detected example file changes followed by Using cached example metadata (no changes detected).

Direct confirmation that the two layers disagree only because of the missing file — --check itself is correct:

$ uv run python ci/meson/example_metadata_cache.py --check examples .build/meson-quick/examples
$ echo $?
1        # correctly reports cache miss

Suggested fix

  1. Do not conflate "no cache" with "changed." If reconfiguring is still the safe default when the cache is absent, say so accurately ("example cache missing - cannot prove unchanged"), rather than claiming files changed.
  2. Stop deleting the cache at :572, or seed it in the same breath. Deleting is what makes one false positive self-perpetuating across fingerprint-cached runs.
  3. Hash content, not mtime, so git operations stop invalidating it. (Or keep mtime purely as the fast-path hint it already is at :543-547, and fall back to content hashing.)
  4. Consider collapsing the two caches. The wrapper and examples/meson.build maintain separate state for the same question and can contradict each other; a single source of truth removes the whole failure class.

Verified / not verified

Verified: the missing cache file, the deterministic code path above, the --check exit code, mtime in the hash input, and the contradictory log pair on a clean tree.

Not chased down: during one observed run meson reported a cache hit while the file was absent both before and after. The most consistent explanation is ordering — the wrapper deleted it, meson's --update rewrote it, and a later fire removed it again — but I did not instrument the sequence to prove that, and it is not load-bearing for the fix.

Filed from an agent session after noticing repeated 20-30s reconfigures on an otherwise clean, fully cached tree.

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