Dizhan Xue 0703e03544
fix(*): stop storing display-only provider addresses, which broke Gemini (#865)
## Summary

Connecting Gemini from the settings dialog stored an address nobody
typed, and that broke both halves of the provider: the key check
reported a working key as refused, and every chat went to a path Google
answers 404. This stops the dialog storing addresses it only shows,
heals installs that already hold one, makes the probe ask each affected
vendor where it actually lists its models, and moves Gemini's default to
a model Google still serves to new projects.

**Root cause.** `model.options` hands each vendor's address to the
dialog for display, and for a vendor whose spec states no default that
address is `shown_api_base`, which `registry.py` documents as display
data only. Both Connect paths seeded their address state with it and
sent it even where no address field is drawn: the Connection block in
the provider detail, and the onboarding wizard's add form. For Gemini
that stored Google's bare host. Measured on main before this change,
with a made-up key against generativelanguage.googleapis.com:

- the probe then sent `Authorization: Bearer` to `/v1/models`. Google's
native routes read that header as an OAuth token and answer 401
`CREDENTIALS_MISSING` whatever the key, so the dialog said "The provider
rejects the saved key".
- chat through LiteLLM 1.85.0, the version `uv.lock` pins, built
`/models/<model>:generateContent` from the bare host. Google answers
that path 404, so every turn failed as `model_unavailable`.

The issue reports a working chat beside the 401, which fits a section
holding `.../v1beta` instead: that base keeps chat working and still
sends the probe down the bearer path. This change fixes that case too.

**The stored address was load-bearing elsewhere.** For OpenAI and
DeepSeek the address the dialog wrote was the only thing that let the
probe find their models: with no address, OpenAI sends nothing (LiteLLM
keeps its address inside the SDK) and DeepSeek derives `/beta`, which
lists none. Stopping the write without the last commit below would have
cost dialog-connected OpenAI and DeepSeek their key check and live model
list, so the probe now knows where both list their models.

**What changes**, one commit each unless noted:

- `fix(ui-web)`: each form sends an address only from a field it draws.
The add form derives drawing and sending from one predicate, so the two
cannot part again. A local deployment still connects by the address
typed into its field.
- `fix(*)`: `ProviderSpec.is_display_only` names that address,
`set_provider_fields` stores it as no address (which also clears a proxy
the section held), and config migration 12 removes it once, with a
notice, from installs the dialog already wrote it into. Only the exact
flat address goes, trailing slash aside, in either key spelling; a
proxy, a versioned root on the vendor's own host and the endpoint list
all stay.
- `fix(config)`: a section holding Anthropic's or Google's own address
is probed the way that vendor answers rather than as a proxy. Google's
refusal of a key it does not know, 400 `INVALID_ARGUMENT` with an
ErrorInfo reason of `API_KEY_INVALID`, now reads as `invalid_key`
instead of `http_400`. The second copy of the shape check, which could
never run once an address was derived, goes.
- `fix(providers)`: Gemini's default is `gemini/gemini-3.8-flash`.
Google's deprecations page (updated 2026-10-01) says the 2.5 models are
not deprecated but limited to users who used them before, and points new
projects at 3.8 Flash or 3.5 Flash-Lite. The model leads the curated
shortlist, which the default must sit in, and the wire baseline's
default entry moves with it; that file's docstring records why.
- `fix(config)`: OpenAI and DeepSeek are filed in `_CATALOGUE_SHAPES` at
the address each lists its models from, with the bearer token. That also
reaches a DeepSeek section still holding `/beta` from before its shown
address moved to the root.
- `fix(config)`: an address that does not parse, such as `http://[`, is
reported as a network error instead of raising `ValueError` out of
`test_provider`, whose contract is a dict. The raise was in the proxy
lookup a failed request takes when no transport is injected; it predates
this change and reached every vendor.
- `fix(*)`: `is_display_only` answers no for anything but a string.
`model.set_fields` takes any JSON value, and a number there raised
`AttributeError` from that check, which the RPC answers as an internal
error; the schema refuses it again, as `config_validation_error`. The
migration, which reads the same raw values, drops the type check it
carried for this.
- `fix(config)`, three commits (the rule, a case for its trailing slash,
and a docstring correction): an address counts as the vendor's own only
when it is, as written, its bare host or the root its catalogue hangs
from (both read off the `_CATALOGUE_SHAPES` URL, trailing slash allowed)
or DeepSeek's `/beta`, which sections saved while the settings field
showed it still hold. Any other address, on the vendor's host or not, is
asked where it points, as on main, so an endpoint pasted whole, such as
`https://api.openai.com/v1/chat/completions`, reads as the 404 it is and
another port gets that port's own answer; neither is taken for the
vendor and read as a verified key.
- `refactor(ui-web)`: the Connection block names once where it draws the
address field, above the key or alone, and both places and the send read
that one value; the field is one element. Behaviour is unchanged.
- `docs(config)`: the comment describing `_CATALOGUE_SHAPES` moves above
that table, from above `_CATALOGUE_EXTRAS`.

**Decided, open to a veto.**

- #763 met the same write on DeepSeek and left already-written configs
alone on purpose. This change migrates, because the stored host breaks
Gemini's chat outright, and the dialog cannot clear it either: the
Advanced field equals its shipped default, so it offers no reset button.
-
`test_a_vendor_with_no_catalogue_endpoint_is_reported_as_unprobed_not_unconfigured`
pinned OpenAI as a vendor the probe cannot reach. OpenAI now has a known
catalogue, and it was the last vendor in the registry that rule fitted,
so the test keeps the rule with OpenAI's entry taken out. The
derived-404 test moves from DeepSeek to Z.ai, which still derives its
address.

**Not fixed here.**

- Gemini as an embedding provider. `resolve_provider_credentials` used
to answer the stored bare host for a dialog-connected Gemini, which an
OpenAI-compatible client turns into `/embeddings`, also a 404 on Google
(measured). It now answers None, so an embedding pin on Gemini reports
no usable credential instead of failing on every call. Making it work
means adding Gemini's OpenAI-compatible base,
`https://generativelanguage.googleapis.com/v1beta/openai`, to
`_PROVIDER_BASE_URL_FALLBACK`, which is left for a follow-up.
- A model picked explicitly from the 2.5 line still meets Google's own
refusal on a new project. The shortlist keeps those rows, since Google
still serves them to the accounts that used them.
- An address on a vendor's own host that is not one of its own addresses
above keeps main's probe, which for Google and Anthropic is still the
bearer path, so Gemini's `/v1`, for one, still reads as a refused key.
Widening the list needs each such address checked against what the
vendor serves there.
- A section holding `https://api.anthropic.com/v1` is probed at
Anthropic's catalogue and its key reads as verified, but LiteLLM appends
`/v1/messages` to any Anthropic base that does not end in it, so chat at
that address goes to `/v1/v1/messages` and is answered 404, on main as
here. The probe checks the key; the route chat builds from the address
is LiteLLM's.
- `tests/integration/test_provider_real_llm.py` still expects Anthropic
to be unprobed, which has not held since Anthropic's catalogue was filed
in `_CATALOGUE_SHAPES`. It fails on main the same way, and CI does not
collect that directory, so it is left alone.

## Type

- [x] Fix
- [ ] Feature
- [ ] Docs
- [ ] CI / tooling
- [ ] Refactor
- [ ] Other

## Verification

Each new test was run red before its fix, failing for the reason it
names: twenty Python cases and two `ui-web` tests. The rest were proved
by withdrawing, one at a time, what they hold:

- forcing the add form's send condition false fails `the add form sends
the address it draws`;
- in `is_display_only`, dropping the default guard, the trailing-slash
fold or the equality (for a prefix match) each fails
`test_only_the_address_a_spec_shows_in_place_of_a_default_is_display_only`,
and dropping the string check fails all seven non-string cases, the
migration's among them;
- in the own-address match, dropping the bare host or the trailing-slash
fold fails the bare-host case, dropping the catalogue root fails the
`/v1beta` and `/v1` cases, emptying the extra list fails DeepSeek's
`/beta`, and comparing hostnames again fails exactly the three cases for
other addresses on a vendor's host;
- in the Connection block, sending only from the field above the key, or
drawing none alone, fails `sends the address from the field it draws
alone for a vendor that takes no key`, which also fails when the send's
former condition loses its second clause, an edit that left the whole
suite green before that test; drawing none above the key fails the local
and Azure tests, and sending whatever the block holds fails the key-only
vendor's.

Python, in an environment from `uv sync --frozen --python 3.12
--all-extras`, proxy variables unset:

```
pytest -q -p no:randomly
-> 27578 passed, 115 skipped, 2 failed
```

Both failures fail identically on main at this branch's base, on this
machine only (an npm elsewhere on PATH, and root reading a file the test
makes unreadable):

```
tests/test_install_script.py::test_resolve_node_dir_answers_each_case_it_exists_for
tests/test_subagent_node_runtime.py::test_what_cannot_be_read_names_nothing
```

Each intermediate commit's own tree passes the config and provider
suites (`tests/test_config_update_providers.py`,
`test_config_loader.py`, `test_provider_registry_data.py`,
`test_provider_catalog.py`, `test_provider_wire_model.py`,
`test_rpc_model.py`): 924 passed after the second commit, 927 after the
third.

`ui-web`, serially, with `--localstorage-file` set because node 26 on
this machine needs it:

```
vitest run --no-file-parallelism
-> Test Files 214 passed (214), Tests 3189 passed (3189), no unhandled errors
```

That run includes the 46 gate files under `ui-web/scripts/`.

Static checks:

```
ruff check; ruff format --check     -> clean
lint-imports                        -> 10 kept, 0 broken
ty check (the lint-types targets)   -> all checks passed
eslint .                            -> 0 errors, 4 warnings in untouched files
tsc --noEmit -p tsconfig.json       -> clean
node scripts/gen-rpc-client.mjs --check -> matches the contract
pre-commit run --from-ref origin/main --to-ref HEAD -> all passed, no file modified
scripts/check_commit_messages.py, commitlint,
scripts/check_large_files.py, scripts/check_source_language.py -> exit 0
```

End to end, on an isolated `raven web` (its own `RAVEN_HOME`,
`--foreground`, serving this branch's `ui-web` build) driven by headless
Chromium, with made-up keys only:

- a config holding Gemini's bare host at migration stamp 11 boots with
the address gone, the notice logged, the other sections untouched and
the stamp at 12;
- "Check connection" on Gemini sends `x-goog-api-key`, and Google's 400
`API_KEY_INVALID` for the made-up key shows as "The provider rejects the
saved key", now because of the key rather than the header;
- Connect on Anthropic, OpenAI and DeepSeek in the dialog, and on OpenAI
in the wizard's add form, sends `model.save_key` with `slug` and
`api_key` only, and no section stores an address;
- with no stored address the probe reaches OpenAI's and DeepSeek's own
catalogues, and each vendor answers the made-up key with its 401, where
OpenAI's probe used to send nothing;
- the address field of a local deployment (Ollama), drawn above the key,
is drawn once and sends the address typed into it;
- a chat turn on the migrated config reaches Google's route and is
refused as `API key not valid` instead of returning 404.

The wizard's add-form run and the chat turn are from before the review
commits, which touch neither the add form nor the chat route; everything
else above was run again on the final build.

The docs box is left unchecked: no user-facing document describes the
address field or which header the probe sends.

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [ ] User-facing docs or screenshots are updated when needed

## Risk

- Config migration 12 rewrites `config.json` once: a provider's flat
`apiBase` / `api_base` that equals the address the dialog shows for a
vendor stating no default (OpenAI, Anthropic, Gemini, DeepSeek, Z.ai,
Groq) is removed, with a notice. Such a section then behaves like one
that never stored an address. For OpenAI, Z.ai and Groq a chat request
goes to the same URL as before; Anthropic's native client uses the same
host; Gemini's chat starts working; DeepSeek's chat moves from the root
to `/beta`, LiteLLM's default and the path every section without a
stored address already uses.
- Writing that exact address through any write path now stores no
address, and clears whatever address the section held.
- The probe now sends a request for an OpenAI or DeepSeek section with
no address, to that vendor's own catalogue, where before it sent nothing
(OpenAI) or asked `/beta` (DeepSeek); the model picker gets a live list
for those sections. A section holding Anthropic's, Google's, OpenAI's or
DeepSeek's own address (the bare host, the root its catalogue hangs
from, or DeepSeek's `/beta`) is probed at that vendor's catalogue with
that vendor's header; any other address is asked where it points, as on
main. Keys go nowhere new: the host is the vendor's either way.
- Gemini's default moves for installs whose Gemini section lists no
models. A configured `gemini/gemini-2.5-flash` still routes to Gemini
and is still accepted (measured on both trees).
- Rollback: revert the squash commit. The migration does not restore
what it removed; each removed value is the vendor's own address, so
typing it back restores the old behaviour exactly, including the old
failure on Gemini.

- [x] Security impact considered
- [x] Backward compatibility considered
- [x] Rollback path is clear for risky changes

## Related Issues

Fixes #820

The same write on DeepSeek: #763

---------

Co-authored-by: Claude (claude-opus-5-5[1m]) <noreply@anthropic.com>
2026-10-08 16:57:30 +08:00
..