Skip to content

fix(session): models that load after the first read show up without reopening - #78

Merged
Tarquinen merged 1 commit into
devfrom
reload-models-on-update
Nov 14, 2026
Merged

Tarquinen merged 1 commit into
devfrom
reload-models-on-update

Conversation

@rekram1-node

Copy link
Copy Markdown
Member

The server changes its model, provider and agent lists after the app reads them. Plugins finish loading after a cold start, and config edits, plugin installs and logins change the lists too. The server announces each change on the event stream (model.updated, provider.updated, agent.updated), but the app dropped those events. A session screen read its model list once and only read it again after a failure or when it was empty.

Before: a model from a plugin that finished loading late never appeared in the model picker until the session was reopened. Even then, the 30 s catalog cache could return the partial list.

After: the open session screen reads the model list again when the server says it changed. A partial list is replaced by the full one, without reopening anything.

What changed

  • model.updated and provider.updated decode to OpenCodeServerEvent.ModelsChanged, and agent.updated decodes to AgentsChanged. The payloads aren't read.
  • A ModelsChanged clears that server's cached model lists (OpenCodeReadCache.forgetModelCatalogs) before the event reaches the reducers, so the next read goes to the server.
  • Home forwards both events to every open session screen. ModelsChanged rereads the list through the existing reloadModels, which cancels a read in flight, so a burst of events while plugins load leaves one read standing. AgentsChanged lists the agents again while Agent Selection is on.
  • The parity rows in docs/parity/server.md, session.md and drawer.md note that this differs from iOS on purpose.

This pairs with anomalyco/opencode#63814, where the server stops waiting for plugins before answering /api/model. After that change, the first read on a cold server can return a partial list. That PR should merge after this one ships.

Verified

  • scripts/check.sh :server :feature:session :feature:drawer (assembleDebug, lintDebug, testDebugUnitTest) passes: 337 server tests (2 skipped live checks), 812 session tests, 558 drawer tests.
  • New tests:
    • OpenCodeEventDecodingTests.catalogUpdatesDecodeAsCatalogChanges: the three events decode, with or without location and data. This replaces the old check that model.updated and provider.updated decode to null.
    • OpenCodeClientDecodingTests.forgettingModelCatalogsDropsOnlyThatServersCatalogs
    • ModelPickerTests.aCatalogChangeRereadsModelsAndReplacesAPartialList: a second change cancels the hung first read, and the answer replaces the partial list.
    • SessionFeatureTestsAgentSelection.anAgentsChangeListsAgentsAgain
  • Not checked on the emulator.

…eopening

The server changes its model, provider and agent catalogs after the app
reads them: plugins finish loading after a cold start, and config edits,
plugin installs and logins change them too. It announces each change with
`model.updated`, `provider.updated` or `agent.updated`, but the app
dropped those events, and a session screen read its model catalog once.
A model from a plugin that loaded late never appeared in the picker until
the session was reopened, and the 30 s catalog cache could hand back the
partial list even then.

Now `model.updated` and `provider.updated` decode to `ModelsChanged`,
which forgets the server's cached model catalogs and makes every open
session screen reread its catalog through `reloadModels` (cancelling a
read in flight, so a burst leaves one read standing). `agent.updated`
decodes to `AgentsChanged`, which lists the agents again while Agent
Selection is on. The parity rows note the difference from iOS.

Verified: scripts/check.sh :server :feature:session :feature:drawer
(assembleDebug, lintDebug, testDebugUnitTest) passes; new tests cover the
decoding, the cache, the model reread replacing a partial list after a
cancelled read, and the agents relist.
@Tarquinen
Tarquinen merged commit a59a8c6 into dev Nov 14, 2026
3 checks passed
@Tarquinen Tarquinen mentioned this pull request Nov 15, 2026

This branch was previously deployed

1 inactive deployment
release — 5ce0e28f Deployed Nov 14, 2026 by rekram1-node via check #228
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.

2 participants