Repository navigation
fix(server): serve last settled models from /api/model while plugins reload - #57011
Draft
kitlangton wants to merge 1 commit into
Draft
kitlangton wants to merge 1 commit into
kitlangton wants to merge 1 commit into
Conversation
3 of 6 tasks
This branch has not been deployed
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.
Issue for this PR
N/A
Type of change
What does this PR do?
Serves the last settled model catalog and default model from
GET /api/modelandGET /api/model/defaultwhile plugins/config are reloading instead of blocking onawaitPluginsand failing with503 ServiceUnavailableErrorafter 5 s.When global config (
opencode.json) is edited on a server with many loaded Locations (e.g. 133 booted Locations in our Studio server trace),PluginSupervisorholdsPlugin.awaitActivationacross all loaded Locations while debouncing and re-runningPlugin.activateinsideState.batch. During that reload window:Plugin.awaitActivationcan stay pending for >5 s across the loaded Location set (5.1–11.6 s inopencode.log), causingawaitPluginsinModelHandlerto failGET /api/modelwith HTTP 503 (Location plugins did not finish activating within 5 seconds).Plugin.activate'sState.batch, closing a changed plugin's scope removes itsprovider.transform/model.transformregistrations and invalidatesProvider.Service/Model.Servicebefore the replacement finishes loading, so rebuilding on the HTTP fiber mid-batch would observe an incomplete catalog.Changes in
packages/server/src/handlers/model.ts:{ available, default }snapshot perModel.Interfacein aWeakMapwheneverPlugin.awaitActivationis open (Duration.zerocheck).Plugin.awaitActivationis pending on a Location that has already settled a snapshot, immediately return that last settled snapshot (model.updatednotifies clients once the reload batch finishes).awaitPlugins, and if the 5 s wait times out, fall back to the currently available models rather than returning 503.How did you verify your code works?
waits for plugin initialization before listing models).serves the last settled model list and default model while plugins reload, which holds a plugin reload mid-batch afterv1scope teardown, verifiesGET /api/modelandGET /api/model/defaultreturn 200 withchat-v1immediately, then releases the reload gate and verifies both endpoints returnchat-v2.Screenshots / recordings
N/A
Checklist