mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix(coderd): invalidate chatd provider cache on AI provider changes (#26987)
chatd subscribes to `ChatConfigEventChannel` and invalidates its provider cache on a `providers` event kind, but nothing ever published that kind. AI provider CRUD only publishes on `AIProvidersChangedChannel` (consumed by aibridged and aibridgeproxyd), so chatd's provider cache only converged via its 10 second TTL. Subscribe chatd to the same `AIProvidersChangedChannel` publish instead of adding a second publish, per the review feedback on #26207: one publish, multiple subscribers. The now-unused `ChatConfigEventProviders` kind is removed so `ChatConfigEvent` stays scoped to model configs, user prompts, and advisor config, and can't regrow a dead subscriber. Follow-up to CRF-5 from the review of #25673. Supersedes #26207. Closes CODAGT-499
This commit is contained in:
@@ -2,8 +2,8 @@ package pubsub
|
||||
|
||||
// AIProvidersChangedChannel is the pubsub channel that carries AI
|
||||
// provider lifecycle events: provider create / update / soft-delete
|
||||
// and key insert / delete. Subscribers (aibridged, aibridgeproxyd)
|
||||
// reload their in-memory provider snapshot on receipt.
|
||||
// and key insert / delete. Subscribers (aibridged, aibridgeproxyd,
|
||||
// chatd) reload their in-memory provider snapshot on receipt.
|
||||
//
|
||||
// The payload is an empty invalidation hint; subscribers refetch the
|
||||
// authoritative state from the database, so dropped messages only
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
// ChatConfigEventChannel is the pubsub channel for chat config
|
||||
// changes (providers, model configs, user prompts, advisor config).
|
||||
// changes (model configs, user prompts, advisor config).
|
||||
// All replicas subscribe to this channel to invalidate their local
|
||||
// caches.
|
||||
const ChatConfigEventChannel = "chat:config_change"
|
||||
@@ -33,13 +33,11 @@ func HandleChatConfigEvent(cb func(ctx context.Context, payload ChatConfigEvent,
|
||||
}
|
||||
|
||||
// ChatConfigEvent is published when chat configuration changes
|
||||
// (provider CRUD, model config CRUD, user prompt updates, or advisor
|
||||
// config updates). Subscribers use this to invalidate their local
|
||||
// caches.
|
||||
// (model config CRUD, user prompt updates, or advisor config
|
||||
// updates). Subscribers use this to invalidate their local caches.
|
||||
type ChatConfigEvent struct {
|
||||
Kind ChatConfigEventKind `json:"kind"`
|
||||
// EntityID carries context for the invalidation:
|
||||
// - For providers: uuid.Nil (all providers are invalidated).
|
||||
// - For model configs: the specific config ID.
|
||||
// - For user prompts: the user ID.
|
||||
// - For advisor config: uuid.Nil (singleton site-config row).
|
||||
@@ -49,7 +47,6 @@ type ChatConfigEvent struct {
|
||||
type ChatConfigEventKind string
|
||||
|
||||
const (
|
||||
ChatConfigEventProviders ChatConfigEventKind = "providers"
|
||||
ChatConfigEventModelConfig ChatConfigEventKind = "model_config"
|
||||
ChatConfigEventUserPrompt ChatConfigEventKind = "user_prompt"
|
||||
ChatConfigEventAdvisorConfig ChatConfigEventKind = "advisor_config"
|
||||
|
||||
Reference in New Issue
Block a user