Skip to content

fix(ci): defuse recompact crash cascade on Windows (#2857) - #2860

Merged
zackees merged 1 commit into
masterfrom
fix/2857-ninja-recompact-crash
Jun 6, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/2857-ninja-recompact-crash

Conversation

@zackees

@zackees zackees commented Jun 6, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes #2857 — the ~150-minidump crash cascade that fires on every bash test --cpp run on Windows when the dep-log maintenance step is invoked.

Two changes in ci/meson/build_config.py::perform_ninja_maintenance:

  1. Quarantine .ninja_deps before 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.bak makes recompact always see a clean state. A stale .bak from a prior run is unlinked first.
  2. Touch the marker on success OR non-fatal failure. Previously the marker was only touched on 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.py pin the contract:

  • test_quarantines_existing_deps_before_recompact — .ninja_deps moved to .bak before the tool runs
  • test_stale_bak_is_replaced — a pre-existing .bak is overwritten
  • test_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 works
  • test_no_deps_file_is_a_clean_no_op — empty build dir runs cleanly

All 5 pass via uv run pytest ci/tests/test_ninja_maintenance.py -v and bash lint is green.

Acceptance criteria (from issue)

  • bash test --cpp on Windows no longer cascades minidumps (recompact sees a fresh .ninja_deps)
  • If recompact does fail, the marker is now touched anyway, so only the next day's run can re-trigger it
  • The downstream phantom fl_codec failure resolves once the crash output stops contaminating the runner output stream

Out of scope

  • Upstream Kitware-ninja / ninja-build bugs (access violation in recompact + recursive crash handler) — separate filings if/when isolated.
  • Periodic cleanup of accumulated .dmp files (issue's "bonus" — can be done in a follow-up).

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Chores
    • Improved Windows build stability by enhancing build tool maintenance procedures to prevent crashes
    • Expanded test coverage for build configuration components to ensure reliability

`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]>
@coderabbitai

coderabbitai Bot commented Jun 6, 2026 •

Copy link
Copy Markdown

Too many files changed? Review this PR in Change Stack to see how the pieces fit before you dive in.

Review Change Stack

📝 Walkthrough

Walkthrough

perform_ninja_maintenance now quarantines the existing .ninja_deps file to .ninja_deps.bak before invoking ninja -t recompact, preventing recompact from reading a corrupted file. The maintenance marker is now touched unconditionally after the maintenance attempt, ensuring that even non-fatal failures trigger cooldown and prevent repeated invocations.

Changes

Ninja Deps Maintenance Quarantine and Marker Touching

Layer / File(s) Summary
Quarantine logic and unified marker-touch footer
ci/meson/build_config.py
Docstring extended with Windows crash explanation. Before recompact, .ninja_deps is quarantined to .ninja_deps.bak (with safe handling of existing backups). Exception handling reorganized and marker touching moved to unified footer that executes on both success and non-fatal failure, with logging selected based on returncode.
Test coverage for quarantine and marker semantics
ci/tests/test_ninja_maintenance.py
New test module with _FakeRepairProc mock validating: (1) existing .ninja_deps is quarantined to .ninja_deps.bak before recompact, (2) stale backups are replaced, (3) marker is created/touched even on recompact failure, (4) cooldown exists-check short-circuits RunningProcess, (5) no-op behavior when no deps file exists. Includes unittest entrypoint.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A quarantine, a backup made so true,
When Ninja crashes, we know what to do—
Touch the marker, declare it done,
No more cascades, recompact won! 🔧

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 'fix(ci): defuse recompact crash cascade on Windows' is a clear, specific summary of the main change: fixing a ninja recompact crash issue on Windows.
Linked Issues check ✅ Passed The PR implements both key objectives from #2857: quarantining .ninja_deps before recompact and touching the maintenance marker even on non-fatal failure to prevent cascade re-triggering.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing issue #2857: build_config.py changes implement the quarantine and marker logic, and test_ninja_maintenance.py validates these specific behaviors.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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/2857-ninja-recompact-crash

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 and usage tips.

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

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 win

Docstring 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 win

Consider 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 from RunningProcess would 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

📥 Commits

Reviewing files that changed from the base of the PR and between 4c31af9 and 09d2dbe.

📒 Files selected for processing (2)
  • ci/meson/build_config.py
  • ci/tests/test_ninja_maintenance.py

@zackees
zackees merged commit 6590c59 into master Jun 6, 2026
9 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Jun 6, 2026
pull Bot pushed a commit to manmuqingshan/FastLED that referenced this pull request Jun 6, 2026
…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]>
@zackees
zackees deleted the fix/2857-ninja-recompact-crash branch August 21, 2026 19:15
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.

ninja recompact crash cascade on Windows: 150 minidumps + 0xC00000FD stack overflow per bash test --cpp run

1 participant