Repository navigation
What each upstream serves, and routing that respects it - #31
Merged
Merged
Conversation
Two failures shared one cause: the model catalog knew which models existed,
but not reliably which upstream served them.
- A config reload rebuilt the catalog from the hand-written `models` lists
alone. Every model discovered from an upstream's /v1/models vanished,
so requests for them were refused, until the daily refresh. A newly
added upstream also waited up to a day to be asked for its models.
- Routing ignored the catalog. When a group put an upstream first that did
not offer the requested model, that upstream answered 404, which does
not trigger failover, and the request failed with an upstream that
could serve it right beside.
The gateway now keeps a model directory beside the catalog:
- Each upstream's last answer is kept across reloads: listed, no list
(and why), or failed (and why), with the time it was checked. An answer
stays valid while the address, credential account, protocol and proxy
stay the same.
- The catalog is derived from the directory and the current config on
every change, so disabling an upstream or narrowing its scope applies
at once. New and changed upstreams are asked straight away in the
background. Everything else is re-asked daily, and a failure retries
after an hour. Checks compare wall-clock time, so a laptop that slept
still refreshes.
- Candidates are filtered before a group orders them. Disabled upstreams,
models outside `models_only`, and models missing from a known list are
skipped. An upstream without a list is kept, since not knowing is not
the same as not offering. When nothing is left, the error names each
upstream and why. The dry run reports the same skips, with an
`unavailable` outcome.
- Admission says "no upstream offers this model" when that is the reason,
rather than blaming the client's allow list.
Config:
- `disabled` keeps an upstream's settings but takes it out of routing and
out of /v1/models.
- `models_only` limits which of an upstream's models are used, by ID or
glob. An empty list is refused in favour of `disabled`.
- `billing: free` records an exact $0, and sorts first for `cheapest`.
Control plane:
- `GET /providers/{name}/models` lists an upstream's models with source,
check time, error, scope, context window and price.
`POST /providers/{name}/models/refresh` asks the upstream now.
- `ProviderView` reports `model_source`, `model_count`, `models_only` and
`disabled`. `ProviderInput` accepts the last two.
- Speed-test and replay quotes share one quote per billing mode, and
carry `billing` in place of `subscription`. A quote for an upstream
with unknown billing no longer reads as a per-token price.
- The diagnostics bundle shows each upstream's state and model list.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Thanks for the PR. One thing before review: this targets
No need to close and reopen: click Edit next to the PR title and change the base branch to See CONTRIBUTING.md and CONTRIBUTING.md for the branch contract. |
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Two failures with one cause: the model catalog knew which models existed, but not reliably which upstream served them.
modelslists alone. Everything discovered from/v1/modelsvanished and requests for those models were refused ("the client is not allowed to use …") until the daily refresh. A newly added upstream also waited up to a day to be asked for its models, which is exactly the flow the new "create upstream" dialog relies on.Both are reproduced by integration tests written before the fix (
tw-gateway/tests/models.rs).What
Model directory (
tw-gateway/src/models.rs)Routing
cheapestandurl-testchoose among upstreams that can serve the request. Skipped:models_only;skipped), andoutcome: unavailablewhen no candidate remains.Config
disabledkeeps an upstream's settings but takes it out of routing and out of/v1/models.models_onlylimits which of an upstream's models are used, by ID or glob. An empty list is refused and points todisabled.billing: freerecords an exact $0 with no price source, and sorts first forcheapest.models) is fixed.Control plane
GET /providers/{name}/modelsreturnssource(discovered / manual / none),checked_at_ms,error, and for each model: whether it is in scope, its context window, and its price and price source under the upstream's price sheet.POST /providers/{name}/models/refreshasks the upstream now and returns the same view.ProviderViewgainsmodel_source,model_count(in scope, 0 when disabled),models_onlyanddisabled.ProviderInputacceptsmodels_onlyanddisabled.tw_gateway::quote, one wording per billing mode, and carrybillinginstead ofsubscription. An upstream with unknown billing no longer gets a per-token price. A subscription reads "counts against the subscription quota" rather than "free".tw-apiand bundlestwcoreby tag, and Run the inference speed test the way each upstream expects #28 to What each upstream serves, and routing that respects it #31 change the control API it compiles against. The tag follows this merge.Tests
tw-gateway/tests/models.rs, 5 tests. Two reproduce the bugs above:Three cover the new behaviour:
models_onlyin listing and routing;tw-control/tests/models.rs, 4 tests:disabledandmodels_onlywritten through the resource API, and an empty scope refused;unavailable.Unit tests:
freerecorded as $0;models_onlyvalidation.Gates:
fmt,clippy -D warningsandcargo test --workspace(1,246 tests) pass.scripts/smoke.sh: 48 passed, 0 failed, 1 over target and not a regression (memory 35 MB against a 30 MB target).🤖 Generated with Claude Code