Fix pinned ref cache miss to avoid policy refetch#3431
Conversation
URL pinning mutates p.Url after the first GetPolicy call (e.g. github.com/org/repo -> git::github.com/org/repo?ref=abc123), causing subsequent cache lookups to miss and re-download into a second directory. OPA then sees duplicate packages and errors out. Fix by also storing the cached download function under the pinned URL. I noticed this problem when testing the new http service with a git url in the policy.yaml. Ref: https://redhat.atlassian.net/browse/EC-2017 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe changes synchronize ChangesPolicy cache consistency
Startup version logging
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant GetPolicy
participant Downloader
participant DownloadCache
GetPolicy->>Downloader: Pin and download policy
Downloader-->>GetPolicy: Return pinned URL and destination
GetPolicy->>DownloadCache: Copy entry to pinned URL
GetPolicy->>DownloadCache: Reuse cached destination
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
PR Summary by QodoFix pinned URL cache miss by aliasing download cache entries
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
|
🤖 Finished Review · ✅ Success · Started 8:54 PM UTC · Completed 9:05 PM UTC |
Code Review by Qodo
Context used✅ Compliance rules (platform):
27 rules 1.
|
ReviewFindingsLow
Labels: PR fixes a cache consistency bug in Go policy source code |
Codecov Report❌ Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Add sync.RWMutex to PolicyUrl and a url() helper so all reads/writes of the Url field are synchronized. The pinOnce.Do write raced with unsynchronized reads from concurrent HTTP requests sharing the same evaluator. Suggested by Qodo in review. Ref: https://redhat.atlassian.net/browse/EC-2017 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace inline `downloadCache = sync.Map{}` with
ClearDownloadCache() across all tests for consistency and more
thorough cleanup (also resets symlinkMutexes).
Suggested by fullsend-ai-review in PR review.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
🤖 Finished Review · ❌ Failure · Started 9:16 PM UTC · Completed 9:50 PM UTC |
URL pinning mutates p.Url after the first GetPolicy call (e.g. github.com/org/repo -> git::github.com/org/repo?ref=abc123), causing subsequent cache lookups to miss and re-download into a second directory. OPA then sees duplicate packages and errors out. Fix by also storing the cached download function under the pinned URL.
I noticed this problem when testing the new http service with a git url in the policy.yaml.
Ref: https://redhat.atlassian.net/browse/EC-2017