GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(core): register a new ChatGPT client when adding an account by rekram1-node · Pull Request #64945 · anomalyco/opencode

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Nov 19, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Closes #56298

Adding a second ChatGPT account while one was connected failed on OpenAI's page with 3p_login_workspace_scope_denied (#56298). Each issued ChatGPT client belongs to one account and workspace, and "Sign in with ChatGPT" always reused the active connection's client, including from Add account.

Sign in with ChatGPT (incl. Add account)
- active connection's client, always
+ active connection expired (refresh got invalid_grant) → reuse its client, with login_hint (its email)
+ otherwise → client_id=dynamic_agent_client (register a new client)
                          before        after
add a second account B    error         new client for B
A expired, Add, remove A  reuses A      reuses A
A working, Add as A       reuses A      new client (same as any other add)
  • When a refresh gets invalid_grant (the "Connect again" case), I record that client as expired in plugin storage. A successful sign-in with that client clears it.
  • The account's email (from the verified ID token) now lives in the credential's metadata. It's only sent as login_hint when reconnecting that connection, and logout deletes it with the credential. I don't store or send the ID token itself.
  • Signing in after removing every ChatGPT account still registers a new client, same as today. Choosing the client has to happen before the user picks an account, and with nothing connected there's no way to tell "same account again" from "a different one" without asking.

No UI or public API change. It's only packages/core/src/plugin/provider/chatgpt.ts and its test.

Verification

  • bun test test/plugin/provider-chatgpt.test.ts in packages/core: 27 pass. The reauthorization test now checks that a working connection registers fresh (no hints) and an expired one reuses its client with login_hint.
  • bun typecheck and bun run typecheck:tsc in packages/core: pass.
  • Not covered by a test: recording the expired client from a real refresh, since the token URL isn't injectable through the method. Not tried live with two ChatGPT accounts.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
opencodejr[bot]
opencodejr Bot reviewed Nov 19, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I couldn't verify this live because it needs a real ChatGPT account. I read through the code and ran bun test test/plugin/provider-chatgpt.test.ts in packages/core: 26 pass. I couldn't run the type check here because of a sandbox problem. The approach matches the guide and looks sound to me: profiles kept per issued client, a separate method that registers fresh, and the last client seeded from existing connections.

Public API: unchanged. The new OAuth method ID chatgpt-token-sharing-new shows up in the openai integration's method list. Credentials are still saved as chatgpt-token-sharing, so nothing that checks the method ID needs to change.

Concerns:

  • The saved id_token_hint is never refreshed (inline). If OpenAI rejects an expired hint, every sign-in after logout fails and nothing falls back. Please check this live before merging.
  • In the flow from #56298 ("Add account → Sign in with ChatGPT" while connected as account A), the default method still reuses A's client and now also sends A's hints. Signing in as B still fails on OpenAI's page with 3p_login_workspace_scope_denied, not with the new "Use a different ChatGPT account" message. That issue now has a way around it but isn't fixed by its own steps. Consider having "Add account" use the new-account method, or at least point to it.

Related: #56298

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/core/src/plugin/provider/chatgpt.ts Outdated
...(savedID ? {} : { agent_name_hint: agentName }),
ext_agent_host_id: hostID,
// Preselect this connection's account on reauthorization.
...(profile ? { id_token_hint: profile.idToken } : {}),

@opencodejr opencodejr Bot Nov 19, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

profile.idToken is only written at sign-in. Refreshes don't update it, so after logout this hint is usually long past its exp. OIDC says an OP should accept an expired id_token_hint, but some reject it with an error. If OpenAI does, sign-in after logout fails on every attempt and nothing falls back. Since this hasn't been tried live, please check it with a token older than an hour. If it's rejected, you could send only login_hint once the token has expired, or retry without the hints.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@rekram1-node rekram1-node Nov 23, 2026

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

OpenAI's token-sharing guide covers this: "The hint may be expired; it identifies the account, not a valid authenticated session." So sending the saved ID token after logout is what they intend. Leaving it as is.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

opencodejr[bot] reacted with eyes emoji
All reactions
  • 👀 1 reaction

@opencodejr opencodejr Bot Nov 23, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Agreed. If OpenAI's guide says an expired hint is accepted because it only identifies the account, then sending the ID token saved at sign-in is the intended use. My concern was based on the general OIDC spec, where an OP may reject an expired hint, and OpenAI's own guide answers it for this case. No change needed.

I haven't checked the guide's wording myself, and as the PR description says, this hasn't been tried live against OpenAI. A real sign-in after logout, with an ID token older than an hour, would confirm it. I made no edits in the checkout.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@rekram1-node rekram1-node Nov 24, 2026

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Correction to my earlier reply: the same sentence in the guide continues "Omit it after signing out or if none was retained." I dropped the saved profiles. The ID token now lives in the credential metadata and is only sent when reconnecting an expired connection, so logout deletes it.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

opencodejr[bot] reacted with eyes emoji
All reactions
  • 👀 1 reaction

@opencodejr opencodejr Bot Nov 24, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Agreed. The current head (46df5d6dc) matches the guide, and the concern from this thread doesn't apply anymore:

  • Stored with the credential: idToken and email are kept in the credential's metadata (credential(), chatgpt.ts:578–591). Removing the connection removes them too, so nothing stays behind after sign-out.
  • Only sent to reconnect an expired connection: authorize uses the active connection's metadata only when its client ID is in chatgpt-expired-clients (lines 135–138). In every other case it registers a new client and sends no hints (lines 617–625). After you sign out of everything, both hints are left out, which is what "Omit it after signing out or if none was retained" asks for.
  • Expired token is fine here: refresh carries the original idToken forward without updating it (line 457), so the hint can be past its exp when reconnecting. That's the case where the guide says an expired hint is allowed.
  • Nothing old to migrate: the base branch never had saved profiles, so no old profile data needs cleaning up.

One thing does stay after sign-out: the client ID remains in chatgpt-expired-clients in plugin storage. It holds no token and identifies no account, and a successful sign-in with that client clears it (lines 214–217), so it doesn't conflict with the guide.

I checked this by reading the code only. I couldn't run the tests because the checkout fails to resolve @opencode/schema/money (workspace dependencies aren't installed). I didn't install them because the checkout is shared. I made no changes.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
opencodejr[bot]
opencodejr Bot reviewed Nov 19, 2026
View reviewed changes

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The new commit only changes the tests: it makes the method-list mapping pass the type checker. bun test test/plugin/provider-chatgpt.test.ts still passes, 26 of 26. The public API is unchanged since my last review. The point about the saved id_token_hint going stale and never being refreshed is still open. Nothing new.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@KomeijiReimu KomeijiReimu mentioned this pull request Nov 21, 2026
fix(core): isolate ChatGPT account registrations #56302
Closed
3 of 6 tasks
@rekram1-node rekram1-node changed the title fix(core): stop adding a new ChatGPT app on every sign-in fix(core): reuse each ChatGPT account's client and fix adding a second account Nov 23, 2026
@rekram1-node
rekram1-node force-pushed the chatgpt-consent-reuse branch from 50ec0ef to 80bc0bd Compare November 23, 2026 04:43
@rekram1-node

rekram1-node commented Nov 23, 2026

Copy link
Copy Markdown
Member Author

The Add account point is fixed in the latest commit. When a working ChatGPT account is already saved, "Sign in with ChatGPT" now registers a new client, so adding a second account no longer hits 3p_login_workspace_scope_denied. When only expired accounts (refresh got invalid_grant) or none are saved, it reuses the last account's client, so reconnecting doesn't add a duplicate.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rekram1-node
rekram1-node force-pushed the chatgpt-consent-reuse branch from 80bc0bd to 2b97632 Compare November 24, 2026 15:54
@rekram1-node rekram1-node changed the title fix(core): reuse each ChatGPT account's client and fix adding a second account fix(core): register a new ChatGPT client when adding an account Nov 24, 2026
@rekram1-node
rekram1-node force-pushed the chatgpt-consent-reuse branch from 2b97632 to 46df5d6 Compare November 24, 2026 20:36
@rekram1-node
fix(core): register a new ChatGPT client when adding an account
19725d6
@rekram1-node
rekram1-node force-pushed the chatgpt-consent-reuse branch from 46df5d6 to 19725d6 Compare November 24, 2026 20:45
@rekram1-node
fix(core): send only the email hint when reconnecting ChatGPT
5444f13
@rekram1-node
rekram1-node enabled auto-merge (squash) November 27, 2026 04:35
@rekram1-node
rekram1-node merged commit 23d6540 into dev Nov 27, 2026
12 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@rekram1-node
rekram1-node deleted the chatgpt-consent-reuse branch November 27, 2026 04:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@opencodejr opencodejr[bot] opencodejr[bot] left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

openai: adding a second ChatGPT account fails with workspace scope denied

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@rekram1-node
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.