Fail LLM setup when callback port is busy - #6432
Conversation
There was a problem hiding this comment.
Pull request overview
This PR makes the OAuth/OIDC callback-port handling stricter for thv llm setup so that when a pre-registered redirect URI requires a specific callback port, the setup fails immediately (instead of silently falling back to a random port that will break provider redirect-URI matching). The strict behavior is implemented as an opt-in flag at the shared OAuth layer and enabled for the LLM token source only, preserving existing fallback behavior for other OAuth consumers (e.g., registry auth).
Changes:
- Introduces a typed
CallbackPortInUseErrorand propagates it through OAuth flow creation and LLM setup for actionable user-facing errors. - Adds
RequireExactCallbackPortplumbing frompkg/auth/tokensource→pkg/auth/oauthand enables it for LLM tokens. - Adds/extends unit tests to cover strict “port in use” failure vs. fallback behavior.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/networking/port.go | Adds CallbackPortInUseError and uses it from callback-port validation. |
| pkg/llm/tokensource.go | Enables strict callback-port behavior for LLM OIDC token source. |
| pkg/llm/setup.go | Detects callback-port conflicts and returns a remediation-focused error message. |
| pkg/llm/setup_test.go | Adds tests for callback-port-in-use failures (pre-login and during login). |
| pkg/auth/tokensource/tokensource.go | Adds RequireExactCallbackPort to OIDC params and passes it into oauth config. |
| pkg/auth/oauth/flow.go | Enforces strict callback-port behavior when requested port is busy. |
| pkg/auth/oauth/flow_test.go | Adds tests for strict failure vs. fallback when the requested callback port is occupied. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6432 +/- ##
==========================================
+ Coverage 77.81% 77.84% +0.03%
==========================================
Files 760 761 +1
Lines 73133 73204 +71
==========================================
+ Hits 56908 56987 +79
+ Misses 16220 16212 -8
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
Type of change
Test plan
task test)task test-e2e)task lint-fix)Does this introduce a user-facing change?
thv llm setupnow fails immediately when its requested OIDC callback port is occupied. The error tells users to stop the process using that port or choose another redirect URI registered with their identity provider usingthv llm setup --callback-port <port>.Special notes for reviewers
Strict callback-port behavior is opt-in at the shared OAuth layer and enabled for the LLM token source only, so existing OAuth flows that support dynamic callback ports retain their fallback behavior.