Skip to content

Commit 29195ec

Browse files
authored
fix: match vendor-prefixed gateway model ids such as OpenRouter's (#731)
### Summary Fixes [IJAI-5619](https://youtrack.jetbrains.com/issue/IJAI-5619): a Codex session set up through `providers/set` with an OpenRouter key showed no models, so the client hid the model picker. Since #627, `providers/set` fetches the gateway's `GET {baseUrl}/models` and keeps only the Codex models it lists. Ids were compared without case or date suffix, but OpenRouter lists models as `vendor/model` (`openai/gpt-6.1-sol`). No Codex model matched, so `session/new` and `session/resume` returned `availableModels: []` and no `model` config option. The reporter's log shows exactly this after the switch to the OpenRouter proxy. - `normalizeModelId` now also drops a `vendor/` prefix, so `openai/gpt-5.4` matches `gpt-5.4`. The narrowing and the "listed thread model is kept" check both go through it. - `readme-dev.md` describes the new matching rule.
1 parent caf2e87 commit 29195ec

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

‎readme-dev.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ JSON-RPC batches. Parent setup operations serialize without waiting on each othe
305305

306306
`providers/set` lists the models of the gateway (`GET {baseUrl}/models`, with the headers Codex sends to it)
307307
before it responds. The models reported to the client are then only the Codex models whose `model` or `id` the
308-
gateway lists, matched without case and date suffix. A session whose thread model the gateway does not list uses
308+
gateway lists, matched without case, vendor prefix (`openai/gpt-5.4`, as OpenRouter lists it) and date suffix. A session whose thread model the gateway does not list uses
309309
the default of these models; a thread model that the gateway lists but Codex does not know is kept. A gateway that
310310
lists none of the Codex models leaves no model option at all, and the session keeps the thread's model as current.
311311
Sessions already open get the models of the new routing when the provider restart resumes them, after

‎src/GatewayModelDiscovery.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,15 @@ function readModelIds(body: unknown): string[] | null {
8787
return ids.length === data.length ? ids : null;
8888
}
8989

90-
/** Lower case, without a date suffix: `GPT-5-2025-08-07` and `gpt-5-20250807` are both `gpt-5`. */
90+
/**
91+
* Lower case, without a vendor prefix or a date suffix: `GPT-5-2025-08-07`, `gpt-5-20250807` and `openai/gpt-5`
92+
* are all `gpt-5`. Aggregators such as OpenRouter list models as `vendor/model`.
93+
*/
9194
function normalizeModelId(id: string): string {
92-
return id.toLowerCase().replace(/-(\d{8}|\d{4}-\d{2}-\d{2})$/, "");
95+
return id
96+
.toLowerCase()
97+
.replace(/^.*\//, "") // remove vendor prefix
98+
.replace(/-(\d{8}|\d{4}-\d{2}-\d{2})$/, ""); // remove date suffix
9399
}
94100

95101
/** Whether the gateway lists the Codex model, by its `model` or its `id`. */

‎src/__tests__/CodexACPAgent/gateway-model-discovery.test.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,11 @@ describe("Gateway model discovery (providers/set)", () => {
103103
await expect(JSON.stringify(models, null, 2)).toMatchFileSnapshot("data/gateway-model-discovery-narrowed.json");
104104
});
105105

106-
it("reports the narrowed models in a new session", async () => {
107-
fetchMock.mockResolvedValue(listing(["gpt-5.4", "gpt-5.4-mini"]));
106+
it.each([
107+
["plain ids", ["gpt-5.4", "gpt-5.4-mini"]],
108+
["vendor-prefixed ids (OpenRouter)", ["openai/gpt-5.4", "openai/gpt-5.3-codex:batch", "openai/gpt-5.4-mini", "google/gemini-4-argon"]],
109+
])("reports the narrowed models in a new session for a listing with %s", async (_name, ids) => {
110+
fetchMock.mockResolvedValue(listing(ids));
108111
const fixture = createFixture();
109112
await fixture.getCodexAcpAgent().setProvider(GATEWAY);
110113

0 commit comments

Comments
 (0)