Skip to content

fix(ci): stop test caches absorbing files added during a run - #3739

Merged
zackees merged 3 commits into
masterfrom
fix/test-cache-stale-watermarks
Jul 27, 2026
Merged

zackees merged 3 commits into
masterfrom
fix/test-cache-stale-watermarks

Conversation

@zackees

@zackees zackees commented Jul 27, 2026 •

Copy link
Copy Markdown
Member

The bug

Two test caches record their invalidation watermark at cache-write time, which happens after the run finishes. Any file created while a run is in flight therefore ends up older than the watermark, so every subsequent run concludes "no changes" and skips it — permanently, and while still reporting the suite all-green.

Concretely: a newly added test can silently never build, and bash test --cpp prints "All tests passed".

Reproduction

Added tests/fl/zz_cache_probe.cpp, then ran bash test --cpp:

✅ All tests passed (356/356 in 25.62s)     <- ran for real, but count should be 357

The new test was absent. It only appeared under --clean (357). Instrumenting detect_test_file_changes() showed why:

max_tests_dir_mtime = 1785179284.83   (tests/fl bumped when the file was added)
test_list_cache.txt = 1785179287.04   (written 2.2s LATER)
shortcut_skips      = True            -> returns "unchanged", file lists never compared

Because the shortcut compares against the cache file's own mtime, and the cache is written at the end of a run that began before the file existed, the file is masked on every future run.

Fix

  • meson_setup_phases — compare against a watermark captured before discovery (test_list_watermark.txt) instead of the cache file's mtime, and drop the touch() that created the masking window. The authoritative file-list comparison still runs whenever the watermark is missing or stale.
  • cache_utils / test_runner — add capture_source_watermarks(), taken before the build starts, threaded into save_full_run_result(). The cache-hit path now carries the previous watermarks forward instead of rescanning: that path runs when tests were skipped, so rescanning was marking untested files as covered by a pass they never took part in.

The fast paths are preserved — only the reference point changes — so there's no added scan cost on the hot path.

Testing

  • bash test --cpp --clean — 356/356 pass
  • bash lint — fully green

Follow-ups found while investigating (not in this PR)

  1. zccache daemon serves hits for deleted caches. With no cache file on disk, the daemon-backed path returns rc=1 skip (no changes) while the standalone binary correctly returns rc=0 run (no cache file). After zccache stop the identical call flips to rc=0. The daemon keys state by cache-file path and never revalidates the backing file exists. This affects every daemon-backed consumer today (cpp_lint, js_lint, python_lint) and belongs in the zccache repo.
  2. cpp_test doesn't use zccache at all — it hand-rolls the mtime fast-path plus a Python SHA-256 calculator. Delegating to zccache-fp would be correct by construction (it hashes at check time and only promotes on success) and measured faster than the Python miss path: ~170ms vs 200-400ms over ~2800 files. Worth doing once (1) is fixed.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved test-result caching by tracking source/test “watermarks” and only reusing cached outputs when inputs truly match.
    • Fixed cache invalidation when the test list changes by using a dedicated watermark file instead of touching cache timestamps.
    • Improved fingerprint fast-path correctness by persisting and carrying forward source max mtimes across runs.
    • Ensured Meson reconfiguration propagates correctly when using the zccache meson configure wrapper.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

The test caching flow now captures source-tree mtimes before execution, persists complete watermark sets with full-run results, validates test-list freshness with a dedicated watermark file, and uses source watermarks for fingerprint fast paths.

Cache watermark flow

Layer / File(s) Summary
Full-run watermark capture and persistence
ci/meson/cache_utils.py
Captures source-tree and Meson build-definition watermarks and prevents full-run cache writes when the supplied watermark set is incomplete.
Test-list watermark validation
ci/meson/meson_setup_phases.py
Uses an atomically written tests-directory watermark to choose between fast-path validation and authoritative test-file comparison.
Fingerprint source watermark fast path
ci/util/fingerprint.py, ci/util/test_types.py
Persists source mtimes in fingerprint results and gates fast-path reuse on unchanged scanned source mtimes.
Runner capture and cache refresh
ci/util/test_runner.py, ci/meson/meson_setup_execute.py
Passes captured or carried watermarks to full-run cache saving and forwards --reconfigure through the zccache wrapper path.

Estimated code review effort: 3 (Moderate) | ~30 minutes

Sequence Diagram(s)

sequenceDiagram
  participant TestRunner
  participant Meson
  participant FingerprintManager
  participant CacheUtils
  participant FullRunCache
  TestRunner->>TestRunner: Capture source watermarks
  TestRunner->>FingerprintManager: Check source watermark fast path
  FingerprintManager->>Meson: Build and run tests when needed
  TestRunner->>CacheUtils: Save result with complete watermarks
  CacheUtils->>FullRunCache: Persist result and watermark fields
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main fix: preventing CI test caches from masking files added during an in-progress run.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/test-cache-stale-watermarks

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
ci/meson/meson_setup_phases.py (1)

497-517: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Only advance the watermark after the cache-list write succeeds.

If temp_cache.replace() fails, the old test_list_cache.txt remains, but Line 516 records the current mtime. The next fast path then trusts a stale list and skips discovery. Return after the write failure, or gate _write_test_list_watermark() on successful replacement.

Proposed fix
             except (OSError, IOError) as e:
                 _ts_print(
                     f"[MESON] Warning: Could not update test cache atomically: {e}"
                 )
                 try:
                     temp_cache.unlink()
                 except (OSError, IOError):
                     pass
+                return True
             _write_test_list_watermark(build_dir, max_tests_dir_mtime)
             return True
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ci/meson/meson_setup_phases.py` around lines 497 - 517, Update the
cache-writing flow around temp_cache.replace and _write_test_list_watermark so
the watermark is written only after the temporary cache is successfully
replaced. On any write or replacement failure, clean up the temporary file as
currently done and return without advancing the watermark, preserving the
stale-cache recovery path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ci/meson/cache_utils.py`:
- Around line 584-593: Require complete pre-run watermarks before persisting a
full-run cache entry: update the marks selection in
ci/meson/cache_utils.py:584-593 to remove the post-run
_get_max_source_file_mtime fallback and skip persistence when required fields
are unavailable. In ci/util/test_runner.py:1907-1922, update the refresh logic
to run only when every persisted watermark field exists, and never pass _carry
or None; preserve the existing behavior when complete watermarks are available.
- Around line 536-541: Define a `@typechecked` `@dataclass` value object for the
four watermark fields currently returned by capture_source_watermarks(), and
return an instance of it instead of a dict. Update capture_source_watermarks()
and save_full_run_result() so their annotations and watermarks parameter use
this dataclass, preserving the existing mtime values and enabling runtime
validation of cached source state.

In `@ci/util/test_runner.py`:
- Around line 1534-1541: Move capture_source_watermarks(PROJECT_ROOT) out of the
unit_only path and remove the unused _watermarks assignment there. In
ci/util/test_runner.py lines 1704-1710, capture the snapshot immediately before
the mixed-mode run_meson_build_and_test() call and pass that initialized
_watermarks value to the persistence logic.

---

Outside diff comments:
In `@ci/meson/meson_setup_phases.py`:
- Around line 497-517: Update the cache-writing flow around temp_cache.replace
and _write_test_list_watermark so the watermark is written only after the
temporary cache is successfully replaced. On any write or replacement failure,
clean up the temporary file as currently done and return without advancing the
watermark, preserving the stale-cache recovery path.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 7d60ad3a-40f0-458a-ad23-7184aee7dba8

📥 Commits

Reviewing files that changed from the base of the PR and between 3d921d6 and 77df3ca.

📒 Files selected for processing (3)
  • ci/meson/cache_utils.py
  • ci/meson/meson_setup_phases.py
  • ci/util/test_runner.py

Comment thread ci/meson/cache_utils.py
Comment on lines +536 to +541
return {
"src_max_file_mtime": _get_max_source_file_mtime(root / "src"),
"tests_max_file_mtime": _get_max_source_file_mtime(root / "tests"),
"examples_max_file_mtime": _get_max_source_file_mtime(root / "examples"),
"meson_max_file_mtime": _meson_max,
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== locate file =="
fd -a 'cache_utils.py$' . || true

echo "== file outline (if available) =="
ast-grep outline ci/meson/cache_utils.py --view compact 2>/dev/null | sed -n '1,220p' || true

echo "== relevant source around get/save/save_full =="
sed -n '480,620p' ci/meson/cache_utils.py

echo "== usages of save_full_run_result and get_full_run_result watermark =="
rg -n "save_full_run_result|get_full_run_result|watermark|src_max_file_mtime|tests_max_file_mtime|examples_max_file_mtime|meson_max_file_mtime" ci/meson/cache_utils.py ci -g '*.py' | sed -n '1,220p'

echo "== typechecked/dataclass usage =="
rg -n "`@typechecked`|`@dataclass`|Save.*Run.*Result|FullRunResult|watermark" ci/meson/cache_utils.py ci -g '*.py' | sed -n '1,220p'

Repository: FastLED/FastLED

Length of output: 26262


Return a typed watermark value object.

capture_source_watermarks() returns an untyped dict, and save_full_run_result() accepts Optional[dict[str, float]]. Define a @typechecked @dataclass`` for these four coupled mtimes, use it as the return type, and update the watermarks parameter so the cached source state is runtime-validated.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ci/meson/cache_utils.py` around lines 536 - 541, Define a `@typechecked`
`@dataclass` value object for the four watermark fields currently returned by
capture_source_watermarks(), and return an instance of it instead of a dict.
Update capture_source_watermarks() and save_full_run_result() so their
annotations and watermarks parameter use this dataclass, preserving the existing
mtime values and enabling runtime validation of cached source state.

Source: Coding guidelines

Comment thread ci/meson/cache_utils.py Resolved
Comment thread ci/util/test_runner.py Resolved
@zackees
zackees force-pushed the fix/test-cache-stale-watermarks branch from 77df3ca to 4030562 Compare July 27, 2026 20:30

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
ci/meson/cache_utils.py (1)

597-606: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Remove the obsolete post-run Meson scan.

Lines 582-595 still stat five Meson files on every successful save, but _meson_max is no longer used after the mandatory pre-run watermark check. Delete that scan and rely on the captured meson_max_file_mtime.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ci/meson/cache_utils.py` around lines 597 - 606, Remove the obsolete post-run
Meson file-stat scan in the surrounding cache-save logic, including the unused
_meson_max calculation and its five file reads. Preserve the mandatory pre-run
watermarks validation and use the already captured meson_max_file_mtime when
constructing the persisted marks.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ci/meson/cache_utils.py`:
- Around line 544-548: Update the exception handling in meson_max_file_mtime’s
_meson_files loop so only intentionally missing optional files are ignored;
detect the missing-file condition explicitly, while propagating other OSError
cases as descriptive failures that include the affected path. Do not allow stat
failures to produce a valid cache watermark.
- Around line 571-575: Update the docstring for the watermarks argument in the
relevant cache utility function to state that omitting watermarks fails closed
and returns without persisting a cache entry, rather than falling back to a
current scan. Preserve the existing requirement that callers provide source
mtimes captured before the run.

---

Nitpick comments:
In `@ci/meson/cache_utils.py`:
- Around line 597-606: Remove the obsolete post-run Meson file-stat scan in the
surrounding cache-save logic, including the unused _meson_max calculation and
its five file reads. Preserve the mandatory pre-run watermarks validation and
use the already captured meson_max_file_mtime when constructing the persisted
marks.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 4a19917f-6b4c-49a8-947d-15e7c7aa2a7d

📥 Commits

Reviewing files that changed from the base of the PR and between 77df3ca and 4030562.

📒 Files selected for processing (6)
  • ci/meson/cache_utils.py
  • ci/meson/meson_setup_execute.py
  • ci/meson/meson_setup_phases.py
  • ci/util/fingerprint.py
  • ci/util/test_runner.py
  • ci/util/test_types.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • ci/meson/meson_setup_phases.py
  • ci/util/test_runner.py

Comment thread ci/meson/cache_utils.py Resolved
Comment thread ci/meson/cache_utils.py Resolved
zackees and others added 3 commits July 27, 2026 14:03
Two caches recorded their invalidation watermark at cache-WRITE time, which
is after the run finished. Any file created while a run was in flight ends
up older than that watermark, so every later run concluded "no changes" and
skipped it -- permanently, and while still reporting the suite all-green. A
newly added test could silently never build.

Reproduced: added tests/fl/zz_cache_probe.cpp, then `bash test --cpp`
reported "All tests passed (356/356)" with the new test absent; the count
only became 357 under --clean. Instrumented detect_test_file_changes() and
found test_list_cache.txt stamped 2.2s AFTER the tests/fl dir mtime that the
new file had bumped, so the mtime shortcut returned "unchanged" without ever
comparing the file lists.

- meson_setup_phases: compare against a watermark captured BEFORE discovery
  (test_list_watermark.txt) instead of the cache file's own mtime, and drop
  the touch() that created the masking window.
- cache_utils/test_runner: add capture_source_watermarks(), taken before the
  build starts, and thread it into save_full_run_result(). The skip path now
  carries the previous watermarks forward rather than rescanning -- that path
  runs when tests were SKIPPED, so rescanning marked untested files as
  covered by a pass they never took part in.

Co-Authored-By: Claude <[email protected]>
Root cause of "a new test file never builds unless you pass --clean".

build_meson_setup_cmd() appends --reconfigure on the direct path but DROPPED
it on the zccache configure-wrapper path. With a sidecar present (the normal
case) a source-triggered reconfigure therefore ran a plain setup against an
already-configured dir, the build system printed "Directory already
configured / Just run your build command" and regenerated nothing. The
change was detected and reported, then silently discarded:

  [MESON] Reconfiguration required:
  [MESON]     - test files changed (tests/)
  ...
  Directory already configured.

So the test list never picked up the new file and the suite still reported
all-green at the old count.

Verified end-to-end: adding tests/fl/zz_probe.cpp and running `bash test
--cpp` (no --clean) now yields

  [BUILD] Linking target .build/meson-quick/tests/fl_zz_probe.dll
  [1/1] OK fl_zz_probe

where before the target was never generated.

Also addresses review feedback on the watermark work:

- save_full_run_result() now REQUIRES a complete pre-run watermark and skips
  persisting otherwise. The old scan-now fallback reintroduced the very bug
  it was meant to fix for any caller that omitted them.
- the skip-path refresh only carries watermarks forward when the whole set
  survives, instead of passing `_carry or None` and silently re-triggering
  that fallback.
- FingerprintManager gates its mtime fast path on a watermark captured at run
  START, with no fall back to the fingerprint file's own mtime; a cache
  predating the field just takes the slow path once.

Co-Authored-By: Claude <[email protected]>
Review follow-up. Two issues, both valid.

1. `except OSError: pass` around the build-definition stat loop swallowed
   permission/IO errors and produced a LOW maximum. Low is the dangerous
   direction: the check side compares `now > saved -> invalidate`, so an
   under-reported "now" reads as "unchanged" and serves a stale cache entry
   for a build file that actually changed -- the same silent-staleness class
   these watermarks exist to prevent.

   Extract _max_meson_build_mtime(), which skips genuinely-absent files
   (not every checkout has examples/meson.build) but raises with path
   context on any other stat error. check_full_run_cache()'s enclosing
   handler turns that into a cache miss, and the capture site in
   test_runner falls back to None so save_full_run_result() skips
   persisting. Worst case is one lost fast path, never a stale green -- and
   an unreadable file never takes down the test run.

2. The `watermarks` docstring still described a scan-now fallback that the
   previous commit removed. Corrected to state the actual fail-closed
   contract, so a future caller does not assume an entry will be written.

Also drops the now-dead _meson_max computation in save_full_run_result();
`marks` comes solely from the passed-in watermarks.

Validation: `bash test --cpp --clean` 356/356; adding a new test file and
running without --clean still builds and runs it (fl_zz_probe); bash lint
green.

Co-Authored-By: Claude <[email protected]>
@zackees
zackees force-pushed the fix/test-cache-stale-watermarks branch from 4030562 to e7c0059 Compare July 27, 2026 21:09

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🧹 Nitpick comments (2)
ci/meson/cache_utils.py (2)

516-550: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Reuse the new fail-closed helpers in check_ninja_skip too.

check_ninja_skip (lines 191-203, unchanged) still hardcodes its own copy of the same 5 meson.build paths and computes _meson_max with a bare except OSError: pass — the exact silent-staleness pattern _max_meson_build_mtime/_meson_build_files were introduced to eliminate. Since this PR's whole point is closing that gap, leaving check_ninja_skip on the old swallow-and-continue path means a permission/I/O error there can still under-report the max mtime and serve a stale ninja-skip decision.

Consider having check_ninja_skip call _meson_build_files() / _max_meson_build_mtime() instead of duplicating the list and the try/except.

♻️ Suggested consolidation
-        cwd = Path.cwd()
-        _meson_files = [
-            cwd / "meson.build",
-            cwd / "tests" / "meson.build",
-            cwd / "ci" / "meson" / "native" / "meson.build",
-            cwd / "ci" / "meson" / "wasm" / "meson.build",
-            cwd / "examples" / "meson.build",
-        ]
-        _meson_max = 0.0
-        for mf in _meson_files:
-            try:
-                _meson_max = max(_meson_max, mf.stat().st_mtime)
-            except OSError:
-                pass
+        cwd = Path.cwd()
+        _meson_max = _max_meson_build_mtime(cwd)
         if _meson_max > saved.get("meson_max_file_mtime", -1.0) + 0.001:
             return False  # meson.build file modified since last build

Note: _max_meson_build_mtime can now raise OSError on unreadable files, so the caller's enclosing except (OSError, ...) (already present at the bottom of check_ninja_skip) will convert it to a cache miss — consistent with the fail-closed behavior in check_full_run_cache.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ci/meson/cache_utils.py` around lines 516 - 550, Update check_ninja_skip to
reuse _meson_build_files and _max_meson_build_mtime instead of duplicating the
Meson path list and swallowing OSError. Preserve its existing enclosing
exception handling so stat failures become a cache miss, while missing optional
files remain handled by the shared fail-closed helper.

527-575: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add unit tests for the new fail-closed watermark logic.

_max_meson_build_mtime's FileNotFoundError-vs-OSError split and capture_source_watermarks's all-or-nothing contract are exactly the kind of subtle, easy-to-regress logic this PR exists to fix (per the PR history, a prior masking bug already slipped through once). No test file is included in this change; consider adding coverage for: a missing optional meson.build, an unreadable one raising OSError, and save_full_run_result skipping persistence on a partial watermark dict.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ci/meson/cache_utils.py` around lines 527 - 575, The new fail-closed
watermark behavior lacks regression tests. Add unit coverage for
_max_meson_build_mtime confirming missing optional files are skipped while other
OSError failures propagate, and for the capture/save flow confirming
save_full_run_result does not persist results when given a partial watermark
dictionary.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ci/util/fingerprint.py`:
- Around line 222-246: Update the source-scan flow around
_get_max_source_file_mtime so missing roots or OSError failures are
distinguishable from a legitimate 0.0 mtime. Invalidate the fast path, or raise
a descriptive error, when any source scan fails; do not allow the max_file_mtime
comparison to treat scan failure as an unchanged tree. Preserve normal watermark
gating for successful scans.
- Around line 79-80: Update FingerprintManager.__init__ to include the explicit
-> None return annotation, preserving its existing initialization behavior.

---

Nitpick comments:
In `@ci/meson/cache_utils.py`:
- Around line 516-550: Update check_ninja_skip to reuse _meson_build_files and
_max_meson_build_mtime instead of duplicating the Meson path list and swallowing
OSError. Preserve its existing enclosing exception handling so stat failures
become a cache miss, while missing optional files remain handled by the shared
fail-closed helper.
- Around line 527-575: The new fail-closed watermark behavior lacks regression
tests. Add unit coverage for _max_meson_build_mtime confirming missing optional
files are skipped while other OSError failures propagate, and for the
capture/save flow confirming save_full_run_result does not persist results when
given a partial watermark dictionary.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f8853007-3cf4-4c50-8f63-1537665c4a69

📥 Commits

Reviewing files that changed from the base of the PR and between 4030562 and e7c0059.

📒 Files selected for processing (6)
  • ci/meson/cache_utils.py
  • ci/meson/meson_setup_execute.py
  • ci/meson/meson_setup_phases.py
  • ci/util/fingerprint.py
  • ci/util/test_runner.py
  • ci/util/test_types.py
🚧 Files skipped from review as they are similar to previous changes (4)
  • ci/util/test_types.py
  • ci/meson/meson_setup_execute.py
  • ci/meson/meson_setup_phases.py
  • ci/util/test_runner.py

Comment thread ci/util/fingerprint.py
Comment on lines +79 to +80
# name -> max source mtime seen at the START of this invocation's check
self._observed_max_mtime: dict[str, float] = {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate and inspect the relevant Python file and the constructor signature.
if [ -f ci/util/fingerprint.py ]; then
  echo "FOUND ci/util/fingerprint.py"
  wc -l ci/util/fingerprint.py
  sed -n '1,120p' ci/util/fingerprint.py
else
  echo "ci/util/fingerprint.py not found"
  fd -a 'fingerprint.py' . || true
fi

echo
echo "Return annotations in fingerprint.py definitions:"
python3 - <<'PY'
import ast
from pathlib import Path
path = Path("ci/util/fingerprint.py")
tree = ast.parse(path.read_text(), filename=str(path))
for node in ast.walk(tree):
    if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
        lineno = node.lineno
        fname = node.name
        ret = ast.get_docstring(node)
        annot = None
        if node.returns:
            if isinstance(node.returns, ast.Constant):
                annot = ast.unparse(node.returns)
            else:
                annot = ast.unparse(node.returns)
        if "FingerprintManager" in fname or fname == "__init__":
            print(f"{lineno}: {fname}, return_annotation={annot}, args={[a.arg for a in node.args.args]}")
PY

Repository: FastLED/FastLED

Length of output: 5282


Add the required constructor return annotation.

Add -> None to FingerprintManager.__init__. Coding guidelines require explicit return type annotations for all Python functions.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ci/util/fingerprint.py` around lines 79 - 80, Update
FingerprintManager.__init__ to include the explicit -> None return annotation,
preserving its existing initialization behavior.

Source: Coding guidelines

Comment thread ci/util/fingerprint.py
Comment on lines 222 to +246
max_file_mtime = max(
(_get_max_source_file_mtime(d, exts=exts) for d in dirs), default=0.0
)
if max_file_mtime > fp_mtime:
return False # a source file was modified after fingerprint write
# Remember what this scan saw. If a run follows, save_all() persists
# it as the new watermark, describing the tree at that run's START.
self._observed_max_mtime[name] = max_file_mtime
prev = self.read(name)
if prev is None or prev.status != "success":
return False # no previous result or previous run failed
# Fast-path fires: record the cached result without running the calculator
# Gate on the watermark recorded when the cached run BEGAN. There is
# deliberately no fall back to fp_file.stat().st_mtime: that file is
# written at run END, so a source file created mid-run compares as
# older and is skipped forever. A cache without a watermark (written
# before this field existed) simply takes the slow path once.
if prev.source_max_mtime is None:
return False
if max_file_mtime > prev.source_max_mtime:
return False # a source file changed after the cached run began
# Fast-path fires: nothing will be rebuilt, so do NOT advance the
# watermark -- keep the one the cached run was actually gated on.
self._observed_max_mtime.pop(name, None)
self._prev_fingerprints[name] = prev
self._fingerprints[name] = FingerprintResult(hash=prev.hash)
self._fingerprints[name] = FingerprintResult(
hash=prev.hash, source_max_mtime=prev.source_max_mtime
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Do not treat failed source scans as an unchanged tree.

_get_max_source_file_mtime() returns 0.0 for missing roots and every OSError. That value passes the new max_file_mtime <= prev.source_max_mtime gate, so an inaccessible or deleted source directory can produce a false cache hit and skip the test run. Make scan failure invalidate the fast path (or fail with a descriptive error), rather than using 0.0 as a valid watermark. As per coding guidelines, “Never use silent fallbacks for missing critical resources - always fail fast with descriptive errors.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ci/util/fingerprint.py` around lines 222 - 246, Update the source-scan flow
around _get_max_source_file_mtime so missing roots or OSError failures are
distinguishable from a legitimate 0.0 mtime. Invalidate the fast path, or raise
a descriptive error, when any source scan fails; do not allow the max_file_mtime
comparison to treat scan failure as an unchanged tree. Preserve normal watermark
gating for successful scans.

Source: Coding guidelines

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

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant