fix(server): return Codex metadata from /v1/models - #304
Conversation
WalkthroughThe ChangesCodex model discovery
Estimated code review effort: 3 (Moderate) | ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/switchyard-server/tests/server.rs (1)
1152-1156: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert the raw Codex array before collecting it into
BTreeMap.
BTreeMapremoves entry order and collapses duplicateslugvalues. The test can pass whenmodelshas extra duplicate entries or incorrect priorities. Assert raw-array length, order relative todata, and each zero-basedprioritybefore buildingcodex_metadata.Proposed test coverage
let codex_models = body["models"].as_array().cloned().unwrap_or_default(); + assert_eq!(codex_models.len(), data.len()); + for (priority, (codex_model, data_model)) in codex_models.iter().zip(data.iter()).enumerate() { + assert_eq!(codex_model["slug"], data_model["id"]); + assert_eq!(codex_model["priority"], json!(priority)); + } + let codex_metadata = codex_modelsAs per PR objectives, the
modelsarray must preserve order and assign priorities.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/switchyard-server/tests/server.rs` around lines 1152 - 1156, Update the test around the raw `body["models"]` value before constructing `codex_metadata`: assert the array length, verify its order against `data`, and validate each entry’s zero-based `priority`. Keep the existing `BTreeMap` collection only for subsequent lookup, so duplicate slugs or reordered entries cannot make the test pass.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@crates/switchyard-server/tests/server.rs`:
- Around line 1152-1156: Update the test around the raw `body["models"]` value
before constructing `codex_metadata`: assert the array length, verify its order
against `data`, and validate each entry’s zero-based `priority`. Keep the
existing `BTreeMap` collection only for subsequent lookup, so duplicate slugs or
reordered entries cannot make the test pass.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: f8f63007-afbe-4494-976e-73a64d82570f
📒 Files selected for processing (2)
crates/switchyard-server/src/lib.rscrates/switchyard-server/tests/server.rs
abf1b38 to
bbb667c
Compare
|
bbb667c to
b18869c
Compare
Signed-off-by: Elyas Mehtabuddin <emehtabuddin@nvidia.com>
Signed-off-by: Elyas Mehtabuddin <emehtabuddin@nvidia.com>
Signed-off-by: Elyas Mehtabuddin <emehtabuddin@nvidia.com>
81f2d13 to
271fd5a
Compare
{ "object": "list", "data": [{"id": "switchyard", "object": "model"}], "model_pool": ["switchyard"] }What happens
Codex direct-provider discovery decodes this response as a Codex model catalog, not only as an OpenAI model list.
Why
GET /v1/modelscurrently returns only the OpenAI-compatibledataarray. Codex expects a top-levelmodelsarray whose entries include its model metadata fields, so it discards the route's declared context window and tool support.The endpoint now returns both arrays from the same route registry. Existing
data,model_pool, and default-model fields remain unchanged. Each Codex entry reflects the route's declared context window, tool support, and reasoning, which the route registry owns and feeds to both arrays. The constant Codex card shape is a static mirror of Codex'sModelInfo; the launcher builds the same card inswitchyard/cli/launchers/codex_model_catalog.py, and the two are kept in step by hand.This is an additive response change. Existing OpenAI-compatible model discovery keeps the same fields and values.
Proof
The same local route now returns both catalogs:
The installed Codex CLI then completes the direct-provider request without the decode or fallback warning:
The proof used a local OpenAI-compatible upstream; it did not contact a model provider.
How tested
The regression test checks the OpenAI and Codex catalogs together, including declared, restricted, and undeclared route capabilities.
Summary by CodeRabbit