Skip to content

fix: optimize login scope deduplication#235

Open
michiosw wants to merge 1 commit into
mainfrom
fix/optimize-login-scope-deduplication
Open

fix: optimize login scope deduplication#235
michiosw wants to merge 1 commit into
mainfrom
fix/optimize-login-scope-deduplication

Conversation

@michiosw
Copy link
Copy Markdown
Contributor

Summary

  • explain the user-facing change
  • link the issue or context if relevant

Verification

  • go test ./...
  • go test -race ./...
  • go vet ./...
  • buf generate if protobuf or generated code changed

Release notes

  • conventional commit title matches semver intent

Summary
This optimizes login scope resolution by deduplicating scopes in one pass.

Before this, resolveLoginScopes in internal/auth/oidc.go rescanned the growing resolved slice for every requested scope, which made repeated custom scopes cost more work and made the merge path harder to reason about.

Now one seen-map tracks both base scopes and custom scopes as the canonical path.

Why
This gives kontext-cli a cheaper runtime path for OIDC login scope assembly:

custom scope input
-> resolveLoginScopes
-> deduplicated scope list in stable order

This PR does not broaden behavior beyond the optimization scope.

What changed
Optimized resolveLoginScopes in internal/auth/oidc.go
Removed repeated linear scans during custom scope deduplication
Preserved default scope selection and custom scope order
Updated tests for repeated custom scopes and default-scope overlap

Verification
go test ./internal/auth -count=1
go test ./internal/guard/judge -count=1
go test ./internal/guard/judge -count=5
go test ./... -count=1 -p 1
go vet ./...
git diff --check

Notes
The required go test ./... -count=1 run still fails on fresh main in internal/guard/judge with two llama-server startup timing tests under package-parallel load. The auth change does not touch that package, and the judge package passes when rerun directly and when the suite is serialized with -p 1.
Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 30, 2026

Greptile Summary

This PR optimizes login scope resolution while keeping the same OAuth scope order. The main changes are:

  • Replaces repeated scope scans with a seen map in resolveLoginScopes.
  • Deduplicates repeated custom scopes while preserving first occurrence order.
  • Removes the old hasScope helper.
  • Adds a test for repeated custom scope deduplication.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Reviews (1): Last reviewed commit: "fix: optimize login scope deduplication" | Re-trigger 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.

1 participant