fix: prevent the local plugin to break the built-in openai auth plugin#22026
Open
cynicalight wants to merge 1 commit intoanomalyco:devfrom
Open
fix: prevent the local plugin to break the built-in openai auth plugin#22026cynicalight wants to merge 1 commit intoanomalyco:devfrom
cynicalight wants to merge 1 commit intoanomalyco:devfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a regression in provider auth resolution where an externally loaded (e.g., local) plugin declaring auth.provider = "openai" could override the built-in OpenAI (ChatGPT subscription) auth hook, causing the login flow to skip ChatGPT Pro/Plus options.
Changes:
- Adjust provider auth hook resolution to preserve the first registered OpenAI auth hook instead of allowing later plugins to overwrite it.
- Add a regression test ensuring a user plugin with
provider: "openai"cannot hide the built-in ChatGPT Pro/Plus auth methods.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/opencode/src/provider/auth.ts | Changes auth hook mapping to prevent external OpenAI auth hooks from overwriting the built-in one. |
| packages/opencode/test/plugin/auth-override.test.ts | Adds regression coverage for OpenAI auth override behavior via a local plugin. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
120
to
+131
| const plugins = yield* plugin.list() | ||
|
|
||
| const hooks: Record<ProviderID, Hook> = {} | ||
|
|
||
| for (const item of plugins) { | ||
| const auth = item.auth | ||
| if (!auth?.provider) continue | ||
|
|
||
| const id = ProviderID.make(auth.provider) | ||
| if (id === "openai" && hooks[id]) continue | ||
| hooks[id] = auth | ||
| } |
There was a problem hiding this comment.
The new hook-resolution loop no longer uses Arr or Result, but packages/opencode/src/provider/auth.ts still imports them from effect. Please remove the unused imports to avoid TS/lint failures and keep the module tidy.
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.
Issue for this PR
Closes #18582
Type of change
What does this PR do?
This PR fixes a regression where the built-in OpenAI ChatGPT subscription auth flow could be silently replaced by another openai auth plugin(many people in that issue may have different plugins installed, in my case it seems that the non-auth plugin would also break down the built-in auth method, pretty weird). That caused providers login and the TUI connect flow to skip the ChatGPT Pro/Plus options and fall straight to manual API key entry. The change updates provider auth resolution to preserve the built-in openai auth hook instead of letting later plugins overwrite it, and adds a regression test proving that external OpenAI auth hooks no longer hide the built-in ChatGPT login methods.
How did you verify your code works?
I verified it in two ways:
bun test test/plugin/auth-override.test.ts,bun test test/cli/tui/sync-provider.test.tsx.Screenshots / recordings
NO UI CHANGE.
Checklist