Repository navigation
fix(ci): defuse recompact crash cascade on Windows (#2857) - #2860
Conversation
`bash test --cpp` on Windows triggered a ~150-minidump crash cascade
from the recompact maintenance step whenever .ninja_deps was in a
corrupt "valid header + partial second record" state, followed by a
0xC00000FD stack overflow from the tool's recursive crash handler.
The non-fatal error path also never touched the maintenance marker,
so the cascade re-ran on every invocation.
Two targeted changes in perform_ninja_maintenance:
1. Quarantine an existing .ninja_deps to .ninja_deps.bak before
calling recompact, so the tool always sees a clean state. A
stale .bak from a prior run is replaced.
2. Touch the marker on success OR non-fatal failure, so the 24h
cooldown also applies after a crash. A host where recompact
deterministically fails no longer regenerates the noise on
every invocation.
Adds ci/tests/test_ninja_maintenance.py pinning both behaviors plus
the cooldown short-circuit and the no-deps-file no-op.
Closes #2857
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Too many files changed? Review this PR in Change Stack to see how the pieces fit before you dive in. 📝 WalkthroughWalkthrough
ChangesNinja Deps Maintenance Quarantine and Marker Touching
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
ci/meson/build_config.py (1)
370-371:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winDocstring return value no longer matches implementation.
The docstring states "False on error" but the function now always returns
True(line 435). Since the maintenance is intentionally non-fatal, consider updating the docstring to reflect this:📝 Suggested docstring update
Returns: - True if maintenance was performed or skipped successfully, False on error + True always — maintenance is non-fatal; failures are logged but do not propagate🤖 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/build_config.py` around lines 370 - 371, The docstring's "Returns" section is out of sync: the maintenance function now always returns True (errors are non-fatal), so update the Returns description to reflect that it always returns True on success or skipped maintenance and that errors are logged but do not change the return value; locate the maintenance function in ci/meson/build_config.py (the function that currently returns True unconditionally) and change the docstring to clearly state the non-fatal error behavior and that the return value is always True.
🧹 Nitpick comments (1)
ci/tests/test_ninja_maintenance.py (1)
52-127: ⚡ Quick winConsider adding a test for the exception handling path.
The implementation catches
Exception(lines 414-418 in build_config.py) and still touches the marker. Adding a test that raises an exception fromRunningProcesswould verify the marker is touched even when the process constructor or wait() throws:🧪 Suggested additional test
def test_marker_touched_on_exception(self) -> None: """Marker is touched even when RunningProcess raises an exception.""" with TemporaryDirectory() as td: build_dir = Path(td) marker = build_dir / ".ninja_deps_maintenance" def _raise(*args: Any, **kwargs: Any) -> None: raise OSError("simulated subprocess failure") with mock.patch.object(build_config, "RunningProcess", _raise): result = build_config.perform_ninja_maintenance(build_dir) self.assertTrue(result) self.assertTrue( marker.exists(), "marker must be touched on exception to honor the 24h cooldown", )🤖 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/tests/test_ninja_maintenance.py` around lines 52 - 127, Add a unit test for the exception path that verifies perform_ninja_maintenance still touches the marker even if RunningProcess raises: in TestPerformNinjaMaintenance add a test (e.g. test_marker_touched_on_exception) that creates a TemporaryDirectory, patches build_config.RunningProcess to a callable that raises (e.g. OSError), calls build_config.perform_ninja_maintenance(build_dir), asserts the call returns True, and asserts the ".ninja_deps_maintenance" marker file exists; reference the RunningProcess mock and perform_ninja_maintenance function to locate where to add the test.
🤖 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.
Outside diff comments:
In `@ci/meson/build_config.py`:
- Around line 370-371: The docstring's "Returns" section is out of sync: the
maintenance function now always returns True (errors are non-fatal), so update
the Returns description to reflect that it always returns True on success or
skipped maintenance and that errors are logged but do not change the return
value; locate the maintenance function in ci/meson/build_config.py (the function
that currently returns True unconditionally) and change the docstring to clearly
state the non-fatal error behavior and that the return value is always True.
---
Nitpick comments:
In `@ci/tests/test_ninja_maintenance.py`:
- Around line 52-127: Add a unit test for the exception path that verifies
perform_ninja_maintenance still touches the marker even if RunningProcess
raises: in TestPerformNinjaMaintenance add a test (e.g.
test_marker_touched_on_exception) that creates a TemporaryDirectory, patches
build_config.RunningProcess to a callable that raises (e.g. OSError), calls
build_config.perform_ninja_maintenance(build_dir), asserts the call returns
True, and asserts the ".ninja_deps_maintenance" marker file exists; reference
the RunningProcess mock and perform_ninja_maintenance function to locate where
to add the test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: d25c8be0-6d62-4bc5-b308-4bfc2bcb642b
📒 Files selected for processing (2)
ci/meson/build_config.pyci/tests/test_ninja_maintenance.py
…D#2873) PR FastLED#2860 stopped the recompact crash cascade by renaming .ninja_deps out of the way before invoking the maintenance step. That defused the noise but discarded valid deps records once per 24h, silently degrading one build's worth of header-driven incremental rebuilds (a header change wouldn't trigger a recompile of any TU that wasn't otherwise dirty, until that TU was rebuilt for some other reason). Replace the rename with a copy-based snapshot + restore + broken-marker scheme so the deps log stays intact: * Skip recompact entirely if .ninja_deps_recompact_broken exists. Recompact is an optimization, not a correctness requirement. * Snapshot .ninja_deps -> .ninja_deps.bak before invoking recompact. * On success: delete the snapshot, log success. * On failure: restore the snapshot over .ninja_deps, touch the broken marker so future calls short-circuit, log a warning. * Touch the 24h cooldown marker on every attempt (kept from FastLED#2860). Result vs PR FastLED#2860: Healthy host: no behavior change. Broken host (1st): 12s crash cascade once, deps survive (restored). Broken host (2nd+): 0s, skipped via broken marker, deps untouched. Incremental loss: never (after first run) — was once per 24h. Trade-off: one visible cascade per build dir lifetime in exchange for zero data loss and zero recurrence. Upstream root cause tracked at ninja-build/ninja#2787. Test suite (ci/tests/test_ninja_maintenance.py) updated to pin the new contract: * test_snapshot_taken_then_discarded_on_success * test_snapshot_restored_on_recompact_failure * test_broken_marker_set_on_recompact_failure * test_broken_marker_skips_future_runs * test_stale_bak_is_replaced (updated for new semantics) * existing cooldown / marker / no-deps no-op tests retained Closes FastLED#2873 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Fixes #2857 — the ~150-minidump crash cascade that fires on every
bash test --cpprun on Windows when the dep-log maintenance step is invoked.Two changes in
ci/meson/build_config.py::perform_ninja_maintenance:.ninja_depsbefore recompact. A real-world deps log with a valid header plus a partial second record (the leftover from a previously-killed build) is the trigger for the recursive crash handler. Renaming the file to.ninja_deps.bakmakes recompact always see a clean state. A stale.bakfrom a prior run is unlinked first.returncode == 0, so a Windows host where recompact deterministically crashes re-ran the maintenance — and the 150-minidump cascade — on every invocation. Now the 24h cooldown applies after a crash too.Test plan
New tests in
ci/tests/test_ninja_maintenance.pypin the contract:test_quarantines_existing_deps_before_recompact—.ninja_depsmoved to.bakbefore the tool runstest_stale_bak_is_replaced— a pre-existing.bakis overwrittentest_marker_touched_on_recompact_failure— marker exists even when the subprocess returns non-zero (regression for the cascade-every-run bug)test_within_cooldown_short_circuits— existing 24h skip still workstest_no_deps_file_is_a_clean_no_op— empty build dir runs cleanlyAll 5 pass via
uv run pytest ci/tests/test_ninja_maintenance.py -vandbash lintis green.Acceptance criteria (from issue)
bash test --cppon Windows no longer cascades minidumps (recompact sees a fresh.ninja_deps)fl_codecfailure resolves once the crash output stops contaminating the runner output streamOut of scope
.dmpfiles (issue's "bonus" — can be done in a follow-up).🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes