Skip to content

fix(ci): harden PCH staleness (real-clang e2e test, WASM reuse fixes, stale-PCH fail-safe) - #4843

Merged
zackees merged 1 commit into
masterfrom
fix/pch-hardening
Oct 15, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/pch-hardening

Conversation

@zackees

@zackees zackees commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #4839: hardens every place that reuses a precompiled header (PCH) so the stale-PCH #pragma once bug cannot come back.

Changes

  1. E2E regression test ci/tests/test_pch_e2e.py (added to the routine ci/native_ci.py Python smoke list; the size guard goes from 8 to 9). It uses FastLED's real clang driver (.cached/clang-native/ctc-clang++, falling back to clang-tool-chain-cpp). It skips only when that driver is missing, and under CI it fails instead of skipping. It builds a PCH from a #pragma once header with the same flags as the meson PCH target, runs ci/compile_pch.py and invalidate_stale_pch, then compiles a consumer TU. Cases covered:
    • header touched (same content, newer mtime)
    • header content changed
    • no change (the PCH must be reused byte-for-byte, so there is no rebuild loop)
    • a flag changed
    • .o compiles routed through the wrapper
    • the real clang redefinition output, checked against the fail-safe detector
  2. Audit of the other PCH reuse paths:
    • ci/wasm_compile_pch.py check_dependencies_changed: it returned "unchanged" whenever the depfile was older than the PCH. The depfile is always older than the PCH, so the check never ran, and touched or edited transitive headers never rebuilt the WASM PCH. Fixed.
    • compute_flags_hash: it sorted the flags, so an order change was invisible, and it ignored the checkout root. Fixed.
    • ci/wasm_compile_native.py needs_compilation: the sketch object was not recompiled after a PCH rebuild. Fixed.
    • ci/compile_pch.py: skipping on a hash match now applies only to .pch outputs. This is defensive; .o compiles were not observed being skipped in practice.
    • meson_setup_execute._PCH_ARTIFACT_SUFFIXES: now includes .pch.flags_hash.
    • Native compiler-version changes were already handled: build_config.py wipes the build when the version changes, including *.pch.
  3. Fail-safe: compile_meson (used for single-test runs) and the streaming runner check for a redefinition of or redefines default argument error in a header that is listed in a PCH depfile. When they see one, they purge only the PCHs and their sidecar files, retry once, and print STALE PCH DETECTED ... please report it. They rebuild the PCH rather than "compile without PCH", because -include-pch is baked into the meson cpp_args.
  4. Docs: agents/docs/testing-commands.md gains a "Precompiled Header Invariant" section explaining the rule and the clang bug, with a minimal repro.

Evidence

  • Old logic (the fix(ci): rebuild PCH when a header is touched (stale-PCH pragma once redefinitions) #4839 mtime rule removed, WASM files from master): pytest ci/tests/test_pch_e2e.py gives 6 failed, 7 passed. The failures:
    • touched header via the wrapper
    • touched header via the pre-compile pass
    • WASM touched dependency
    • WASM flag order
    • WASM project root
    • WASM object older than the PCH
  • New logic: all 13 pass. Full bash lint is clean.
  • Fail-safe, end to end, with the old logic forced and a header in the PCH touched, bash test adl_barrier prints:
    [MESON] ⚠️  STALE PCH DETECTED: redefinition errors in a header that is in a precompiled header. Purging PCHs and retrying once. ...
    [MESON] 🗑️  Purged 4 PCH artifact(s)
    [MESON] ✅ Stale-PCH retry succeeded on attempt 1
    ✅ All tests passed
    

Summary by CodeRabbit

  • Bug Fixes
    • Improved precompiled-header freshness checks so changed headers, newer dependencies, or modified compiler flags trigger rebuilds, including in WebAssembly builds.
    • Failed builds caused by stale precompiled headers now clear the affected cached files and retry compilation once.
    • Corrected dependency and flag checks to prevent outdated build artifacts from being reused.
  • Tests
    • Added regression coverage for precompiled-header rebuilds, reuse, and recovery from stale-header errors.

… stale-PCH fail-safe

- ci/tests/test_pch_e2e.py drives ci/compile_pch.py with FastLED's real clang
  driver: touched header, content change, no change (no rebuild loop), flag
  change, .o through the wrapper, plus the real clang redefinition output for
  the fail-safe. Added to the routine Python smoke list.
- WASM: check_dependencies_changed ignored the depfile whenever it was older
  than the PCH (always), so transitive header changes never rebuilt the PCH;
  compute_flags_hash sorted flags and ignored the checkout root; sketch
  objects did not recompile after a PCH rebuild.
- compile_pch.py: hash-match skip applies to .pch outputs only.
- Fail-safe in compile_meson and the streaming runner: on a redefinition error
  in a header that is in a PCH, purge only the PCHs, retry once, warn loudly.
- agents/docs/testing-commands.md: Precompiled Header Invariant + clang repro.
@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: FastLED/FastLED/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1ff54a20-1627-4050-abbd-26760c1cc385
📥 Commits

Reviewing files that changed from the base of the PR and between 7756a9d and 8b944f4.

📒 Files selected for processing: 10
  • agents/docs/testing-commands.md
  • ci/compile_pch.py
  • ci/meson/compile.py
  • ci/meson/meson_setup_execute.py
  • ci/meson/streaming_runner.py
  • ci/native_ci.py
  • ci/tests/test_native_ci_modes.py
  • ci/tests/test_pch_e2e.py
  • ci/wasm_compile_native.py
  • ci/wasm_compile_pch.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

📝 Walkthrough

The changes update native and WASM PCH invalidation checks, add PCH artifact cleanup and one-retry recovery for matching redefinition errors, and add end-to-end tests for PCH freshness and reuse.

Changes: PCH validity and recovery

Layer / File(s) Summary
PCH invalidation and reuse
ci/compile_pch.py, ci/wasm_compile_native.py, ci/wasm_compile_pch.py, ci/tests/test_pch_e2e.py, ci/native_ci.py, ci/tests/test_native_ci_modes.py, agents/docs/testing-commands.md
Native PCH reuse skips now apply only to .pch outputs. WASM freshness checks account for dependency timestamps, flag order, project root, and whether the object is older than the PCH. End-to-end tests and the smoke-test inventory cover these checks. The documentation describes the PCH invariant and recovery behavior.
Redefinition detection and retry
ci/compile_pch.py, ci/meson/compile.py, ci/meson/meson_setup_execute.py, ci/meson/streaming_runner.py, ci/tests/test_pch_e2e.py
The build wrappers match redefinition errors against PCH dependencies, purge PCH files and sidecars, and retry once. The streaming runner uses the remaining compile deadline for its retry. Tests cover detection and artifact purging.

Priority: ➖ Normal

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

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Ninja
  participant compile_meson
  participant is_pch_redefinition_error
  participant purge_pch_artifacts
  Ninja->>compile_meson: Return failed build output
  compile_meson->>is_pch_redefinition_error: Check output against PCH dependencies
  is_pch_redefinition_error-->>compile_meson: Return match result
  compile_meson->>purge_pch_artifacts: Remove PCH files and sidecars
  compile_meson->>Ninja: Retry the same command once
  Ninja-->>compile_meson: Return retry result and output
Loading
Merge Risk: ⚪ Minimal · up to 8b944

This change makes precompiled header staleness handling more robust in CI builds and adds regression tests. No concrete merge-blocking risk was identified in the reviewed changes.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 38 functions across 9 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely summarizes the main changes: improved PCH staleness handling, WASM reuse fixes, real-Clang testing, and stale-PCH recovery.
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 38 functions across 9 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

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