Skip to content

Accept OpenRouter variant suffixes such as :nitro in the widget's model check - #554

Merged
neuromechanist merged 7 commits into
developfrom
feature/issue-552-openrouter-variant-slugs
Sep 29, 2026
Merged

neuromechanist merged 7 commits into
developfrom
feature/issue-552-openrouter-variant-slugs

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

Closes #552.

What was wrong

The widget's Settings dialog refused an OpenRouter slug with a variant suffix (openai/gpt-oss-120b:nitro): "Invalid model format. Expected a Claude model id or provider/model-name". A saved one was dropped on load.
isValidModelId in frontend/osa-chat-widget.js had no room for :variant, while the server's own check for a community's ids (_MODEL_ID_PATTERN) has, and the request's model field has no pattern at all: the server accepted what the widget refused.
I reproduced the server side in-process against a local fake of OpenRouter: the slug reaches OpenRouter intact (model: openai/gpt-oss-120b:nitro) and no provider order is sent for a caller's custom slug.

Changes

  • Widget: isValidModelId uses the server's pattern and its 100-character limit; the refusal message names a variant such as :nitro.
  • Stacked suffixes: OpenRouter lets suffixes be stacked (openai/gpt-5.2:nitro:exacto: any number of routing variants, at most one catalog variant), so both the server pattern and the widget's take any number; the server test that pinned a single suffix now pins an empty variant instead.
  • One list, two readers: tests/fixtures/model_ids.json holds valid and invalid ids. The widget's Settings suite saves or refuses each one through the real dialog, tests/test_core/test_model_id_corpus.py holds the server's validator to the same list, and tests/test_frontend/test_widget_model_id_parity.py checks the two patterns are the same text (apart from the escaped slash) and that the widget's check uses the pattern and limit it declares.
  • Reasoning level for a variant: routing variants (:nitro, :floor, :exacto and the deprecated :online, which OpenRouter documents as accepted on any model and stackable in any order) are looked through when a slug is mapped to an offered model, so openai/gpt-oss-120b:nitro runs at the same level as the plain slug (Default every model to high reasoning effort, including Claude Haiku through its thinking budget #548) instead of OpenRouter's own default. :free, :batch, :thinking and :extended are catalog entries of their own and are left alone (stripping :free would resolve to the paid entry).
  • No provider pinned on a variant slug: an anthropic/ slug that carries a variant is no longer pinned to provider.order = [Anthropic], so a routing the caller chose (:floor for the cheapest) is not overridden. A plain anthropic/ slug is pinned as before.
  • A hang in the fake-OpenRouter tests, fixed (found because this PR adds many streaming tests and made it likely): the intermittent stall seen in local runs and in CI was a self-deadlock, not slowness. httpcore's connection-pool lock is not reentrant, and LiteLLM can leave a streaming response unclosed; when the garbage collector finalizes it inside a later request, while the pool lock is held, it takes the same lock on the same thread and never returns. Automatic collection is now held off while FakeOpenRouter is up and run when it closes. Twelve consecutive runs of the OpenRouter test files (with two more streaming files added) had no hang; a smaller set stalled about one run in three before. Test-only: production uses the async client.
  • CHANGELOG, and ADR 0015 records what the maintainer verified by a live request and what has not been run yet, with the wording kept to what was reported.

Not verified

OpenRouter's documentation does not say whether a routing variant conflicts with an explicit provider.order. OSA sends none for a caller's own slug, and no longer pins one on an anthropic/ variant slug, so it does not arise for a typed slug; the slug is the caller's to have verified.
A community default_model that is a variant slug passes config validation but is refused at request time by the pricing check (_check_model_cost), which does not look through the suffix: loud, and not changed here.
I could not reproduce the dialog error against the deployed widget; it follows from the code and is covered by tests that fail on the old validator.

Tests

  • Settings suite: 95 checks; each valid id (stacked, upper-case, underscore, 100 characters) is saved and each invalid id refused with the reason, through the real dialog, plus a saved :nitro model coming back as Custom.
  • Backend corpus and parity tests; variant mapping (any order, catalog variant kept, alias variant unmapped) and request-body tests (the model id keeps its suffix on the wire, the level matches the plain slug, Haiku through a variant gets its budget and no temperature, :free gets no reasoning field, provider pinning with and without a variant).
  • Mechanism tests for the collector state of the fake server.
  • Mutation-checked: the original bug (Bun suite and parity test), the length limit, one suffix only (widget and server), character classes, :online, stacked and catalog handling, and the provider pinning; all killed.
  • All 22 Bun suites and the full offline Python suite (3,865 tests) pass; ruff clean.

Review

An independent Sonnet review found no critical issue and three important ones, all addressed: stacked suffixes (fixed), anthropic/ variant slugs still pinned to a provider (fixed, and the claim corrected), and an ADR bullet that went beyond what was verified (reworded). Also fixed: :online, corpus character classes, the parity test's reach, wording, and comment density. Left as documented behavior: a community default_model variant slug is refused by the pricing check.

  • Tests
  • Ruff

The Settings dialog refused openai/gpt-oss-120b:nitro: isValidModelId had no
:variant, while the server's _MODEL_ID_PATTERN has one. The widget now uses the
server's pattern and 100-character limit, and one shared list of valid and
invalid ids (tests/fixtures/model_ids.json) is read by the widget's Settings
test and by a backend test, with a source-level check that the two patterns are
the same text.

Tested: Settings suite 89 checks (each corpus id saved or refused through the
real dialog), 22 Bun suites, parity and corpus tests; 8 mutations killed.
:nitro, :floor and :exacto only change which providers serve a request, so
openai/gpt-oss-120b:nitro is gpt-oss-120b and runs at the plain slug's reasoning
level instead of OpenRouter's own default. :free, :batch, :thinking and :extended
are catalog entries of their own and are left alone.

Tested: variant mapping and request-body tests; 3 mutations killed.
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Preview Deployment

Name Link
Preview URL https://feature-issue-552-openrouter-demo.osc.earth
Branch feature/issue-552-openrouter-variant-slugs
Commit 4fae0ad

This preview will be updated automatically when you push new commits.

OpenRouter lets suffixes be stacked (openai/gpt-5.2:nitro:exacto), so the server
pattern and the widget's both take any number of them; the test that pinned one
suffix now pins an empty variant instead. The shared corpus gains stacked ids and
an upper-case and underscore id, the parity test checks that the widget's check
uses the pattern and limit it declares, and the corpus test documents trimming.

Tested: Settings suite 95 checks, corpus and parity tests; 5 mutations killed.
…ug's provider alone

:online is a documented routing variant, and routing variants stack in any order
with at most one catalog variant, so all of them are stripped before the lookup
and a leftover catalog variant (:free) still means a different entry. An
anthropic/ slug that carries a variant is no longer pinned to the Anthropic
provider: the caller chose how it is routed.

Tested: stacked, order, alias-variant and provider tests; 4 mutations killed.
…eadlock

httpcore's pool lock is not reentrant, and LiteLLM can leave a streaming response
unclosed. When the collector then finalizes it inside a later request, while the
pool lock is held, it takes the same lock on the same thread and never returns:
the intermittent hang seen in local runs and in CI, always in a test using
FakeOpenRouter. Automatic collection is now held off while the fake server is up
and run when it closes.

Tested: 12 consecutive runs of the OpenRouter test files with no hang (a smaller
set stalled about 1 run in 3 before); mechanism tests for the collector state.
@neuromechanist
neuromechanist merged commit a040482 into develop Sep 29, 2026
10 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-552-openrouter-variant-slugs branch September 29, 2026 23:45
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.

1 participant