Skip to content

BUILD-10779: Always restore from cache key with fallback-to-default-branch#49

Merged
bwalsh434 merged 1 commit intomasterfrom
BUILD-10779-fix-restore-keys-bug-with-default-fallback
Mar 23, 2026
Merged

BUILD-10779: Always restore from cache key with fallback-to-default-branch#49
bwalsh434 merged 1 commit intomasterfrom
BUILD-10779-fix-restore-keys-bug-with-default-fallback

Conversation

@bwalsh434
Copy link
Copy Markdown
Contributor

@bwalsh434 bwalsh434 commented Mar 23, 2026

What Changed?

Prioritizes the cache keys in order of:

  • direct hit with the specific branch as first attempt
  • cache key from fallback branch if set OR cache key from default branch if fallback-to-default-branch: 'true'
  • restore key from specific branch
  • restore key from fallback branch if set OR restore key from default branch if fallback-to-default-branch: 'true'

Also changes:

  • The go module test case ("Cache Go modules with fallback branch") for testing the priority above in a case where we set both the fallback-branch and fallback-to-default-branch: 'true'
  • The README to reflect that the default value of fallback-to-default-branch is 'false'

Test Plan

  • ✅ Test that the ordering above is what is actually used with the newly modified "Cache Go modules with fallback branch" test, which explicitly sets both the fallback-branch and fallback-to-default-branch: true

@bwalsh434 bwalsh434 marked this pull request as ready for review March 23, 2026 14:14
@bwalsh434 bwalsh434 requested a review from a team as a code owner March 23, 2026 14:14
@sonar-review-alpha
Copy link
Copy Markdown

sonar-review-alpha bot commented Mar 23, 2026

Summary

This PR restructures cache key lookup priority to prioritize exact-match fallbacks over prefix-based restore keys. The key change: when fallback-to-default-branch: true or a fallback-branch is configured, the action now tries an exact-match key on the fallback branch before falling back to prefix-based restore keys on any branch. This fixes a scenario where a feature branch could inadvertently use a stale prefix-match from its own branch instead of a fresh exact-match from the default branch.

The default value of fallback-to-default-branch is also changed from true to false, requiring explicit opt-in to default branch fallback behavior.

What reviewers should know

Code changes to review:

  • scripts/prepare-keys.sh: The key logic reorganization. Look for where FALLBACK_EXACT_KEY is injected first, then branch-specific keys, then fallback keys—this ordering is now explicit in the code rather than incidental.
  • README.md cache search order: The numbered list (items 1-4) documents the new priority. Compare against the old version to understand what shifted.
  • Test workflow: The test now explicitly enables both fallback-branch and fallback-to-default-branch, making it a good validation that both work together correctly.

Gotchas:

  • The default value flip (fallback-to-default-branch: false) is a breaking change. Workflows that relied on implicit fallback to default branch must now opt in explicitly.
  • The test uses github.run_id as the cache key, so it will never hit the cache—this is intentional, allowing the test to verify the key search order without cache interactions.

  • Generate Walkthrough
  • Generate Diagram

🗣️ Give feedback

Copy link
Copy Markdown

@sonar-review-alpha sonar-review-alpha bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conclusion: Clean, minimal fix. The logic is correct in both the INPUT_RESTORE_KEYS-provided and not-provided paths, and the new line 84 handles the empty/non-empty RESTORE_KEYS transition correctly via ${RESTORE_KEYS:+${RESTORE_KEYS}$'\n'} — no leading newline when RESTORE_KEYS is empty, proper separator when it isn't.

🗣️ Give feedback

@bwalsh434 bwalsh434 force-pushed the BUILD-10779-fix-restore-keys-bug-with-default-fallback branch from 716a5a1 to 40957f6 Compare March 23, 2026 18:46
Copy link
Copy Markdown

@sonar-review-alpha sonar-review-alpha bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conclusion: Clean, well-reasoned fix. One duplication worth addressing before merge.

🗣️ Give feedback

Copy link
Copy Markdown

@sonar-review-alpha sonar-review-alpha bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conclusion: The new commit only updates the test workflow; the logic duplication in scripts/prepare-keys.sh flagged in the previous review is still present.

🗣️ Give feedback

@bwalsh434 bwalsh434 force-pushed the BUILD-10779-fix-restore-keys-bug-with-default-fallback branch from c050dab to 1fb4755 Compare March 23, 2026 19:00
Copy link
Copy Markdown

@sonar-review-alpha sonar-review-alpha bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous logic duplication issue in scripts/prepare-keys.sh has not been fixed — the two INPUT_RESTORE_KEYS loops with inconsistent append idioms remain as flagged.

🗣️ Give feedback

@bwalsh434 bwalsh434 force-pushed the BUILD-10779-fix-restore-keys-bug-with-default-fallback branch from 1fb4755 to c0f07df Compare March 23, 2026 19:06
Copy link
Copy Markdown

@sonar-review-alpha sonar-review-alpha bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conclusion: The new commit only adjusts README line wrapping — the logic duplication in scripts/prepare-keys.sh flagged in the previous review remains unfixed.

🗣️ Give feedback

@bwalsh434 bwalsh434 force-pushed the BUILD-10779-fix-restore-keys-bug-with-default-fallback branch from c0f07df to a03bf74 Compare March 23, 2026 19:13
Copy link
Copy Markdown

@sonar-review-alpha sonar-review-alpha bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! ✅

🗣️ Give feedback

Copy link
Copy Markdown

@sonar-review-alpha sonar-review-alpha bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! ✅

🗣️ Give feedback

@bwalsh434 bwalsh434 force-pushed the BUILD-10779-fix-restore-keys-bug-with-default-fallback branch from a5fe6ff to 7889953 Compare March 23, 2026 19:41
@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

@sonar-review-alpha sonar-review-alpha bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! ✅

🗣️ Give feedback

@sonarqube-cloud-us
Copy link
Copy Markdown

@bwalsh434 bwalsh434 merged commit e1bd24c into master Mar 23, 2026
14 checks passed
@bwalsh434 bwalsh434 deleted the BUILD-10779-fix-restore-keys-bug-with-default-fallback branch March 23, 2026 21:05
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.

2 participants