Skip to content

fix: look up the current lockfile's store before the fallback - #107

Open
zkochan wants to merge 1 commit into
mainfrom
restore-lockfile-store-first
Open

zkochan wants to merge 1 commit into
mainfrom
restore-lockfile-store-first

Conversation

@zkochan

@zkochan zkochan commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Closes #102.

Problem

The store cache was restored with a single restoreCache call that passed both the lockfile prefix and the lockfile-agnostic fallback prefix. GitHub tries every key in the current scope before it moves on to the default branch. So an older store under the fallback prefix in the pull request's own scope (or its base branch) was restored in preference to an entry for the current lockfile on the default branch. The job then installed the difference and uploaded a duplicate entry.

Fix

Restore in two lookups: first with only the lockfile prefix, which searches every accessible scope for the current lockfile, then, only on a miss, with the fallback prefix. The extra request happens only when no entry exists for the lockfile.

getRestoreKeys had no other caller, so it is removed along with its unit test.

Tests

  • The restore test now expects two separate lookups on a miss, and a new test checks that a lockfile hit skips the fallback lookup.
  • The cache-hit tests mock restoreCache with prefix matching, so the "different lockfile" case is served by the fallback lookup rather than by the first one.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Cache restoration now checks for a cache matching the current lockfile before trying a broader runtime cache. When the lockfile-specific cache is found, the broader lookup is skipped; if it is not found, restoration falls back to the runtime-wide cache. This makes cache selection follow a clearer priority order.

The store cache was restored with one lookup that passed both the
lockfile prefix and the lockfile-agnostic fallback prefix. GitHub tries
every key in the current scope before the default branch's, so an older
store in a pull request's scope was restored instead of an entry for the
current lockfile on the default branch.

Look up the lockfile prefix on its own first, and the fallback prefix
only on a miss.

Closes #102

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The cache restore flow now looks up the lockfile-specific prefix first. If that lookup returns no key, it tries the broader runtime prefix. The getRestoreKeys helper and its test are removed, and the restore tests cover the new lookup order.

Changes: Cache restore lookup order

Layer / File(s) Summary
Implement and validate sequential cache lookups
src/cache-restore/run.ts, src/cache-restore/run.test.mjs, src/cache-restore/keys.ts, src/cache-restore/keys.test.mjs
runRestoreStoreCache first looks up the lockfile prefix and tries the runtime prefix only if the first lookup misses. Tests check both the fallback behavior and that a first-lookup hit skips the second lookup. The getRestoreKeys helper and its test are removed.

Estimated code review effort: 2 (Simple) | ~8 minutes

Severity of issue fixed: Medium

Possibly related issues

  • pnpm/setup#103 — The change does not add project scoping to the broader fallback prefix or add the requested cache-path or cache-prefix input.

Suggested reviewers: poulet42, ehaby

Merge Risk: Minimal · up to ba737

The cache restore now prefers an exact current-lockfile store before falling back to a broader entry, which fixes stale fallback entries taking precedence. The change is small and localized, with no identified merge-blocking risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main behavior change: the restore step now looks up the current lockfile's cache before the fallback. The raw summary confirms that run.ts now performs a lockfile-prefix lookup fir…
Linked Issues check Passed [#102] Requirement: restore the exact current-lockfile entry from any accessible scope before the lockfile-agnostic fallback, and run the fallback only on a miss. The PR replaces the single combined `…
Out of Scope Changes check Passed All changed files relate to the #102 fix. src/cache-restore/run.ts implements the two-lookup order. src/cache-restore/keys.ts removes getRestoreKeys, which only built the old combined restore ke…
Full details: Title check

Explanation

The title names the main behavior change: the restore step now looks up the current lockfile's cache before the fallback. The raw summary confirms that run.ts now performs a lockfile-prefix lookup first and a keyPrefix lookup only on a miss, and that getRestoreKeys was removed. The title follows the conventional commit style and matches the linked issue's request.

Full details: Linked Issues check

Explanation

[#102] Requirement: restore the exact current-lockfile entry from any accessible scope before the lockfile-agnostic fallback, and run the fallback only on a miss. The PR replaces the single combined restoreCache call in runRestoreStoreCache (src/cache-restore/run.ts) with two sequential lookups. The first lookup uses lockfileKeyPrefix. The second lookup uses keyPrefix and runs only when the first returns no key. Per the PR summary, the test file covers a miss (two lookups) and a lockfile hit (fallback skipped). The removed getRestoreKeys had no other caller, so the old combined key order no longer exists in source. No coding requirement in #102 is unmet in the reviewed source. The ignored file dist/index.js was not inspected. It is a generated bundle and was excluded by the !**/dist/** rule. This does not affect the source-level verdict, but the shipped action behavior depends on a rebuilt bundle that was not verified.

Full details: Out of Scope Changes check

Explanation

All changed files relate to the #102 fix. src/cache-restore/run.ts implements the two-lookup order. src/cache-restore/keys.ts removes getRestoreKeys, which only built the old combined restore key list. Its unit test is removed in src/cache-restore/keys.test.mjs, which matches the removal. src/cache-restore/run.test.mjs updates the restore tests for two lookups and updates the fallback mock to use prefix matching, which supports the new behavior. The change set contains no unrelated functional changes. The removed exported function is an API removal, but the PR description states it had no other caller, and the PR summary reports no other reference in the reviewed source.

Finishing Touches

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

A rabbit checks the lockfile key,
Then tries the wider cache if free.
One lookup lands; the next can wait,
Or fallback finds a matching state.
Hop, hop—the tests confirm the rate.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8abb6dc6-930e-41ef-a561-d339f49b723e
Commits

Reviewing files that changed from the base of the PR and between 4a44b91 and ba737fe.

Files ignored due to path filters: 1

  • dist/index.js is excluded by !**/dist/**
Files selected for processing: 4

  • src/cache-restore/keys.test.mjs
  • src/cache-restore/keys.ts
  • src/cache-restore/run.test.mjs
  • src/cache-restore/run.ts
Files with no reviewable changes: 1

  • src/cache-restore/keys.ts

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

Recent review details

Context from checks skipped due to timeout: 2

  • GitHub Check: CodeRabbit
  • GitHub Check: Greptile Review
Additional comments: 3

src/cache-restore/run.ts: 1

16-16: LGTM!

Also applies to: 71-76

src/cache-restore/run.test.mjs: 1

104-119: LGTM!

Also applies to: 127-127

src/cache-restore/keys.test.mjs: 1

4-4: LGTM!

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Restore the current lockfile’s store before trying the fallback

🐞 Bug fix 🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Search all accessible cache scopes for the current lockfile before trying a broader store
 fallback.
• Avoid restoring an older pull-request store when a matching default-branch store exists.
• Test both lookup paths and remove the unused combined-key helper.
Diagram

graph TD
  A["Store restore"] --> B["Lockfile lookup"] --> C{"Entry found?"}
  C -- "No" --> D["Runtime fallback"] --> E["Restore result"] --> F["Cache hit status"]
  C -- "Yes" --> E
Loading
High-Level Assessment

Keep the two sequential lookups. A single request with both prefixes cannot prioritize a default-branch lockfile match over a fallback in the current scope; the second request is incurred only on a lockfile miss.

Files changed (4) +22 / -19

Bug fix (1) +7 / -3
run.tsPrioritize the lockfile lookup across cache scopes +7/-3

Prioritize the lockfile lookup across cache scopes

• Restores with only the current lockfile prefix first, then searches the broader runtime prefix on a miss. This prevents a current-scope fallback from outranking a matching store on the default branch.

src/cache-restore/run.ts

Refactor (1) +0 / -4
keys.tsRemove the unused combined restore-key helper +0/-4

Remove the unused combined restore-key helper

• Deletes getRestoreKeys now that the two prefixes are passed in separate cache lookups.

src/cache-restore/keys.ts

Tests (2) +15 / -12
keys.test.mjsRemove the obsolete restore-key helper test +1/-8

Remove the obsolete restore-key helper test

• Removes the test for combining lockfile and fallback prefixes, which no longer reflects the restore strategy.

src/cache-restore/keys.test.mjs

run.test.mjsCover sequential cache lookups and fallback behavior +14/-4

Cover sequential cache lookups and fallback behavior

• Asserts that a miss makes separate lockfile and runtime lookups, while a lockfile hit skips fallback. Prefix-aware mocks keep cache-hit cases aligned with the lookup that can return each key.

src/cache-restore/run.test.mjs

@greptile-apps

greptile-apps Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Reviews (1) · Last reviewed commit: "fix: look up the current lockfile's stor..." · Reviewed by Greptile

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.

A stale store in the pull request's cache scope is restored instead of an exact lockfile match on the default branch

1 participant