Skip to content

fix: keep ChatGPT model discovery independent of npm - #201493

Merged
hannesrudolph merged 1 commit into
mainfrom
openclaw/mellow-crayfish-2
Nov 19, 2026
Merged

hannesrudolph merged 1 commit into
mainfrom
openclaw/mellow-crayfish-2

Conversation

@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Fixes #201480

What Problem This Solves

ChatGPT model discovery depends on npm to choose the client version it reports. When that lookup fails, discovery reports the bundled Codex version, which can hide models requiring a newer client; cache misses also add an unnecessary registry request.

User Impact

User impact: ChatGPT model discovery no longer depends on npm availability or the installed Codex version. No configuration changes are needed.

Discovery can list a model that an older native Codex binary cannot run. The existing update instructions remain unchanged; this does not update Codex or change its binary selection.

Why This Change Was Made

Use the same OpenClaw version source as Responses requests. Accept calendar versions with a four-digit year from 2026 onward, preserving versioned prereleases and build metadata; use 99.0.0 when unavailable or invalid. Responses headers themselves are unchanged.

Remove the npm fetch, six-hour version cache, bundled-version floor, obsolete mocks and fixture routes, and superseded pin-equality test. Update the affected docs and test registration together.

Evidence

  • Before/after: the final discovery regression fails on unchanged main and passes with the fix. The 2027 case also failed with the earlier year-locked patch and passes now. Cases cover stable/prerelease/build versions, placeholders, Codex-style versions, the lower year bound, and the four-digit upper bound.
  • Fresh focused run: 149 tests passed across 9 files, covering subscription and API-key catalogs, account isolation/access programs, endpoint routing, Responses attribution, and prompt stability. Wall time: 35.2 seconds; hosted CI time is not yet available.
  • Earlier affected test-planner run: 326 tests passed. Its inputs are unchanged.
  • Production/test typechecks, targeted lint, formatting, docs MDX validation, and diff checks passed. Full pnpm build on the committed candidate passed in 1m 39s. The earlier uncached build reported UI size-budget warnings; their baseline attribution was not investigated.
  • pr-simplify: no further removals in the final pass. Whole-change delta: 16 files, +74/-250; production +14/-75. All remaining hunks serve version selection or its tests/docs/obsolete fixture cleanup.
  • Independent Auto Review was attempted but produced no report because its reviewer handoff failed. This is not a clean-review claim.
  • Not verified: live authenticated ChatGPT requests, the full native Codex end-to-end scenario, or hosted CI. The historical endpoint probe reported in the issue was not repeated here.

Reported and co-designed by @daniel-lxs, credited in the commit co-author trailer.

Work sessions

Linked for team reference; these sessions aren’t public.

Worked on by

Worked on by:
- @daniel-lxs

Co-authored-by: daniel-lxs <[email protected]>
OpenClaw-Publication: c129cc53-fbc7-47e1-9b45-e9767691bac5
@clawsweeper

clawsweeper Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts extensions: openai size: M labels Nov 18, 2026
@roboclaw-bot
roboclaw-bot marked this pull request as ready for review November 18, 2026 22:36
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 18, 2026
@clawsweeper

clawsweeper Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR replaces npm-based ChatGPT discovery version selection with the OpenClaw request-attribution version and a validated fallback.

Example: ChatGPT model discovery runs with npm unavailable.

  • Before: Discovery falls back to Codex 0.169.0, potentially omitting models requiring a newer client.
  • After: The supplied Gateway trace sends client_version=2026.11.5, receives HTTP 200, and publishes openai/gpt-6.2-sol as available.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused owner-level repair with shipped Gateway evidence, regression coverage, green exact-head CI, and no open findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The supplied exact-head authenticated Gateway trace exercises the changed endpoint with npm blocked, records ChatGPT accepting 2026.11.5, and shows the returned model published by models.list; prerelease selection has controlled coverage and the fallback has historical live evidence.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: ChatGPT users can miss newer models when npm is unavailable.
Reason: Removing an unrelated availability dependency has clear user value; the maintainer-authored PR records the deliberate visibility-policy change.

Merge readiness

✅ Ready for maintainer review

This PR addresses a current model-discovery failure with a focused change, sufficient Gateway proof, and no actionable findings.

Priority: P2
Reviewed head: 4cb3239f490d52d30400297cdec495d17aa50a94

Before merge

None.

Findings

None.

Agent review details

How this fits together

The OpenAI plugin turns authenticated ChatGPT catalog responses into model rows published by the Gateway; this change controls the catalog request's client_version.

flowchart LR
  A[Runtime OpenClaw version] --> B[Provider attribution policy]
  B --> C[ChatGPT catalog endpoint]
  D[Selected account credential] --> C
  C --> E[Authenticated model catalog]
  E --> F[Gateway models list]
Loading

Technical review

Best possible solution:

Use the existing attribution owner for npm-independent discovery and preserve actionable native Codex compatibility errors.

Do we have a high-confidence way to reproduce the issue?

Current-main source deterministically falls back to 0.169.0 after npm failure, and the listing contract models omission above that version; this review executed no target code.

Is this the best way to solve the issue?

The patch directly removes the failing dependency, reuses the existing version owner, and completes the associated cleanup without unnecessary production machinery.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 07baab52b414.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit cbaa9ab adds extensions/openai/base-url.ts:32 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: cbaa9abada32; files: extensions/openai/base-url.ts)

PR surface

Source -61, Tests -118, Docs +3. Total -176 across 16 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 14 75 -61
Tests 11 49 167 -118
Docs 3 11 8 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 16 74 250 -176

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Root-cause cluster

Relationship: same_root_cause
Canonical: #201480
Summary: This PR implements the npm-independent discovery repair requested by the linked issue.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: Registry failure can hide newly available subscription models while existing model choices remain usable.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-18T22:54:05.772Z sha 4cb3239 :: needs maintainer review before merge. :: none

Reviewed November 18, 2026, 6:42 PM ET / 23:42 UTC (Revision 2).

@daniel-lxs

Copy link
Copy Markdown
Member

Live authenticated Gateway proof for 4cb3239f490d52d30400297cdec495d17aa50a94 (2026-11-18). With npm blocked, ChatGPT accepted client_version=2026.11.5 and returned gpt-6.2-sol. The Gateway published it as available in models.list.

Gateway build commit: 4cb3239f490d52d30400297cdec495d17aa50a94
npm registry control: ENOTFOUND
ChatGPT catalog request: GET client_version=2026.11.5 bearer_present=true
ChatGPT catalog response: HTTP 200
ChatGPT catalog includes gpt-6.2-sol: true
Gateway models.list: openai/gpt-6.2-sol available=true
Gateway OAuth endpoint attempts: 0

The Gateway ran with isolated state and used the access token from an existing ChatGPT sign-in as a non-refreshable credential. The OAuth endpoint was blocked, and the original sign-in file was unchanged. The Gateway was stopped and its credential copy and state were removed.

The earlier full build and all 54 focused tests passed. The prerelease and 99.0.0 fallback passed version selection in controlled tests. Live server acceptance of those two values remains unverified.

@daniel-lxs

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Nov 18, 2026
@hannesrudolph
hannesrudolph merged commit 779c260 into main Nov 19, 2026
241 checks passed
@hannesrudolph
hannesrudolph deleted the openclaw/mellow-crayfish-2 branch November 19, 2026 03:49
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 19, 2026
RomneyDa added a commit that referenced this pull request Nov 19, 2026
obviyus added a commit that referenced this pull request Nov 20, 2026
…202380)

Supersedes #202284. Restores the approach of #201493. Related: #201130.

## What Problem This Solves

ChatGPT subscription model discovery calls `/backend-api/codex/models?client_version=<X>`, and the backend hides every model whose `minimal_client_version` is above X. On main (#202284), X comes from a lookup of the latest `@openai/codex` on npm, cached in memory for six hours. That puts a registry request (1 s budget) on the model-listing path. A failed or slow lookup lists at the bundled 0.169.0 floor and can hide newly launched models. The in-memory cache also does not survive a restart or eviction.

## Solution

- List with the OpenClaw release that OpenClaw-harness Responses turns already send as the `version` header (provider attribution). The list and the turn use one value from one owner.
- Send only the numeric `YYYY.M.P` part (year 2026 or later). For example, `2026.11.5-beta.1` lists as `2026.11.5`. Anything else (`unknown`, `0.0.0-dev`, a bad `OPENCLAW_VERSION` override, or a proxy without attribution headers) lists as `99.0.0`.
- Treat an empty subscription list as a failed listing. A ChatGPT account always has models, so an empty 200 response keeps the last good rows instead of replacing them. API-key access-program discovery, where an empty list is valid, is unchanged.
- Delete the npm lookup, the six-hour cache, the 0.169.0 floor, the floor contract test, and the test mocks that existed only for them. Production: +19 / −74 lines.
- Keep the Responses `version` header unchanged. Keep Codex binary selection and update behavior unchanged.

Why this replaces the earlier designs:
- #201130 and #202284 needed a network request for a value the backend only compares numerically. Any version at or above a model's minimum shows the model.
- Peer clients hardcode a value for the same reason: Hermes `99.0.0`, Zed `0.999.0`, Crush `999.0.0`.
- #202284's concern was that an OpenClaw version goes into a Codex-version parameter. The same value already passes the same gate on every Responses turn, and an npm-latest value does not describe the binary that runs a turn either.
- A version starting with 2026 stays above every Codex 0.x release, so new models appear on launch day without a lookup.
- The version check is stricter than #201493's: suffixes are dropped instead of sent, because no live probe has tested a prerelease string.

Accepted edge cases (code comment in `base-url.ts`):
- A Codex-harness binary older than a listed model fails that turn with the existing update instructions and **Start a new session** (#201130). npm-latest had the same tradeoff.
- An old OpenClaw release can list a future model whose request shape it does not support yet. Every fixed-version and npm-latest approach has this.

I also considered an omp-style background npm refresh with persistence (oh-my-pi `codex-version.ts`). Plugin keyed state is unavailable in the catalog worker threads where discovery runs (`Shared-state admission requires the host broker`). An in-memory variant still needed a network request and reset to the floor on every restart.

## User Impact

- ChatGPT subscription users see newly launched models without an OpenClaw release, without a network lookup, and without depending on npm availability.
- Listing makes one request: the ChatGPT `/models` call.
- A transient empty model list from ChatGPT no longer clears the model picker.

## Evidence

- **Red on main, green on the fix** (`extensions/openai/openai-codex-discovery.test.ts`):
  - The version-table cases fail on main, which makes two requests (npm, then `/models`). The fix makes exactly one, to chatgpt.com, with the expected `client_version`.
  - The empty-list case fails on main (`expected ['ready'] to deeply equal ['unavailable']`) and passes on the fix.
  - Main result: 14 of 16 failed (the 2 GPT-6.1 Sol cases pass on both).
- **Focused suites green:** `openai-codex-discovery`, `openai-provider`, `openai-provider.codex-catalog`, `openai-api-key-catalog`, `platform-access-programs`, `base-url`, `src/plugins/contracts/provider-live-listing.contract.test.ts`, `test/openai-model-discovery-auth-order.test.ts`, `test/model-account-catalog-authority.integration.test.ts`.
- **Live, real ChatGPT Pro login (2026-11-18 probe):**
  - `client_version` 2026.11.5, 0.166.0, 0.169.0 and 99.0.0 return the same 13 models, including `gpt-6.2-sol` and `gpt-6.2-astra` (`minimal_client_version` 0.166.0).
  - 0.164.0 and 0.165.0 hide GPT-6.2. 0.0.0 returns a frozen legacy list of 7 models.
  - `/responses` with `version: 2026.11.5` on `gpt-6.2-sol` returns 200.
- **End to end on this branch** (isolated Gateway from source, fresh ChatGPT device-code login, nothing live touched):
  - `models.list` returned 11 subscription models with outcome `ready`, including `gpt-6.2-sol` (1.05M context) and `gpt-6.2-astra`.
  - The Gateway log shows no `registry.npmjs.org` request.
  - A real turn on `openai/gpt-6.2-sol` returned `CXV_OK2`.
  - The same account listed identical models at 0.169.0 and 0.171.0 earlier today. No live model is currently gated between the bundled pin and npm latest, so the "floor hides a model" case was proven in tests, not live.
- **Not proven live:** a Gateway with `OPENCLAW_VERSION=unknown` (the dev tooling strips `OPENCLAW_*`). The version table covers that fallback.

## Merge Risk

Two-way door: no state, schema, config or published contract changes, and a revert fully restores the npm lookup. Blast radius: ChatGPT subscription model listing for OpenAI OAuth and token profiles. API-key listing, Responses headers and Codex binary selection are unchanged.

Co-authored-by: Daniel <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 21, 2026
…penclaw#202380)

Supersedes openclaw#202284. Restores the approach of openclaw#201493. Related: openclaw#201130.

## What Problem This Solves

ChatGPT subscription model discovery calls `/backend-api/codex/models?client_version=<X>`, and the backend hides every model whose `minimal_client_version` is above X. On main (openclaw#202284), X comes from a lookup of the latest `@openai/codex` on npm, cached in memory for six hours. That puts a registry request (1 s budget) on the model-listing path. A failed or slow lookup lists at the bundled 0.169.0 floor and can hide newly launched models. The in-memory cache also does not survive a restart or eviction.

## Solution

- List with the OpenClaw release that OpenClaw-harness Responses turns already send as the `version` header (provider attribution). The list and the turn use one value from one owner.
- Send only the numeric `YYYY.M.P` part (year 2026 or later). For example, `2026.11.5-beta.1` lists as `2026.11.5`. Anything else (`unknown`, `0.0.0-dev`, a bad `OPENCLAW_VERSION` override, or a proxy without attribution headers) lists as `99.0.0`.
- Treat an empty subscription list as a failed listing. A ChatGPT account always has models, so an empty 200 response keeps the last good rows instead of replacing them. API-key access-program discovery, where an empty list is valid, is unchanged.
- Delete the npm lookup, the six-hour cache, the 0.169.0 floor, the floor contract test, and the test mocks that existed only for them. Production: +19 / −74 lines.
- Keep the Responses `version` header unchanged. Keep Codex binary selection and update behavior unchanged.

Why this replaces the earlier designs:
- openclaw#201130 and openclaw#202284 needed a network request for a value the backend only compares numerically. Any version at or above a model's minimum shows the model.
- Peer clients hardcode a value for the same reason: Hermes `99.0.0`, Zed `0.999.0`, Crush `999.0.0`.
- openclaw#202284's concern was that an OpenClaw version goes into a Codex-version parameter. The same value already passes the same gate on every Responses turn, and an npm-latest value does not describe the binary that runs a turn either.
- A version starting with 2026 stays above every Codex 0.x release, so new models appear on launch day without a lookup.
- The version check is stricter than openclaw#201493's: suffixes are dropped instead of sent, because no live probe has tested a prerelease string.

Accepted edge cases (code comment in `base-url.ts`):
- A Codex-harness binary older than a listed model fails that turn with the existing update instructions and **Start a new session** (openclaw#201130). npm-latest had the same tradeoff.
- An old OpenClaw release can list a future model whose request shape it does not support yet. Every fixed-version and npm-latest approach has this.

I also considered an omp-style background npm refresh with persistence (oh-my-pi `codex-version.ts`). Plugin keyed state is unavailable in the catalog worker threads where discovery runs (`Shared-state admission requires the host broker`). An in-memory variant still needed a network request and reset to the floor on every restart.

## User Impact

- ChatGPT subscription users see newly launched models without an OpenClaw release, without a network lookup, and without depending on npm availability.
- Listing makes one request: the ChatGPT `/models` call.
- A transient empty model list from ChatGPT no longer clears the model picker.

## Evidence

- **Red on main, green on the fix** (`extensions/openai/openai-codex-discovery.test.ts`):
  - The version-table cases fail on main, which makes two requests (npm, then `/models`). The fix makes exactly one, to chatgpt.com, with the expected `client_version`.
  - The empty-list case fails on main (`expected ['ready'] to deeply equal ['unavailable']`) and passes on the fix.
  - Main result: 14 of 16 failed (the 2 GPT-6.1 Sol cases pass on both).
- **Focused suites green:** `openai-codex-discovery`, `openai-provider`, `openai-provider.codex-catalog`, `openai-api-key-catalog`, `platform-access-programs`, `base-url`, `src/plugins/contracts/provider-live-listing.contract.test.ts`, `test/openai-model-discovery-auth-order.test.ts`, `test/model-account-catalog-authority.integration.test.ts`.
- **Live, real ChatGPT Pro login (2026-11-18 probe):**
  - `client_version` 2026.11.5, 0.166.0, 0.169.0 and 99.0.0 return the same 13 models, including `gpt-6.2-sol` and `gpt-6.2-astra` (`minimal_client_version` 0.166.0).
  - 0.164.0 and 0.165.0 hide GPT-6.2. 0.0.0 returns a frozen legacy list of 7 models.
  - `/responses` with `version: 2026.11.5` on `gpt-6.2-sol` returns 200.
- **End to end on this branch** (isolated Gateway from source, fresh ChatGPT device-code login, nothing live touched):
  - `models.list` returned 11 subscription models with outcome `ready`, including `gpt-6.2-sol` (1.05M context) and `gpt-6.2-astra`.
  - The Gateway log shows no `registry.npmjs.org` request.
  - A real turn on `openai/gpt-6.2-sol` returned `CXV_OK2`.
  - The same account listed identical models at 0.169.0 and 0.171.0 earlier today. No live model is currently gated between the bundled pin and npm latest, so the "floor hides a model" case was proven in tests, not live.
- **Not proven live:** a Gateway with `OPENCLAW_VERSION=unknown` (the dev tooling strips `OPENCLAW_*`). The version table covers that fallback.

## Merge Risk

Two-way door: no state, schema, config or published contract changes, and a revert fully restores the npm lookup. Blast radius: ChatGPT subscription model listing for OpenAI OAuth and token profiles. API-key listing, Responses headers and Codex binary selection are unchanged.

Co-authored-by: Daniel <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to clawhaven/openclaw that referenced this pull request Nov 23, 2026
(cherry picked from commit 779c260)
Release adaptation: approved 2026.11.7 models replay; see models-hook-safe-v2/REPORT.md.
Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: openai P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. scripts Repository scripts size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: ChatGPT model discovery depends on npm and can hide newer models

3 participants