Repository navigation
pkg/llm: implement OIDC token source and thv llm token command - #5033
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5033 +/- ##
==========================================
+ Coverage 69.75% 69.77% +0.01%
==========================================
Files 557 558 +1
Lines 56254 56425 +171
==========================================
+ Hits 39239 39368 +129
- Misses 13996 14032 +36
- Partials 3019 3025 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Implements OIDC token lifecycle management for the LLM gateway and wires it into the thv llm token CLI helper so external tools can fetch a fresh access token non-interactively.
Changes:
- Added
pkg/llm.TokenSourceimplementing a three-tier strategy (in-memory → secrets-backed refresh token → interactive browser flow). - Added unit tests for key derivation, scope handling, and non-interactive error behavior.
- Implemented
thv llm tokento print a fresh JWT to stdout while keeping diagnostics on stderr.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
pkg/llm/tokensource.go |
New LLM gateway token source with tiered token acquisition + persistence hooks. |
pkg/llm/tokensource_test.go |
New unit tests covering core helper functions and non-interactive behavior. |
cmd/thv/app/llm.go |
Implements the thv llm token command execution path using the new token source. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Implements the LLM gateway OIDC token lifecycle needed for thv llm by adding a three-tier token source (in-memory → cached refresh token → interactive browser flow) and wiring up thv llm token to emit a fresh access token for external tools.
Changes:
- Added
pkg/llm.TokenSourcewith deterministic refresh-token secret keys, refresh-token persistence, and a 30s preemptive refresh window. - Implemented
thv llm tokenas a non-interactive command that prints only the JWT to stdout. - Added unit tests covering key derivation, scope handling, cache-restore behavior, and preemptive refresh behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
pkg/llm/tokensource.go |
New three-tier OIDC TokenSource with refresh-token persistence and preemptive refresh behavior. |
pkg/llm/tokensource_test.go |
Unit tests validating TokenSource helpers, cache restore paths, and refresh-window logic. |
cmd/thv/app/llm.go |
Implements thv llm token to fetch a fresh token non-interactively and print it to stdout. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
3091f94 to
5edaa27
Compare
There was a problem hiding this comment.
Pull request overview
Implements an OIDC-based token lifecycle for the LLM gateway along with a non-interactive thv llm token CLI helper that prints a usable access token to stdout for integration with external AI tools.
Changes:
- Added
pkg/llm.TokenSourceimplementing a 3-tier strategy (in-memory → refresh token via secrets provider → interactive browser OIDC+PKCE flow) with a 30s preemptive refresh window. - Added unit tests covering secret-key derivation, cache-miss vs backend-error behavior, persisting refresh tokens, and preemptive refresh behavior.
- Implemented
thv llm tokento print a fresh JWT to stdout (diagnostics to stderr) and persist refresh-token references back into config.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/llm/tokensource.go | New LLM gateway OIDC token source with cache restore + persistence + preemptive refresh behavior. |
| pkg/llm/tokensource_test.go | Unit test coverage for key token-source behaviors and edge cases. |
| cmd/thv/app/llm.go | Implements thv llm token command to emit a valid access token and persist token references. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Adds a three-tier TokenSource (in-memory → cached refresh token → browser OIDC+PKCE flow) for the LLM gateway. Access tokens are held in memory only; refresh tokens are persisted via ScopeLLM secrets. A 30 s preemptive refresh window avoids gateway rejections on expiry. thv llm token is now fully implemented: non-interactive, prints a fresh JWT to stdout with all other output on stderr, suitable for use as apiKeyHelper or auth.command in Claude Code / Cursor. Part of #5028 Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
5edaa27 to
3c7f67a
Compare
There was a problem hiding this comment.
Pull request overview
Implements OIDC token lifecycle support for the LLM gateway, including a three-tier token acquisition strategy and a non-interactive thv llm token helper intended for integration with external AI tools.
Changes:
- Added
pkg/llm.TokenSourceimplementing in-memory → cached refresh token → (interactive) browser OIDC+PKCE fallback with a 30s preemptive refresh window. - Added unit tests covering key behaviors of secret-key derivation, scope normalization, cache restore behavior, and preemptive expiry shifting.
- Implemented
thv llm tokencommand to print a fresh access token to stdout and persist refresh-token references back into config.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| pkg/llm/tokensource.go | New OIDC token source with caching, refresh-token persistence, and preemptive refresh handling for LLM gateway auth. |
| pkg/llm/tokensource_test.go | New unit tests for token source helpers and cache restore/persist behavior. |
| cmd/thv/app/llm.go | Implements thv llm token using the new token source (non-interactive; stdout token, stderr diagnostics). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
3c7f67a to
e38ffa2
Compare
There was a problem hiding this comment.
Large PR Detected
This PR exceeds 1000 lines of changes and requires justification before it can be reviewed.
How to unblock this PR:
Add a section to your PR description with the following format:
## Large PR Justification
[Explain why this PR must be large, such as:]
- Generated code that cannot be split
- Large refactoring that must be atomic
- Multiple related changes that would break if separated
- Migration or data transformationAlternative:
Consider splitting this PR into smaller, focused changes (< 1000 lines each) for easier review and reduced risk.
See our Contributing Guidelines for more details.
This review will be automatically dismissed once you add the justification section.
Large PR justification has been provided. Thank you!
|
✅ Large PR justification has been provided. The size review has been dismissed and this PR can now proceed with normal review. |
e38ffa2 to
1ef77f8
Compare
There was a problem hiding this comment.
Pull request overview
Implements an OIDC-based token acquisition flow for the LLM gateway, plus a thv llm token CLI command intended to emit a fresh JWT for external tool integration.
Changes:
- Added
pkg/llm.TokenSourceimplementing a multi-tier token retrieval strategy with preemptive refresh behavior. - Implemented
thv llm tokento print an access token to stdout while keeping diagnostics on stderr. - Added unit tests covering key token-source behaviors (cache restore, refresh window logic, persistence callbacks).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/llm/tokensource.go | New LLM TokenSource with OIDC refresh, persistence, and preemptive refresh behavior. |
| pkg/llm/tokensource_test.go | New unit tests for the LLM TokenSource behavior. |
| cmd/thv/app/llm.go | Implements thv llm token command using the new token source. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
1ef77f8 to
cb2ae1f
Compare
aponcedeleonch
left a comment
There was a problem hiding this comment.
Three inline comments on the new token source: one architectural (the bulk of this file duplicates pkg/registry/auth/oauth_token_source.go), and two concrete correctness issues (withPreemptiveRefresh composition, and the _AT cache not being invalidated on refresh-token rotation). Happy to pair on the shared extraction if that's the direction.
Summary
Adds a three-tier TokenSource (in-memory → cached refresh token → browser OIDC+PKCE flow) for the LLM gateway. Access tokens are held in memory only; refresh tokens are persisted via ScopeLLM secrets. A 30 s preemptive refresh window avoids gateway rejections on expiry.
thv llm token is now fully implemented: non-interactive, prints a fresh JWT to stdout with all other output on stderr, suitable for use as apiKeyHelper or auth.command in Claude Code / Cursor.
Fixes #5028
Type of change
Test plan
task test)task test-e2e)task lint-fix)API Compatibility
v1beta1API, OR theapi-break-allowedlabel is applied and the migration guidance is described above.Changes
Does this introduce a user-facing change?
Implementation plan
Approved implementation plan
Special notes for reviewers
Large PR Justification
This is an isolated PR that covers a single functionality. Cannot be split.