Repository navigation
Models added by hand count as offered next to the upstream's own list (protocol 42) - #300
Merged
Merged
Conversation
…eam's list An upstream's `models` used to be a fallback, used only when `/v1/models` could not be fetched. Once the upstream answered, a model missing from its answer was skipped for that upstream (`Skip::NotOffered`), even for a rule that pins it. Real upstreams leave out models they serve: the ChatGPT account backend hides new models from older client versions, and relays list only part of what they carry. There was no way to say "this upstream has it anyway". `providers[].models` now means "models added by hand": always offered by that upstream, merged after the models it lists, and still the whole list when it lists none. The union is made once, in the gateway's listing, so the catalog, `/v1/models`, admission, aliases, pinned models, key `allow`, the dry run and the speed test all see a manual model exactly like a listed one. `models_only` still applies on top. No new field and no migration: an old fallback list keeps meaning the same thing. The control plane says which rows are manual and which the upstream lists (`ModelRow.manual`, `ModelRow.listed`), and sets the list through `PUT /provider-manual-models` (`ManualModelsSave` -> `ConfigWritten`), which writes only that upstream's `models` like the model-spec endpoint does. Entries are trimmed, then checked by the same rules the config validation now applies: not blank, no surrounding whitespace, no `*` or `?`, at most 256 characters, no duplicates (`config.manual_model_*`). Protocol 42. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
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
Core treated an upstream's model list as authoritative. Once the upstream answered
/v1/models, a model missing from the answer was skipped for that upstream (Skip::NotOffered), even for a rule that pins it.providers[].modelsonly stood in when the list could not be fetched.Real upstreams leave out models they actually serve: the ChatGPT account backend hides new models from older client versions, and relays list only part of what they carry. There was no way to say "this upstream has it anyway".
What changes
providers[].modelsnow means "models added by hand". They are always offered by that upstream, appended after the models it lists (models it lists too are not repeated), and they are still the whole list when it lists none. There is no new field and no migration: an old fallback list keeps working as before.tw_gateway::models::listing_of). The catalog,/v1/models(with specs from the price table ormodel_specs), admission, aliases (resolve), rule-pinned models, keyallow, the dry run, the speed test and the control plane's lists all read from it, so a manual model behaves exactly like a listed one.models_onlystill applies on top. Changing the list needs no re-fetch: the reload republishes the catalog.ModelRowhas two new fields:manual(the model is in the upstream'smodels) andlisted(the upstream's own list has it). A manual model the upstream also lists has both set.listedis false for every row when the upstream gives no list.PUT /provider-manual-models(SetManualModels):ManualModelsSave { provider, models, base_version? }→ConfigWritten. It replaces the upstream's whole manual list in the given order, and an empty list removes the key. LikePUT /provider-model-spec, it writes only that upstream'smodelsand leaves the rest of the item and its comments alone (tw_config::edit::set_models).tw_config::check_manual_models, which the config validation also runs now. An entry must not be blank, have whitespace at either end, contain*or?, or exceed 256 characters (MANUAL_MODEL_MAX), and must not repeat another. Failures are 400 with new codesconfig.manual_model_blank,_padded,_wildcard,_duplicateand_too_long. An unknown upstream is 404config.edit.not_found, a line break isconfig.edit.multiline, and a stalebase_versionis 409.CONTROL_API_VERSION41 → 42, with a "42 起…" note. Docs: themodelsrow and a short paragraph indocs/config.mdanddocs/config.zh-CN.md. Diagnostics count models added by hand separately.Tests
tw-config: validation rules;set_modelsset/replace/clear, inline items, missing upstream, line breaks.tw-gatewayunit test: union order,listed, catalog offers, routing by name, through an alias and through a pinned rule; scope still excludes; removing the model restores the old behaviour without a re-fetch.tw-gateway/tests/models.rs: against a fake upstream that serves a model it does not list. The model appears in/v1/models, is routed by name, through an alias and through a pinned rule, and is skipped by the upstream earlier in the group. Scope excludes it. Once removed, the pinned rule reports that the upstream does not offer it.tw-control/tests/manual_models.rs: row flags, overview count,GET /models, dry run; the endpoint trims, sets, shortens and clears, and the file returns to its original text; refusal codes; 409 on a stale version; the fallback when the upstream refuses the key; scope.Local runs:
cargo fmt --check,cargo clippy --workspace --all-targets -D warnings,cargo test --workspace(3078 passed),cargo test -p tw-api --features tsplus the exported TS throughtsc --strict,scripts/release_notes_test.py,scripts/smoke.sh(75/0).No version bump and no tag: the desktop app follows in its own PR once a release is cut.
🤖 Generated with Claude Code