Skip to content

Models added by hand count as offered next to the upstream's own list (protocol 42) - #300

Merged
fylorn merged 1 commit into
mainfrom
feat/manual-models
Oct 9, 2026
Merged

fylorn merged 1 commit into
mainfrom
feat/manual-models

Conversation

@fylorn

@fylorn fylorn commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

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[].models only 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[].models now 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.
  • The union is made once, in the gateway's listing (tw_gateway::models::listing_of). The catalog, /v1/models (with specs from the price table or model_specs), admission, aliases (resolve), rule-pinned models, key allow, 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_only still applies on top. Changing the list needs no re-fetch: the reload republishes the catalog.
  • Control plane
    • ModelRow has two new fields: manual (the model is in the upstream's models) and listed (the upstream's own list has it). A manual model the upstream also lists has both set. listed is false for every row when the upstream gives no list.
    • New endpoint 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. Like PUT /provider-model-spec, it writes only that upstream's models and leaves the rest of the item and its comments alone (tw_config::edit::set_models).
    • Validation: entries are trimmed, then checked by 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 codes config.manual_model_blank, _padded, _wildcard, _duplicate and _too_long. An unknown upstream is 404 config.edit.not_found, a line break is config.edit.multiline, and a stale base_version is 409.
  • CONTROL_API_VERSION 41 → 42, with a "42 起…" note. Docs: the models row and a short paragraph in docs/config.md and docs/config.zh-CN.md. Diagnostics count models added by hand separately.

Tests

  • tw-config: validation rules; set_models set/replace/clear, inline items, missing upstream, line breaks.
  • tw-gateway unit 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 ts plus the exported TS through tsc --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

…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>
@fylorn
fylorn merged commit ce641c5 into main Oct 9, 2026
5 checks passed
@fylorn
fylorn deleted the feat/manual-models branch October 9, 2026 03:39
@fylorn fylorn mentioned this pull request Oct 9, 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.

1 participant