Refactor current-repository lookup caches to shared syncutil.OnceLoader#33180
Merged
Conversation
4 tasks
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor shared singleflight cache for current-repository lookups
Refactor current-repository lookup caches to shared May 19, 2026
syncutil.OnceLoader
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the duplicated mutex-guarded one-shot caches for current-repository lookup in pkg/cli and pkg/workflow into a shared generic syncutil.OnceLoader[T] primitive, eliminating drift risk between the two call sites.
Changes:
- Introduce
pkg/syncutil/onceloader.gowith a genericOnceLoader[T]providingGet(loader)andReset(), plus accompanying unit tests covering success/error caching, concurrency, and reset. - Replace the bespoke
repoSlugCacheState/currentRepositoryCacheStatestructs inpkg/cli/repo.goandpkg/workflow/repository_features_validation.gowithsyncutil.OnceLoader[string], and simplify the test helperClearCurrentRepoSlugCacheto callReset(). - Unrelated edit in
.github/workflows/mcp-inspector.lock.ymlrenamingDD_APP_KEYtoDD_APPLICATION_KEYin one inspector config block.
Show a summary per file
| File | Description |
|---|---|
| pkg/syncutil/onceloader.go | New generic one-shot loader with mutex-based caching and reset support. |
| pkg/syncutil/onceloader_test.go | Tests for cached success/error, concurrent single invocation, and reset semantics. |
| pkg/cli/repo.go | Migrates current repo slug cache to syncutil.OnceLoader[string]. |
| pkg/cli/repo_test_helpers_test.go | Resets cache via OnceLoader.Reset() instead of touching internal fields. |
| pkg/workflow/repository_features_validation.go | Migrates current repository cache to syncutil.OnceLoader[string]. |
| .github/workflows/mcp-inspector.lock.yml | Unrelated rename of DD_APP_KEY to DD_APPLICATION_KEY in one config entry. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 6/6 changed files
- Comments generated: 1
| "headers": { | ||
| "DD_API_KEY": "\${DD_API_KEY}", | ||
| "DD_APPLICATION_KEY": "\${DD_APP_KEY}", | ||
| "DD_APPLICATION_KEY": "\${DD_APPLICATION_KEY}", |
Collaborator
|
@copilot review all comments |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Contributor
Author
Reviewed the comments and addressed the actionable feedback. I reverted the unrelated |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pkg/cliandpkg/workfloweach maintained an identical mutex-guarded one-shot cache for current-repository resolution. This duplicated synchronization logic across production paths and risked behavioral drift as either side evolves.Shared cache primitive
pkg/syncutil/onceloader.gowith genericOnceLoader[T]:Get(loader func() (T, error))for one-shot cached loadReset()for safe test/cache reset without exposing internal stateCall-site consolidation
repoSlugCacheStateinpkg/cli/repo.gowithsyncutil.OnceLoader[string].currentRepositoryCacheStateinpkg/workflow/repository_features_validation.gowithsyncutil.OnceLoader[string].OnceLoader.Get(...).Test/helper alignment
pkg/cli/repo_test_helpers_test.goto reset cache throughOnceLoader.Reset().pkg/syncutil/onceloader_test.gocovering success/error caching, repeated calls, and concurrent single invocation.