Skip to content

chore(server): guard that /v1/models reports null model capabilities#105

Closed
elyasmnvidian wants to merge 1 commit into
mainfrom
emehtabuddin/qa-v2-server
Closed

chore(server): guard that /v1/models reports null model capabilities#105
elyasmnvidian wants to merge 1 commit into
mainfrom
emehtabuddin/qa-v2-server

Conversation

@elyasmnvidian

@elyasmnvidian elyasmnvidian commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

What

GET /v1/models leaves each model's context_window and tool_calling as null, and this PR keeps it that way on purpose, with a test that locks it in.

Why

The id in /v1/models is a symbolic route name (like random or smart), not the upstream model behind it — so there's nothing to read a real context window or tool-calling flag from. Inferring one from the route name (or from a target) would be a guess, and a wrong one. The operator picks the models they route to and already knows their limits, so Switchyard doesn't need to advertise them.

This replaces the earlier version of this PR, which inferred the context window from the model id and broke once the id became a route name (flagged in review).

Change

  • A comment on model_entry_json explaining why the two fields are null.
  • A test that serves a route named random over a big-context target and asserts both fields are null — written so any future attempt to infer a value (from the route name or the target) fails the test.
  • streaming and the supported inbound formats stay populated; those are facts about this server, not the upstream model.

If someone later needs these reported, the operator can declare them in the server config and we report exactly what they set — no guessing.

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The server maps context exhaustion errors to HTTP 400 responses with an OpenAI-compatible error code. Model listings now expose tool-calling support and inferred context-window values, with integration tests covering both changes.

Changes

Server behavior

Layer / File(s) Summary
Context overflow error mapping
crates/switchyard-server/src/lib.rs, crates/switchyard-server/tests/server.rs
Context window and pool exhaustion errors return HTTP 400 with context_length_exceeded; an overflow profile and integration test validate the response.
Model capability metadata
crates/switchyard-server/src/lib.rs, crates/switchyard-server/tests/server.rs
Model listings report tool_calling: true and infer context_window from display-name substrings with a 128_000 fallback; endpoint assertions cover the values.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Poem

I’m a rabbit with tests in my burrow,
Errors now hop client-side in a hurry.
Models show tools and windows bright,
Context clues make their numbers right.
400 says, “Your prompt’s too furry!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes one major part of the change: reporting tool_calling and context_window in /v1/models.

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
crates/switchyard-server/tests/server.rs (1)

217-242: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Cover ContextPoolExhausted separately.

This test exercises only ContextWindowExceeded, while the production mapping also handles ContextPoolExhausted. Add a profile/test for the second variant so regressions in that branch cannot pass unnoticed.

🤖 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 217 - 242, Add a
separate test alongside context_window_overflow_maps_to_client_error using a
profile that triggers ContextPoolExhausted. Send the same chat completion
request through build_switchyard_router, then assert the response is BAD_REQUEST
with error.code set to the expected client-facing code for pool exhaustion,
covering the distinct production mapping branch.
🤖 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 217-242: Add a separate test alongside
context_window_overflow_maps_to_client_error using a profile that triggers
ContextPoolExhausted. Send the same chat completion request through
build_switchyard_router, then assert the response is BAD_REQUEST with error.code
set to the expected client-facing code for pool exhaustion, covering the
distinct production mapping branch.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 4f5c9536-37c6-407c-a66f-fcadc9be076c

📥 Commits

Reviewing files that changed from the base of the PR and between 2fa6b87 and 01a361b.

📒 Files selected for processing (2)
  • crates/switchyard-server/src/lib.rs
  • crates/switchyard-server/tests/server.rs

@elyasmnvidian
elyasmnvidian force-pushed the emehtabuddin/qa-v2-server branch 2 times, most recently from 5a75be1 to fe15312 Compare July 21, 2026 22:15
@elyasmnvidian elyasmnvidian changed the title fix(server): expose /v1/models capabilities and return 400 on context overflow fix(server): report tool_calling and context_window in /v1/models Jul 21, 2026
Comment thread crates/switchyard-server/src/lib.rs Outdated
///
/// Uses the same known-model fragments as the Python `model_listing` table:
/// the first matching substring wins, else a conservative 128k default.
fn inferred_context_window(model: &str) -> u32 {

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.

Won't this be a symbolic / router name like smart or random? We don't advertise the upstream models any more.

@elyasmnvidian
elyasmnvidian force-pushed the emehtabuddin/qa-v2-server branch from f3d5269 to 50f24aa Compare July 23, 2026 19:38
Signed-off-by: Elyas Mehtabuddin <emehtabuddin@nvidia.com>
@elyasmnvidian elyasmnvidian changed the title fix(server): report tool_calling and context_window in /v1/models chore(server): guard that /v1/models reports null model capabilities Jul 23, 2026
@elyasmnvidian elyasmnvidian reopened this Jul 23, 2026
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.

2 participants