Skip to content

fix: prevent the local plugin to break the built-in openai auth plugin#22026

Open
cynicalight wants to merge 1 commit intoanomalyco:devfrom
cynicalight:fix/openai-auth-missing
Open

fix: prevent the local plugin to break the built-in openai auth plugin#22026
cynicalight wants to merge 1 commit intoanomalyco:devfrom
cynicalight:fix/openai-auth-missing

Conversation

@cynicalight
Copy link
Copy Markdown

Issue for this PR

Closes #18582

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

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:

  1. I added a regression test in packages/opencode/test/plugin/auth-override.test.ts that reproduces the bug by installing a local plugin with auth.provider = "openai". Before the fix, that test failed because the built-in ChatGPT Pro/Plus methods disappeared. After the fix, it passes and confirms the built-in OpenAI auth methods are preserved.
  2. I re-ran the nearby auth-related tests: bun test test/plugin/auth-override.test.ts, bun test test/cli/tui/sync-provider.test.tsx.
  3. final test: i test my own gpt subscription. It works with the same local config which broke the auth before.

Screenshots / recordings

NO UI CHANGE.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Copilot AI review requested due to automatic review settings April 11, 2026 11:17
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

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
}
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

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.

OpenAI Auth - ChatGPT Subscription option not available to use

2 participants