Skip to content

Refactor current-repository lookup caches to shared syncutil.OnceLoader#33180

Merged
pelikhan merged 4 commits into
mainfrom
copilot/refactor-singleflight-cache
May 19, 2026
Merged

Refactor current-repository lookup caches to shared syncutil.OnceLoader#33180
pelikhan merged 4 commits into
mainfrom
copilot/refactor-singleflight-cache

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 19, 2026

pkg/cli and pkg/workflow each 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

    • Added pkg/syncutil/onceloader.go with generic OnceLoader[T]:
      • Get(loader func() (T, error)) for one-shot cached load
      • Reset() for safe test/cache reset without exposing internal state
  • Call-site consolidation

    • Replaced repoSlugCacheState in pkg/cli/repo.go with syncutil.OnceLoader[string].
    • Replaced currentRepositoryCacheState in pkg/workflow/repository_features_validation.go with syncutil.OnceLoader[string].
    • Updated both call paths to delegate loading via OnceLoader.Get(...).
  • Test/helper alignment

    • Updated pkg/cli/repo_test_helpers_test.go to reset cache through OnceLoader.Reset().
    • Added pkg/syncutil/onceloader_test.go covering success/error caching, repeated calls, and concurrent single invocation.
var currentRepoSlugCache syncutil.OnceLoader[string]

func GetCurrentRepoSlug() (string, error) {
	return currentRepoSlugCache.Get(getCurrentRepoSlugUncached)
}

Copilot AI and others added 2 commits May 19, 2026 00:54
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 syncutil.OnceLoader May 19, 2026
Copilot AI requested a review from pelikhan May 19, 2026 01:01
@github-actions github-actions Bot mentioned this pull request May 19, 2026
@pelikhan pelikhan marked this pull request as ready for review May 19, 2026 02:14
Copilot AI review requested due to automatic review settings May 19, 2026 02:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.go with a generic OnceLoader[T] providing Get(loader) and Reset(), plus accompanying unit tests covering success/error caching, concurrency, and reset.
  • Replace the bespoke repoSlugCacheState / currentRepositoryCacheState structs in pkg/cli/repo.go and pkg/workflow/repository_features_validation.go with syncutil.OnceLoader[string], and simplify the test helper ClearCurrentRepoSlugCache to call Reset().
  • Unrelated edit in .github/workflows/mcp-inspector.lock.yml renaming DD_APP_KEY to DD_APPLICATION_KEY in 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}",
@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot review all comments

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 19, 2026

@copilot review all comments

Reviewed the comments and addressed the actionable feedback. I reverted the unrelated .github/workflows/mcp-inspector.lock.yml change in commit 3371d8d.

@pelikhan pelikhan merged commit 4189e91 into main May 19, 2026
@pelikhan pelikhan deleted the copilot/refactor-singleflight-cache branch May 19, 2026 02:49
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.

Refactor: extract shared singleflight cache for current-repository lookups

3 participants