fix(oauth): send client_version when listing ChatGPT models - #1251
Merged
Merged
Conversation
ChatGPT's GET /codex/models now rejects a request without the client_version query parameter (HTTP 400, "client_version Field required"). The account model list silently fell back to the pinned pi-ai catalog, so a model the account already offers, such as gpt-6.1-sol, could not be selected and session launch refused it with MODEL_NOT_CONFIGURED. pi-ai never calls this endpoint and has no Codex client version to reuse, so pin the Codex CLI version verified to list the current models in one documented constant. The endpoint also hides models whose minimum client version is newer, so the constant is bumped when an account model goes missing.
The vendor account model-list warning recorded only the HTTP status, so the /codex/models contract change (a new required query parameter) looked like an unexplained 400 and went unnoticed while the account list quietly fell back to the pinned catalog. Keep a short single-line excerpt of the error body on the thrown error and log it with the status. The request's own Authorization / API key value, bearer credentials and JWT-shaped strings are removed before the excerpt leaves the module, in addition to the logger's own redaction.
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.
fix(oauth): send client_version when listing ChatGPT models
Fixes #1249
Problem
For a signed-in ChatGPT Plus/Pro account (
openai-codex), Electron main readsthe account's model list from
GET {base}/codex/models(
apps/desktop/electron/main/vendor-live-models.ts). That endpoint now requiresa
client_versionquery parameter. Without it, the endpoint returns:The failure is swallowed: the account list falls back to the pinned pi-ai
catalog, so a model the account already offers (for example
gpt-6.1-sol)never reaches the provider row, and session launch rejects it locally with
MODEL_NOT_CONFIGURED. Thevendor account model list failedwarning loggedonly the status code, so the log never showed why the request failed.
Verified by hand with the same account: adding
?client_version=0.159.2returns200 and the list includes
gpt-6.1-sol. Theoriginatorheader makes nodifference.
Changes
client_version(vendor-live-models.ts): the Codex request is nowGET {base}/codex/models?client_version=<CODEX_MODELS_CLIENT_VERSION>.reuse (it only sends
originator: piand its own User-Agent). The newconstant therefore pins the official Codex CLI version that was verified to
list the current models (
0.159.2).The doc comment on the constant says to keep it at a current Codex CLI
release and to try a newer value if an account model is missing.
vendor-live-models.ts,oauth.ts): a non-2xxresponse now throws
VendorModelListErrorcarryingstatusandresponseExcerpt. The excerpt is a single line of at most 300 characters.Before it leaves the module, it drops the request's own
Authorization/x-api-keyvalue, anyBearer/Basiccredential, and any JWT-shapedstring. The logger's own redaction still runs after that. The
vendor account model list failedwarning now includesstatusandresponseExcerpt. The error message itself is unchanged.docs/spec/03-runtime/11-provider-model-system.mdand its zh-CNcounterpart now document the
client_versionparameter and the failure logexcerpt.
No IPC, persisted-data, default or permission change. The fallback to pi-ai
behaves as before.
Tests
apps/desktop/test/vendor-live-models.test.mjsclient_versionequal to the constant.client_version/Field requiredin the excerpt. Theraw token, its payload segment and an unrelated JWT are removed, and the
excerpt is truncated.
apps/desktop/test/vendor-oauth-login.test.mjsclient_version(as the real one does) now yields a row withgpt-6.1-soland a usable binding.status: 400and the excerpt, and the serialized logdoes not contain the access token.
vendor-live-models.tsandoauth.ts, the newtests fail (3 failures). With the fix, they pass.
Validation
pnpm build:jspnpm --filter @pi-desktop/desktop typecheckpnpm lintpnpm --filter @pi-desktop/desktop testpnpm docs:checkpnpm check:agent-policy,git diff --checkfetch.Risks
CODEX_MODELS_CLIENT_VERSIONmust be bumped by hand. If it goes stale, therequest may still succeed but could omit newer models. Those then fall back
to the pinned catalog, as they did before this fix.
best-effort beyond the request's own token, and the logger redaction runs on
top of it.