Repository navigation
fix(ci): snapshot+restore + broken-marker for recompact crash (#2873) - #2874
Conversation
PR #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 #2860). Result vs PR #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 #2873 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThis PR changes perform_ninja_maintenance() to snapshot ChangesNinja Maintenance Workaround
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related issues
Possibly related PRs
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.
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/build_config.py`:
- Around line 409-415: The try/except around the file operations for
deps_bak/deps_file is swallowing OSError and allowing the function to return
True even when snapshot/restore failed; change the error handling so
file-operation failures are not silent: catch OSError as e (or remove the bare
except), and either raise a new descriptive RuntimeError (including e and the
paths deps_file and deps_bak) or return False immediately so callers know the
snapshot/restore failed; ensure both the snapshot path (where snapshot_taken is
set) and the restore path propagate errors instead of continuing, and update any
callers if you switch to raising an exception so the build fails fast when
.ninja_deps cannot be copied or restored.
🪄 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
Run ID: 0927b9f2-51c1-40c6-a6a7-e4e29f327adc
📒 Files selected for processing (2)
ci/meson/build_config.pyci/tests/test_ninja_maintenance.py
CodeRabbit flagged that the OSError handlers around snapshot and
restore silently swallowed failures, allowing the function to return
True even when the byte-preservation guarantee couldn't be honored.
Worst case on the restore path: unlink succeeded but rename failed,
leaving the build dir with no .ninja_deps at all.
Two targeted fixes that keep the "maintenance is non-fatal" contract:
1. Snapshot failure path: log a visible warning, set the broken
marker, and skip recompact entirely. Without a rollback path
it's safer to leave the existing .ninja_deps in place than to
run a tool we know can crash mid-write on this host. Calls site
never sees an exception — the deps log is preserved.
2. Restore failure path: replace the unlink+rename pair with a
single atomic os.replace(deps_bak, deps_file). On POSIX and
Windows alike, os.replace is atomic: either the target ends up
with the snapshot's content, or nothing changes. The bad
interleaving (target unlinked, source rename failed) is no
longer reachable. On the unlikely failure case we now log a
visible warning rather than swallowing OSError.
Note on CodeRabbit's specific suggestion (raise RuntimeError on
either failure): rejected — the call sites in ci/util/meson_example_runner.py
and ci/meson/runner.py treat this function as best-effort, and the
existing top-level `except Exception` handler explicitly documents
the maintenance step as non-fatal. Failing the whole build because a
.bak file couldn't be deleted would be a worse outcome than the
silent return. The visible-warning + skip-and-mark-broken pattern
above satisfies the actual concern (no silent data loss) without
breaking the non-fatal contract.
Tests: adds test_snapshot_failure_skips_recompact_and_flags_broken,
which monkey-patches shutil.copy2 to raise OSError and asserts that
RunningProcess is never invoked, .ninja_deps stays byte-identical,
and the broken marker is set. Other tests still pass — the os.replace
swap is semantically equivalent to the prior unlink+rename pair under
non-faulty filesystems.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Closes #2873. Follows up #2860 (closed #2857) which defused the recompact crash cascade by renaming
.ninja_depsout of the way before invoking the maintenance step. That worked but discarded valid deps records once per 24h, silently degrading one build's worth of header-driven incremental rebuilds.This PR replaces the rename with a copy-based snapshot + restore + broken-marker scheme so the deps log stays intact.
Design
Three markers in
build_dir:.ninja_deps_maintenance.ninja_deps_recompact_broken.ninja_deps.bakAlgorithm in
perform_ninja_maintenance():.ninja_deps_recompact_brokenexists → return immediately..ninja_deps_maintenance.shutil.copy2(.ninja_deps, .ninja_deps.bak)so we can restore on failure.ninja -t recompact..bak, log success..bakover.ninja_deps, touch broken marker, log warning.Behavior comparison
Trade-off: one visible cascade per build dir lifetime in exchange for zero data loss and zero recurrence.
Test plan
ci/tests/test_ninja_maintenance.pyupdated to pin the new contract — 8/8 pass viauv run pytest ci/tests/test_ninja_maintenance.py -v:test_snapshot_taken_then_discarded_on_success—.ninja_depssurvives,.bakcleaned uptest_snapshot_restored_on_recompact_failure—.ninja_depsbytes identical to pre-calltest_broken_marker_set_on_recompact_failure— broken marker created on failuretest_broken_marker_skips_future_runs—RunningProcessnever invoked when broken marker presenttest_stale_bak_is_replaced— updated for new semantics (pre-existing.bakis overwritten before recompact runs)test_marker_touched_on_recompact_failure— defense in depth: cooldown marker still touched on failuretest_within_cooldown_short_circuits— existing 24h skip still workstest_no_deps_file_is_a_clean_no_op— empty build dir runs cleanlybash lintis green.Acceptance (from #2873)
bash test --cppon Windows hits the cascade at most once per build dir, then never again (broken marker short-circuits future runs)..ninja_depsis byte-identical before and after a failed-recompact run (pinned bytest_snapshot_restored_on_recompact_failure).bash test --cppruns on the same build dir do not invokeninja -t recompact(pinned bytest_broken_marker_skips_future_runs).Out of scope
ninja_crash_dump_*.dmpfiles. With the broken-marker short-circuit, the source is capped to one cascade per build dir lifetime, so disk bleed becomes a non-issue. Can be filed as a separate follow-up if needed.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Chores
Tests