fix(core): reuse model catalog across credential changes - #49255
Merged
Merged
Conversation
6 tasks
Every credential change reached each open Location and, because the provider snapshot was keyed on every connection of every integration, produced a new snapshot even when the same providers stayed available. Model treated that as a catalog change and rebuilt from scratch: deep copying every model, replaying every transform, re-merging provider settings, and publishing model.updated so clients refetched. With many Locations open, one /connect did all of that per Location, twice. Key the snapshot on which provider definitions are available, so a credential switch that changes nothing returns the same snapshot and publishes nothing. Let Model share provider definition maps and copy a provider's map and a model only on their first edit, and reuse merged output for models whose definition and provider record are unchanged, so the rebuild for a genuinely new provider costs only that provider. Provider's index now gives foreign definitions the registering provider's identity, which Model previously did on every rebuild.
Wait for the connect's model.updated before switching credentials so the event count no longer depends on subscriber fibers keeping pace, and add a test that direct edits to models returned by list and get persist into the catalog without touching shared definitions. Also tidy the definition index write, draft's early returns, and the provider selection in list.
thdxr
force-pushed
the
catalog-sharing
branch
from
September 16, 2026 03:01
9cff874 to
666187a
Compare
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
Closes #49109 (supersedes it). Reported in #core:
/connecttook 3–5 seconds with 10+ Locations open.Type of change
What does this PR do?
Problem. Every credential change fans out to each open Location.
Provider.snapshot()keyed its cache on every connection of every integration, so switching the active credential produced a new snapshot even when the same providers stayed available.Modelused snapshot identity as its invalidation signal and rebuilt the whole catalog:structuredCloneof every model, replay of every transform, re-merge of provider settings, deep freeze, thenprovider.updated+model.updated, which made clients refetch the full model list.Credential.createfires two events, so this ran twice per Location per/connect.Fix, in three parts.
Provider.snapshot()now keys its cache on which provider definitions are available (elementwise compare of theavailablelist). A credential switch that leaves the same providers connected returns the same snapshot, so nothing downstream reacts and no events fire. This is the same idea as fix(core): reuse models across credential switches #49109 with one cache key instead of two; the oldaccessstring is removed.Modelno longer deep-copies every model on rebuild.initial()points at the provider's frozen definition maps; a provider's map and a model are copied on their first edit only (whether viaupdate(),get(), orlist()), mirroring thewritable()pattern already in Provider's editor.read()remembers each model's merged output while its source definition and provider record are unchanged. A rebuild for a genuinely new provider therefore costs that provider's models, not the catalog — the case fix(core): reuse models across credential switches #49109 did not cover.providerIDand gives foreign definitions the registering provider's identity.Model.initial()used to do this fix-up on every rebuild; doing it once where definitions are registered is what lets Model share them as-is.No user-facing or plugin-facing changes. The editor API and its mutable
list()/get()results are unchanged, transforms see the same models they saw before (connected providers only), and the HTTP surface is untouched.Measured with a 6,000-model provider in one Location, before → after:
How did you verify your code works?
packages/core/test/catalog.test.ts: a credential switch reuses the catalog and publishes nomodel.updated; foreign definitions get the registering provider's identity; a newly available provider leaves existing model objects untouched. The first and third fail onv2without this change; the second fails if the fix-up inProvider.indexis removed.bun testacross the model/provider/plugin suites inpackages/core(1,048 pass),bun typecheck,bun run lint.v2for the table above (not committed).Screenshots / recordings
Not a UI change.
Checklist
from OpenCode