Repository navigation
fix(build): stop the example-change detector false-firing on a clean tree (#3761) - #3771
Conversation
…tree `bash test` paid a full ~20-30s reconfigure on an otherwise clean, fully cached tree, while the build system itself reported "Using cached example metadata (no changes detected)" in the same run. Root causes, all in the example-change detector: 1. A missing cache was reported as "example files changed". With the cache absent there was no path to "unchanged", so the outcome was a guaranteed reconfigure with a misleading reason. 2. Firing *deleted* the cache. Only the `--update` step rewrites it, so any following run that was fully fingerprint-cached left the cache missing and primed the next false positive. One false fire perpetuated itself indefinitely. 3. The hash was mtime-based. `git checkout`, `git worktree add` and branch switches rewrite example mtimes with byte-identical content, so every one of them invalidated the cache. Fixes: report "cache missing/unreadable - cannot prove examples unchanged" distinctly from "example files changed"; never delete the cache; hash file contents instead of mtimes. Three further defects found while reviewing the above: 4. The mtime fast path consulted directory mtimes only (`get_max_dir_mtime` stats directories, never files). Directory mtimes do not move on an in-place edit, so editing an existing example -- adding an `// @filter:` line, say -- was reported as "unchanged" and the content hash was never consulted. Now paired with a file-mtime probe, and compared strictly so an entry landing in the same clock tick as the marker falls through to the hash rather than being assumed unchanged. 5. Nothing re-armed the fast path after a matching hash, so a single checkout left every later run paying the full ~0.2s content hash forever. The cache mtime now doubles as a "contents verified at" marker, stamped from before the hash so an edit landing mid-hash is still seen. 6. The file set included build artifacts under `examples/*/.build`, `.fbuild`, `build`, `bin`. A plain `bash compile <board> --examples Blink` rewrites those, which would have re-created the same false positive from artifact content. Pruned with the predicate the mtime scan already used (`should_skip_scan_dir`, promoted from private). Also fixed nearby: - The cache was written UTF-8 but read back with the platform locale codec (cp1252 on Windows). Any non-ASCII example path or filter string made json.load raise; combined with no longer deleting the cache that would have been a permanent per-run reconfigure. - `_recover_stale_build` cleared `<build>/example_metadata.cache`, but the file lives at `<build>/examples/example_metadata.cache` -- a silent no-op, so recovery re-adopted the stale example set it meant to discard. Verified on the real tree: repeated `bash test` runs now reconfigure zero times and the cache persists; a simulated `git checkout` costs one 200ms content hash and then re-arms to an 80ms fast path, where it previously cost a 20-30s reconfigure on every run. 13 new regression tests in ci/tests/test_example_change_detector.py pin each behavior. Closes #3761 Co-Authored-By: Claude <[email protected]>
`bash lint` failed on master with two `invalid-argument-type` diagnostics: narrowing an untyped JSON value with a bare `isinstance(x, dict)` leaves ty with `dict[Never, Never]`, which rejects every string key passed to `.get`. Re-state the payload shape with an explicit cast so the keys type-check. No behavior change. Unrelated to #3761, fixed under the repo's fix-all-encountered-errors policy so lint is green. Co-Authored-By: Claude <[email protected]>
📝 WalkthroughWalkthroughThe PR changes Meson example-file tracking from metadata-based to content-based hashing, adds detailed cache validation reasons, corrects cache cleanup, and adds comprehensive tests. It also applies an explicit type cast during WS2814 pattern validation. ChangesMeson example-cache validation
WS2814 typing correction
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant build_config
participant detect_example_file_changes
participant example_metadata_cache
build_config->>detect_example_file_changes: Check example files
detect_example_file_changes->>example_metadata_cache: Discover files and compute content hash
example_metadata_cache-->>detect_example_file_changes: Return hash and mtimes
detect_example_file_changes-->>build_config: Return reconfiguration reason or None
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/meson_setup_phases.py`:
- Around line 592-595: Update the inner KeyboardInterrupt handler in the meson
setup flow to re-raise the caught interrupt after calling
handle_keyboard_interrupt(ki), matching the outer handler’s behavior and
ensuring worker-thread interrupts unwind instead of falling through to
cached_example_hash handling.
🪄 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: b4d55076-9b3f-442c-bf7e-e0067649b07d
📒 Files selected for processing (7)
ci/autoresearch/phases.pyci/meson/build_config.pyci/meson/cache_utils.pyci/meson/example_metadata_cache.pyci/meson/meson_setup_phases.pyci/meson/runner_helpers.pyci/tests/test_example_change_detector.py
handle_keyboard_interrupt() only raises on the main thread; from a worker it notifies and returns. Without an explicit re-raise the interrupt fell through to `cached_example_hash = ""`, so a Ctrl-C was reported as "example metadata cache unreadable" and forced a reconfigure instead of unwinding. Matches the outer handler in the same function. Reported by CodeRabbit on #3771. Co-Authored-By: Claude <[email protected]>
|
Addressed in 93e29de. Valid finding — fixed. 13 regression tests and Status note on the two red checks, neither of which this PR causes:
Also worth flagging: master currently has four red checks (the esptool job plus |
…3776) handle_keyboard_interrupt() only raises on the main thread; from a worker it notifies and returns. Without an explicit re-raise the interrupt fell through to `cached_example_hash = ""`, so a Ctrl-C was reported as "example metadata cache unreadable" and forced a reconfigure instead of unwinding. Matches the outer handler in the same function. Reported by CodeRabbit on #3771. Co-authored-by: Claude <[email protected]>
Fixes #3761.
What was wrong
bash testpaid a full ~20-30s reconfigure on an otherwise clean, fully cached tree, while the build system reported "Using cached example metadata (no changes detected)" in the same run. Two caches, one run, opposite answers.The three causes named in the issue, all in
detect_example_file_changes:--updatestep rewrites it, so any following run that was fully fingerprint-cached left the cache missing and primed the next false positive. One false fire perpetuated itself indefinitely — which is the state the repo was actually in.git checkout,git worktree addand branch switches rewrite example mtimes with byte-identical content, so every one of them invalidated the cache.What changed
compute_example_files_hashhashes path + SHA256(content) per file.Further defects found while reviewing the above
get_max_dir_mtimestats directories, never files, and directory mtimes do not move on an edit. So editing an existing example — adding an// @filter:line, say — was reported "unchanged" and the content hash was never consulted. Now paired with a file-mtime probe, and compared with a strict<so an entry landing in the same clock tick as the marker (Windows' clock granularity is ~15ms) falls through to the hash instead of being assumed unchanged.git checkoutwould leave every later run paying the full ~0.2s content hash forever. The cache mtime now doubles as a "contents verified at" marker, stamped from before the hash so an edit landing mid-hash is still caught next run.examples/*/.build,.fbuild,build,binwere included, and a plainbash compile <board> --examples Blinkrewrites those — re-creating the same false positive from artifact content instead of artifact mtimes. Pruned with the predicate the mtime scan already used (should_skip_scan_dir, promoted from private so there is one source of truth). 302 → 268 files hashed.Two more fixed in passing:
json.loadraise — and combined with no longer deleting the cache, that would have been a permanent per-run reconfigure._recover_stale_buildcleared<build>/example_metadata.cache, but the file lives at<build>/examples/example_metadata.cache. The delete was a silent no-op, so recovery re-adopted the stale example set it was meant to discard.Verification
On the real tree, before → after:
bash teston a clean treegit checkout(identical content)The reconfigure reason is now accurate and printed once:
13 regression tests in
ci/tests/test_example_change_detector.pypin each behavior, including the two that are easy to regress silently: in-place content edits must be detected, and the fast path must re-arm.bash lintclean. Full C++ suite 357/357 (forced, not a replayed cached number — cf. #3763).Notes for the reviewer
bash lintwas already failing on master with twotydiagnostics inci/autoresearch/phases.py(from the WS2814 change). Fixed here under the repo's fix-all-encountered-errors policy so lint is green; no behavior change.fl_task_executoris flaky, pre-existing.fl::task::run SYSTEM yield pathsfailed in two full-suite runs and passed in two others, passes in isolation on unmodified master, and passes clean under ASAN/UBSAN (--debug). This PR is Python-only and cannot affect C++ runtime behavior. Filed separately.compute_src_files_hashandcompute_test_files_hashstill use the same mtime-based scheme and have the same git-checkout weakness;detect_test_file_changesstill conflates a missing cache with "added N test files" (bounded to one run, so far less costly). Both left out to keep this reviewable — filed as follow-ups.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests