Skip to content

fix(ci): refresh changed sources after restoring Cargo caches - #302

Open
hyperb1iss wants to merge 5 commits into
mainfrom
nova/cache-source-freshness
Open

hyperb1iss wants to merge 5 commits into
mainfrom
nova/cache-source-freshness

Conversation

@hyperb1iss

@hyperb1iss hyperb1iss commented Sep 21, 2026

Copy link
Copy Markdown
Owner

A fallback Cargo target cache can contain artifacts newer than the current checkout. When changed files keep their checkout timestamps, Cargo can reuse an old library even though the source has changed. A native CI run hit this by compiling a new enum-variant test against stale library metadata.

Restore cached timestamps only when source content and executable mode match. Refresh changed and newly tracked inputs after extracting the target archive. Missing, malformed, or incompatible timestamp metadata refreshes the tracked sources, preserving fallback cache reuse without trusting stale fingerprints. A changed symlink inventory also invalidates source freshness.

🧪 Validation

Real Cargo fixtures reproduce the stale Fresh result and verify that restoration forces compilation. Coverage includes changed and new files, executable-mode changes, symlink targets, and missing or legacy metadata. The cache action tests also verify that unchanged inputs retain reuse.

Summary by CodeRabbit

  • Bug Fixes
    • Improved build-cache timestamp restoration for changed, newly tracked, symlinked, or executable files.
    • Invalid or missing timestamp metadata now refreshes source timestamps and correctly triggers recompilation.
    • Prevented stale build artifacts from being treated as up to date after source changes.
  • Tests
    • Added coverage for timestamp changes, new files, executable-mode updates, and malformed metadata.

hyperb1iss and others added 4 commits September 20, 2026 23:30
Fallback target archives can be newer than a fresh checkout, while the
source timestamp snapshot deliberately restores only exact source matches.
Touch changed, new, and mode-mismatched inputs after archive restoration so
Cargo cannot accept stale fingerprints without invoking rustc.

Cover the original failure with a real Cargo build that first reproduces the
false Fresh result, then proves timestamp restoration forces recompilation.

Co-Authored-By: Nova (GPT-6) <noreply@openai.com>
Refresh every tracked source when a restored cache lacks a usable timestamp
snapshot so Cargo cannot accept stale fingerprints from legacy archives.

Use a monotonic whole-second timestamp for refreshed inputs to avoid moving
submillisecond filesystem timestamps backward. Real Cargo fixtures cover
missing, malformed, and legacy metadata alongside changed sources.

Co-Authored-By: Sol (GPT-5.6) <noreply@openai.com>
Use the high-resolution epoch clock when invalidating stale Cargo artifacts.
Advance an already newer source by one microsecond instead of a whole second
so the rebuild output immediately becomes newer and remains reusable.

Cover the rebuild boundary by requiring the next Cargo invocation to report
the fixture as Fresh without another compilation.

Co-Authored-By: Sol (GPT-5.6) <noreply@openai.com>
Validate the full source and symlink snapshot structure before traversal.
Valid JSON primitives and malformed entries now follow the safe cache
invalidation path instead of throwing after target restoration.

Exercise null and malformed-entry snapshots with real Cargo rebuild and
immediate-reuse checks.

Co-Authored-By: Sol (GPT-5.6) <noreply@openai.com>
@coderabbitai

coderabbitai Bot commented Sep 21, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

Understand this PR’s impact

Explore downstream dependencies and potential security impact with Blast Radius.

View blast radius →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 072f4879-564b-4337-8fb6-78a083e21c66

📥 Commits

Reviewing files that changed from the base of the PR and between 80db5e1 and 4823482.

📒 Files selected for processing (2)
  • .github/actions/rust-build-cache/source-mtimes.mjs
  • .github/actions/rust-build-cache/source-mtimes.test.mjs

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Source timestamp restoration now validates snapshot metadata and refreshes tracked source timestamps when metadata or file state is invalid. Unchanged files retain recorded timestamps. Tests cover changed, new, mode-changed, and malformed-source states.

Changes

Source timestamp restoration

Layer / File(s) Summary
Snapshot validation and refresh timing
.github/actions/rust-build-cache/source-mtimes.mjs
Snapshot validation now checks version, root counts, source entries, and symlink entries. Timestamp refreshes use high-resolution wall-clock and current-mtime values.
Current source restoration and coverage
.github/actions/rust-build-cache/source-mtimes.mjs, .github/actions/rust-build-cache/source-mtimes.test.mjs
Restoration refreshes missing, changed, hash-mismatched, executable-bit-changed, or newly tracked files. Tests cover timestamp advancement and invalid snapshot metadata.

Priority: ⬇️ Low

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

Change: Bug fix

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. 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 clearly and concisely describes the main CI change: refreshing changed sources after restoring Cargo caches.
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

Use a submillisecond offset for the timestamp precision case. The file
API accepts seconds, so the previous literal advanced almost a second.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant