Skip to content

fix(core): restore ChatGPT model discovery for token sharing - #64528

Open
rekram1-node wants to merge 1 commit into
devfrom
chatgpt-discovery
Open

rekram1-node wants to merge 1 commit into
devfrom
chatgpt-discovery

Conversation

@rekram1-node

@rekram1-node rekram1-node commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Issue for this PR

Related: #52878 (sync turned off in #53466 while OpenAI's /v1/models left out models some accounts could use)

Type of change

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

What does this PR do?

Sign in with ChatGPT shows only a fixed model list right now, so a new model like gpt-6.2-sol needs a release (#64508). This turns the account model sync back on, using the code that was commented out.

A token-sharing token sent to GET https://api.openai.com/v1/models returned 200 twice today: 13 models, 10 with visibility: "list" and supported_in_api, including gpt-6.2-sol and gpt-6.2-astra. The response matched the existing schema.

startup / account switch
  show the saved list for this credential, or the fixed fallback list
  in the background: GET /v1/models with the stored token (15s timeout)
    usable list (>=1 listed, API-supported model) -> save it, reload providers
    error, timeout, bad body, empty or filtered-to-empty list -> keep what is shown, save nothing
  answer for a credential that is no longer active -> dropped
every 15 minutes: same refresh

Beyond the old commented code:

  • The saved list is keyed by credential ID plus client ID (models:<credential>:<client>). Today "add account" can reuse the same client ID (fix(core): isolate ChatGPT account registrations #56302), so a client-only key could show one account's list under another. Lists under the old models:<clientID> key come from the period when the endpoint was leaving models out, so they're not read.
  • The credential migration from chatgpt-browser no longer seeds that old saved snapshot. It still moves the method ID and strips models from metadata.
  • I didn't bring back the model transform rule that disabled any OpenAI model missing from the account list. Models added in config stay visible, as they are now.
  • Discovery never refreshes the token. If the stored token expires within a minute, it skips that round, and the next poll uses the token that requests refreshed.

Trade-off: when discovery succeeds, the account list decides what shows up again. If OpenAI leaves out a model the account can still use, which is the bug from #52878, it disappears until the list includes it. For example, the probed account's list no longer has gpt-5.5, so that model would stop showing for this account. A fallback is used only when there is no usable list. I didn't merge the account list with the fixed list because that would show models the account may not be able to use.

How did you verify your code works?

packages/core/test/plugin/provider-chatgpt.test.ts, with controlled HTTP responses and the test clock:

  • New sign-in: shows the fallback list while the request is pending, then shows gpt-6.2-sol and an unknown gpt-6.3-nova. Hidden and non-API models are filtered out, and only the filtered list is saved.
  • After a good list, an empty list, a filtered-to-empty list, a 503, a body that doesn't match the schema, and a request that hits the 15s timeout all keep the list and the saved copy. A later good list replaces both.
  • Empty list or 503 before any success keeps the fallback list and saves nothing.
  • Switching accounts while the first account's request is pending drops its late answer. Switching back to the first account shows the fallback list, not the second account's list.
  • Saved lists merge with catalog metadata (limits, variants, compaction).

Mutation checks: a client-only key, no stale-answer guard, no empty-list rejection, and no timeout each make a test fail. The file passes with --rerun-each 10 (290/290). bun typecheck in packages/core passes. bun run check stops at an @opencode/app type error (PluginListOutput.ready in packages/app/src/settings/providers/extensions.tsx), which this PR doesn't touch. Prettier and oxlint pass on the changed files. Prettier also reformatted a few existing lines in the test file.

Not tested: a live run of this build against a ChatGPT account.

Checklist

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

Added by the opencode bot (AI-generated).

Related: #52878

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The change looks sound. I couldn't test discovery live (no ChatGPT credentials). The plugin tests pass (29/29, and 145/145 over 5 repeat runs) and tsc -b for packages/core passes.

I read the restored refresh path closely:

  • Late answers are dropped when the credential or cache key changed while the request was pending.
  • Failures, timeouts, bad bodies and empty or filtered-to-empty lists keep the current list and save nothing. A failure only logs a warning.
  • The new models:<credential>:<client> key prevents one account's list from showing under another account that reuses the same client ID.
  • Not seeding the old models:<clientID> snapshot during migration matches the stated intent.

The trade-off you call out is the main risk: for accounts whose /v1/models list leaves out a model they can still use (the #52878 case), that model disappears again until OpenAI lists it. Config-defined models stay visible, so users have a workaround.

A small side effect: entries under the old models:<clientID> key are no longer read but stay in plugin storage.

Public API: unchanged. The plugin storage keys are internal.

Related: #52878

This branch has not been deployed

No deployments
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.

1 participant