Skip to content

perf(core): ignore credential events for unrelated integrations - #60782

Merged
rekram1-node merged 1 commit into
devfrom
credential-event-filter
Oct 31, 2026
Merged

rekram1-node merged 1 commit into
devfrom
credential-event-filter

Conversation

@rekram1-node

Copy link
Copy Markdown
Collaborator

Problem

Every Location runs two listeners that wake up on any credential event for any integration:

  • credentialSettings (Bedrock, both Cloudflare plugins, GitLab) re-reads its integration's active credential on every credential.updated and credential.switched, even when the event is about some other integration. That's 4 listeners doing a list plus a get each, per Location, per event.
  • Provider runs notify (snapshot plus integrations.list(), which reads every credential) on every credential.updated, even though that event can't change which providers are available.

Change

credential.updated is only published for a create, a label rename or a remove. Any of those that changes the active credential also publishes credential.switched. So updated alone never changes the active credential's value, and never takes an integration from zero connections to some or back.

 credentialSettings
-  subscribe([Credential.Updated, Credential.Switched])
+  subscribe(Credential.Switched)
+  filter(event.integrationID === integrationID)

 Provider
-  subscribe([Integration.Updated, Credential.Updated, Credential.Switched])
+  subscribe([Integration.Updated, Credential.Switched])

What that buys per Location:

event before after
add/switch/remove a credential for an unrelated integration 4 settings reloads (x2 when updated also fires) 0
credential add or active remove 2 provider notifies 1
label rename, inactive add or remove 1 provider notify, 4 settings reloads nothing

I added a test that a Cloudflare Workers AI form login switch still updates the account ID, so the filter doesn't drop its own integration's events.

Out of scope

  • Provider still reacts to every credential.switched, including integrations it has no provider for. Filtering that would mean checking the provider records on each event, and the switch is rare enough that I left it.
  • google-vertex.ts and config/plugin/policy.ts have the same unfiltered subscription shape.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found no problems with this change. I checked the publish sites in credential.ts. credential.updated on its own (a label rename, an inactive create or an inactive remove) never changes the active credential or the number of connections. Every create, activate or remove that does change them also publishes credential.switched, including the first and last credential for an integration. The provider snapshot keys connections by ID and ignores labels, so dropping Updated and filtering Switched by integrationID can't hide a real change. The core plugin, provider, credential and integration tests pass (582). typecheck:tsc passes too; the typecheck script itself fails on both base and PR because the installed bun has no check command.

The public API is unchanged: event shapes and publishers stay the same, and only internal subscriptions changed.

@rekram1-node
rekram1-node merged commit 2d800e4 into dev Oct 31, 2026
18 of 22 checks passed
@rekram1-node
rekram1-node deleted the credential-event-filter branch October 31, 2026 03:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant