knqiufan ba3a3f8c54
fix: initialize the web composer with its configured model (#840)
## Summary

The web composer initially displayed hardcoded `minimax-m3` until a full
provider catalogue finished loading, even when another model was
configured. Read the actual model/provider selection immediately after
the gateway handshake, independently of catalogue building and provider
probes when the gateway supports it.

- Add optional `model.options.include_providers` with its existing
full-catalogue behavior as the default. Advertise selection-only support
through `system.hello.server_capabilities`; older strict gateways
receive their original parameters and share one full catalogue request.
- Show loading, empty and retry states. Permit sending once the
selection arrives, and keep a known selection usable during background
refreshes of the same view. First reads and navigation to another
session or a new draft still wait for that view's selection.
- Allow settings role pickers to use their available rows while the
composer's provider catalogue refreshes. Keep New Task available during
selection loading or failure, retain provider-setup redirects, and clear
catalogue loading state if a gateway call throws synchronously.
- Preserve session bindings, forced default providers and staged draft
picks. Ignore responses superseded by navigation or a local pick, and
prevent slow catalogues from overwriting the selection.
- Update fixtures, generated web/TUI contracts, bilingual messages and
user-facing documentation.

Maintainer follow-up on top of the author's commits (no history
rewritten):

- Restored the design comment in `model_options` that explains why a
catalogue read warms the rate catalogue (the picker's context windows
come from it and nothing else on the page refreshes it), and said why a
selection-only read skips it. The handler and module docstrings now
describe `include_providers`.
- Restored the comment in `loadProviders` that explains why a late
catalogue answer is dropped, now also naming a later refresh of the same
view.
- Reverted the remote CLI test change
(`tests/test_subagent_cli_remote.py`), which was unrelated to this fix.
The final diff no longer touches that file. The race it addressed is
real and still open on main (see Risk), so it should land as its own
change; the original commit remains in this branch's history.
- A draft promoted to a conversation keeps its known selection. The
promotion takes no new view ticket, so the first same-view re-read of
the new conversation (a settings-changing tool result, a provider or
default-model write, a typed id) used to drop the chip to "Loading
model..." and refuse sends until that read answered. The promotion now
hands the draft's selection to the session it minted, but only when that
selection was read under the ticket the promotion began on; a reader who
opened another conversation or a new draft during the create keeps that
view's own selection, and a draft whose selection never arrived or
failed still waits. The README says so.
- Named the provider list as `ui-web/CONTEXT.md` does: the two keys this
change added are now `gui.model.provider_catalogue_loading` and
`gui.model.provider_catalogue_failed` (texts unchanged, generated TUI
catalogue regenerated), and the `ModelSource` comment, the README and
this change's test titles say provider catalogue instead of the bare
word, which the existing `gui.model.catalogue_*` keys use for a vendor's
model list.

## Type

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

## Verification

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

Maintainer verification on Linux, Python 3.12 (`--all-extras`), Node 26,
in isolated worktrees with their own virtualenv and `npm ci`. "Merged
tree" means this branch merged into the latest main without committing;
it merges cleanly.

Branch head:

- `uv run --frozen --python 3.12 --all-extras pytest
tests/test_rpc_model.py tests/test_rpc_schema_match.py
tests/test_rpc_system.py -q`: 772 passed (238 in
`tests/test_rpc_model.py` after the wording change).
- `npx vitest run --maxWorkers=6 --testTimeout=20000` in `ui-web` (with
`NODE_OPTIONS=--localstorage-file=...`, which this Node version needs):
4004 passed, 0 failed.
- The promotion regression, `src/state/session/runtime.promote.test.ts`
"the model chip across a promotion": eight cases on the real registry,
promotion, chip source and store with only the transport faked, each run
with and without the selection-only capability. The first-re-read case
fails on the previous head (status `loading`, send refused) and passes
with the fix. Removing the hand-off call fails exactly those two cases
(179 of 181 model and promotion tests still pass); removing its ticket
guard fails exactly the two cases where the reader left during the
create.
- `npm run type-check`, `npm run gen:check`, `npm run lint` in `ui-web`:
pass, lint 0 errors and 4 existing warnings in untouched files. `npm run
lint:rpc` and `npm run lint:i18n` in `ui-tui`: pass.
- `scripts/check_commit_messages.py`, `scripts/check_large_files.py`,
`scripts/check_source_language.py` over the branch, and `commitlint
--from origin/main`: pass.

Merged tree, this head on the latest main (as of #985), merged without
committing:

- Full `ui-web` vitest run as above: 4158 passed, 0 failed.
`type-check`, `gen:check` and `lint` pass; `python ui-web/build.py`
passes both boot snapshots (365 and 364 nodes).
- `tests/test_rpc_model.py`, `tests/test_rpc_schema_match.py`,
`tests/test_rpc_system.py`: 788 passed. `ui-tui` `lint`, `lint:rpc`,
`lint:i18n`, `type-check`: pass. `ruff check`, `ruff format --check`,
`lint-imports` (10 contracts kept), `deptry raven`, `ty check`: pass.

Earlier merged-tree runs, before this round's two follow-up fixes (which
change only web code, the README, i18n keys, test titles and one Python
comment):

- Full Python suite on the merge with main as of #1002, `uv run --frozen
--python 3.12 --all-extras pytest -q`: 33222 passed, 102 failed. Rerun
on bare main on the same machine, exactly those 102 test ids fail there
too (this machine's environment), so no failure is introduced by this
branch. An earlier full run of the merge, against main before #1002,
also errored in the remote CLI cancel test; that test file is identical
to main's, and whole-file runs of it on bare main failed 1 of 5 with the
same race (see Risk).

Real page, before this round's fixes, isolated gateways (own RAVEN_HOME,
loopback only), headless Chromium, configured model
`deepseek/deepseek-chat` with a dummy key, recording the chip text and
the page's own `model.options` frames:

- Main's page on main's gateway: the chip reads `minimax-m3`, enabled,
from 198 ms until the full catalogue answers at 986 ms. This is the
reported bug.
- This page on this gateway: "Loading model..." (disabled) until the
selection-only read answers about 100 ms after the handshake; the chip
shows `deepseek-chat` at 593 ms while the 55-row catalogue answers at
1817 ms.
- This page on main's gateway (no capability): only the legacy `{}` read
is sent, no validation error, and the chip goes from "Loading model..."
to the configured model when that read answers (706 ms).

Earlier verification by the author on Windows, before the follow-up
commits: `tests/test_rpc_model.py` and `tests/test_rpc_schema_match.py`
665 passed; the hello/ping/version/dispatcher subset of
`tests/test_rpc_system.py` 26 passed; `ui-web/build.py` boot snapshots
matched; `ui-web` `npm test` 3,278 passed across 215 suites,
`gen:check`, `type-check`, `build` and `lint` passed; `ui-tui`
`lint:rpc` and `lint:i18n` matched.

## Risk

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

The new read mode is read-only and returns no provider credentials.
Existing RPC callers (the TUI picker and the ACP config options) omit
the field and keep full provider catalogue responses; web clients
negotiate support before sending it. A failed selection read requires a
retry, while a pending refresh of a known selection, including the first
re-read after a draft becomes a conversation, allows sending. Settings
role pickers and task navigation no longer inherit the composer's
loading restriction.

Known behavior, not changed here:

- Every navigation, including the boot's own switch to the draft view,
waits for that view's selection, by design and as tested. On the real
page this shows "Loading model..." again for about 90 ms right after the
first selection appears. Against an older gateway each such wait lasts
as long as the full provider catalogue read.
- With the remote CLI test change removed,
`test_a_cli_run_left_on_the_machine_when_this_computer_stops_is_picked_up_by_the_next_start`
and its cancel sibling keep main's race: they wait for the pid file,
then read the run record that may not be written yet. A parallel local
run of the three RPC files plus that test file on this branch hit it
once. It is the same flake main has today.

Roll back by reverting this change and rebuilding the served web page;
no configuration migration is required.

## Related Issues

Fixes #819

---------

Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Dizhan Xue <xuedizhan17@mails.ucas.ac.cn>
2026-10-19 21:50:30 +08:00
..