From 5eebd10f465efcf66eeca0e6ced7a913fc0c8073 Mon Sep 17 00:00:00 2001 From: Kanat Date: Mon, 23 Nov 2026 22:50:33 +0100 Subject: [PATCH 01/11] WIP: store sync_hash on connector definitions and router configs --- acceleration/api/openapi.yaml | 20 +++++++++++ acceleration/internal/api/connectors.go | 10 ++++-- acceleration/internal/api/routerconfigs.go | 11 ++++++ acceleration/internal/api/schemas.go | 1 + .../internal/store/connector_definition.go | 35 +++++++++++++++---- acceleration/internal/store/router_config.go | 22 +++++++----- ...70201000800_connector_router_sync_hash.sql | 12 +++++++ 7 files changed, 93 insertions(+), 18 deletions(-) create mode 100644 acceleration/migrations/global/20270201000800_connector_router_sync_hash.sql diff --git a/acceleration/api/openapi.yaml b/acceleration/api/openapi.yaml index 9f916f17fa..37eede5a9e 100644 --- a/acceleration/api/openapi.yaml +++ b/acceleration/api/openapi.yaml @@ -3548,6 +3548,10 @@ components: setup: $ref: '#/components/schemas/ConnectorSetup' description: What a person does at the provider before the first consent, such as registering an OAuth client. Absent when the manifest says nothing. + sync_hash: + description: The fingerprint of the file the CLI last synced onto this connector. Absent on a built-in, and on a connector that was never synced or was written since by anything that is not a sync. + readOnly: true + type: string required: - id - revision @@ -4688,6 +4692,12 @@ components: nullable: true type: array uniqueItems: true + sync_hash: + description: 'The fingerprint of the file this definition was synced from, which the connector then carries. Absent for a write that is no sync: the connector then carries none. Sending a definition the newest revision already says with another hash stores no new revision and records the hash on that one.' + maxLength: 128 + pattern: ^[!-~]*$ + patternDescription: printable ASCII without a space + type: string required: - id - name @@ -8714,6 +8724,10 @@ components: $ref: '#/components/schemas/StsOptions' stt: $ref: '#/components/schemas/SttOptions' + sync_hash: + description: The fingerprint of the file the CLI last synced onto this config. Absent if it was never synced, or was written since by anything that is not a sync. + readOnly: true + type: string tts: $ref: '#/components/schemas/TtsOptions' updated_at: @@ -8738,6 +8752,12 @@ components: $ref: '#/components/schemas/StsOptions' stt: $ref: '#/components/schemas/SttOptions' + sync_hash: + description: The fingerprint of the file this config was synced from, which the config then carries. Absent for a write that is no sync, which clears it. A replace with the hash the config carries and the same content writes nothing. + maxLength: 128 + pattern: ^[!-~]*$ + patternDescription: printable ASCII without a space + type: string tts: $ref: '#/components/schemas/TtsOptions' required: diff --git a/acceleration/internal/api/connectors.go b/acceleration/internal/api/connectors.go index 9375c644eb..6aa8d024fb 100644 --- a/acceleration/internal/api/connectors.go +++ b/acceleration/internal/api/connectors.go @@ -51,6 +51,7 @@ type Connector struct { RedirectURI string `json:"redirect_uri,omitempty" readOnly:"true" format:"uri" doc:"The redirect URI an OAuth client registered for this connector has to list: where every consent of this deployment sends the browser back to, ROUTER_PUBLIC_URL followed by /v1/agents/connectors/oauth/callback. Only on a connector that connects with oauth2_code, and absent when ROUTER_PUBLIC_URL is not set, since no consent can start then."` Channel bool `json:"channel" readOnly:"true" doc:"The connector is an inbound channel: its manifest reads messages a provider delivers to the router, which agents answer. A block that reads only signals, such as Slack with a user token, is not one. A dashboard warns on it before a delete that would end those replies."` Sandbox *ConnectorSandbox `json:"sandbox,omitempty" readOnly:"true" doc:"How code in an agent's sandbox calls the provider's API with a connection's credential without holding it. Absent when the connector offers no such access."` + SyncHash string `json:"sync_hash,omitempty" readOnly:"true" doc:"The fingerprint of the file the CLI last synced onto this connector. Absent on a built-in, and on a connector that was never synced or was written since by anything that is not a sync."` CreatedAt time.Time `json:"created_at" readOnly:"true" doc:"When this revision was stored."` } @@ -162,7 +163,10 @@ type ConnectorPage struct { // scopes is well over the longest list shipped, Slack's 29 (providers/slack.yaml), and is // not measured either. A scope is RFC 6749 section 3.3's scope-token, %x21 / %x23-5B / // %x5D-7E, so it can hold neither a space nor a quote. The schemes have no count: each must -// be a registered one and none may repeat, which bounds them. +// be a registered one and none may repeat, which bounds them. A sync hash is up to 128 +// characters, a SHA-512 hex digest, well over the 32 of the MD5 hex digest the CLI computes +// for an agent (Agentrc.Hash in GetStream/cli internal/agentrc/agentrc.go), and printable +// ASCII without a space, so it holds no NUL, which a Postgres text column refuses. type CustomConnectorRequest struct { ID string `json:"id" pattern:"^custom_[a-z][a-z0-9_]{0,56}$" patternDescription:"custom_ then a lowercase letter, then up to 56 lowercase letters, digits or underscores" doc:"Starts with custom_, which no built-in does, so a custom definition never stands in for one. Creating an id that exists stores the next revision, unless the newest already says the same."` Name string `json:"name" minLength:"1" maxLength:"120"` @@ -172,6 +176,7 @@ type CustomConnectorRequest struct { Schemes []string `json:"schemes" minItems:"1" doc:"How a connection may authenticate. Each must be a scheme this deployment has, except oauth2_client_credentials, which a custom connector cannot use: it needs a token endpoint a custom connector cannot set."` Scopes []string `json:"scopes,omitempty" maxItems:"100" uniqueItems:"true" pattern:"^[!#-\\[\\]-~]+$" patternDescription:"an RFC 6749 scope token" doc:"The scopes a consent asks for, each an RFC 6749 scope token."` Client *ConnectorClient `json:"client,omitempty"` + SyncHash string `json:"sync_hash,omitempty" maxLength:"128" pattern:"^[!-~]*$" patternDescription:"printable ASCII without a space" doc:"The fingerprint of the file this definition was synced from, which the connector then carries. Absent for a write that is no sync: the connector then carries none. Sending a definition the newest revision already says with another hash stores no new revision and records the hash on that one."` } func (*CustomConnectorRequest) TransformSchema(_ huma.Registry, schema *huma.Schema) *huma.Schema { @@ -348,7 +353,7 @@ func (s *Server) createConnector(ctx context.Context, request *createConnectorRe return nil, invalidRequest(store.StreamSource + " is the source of the router's own events, which no connector may be named") } // Every refusal a caller can cause is above, so what the store refuses here is a bug. - definition, err := s.store.ConnectorDefinitions.Revise(ctx, customerID, manifest) + definition, err := s.store.ConnectorDefinitions.ReviseSynced(ctx, customerID, manifest, request.Body.SyncHash) if err != nil { return nil, err } @@ -495,6 +500,7 @@ func connectorOf(definition store.ConnectorDefinition, publicURL string) Connect AuthMethod: ConnectorClientAuthMethod(manifest.Client.AuthMethod), Alg: manifest.Client.Alg, }, + SyncHash: definition.SyncHash, CreatedAt: definition.CreatedAt, } } diff --git a/acceleration/internal/api/routerconfigs.go b/acceleration/internal/api/routerconfigs.go index caf896ad1f..53a4fc464e 100644 --- a/acceleration/internal/api/routerconfigs.go +++ b/acceleration/internal/api/routerconfigs.go @@ -121,6 +121,13 @@ func (s *Server) updateRouterConfig(ctx context.Context, request *updateRouterCo } config := storedRouterConfig(*request.Body, customerID) + // A sync of the file last synced onto the config, which nothing has written since: every + // other write clears the hash. The content is compared too, so a body that differs under + // the same hash is written rather than dropped. + if config.SyncHash != "" && config.SyncHash == existing.SyncHash && + len(auditDiff(routerConfigOf(existing), routerConfigOf(config))) == 0 { + return &updateRouterConfigResponse{Body: routerConfigOf(existing)}, nil + } config.ID = existing.ID config.CreatedAt = existing.CreatedAt if err := s.store.RouterConfigs.Update(ctx, &config); err != nil { @@ -342,6 +349,7 @@ func storedRouterConfig(request RouterConfigRequest, customerID string) store.Ro LLM: llmOptionsOf(request.Llm), STS: stsOptionsOf(request.Sts), Search: searchOptionsOf(request.Search), + SyncHash: request.SyncHash, } config.STT.Keyterms = stt.CleanKeyterms(config.STT.Keyterms) return config @@ -357,6 +365,7 @@ func routerConfigOf(config store.RouterConfig) RouterConfig { Llm: llmOptionsFor(config.LLM), Sts: stsOptionsFor(config.STS), Search: searchOptionsFor(config.Search), + SyncHash: config.SyncHash, CreatedAt: config.CreatedAt, UpdatedAt: config.UpdatedAt, } @@ -549,4 +558,6 @@ type RouterConfigRequest struct { Sts *StsOptions `json:"sts,omitempty"` Stt *SttOptions `json:"stt,omitempty"` Tts *TtsOptions `json:"tts,omitempty"` + // The limits on a sync hash are CustomConnectorRequest's. + SyncHash string `json:"sync_hash,omitempty" maxLength:"128" pattern:"^[!-~]*$" patternDescription:"printable ASCII without a space" doc:"The fingerprint of the file this config was synced from, which the config then carries. Absent for a write that is no sync, which clears it. A replace with the hash the config carries and the same content writes nothing."` } diff --git a/acceleration/internal/api/schemas.go b/acceleration/internal/api/schemas.go index c4c02461cd..7414c2932b 100644 --- a/acceleration/internal/api/schemas.go +++ b/acceleration/internal/api/schemas.go @@ -784,6 +784,7 @@ type RouterConfig struct { Sts *StsOptions `json:"sts,omitempty"` Stt *SttOptions `json:"stt,omitempty"` Tts *TtsOptions `json:"tts,omitempty"` + SyncHash string `json:"sync_hash,omitempty" readOnly:"true" doc:"The fingerprint of the file the CLI last synced onto this config. Absent if it was never synced, or was written since by anything that is not a sync."` UpdatedAt time.Time `json:"updated_at"` } diff --git a/acceleration/internal/store/connector_definition.go b/acceleration/internal/store/connector_definition.go index 772c7f11f9..242e33a32a 100644 --- a/acceleration/internal/store/connector_definition.go +++ b/acceleration/internal/store/connector_definition.go @@ -63,7 +63,11 @@ type ConnectorDefinition struct { Category string `bun:"category,notnull"` Description string `bun:"description,notnull"` Manifest core.Manifest `bun:"manifest,type:jsonb,notnull"` - CreatedAt time.Time `bun:"created_at,notnull"` + // SyncHash is a fingerprint of the file the CLI last synced onto this revision + // (20270201000800_connector_router_sync_hash.sql). Empty for a built-in, and for a revision + // that was never synced or was written since by anything that is not a sync. + SyncHash string `bun:"sync_hash,notnull"` + CreatedAt time.Time `bun:"created_at,notnull"` } // Validate refuses a revision the table's checks refuse: a custom id is a customer's and only a @@ -118,8 +122,15 @@ func (r *ConnectorDefinitions) Seed(ctx context.Context, fsys fs.FS) error { // Revise stores a customer's own definition as the next revision of its // id, or returns the latest revision when that already says the same. The manifest's own -// revision is replaced: the store numbers revisions. +// revision is replaced: the store numbers revisions. It is no sync, so the revision it returns +// carries no sync hash. func (r *ConnectorDefinitions) Revise(ctx context.Context, customerID string, manifest core.Manifest) (ConnectorDefinition, error) { + return r.ReviseSynced(ctx, customerID, manifest, "") +} + +// ReviseSynced is Revise for a write that carries the fingerprint of the file it came from, +// which the revision it returns then carries: empty for a write that is not a sync. +func (r *ConnectorDefinitions) ReviseSynced(ctx context.Context, customerID string, manifest core.Manifest, syncHash string) (ConnectorDefinition, error) { if customerID == BuiltinCustomer { return ConnectorDefinition{}, stack.Wrap(errors.New("store: customer id is required")) } @@ -127,7 +138,7 @@ func (r *ConnectorDefinitions) Revise(ctx context.Context, customerID string, ma if err := probe.Validate(); err != nil { return ConnectorDefinition{}, stack.Wrap(err) } - return r.saveRevision(ctx, customerID, manifest) + return r.saveRevision(ctx, customerID, manifest, syncHash) } // Get returns one revision of a definition the customer can see: a built-in @@ -267,14 +278,15 @@ func (r *ConnectorDefinitions) Select(ctx context.Context, customerID string, fi } // saveRevision stores a custom manifest as the next revision of its id under the customer, -// unless the latest revision already says the same, in which case that one is returned. A -// custom definition has one writer, the customer through the API, so the store numbers it. +// unless the latest revision already says the same, in which case that one is returned with +// syncHash recorded on it. A custom definition has one writer, the customer through the API, +// so the store numbers it. // // It runs under a transaction-scoped advisory lock on the customer and id, so two routers // starting at once, or two requests creating the same custom id, take turns: the second // finds the first's revision and either matches it or follows it. The primary key would // refuse a duplicate revision anyway; the lock is what turns that into a wait, not an error. -func (r *ConnectorDefinitions) saveRevision(ctx context.Context, customerID string, manifest core.Manifest) (ConnectorDefinition, error) { +func (r *ConnectorDefinitions) saveRevision(ctx context.Context, customerID string, manifest core.Manifest, syncHash string) (ConnectorDefinition, error) { var saved ConnectorDefinition err := r.store.global.RunInTx(ctx, nil, func(ctx context.Context, tx bun.Tx) error { if err := lockUntilCommit(ctx, tx, customerID+"/"+manifest.ID, definitionLockSeed); err != nil { @@ -294,7 +306,15 @@ func (r *ConnectorDefinitions) saveRevision(ctx context.Context, customerID stri } if same { saved = latest - return nil + if latest.SyncHash == syncHash { + return nil + } + // The same manifest, from a file of another fingerprint or from a write that is no + // sync: no new revision, but the hash is this write's, so the CLI's next sync of + // that file finds it unchanged, and one after an edit elsewhere does not. + saved.SyncHash = syncHash + _, err := tx.NewUpdate().Model(&saved).Column("sync_hash").WherePK().Exec(ctx) + return err } manifest.Revision = latest.Revision + 1 } @@ -311,6 +331,7 @@ func (r *ConnectorDefinitions) saveRevision(ctx context.Context, customerID stri Category: manifest.Category, Description: manifest.Description, Manifest: manifest, + SyncHash: syncHash, CreatedAt: time.Now().UTC(), } if err := saved.Validate(); err != nil { diff --git a/acceleration/internal/store/router_config.go b/acceleration/internal/store/router_config.go index e72d053683..a4393339a8 100644 --- a/acceleration/internal/store/router_config.go +++ b/acceleration/internal/store/router_config.go @@ -30,14 +30,18 @@ type RouterConfig struct { // The option blocks, one per routed modality. They are the routing package's own // types rather than copies of them, so what is stored and what reaches a provider // cannot drift apart. - STT options.STT `bun:"stt,type:jsonb"` - TTS options.TTS `bun:"tts,type:jsonb"` - LLM options.LLM `bun:"llm,type:jsonb"` - STS options.STS `bun:"sts,type:jsonb"` - Search options.Search `bun:"search,type:jsonb"` - CreatedAt time.Time `bun:"created_at,notnull"` - UpdatedAt time.Time `bun:"updated_at,notnull"` - DeletedAt *time.Time `bun:"deleted_at"` + STT options.STT `bun:"stt,type:jsonb"` + TTS options.TTS `bun:"tts,type:jsonb"` + LLM options.LLM `bun:"llm,type:jsonb"` + STS options.STS `bun:"sts,type:jsonb"` + Search options.Search `bun:"search,type:jsonb"` + // SyncHash is a fingerprint of the file the CLI last synced onto this config + // (20270201000800_connector_router_sync_hash.sql), as AgentConfig.SyncHash is for a + // directory. Empty if it was never synced, or was written since by anything that is not a sync. + SyncHash string `bun:"sync_hash,notnull"` + CreatedAt time.Time `bun:"created_at,notnull"` + UpdatedAt time.Time `bun:"updated_at,notnull"` + DeletedAt *time.Time `bun:"deleted_at"` } // Validate refuses a config the table would refuse. @@ -107,7 +111,7 @@ func (r *RouterConfigs) Update(ctx context.Context, config *RouterConfig) error return tx.NewUpdate().Model(config). With("was", was). TableExpr("was"). - Column("name", "stt", "tts", "llm", "sts", "search", "updated_at"). + Column("name", "stt", "tts", "llm", "sts", "search", "sync_hash", "updated_at"). Where("rc.id = ?", config.ID). Where("rc.customer_id = ?", config.CustomerID). Returning("was.name"). diff --git a/acceleration/migrations/global/20270201000800_connector_router_sync_hash.sql b/acceleration/migrations/global/20270201000800_connector_router_sync_hash.sql new file mode 100644 index 0000000000..5472b1fa65 --- /dev/null +++ b/acceleration/migrations/global/20270201000800_connector_router_sync_hash.sql @@ -0,0 +1,12 @@ +-- +goose Up +SET LOCAL lock_timeout = '5s'; + +-- A fingerprint of the file the CLI last synced onto the row, as agent_configs.sync_hash is for +-- an agent's directory: empty when the row was never synced, or was written since by anything +-- that is not a sync, so the CLI tells an unchanged file from an edit made elsewhere. +ALTER TABLE connector_definitions ADD COLUMN IF NOT EXISTS sync_hash TEXT NOT NULL DEFAULT ''; +ALTER TABLE router_configs ADD COLUMN IF NOT EXISTS sync_hash TEXT NOT NULL DEFAULT ''; + +-- +goose Down +ALTER TABLE router_configs DROP COLUMN IF EXISTS sync_hash; +ALTER TABLE connector_definitions DROP COLUMN IF EXISTS sync_hash; From 0fb170d8daa23de279d8db6bbd07025a275ccef1 Mon Sep 17 00:00:00 2001 From: Kanat Date: Mon, 23 Nov 2026 22:53:56 +0100 Subject: [PATCH 02/11] WIP: tests for connector and router config sync hashes --- acceleration/internal/api/connectors_test.go | 92 +++++++++++++ .../internal/api/routerconfigs_test.go | 123 ++++++++++++++++++ .../store/connector_definition_test.go | 60 +++++++++ 3 files changed, 275 insertions(+) diff --git a/acceleration/internal/api/connectors_test.go b/acceleration/internal/api/connectors_test.go index 113784d546..1f3a29dc79 100644 --- a/acceleration/internal/api/connectors_test.go +++ b/acceleration/internal/api/connectors_test.go @@ -415,6 +415,98 @@ func (s *ConnectorsSuite) TestSendingTheSameConnectorAgainChangesNothingAndAChan s.Equal("Renamed", s.get(id).Name) } +// AI-3663: the hash a sync sends is on the revision it stores, or on the newest when that +// already says the same, and on every read of the connector. +func (s *ConnectorsSuite) TestASyncedConnectorShowsItsHashOnEveryRead() { + id := s.customID() + created := s.create(s.synced(s.customConnector(id), "hash-one")) + s.Equal("hash-one", created.SyncHash) + + s.Equal("hash-one", s.get(id).SyncHash) + listed := s.list(id).Items + s.Require().Len(listed, 1) + s.Equal("hash-one", listed[0].SyncHash) +} + +func (s *ConnectorsSuite) TestSyncingTheSameFileAgainAddsNoRevision() { + id := s.customID() + created := s.create(s.synced(s.customConnector(id), "hash-one")) + + again := s.create(s.synced(s.customConnector(id), "hash-one")) + + s.Equal(created, again, "the revision already stored, as it was") +} + +func (s *ConnectorsSuite) TestTheSameDefinitionUnderAnotherHashRecordsTheHashOnTheSameRevision() { + id := s.customID() + s.create(s.synced(s.customConnector(id), "hash-one")) + + rehashed := s.create(s.synced(s.customConnector(id), "hash-two")) + + s.Equal(1, rehashed.Revision) + s.Equal("hash-two", s.get(id).SyncHash, "so the next sync of the same file finds it unchanged") +} + +// A dashboard or API create sends no hash, so the next sync of the file sees a hash it did not +// write, whether the definition changed or not. +func (s *ConnectorsSuite) TestACreateThatIsNoSyncClearsTheHash() { + id := s.customID() + s.create(s.synced(s.customConnector(id), "hash-one")) + + same := s.create(s.customConnector(id)) + s.Equal(1, same.Revision) + s.Empty(same.SyncHash) + s.Empty(s.get(id).SyncHash) + + s.create(s.synced(s.customConnector(id), "hash-one")) + changed := s.customConnector(id) + changed["name"] = "Renamed" + edited := s.create(changed) + s.Equal(2, edited.Revision) + s.Empty(s.get(id).SyncHash) + + resynced := s.create(s.synced(s.customConnector(id), "hash-one")) + s.Equal(3, resynced.Revision, "the file differs from the edit, so it is the next revision") + s.Equal("hash-one", s.get(id).SyncHash) +} + +// The base's behaviour, checked on 89e9e0c5c: no answer names a sync hash, on a built-in or +// on a connector created without one. +func (s *ConnectorsSuite) TestAConnectorNoSyncWroteShowsNoHash() { + id := s.customID() + var created map[string]any + s.Require().Equal(http.StatusOK, s.serverClient.do(http.MethodPost, "/v1/agents/connectors", s.customConnector(id), &created)) + s.NotContains(created, "sync_hash") + for _, read := range []string{id, "github"} { + var answered map[string]any + s.Require().Equal(http.StatusOK, s.serverClient.do(http.MethodGet, "/v1/agents/connectors/"+read, nil, &answered)) + s.NotContains(answered, "sync_hash", read) + } +} + +func (s *ConnectorsSuite) TestASyncHashThatIsNotPrintableASCIIOrTooLongIsRefused() { + s.Equal(strings.Repeat("f", 128), s.create(s.synced(s.customConnector(s.customID()), strings.Repeat("f", 128))).SyncHash) + for name, hash := range map[string]string{ + "a space": "hash one", + "a NUL": "hash\x00", + "a non-ASCII": "hashé", + "129 of them": strings.Repeat("f", 129), + "a line break": "hash\n", + } { + s.Run(name, func() { + status, _ := s.serverClient.failure(http.MethodPost, "/v1/agents/connectors", + s.synced(s.customConnector(s.customID()), hash)) + s.Equal(http.StatusBadRequest, status) + }) + } +} + +// synced is body as a sync sends it, with hash. +func (s *ConnectorsSuite) synced(body map[string]any, hash string) map[string]any { + body["sync_hash"] = hash + return body +} + func (s *ConnectorsSuite) TestAnotherAppsCustomConnectorIsNeitherListedNorRead() { id := s.customID() s.create(s.customConnector(id)) diff --git a/acceleration/internal/api/routerconfigs_test.go b/acceleration/internal/api/routerconfigs_test.go index 442f27344b..6231a33000 100644 --- a/acceleration/internal/api/routerconfigs_test.go +++ b/acceleration/internal/api/routerconfigs_test.go @@ -4,6 +4,7 @@ package api import ( "net/http" + "strings" "testing" ) @@ -167,6 +168,128 @@ func (s *RouterConfigsSuite) TestOnlyTheAppsOwnBackendMayStoreARouterConfig() { }) } +// AI-3663: the hash of the file a sync wrote is on every read of the config. +func (s *RouterConfigsSuite) TestASyncedRouterConfigShowsItsHashOnEveryRead() { + created := s.createConfig(s.syncedClinic("hash-one")) + s.Equal("hash-one", created.SyncHash) + + s.Equal("hash-one", s.readConfig(created.Id).SyncHash) + var listed []RouterConfig + s.Require().Equal(http.StatusOK, s.serverClient.do(http.MethodGet, "/v1/router/configs", nil, &listed)) + s.Require().Len(listed, 1) + s.Equal("hash-one", listed[0].SyncHash) +} + +func (s *RouterConfigsSuite) TestSyncingTheSameFileAgainWritesNothing() { + created := s.createConfig(s.syncedClinic("hash-one")) + + replaced := s.replaceConfig(created.Id, s.syncedClinic("hash-one")) + + s.Equal("hash-one", replaced.SyncHash) + s.True(created.UpdatedAt.Equal(replaced.UpdatedAt), "answered with the config as it was") + s.True(created.UpdatedAt.Equal(s.readConfig(created.Id).UpdatedAt), "and nothing was written") +} + +func (s *RouterConfigsSuite) TestTheSameHashWithOtherContentIsStillWritten() { + created := s.createConfig(s.syncedClinic("hash-one")) + changed := s.syncedClinic("hash-one") + changed["stt"] = map[string]any{"target": "llm-flow"} + + s.replaceConfig(created.Id, changed) + + read := s.readConfig(created.Id) + s.Equal("llm-flow", value(read.Stt.Target), "a body the hash does not describe is not dropped") + s.True(read.UpdatedAt.After(created.UpdatedAt)) +} + +func (s *RouterConfigsSuite) TestTheSameFileUnderAnotherHashRecordsTheNewHash() { + created := s.createConfig(s.syncedClinic("hash-one")) + + s.replaceConfig(created.Id, s.syncedClinic("hash-two")) + + s.Equal("hash-two", s.readConfig(created.Id).SyncHash) +} + +// A dashboard or API replace sends no hash, so the next sync of the file sees a hash it did +// not write, whether the edit changed the content or not. +func (s *RouterConfigsSuite) TestAReplaceThatIsNoSyncClearsTheHash() { + for name, edit := range map[string]map[string]any{ + "same content": {"name": "clinic", "stt": map[string]any{"target": "en-low-latency"}}, + "other content": {"name": "clinic", "stt": map[string]any{"target": "llm-flow"}}, + } { + s.Run(name, func() { + s.useApp(s.data.createApp()) + created := s.createConfig(s.syncedClinic("hash-one")) + + s.Empty(s.replaceConfig(created.Id, edit).SyncHash) + + s.Empty(s.readConfig(created.Id).SyncHash) + }) + } +} + +// The base's behaviour, checked on 89e9e0c5c: a replace without a hash is written each time, +// even with the same body, and no answer names a sync hash. +func (s *RouterConfigsSuite) TestAReplaceWithoutAHashIsWrittenEveryTime() { + body := map[string]any{"name": "clinic", "stt": map[string]any{"target": "en-low-latency"}} + var created map[string]any + s.Require().Equal(http.StatusCreated, s.serverClient.do(http.MethodPost, "/v1/router/configs", body, &created)) + s.NotContains(created, "sync_hash") + id := created["id"].(string) + + first := s.replaceConfig(id, body) + second := s.replaceConfig(id, body) + + s.True(second.UpdatedAt.After(first.UpdatedAt), "the second replace was written too") + var read map[string]any + s.Require().Equal(http.StatusOK, s.serverClient.do(http.MethodGet, "/v1/router/configs/"+id, nil, &read)) + s.NotContains(read, "sync_hash") +} + +func (s *RouterConfigsSuite) TestASyncHashThatIsNotPrintableASCIIOrTooLongIsRefused() { + s.createConfig(s.syncedClinic(strings.Repeat("f", 128))) + for name, hash := range map[string]string{ + "a space": "hash one", + "a NUL": "hash\x00", + "a non-ASCII": "hashé", + "129 of them": strings.Repeat("f", 129), + "a line break": "hash\n", + } { + s.Run(name, func() { + s.useApp(s.data.createApp()) + stored := s.createConfig(s.syncedClinic("")) + + created := s.syncedClinic(hash) + created["name"] = "other" + status, _ := s.serverClient.failure(http.MethodPost, "/v1/router/configs", created) + s.Equal(http.StatusBadRequest, status, "a create") + status, _ = s.serverClient.failure(http.MethodPut, "/v1/router/configs/"+stored.Id, s.syncedClinic(hash)) + s.Equal(http.StatusBadRequest, status, "a replace") + }) + } +} + +// syncedClinic is a config as a sync sends it, with hash. +func (s *RouterConfigsSuite) syncedClinic(hash string) map[string]any { + body := map[string]any{"name": "clinic", "stt": map[string]any{"target": "en-low-latency"}} + if hash != "" { + body["sync_hash"] = hash + } + return body +} + +func (s *RouterConfigsSuite) replaceConfig(id string, body map[string]any) RouterConfig { + var replaced RouterConfig + s.Require().Equal(http.StatusOK, s.serverClient.do(http.MethodPut, "/v1/router/configs/"+id, body, &replaced)) + return replaced +} + +func (s *RouterConfigsSuite) readConfig(id string) RouterConfig { + var read RouterConfig + s.Require().Equal(http.StatusOK, s.serverClient.do(http.MethodGet, "/v1/router/configs/"+id, nil, &read)) + return read +} + // createConfig stores a router config the router must accept. func (s *RouterConfigsSuite) createConfig(body map[string]any) RouterConfig { var created RouterConfig diff --git a/acceleration/internal/store/connector_definition_test.go b/acceleration/internal/store/connector_definition_test.go index 58ab6375d9..c14d75088a 100644 --- a/acceleration/internal/store/connector_definition_test.go +++ b/acceleration/internal/store/connector_definition_test.go @@ -800,6 +800,66 @@ func (s *StoreSuite) TestCreatingACustomDefinitionAgainIsTheNextRevisionOnlyWhen s.Equal(2, changed.Revision) } +// AI-3663: a sync's hash is recorded on the revision it stores, or on the latest when that +// already says the same, and a write that is no sync leaves the latest with none. +func (s *StoreSuite) TestASyncedDefinitionCarriesItsHashUntilAWriteThatIsNoSync() { + custom := parsed(s.T(), strings.Replace(acmeManifest, "id: acme", "id: custom_crm", 1)) + changed := parsed(s.T(), strings.Replace(acmeChanged, "id: acme", "id: custom_crm", 1)) + + synced, err := s.store.ConnectorDefinitions.ReviseSynced(s.ctx, "acme", custom, "hash-one") + s.Require().NoError(err) + s.Equal(1, synced.Revision) + s.Equal("hash-one", synced.SyncHash) + s.Equal("hash-one", s.latestCustom("custom_crm").SyncHash, "the hash is stored, not only answered") + + before := s.definitionVersion("custom_crm", 1) + again, err := s.store.ConnectorDefinitions.ReviseSynced(s.ctx, "acme", custom, "hash-one") + s.Require().NoError(err) + s.Equal(1, again.Revision) + s.Equal("hash-one", again.SyncHash) + s.Equal(before, s.definitionVersion("custom_crm", 1), "the same file synced again writes nothing") + + rehashed, err := s.store.ConnectorDefinitions.ReviseSynced(s.ctx, "acme", custom, "hash-two") + s.Require().NoError(err) + s.Equal(1, rehashed.Revision, "the same manifest under another hash is no new revision") + s.Equal("hash-two", s.latestCustom("custom_crm").SyncHash) + + edited, err := s.store.ConnectorDefinitions.Revise(s.ctx, "acme", custom) + s.Require().NoError(err) + s.Equal(1, edited.Revision) + s.Empty(edited.SyncHash) + s.Empty(s.latestCustom("custom_crm").SyncHash, "a write that is no sync clears the hash") + + next, err := s.store.ConnectorDefinitions.ReviseSynced(s.ctx, "acme", changed, "hash-three") + s.Require().NoError(err) + s.Equal(2, next.Revision) + s.Equal("hash-three", s.latestCustom("custom_crm").SyncHash, "a new revision carries the sync's hash") + + unsynced, err := s.store.ConnectorDefinitions.Revise(s.ctx, "acme", custom) + s.Require().NoError(err) + s.Equal(3, unsynced.Revision) + s.Empty(s.latestCustom("custom_crm").SyncHash, "a new revision no sync wrote carries none") + first, err := s.store.ConnectorDefinitions.Get(s.ctx, "acme", "custom_crm", 1) + s.Require().NoError(err) + s.Empty(first.SyncHash, "an older revision keeps what it had") +} + +// latestCustom is acme's latest revision of its own definition id, read from the table. +func (s *StoreSuite) latestCustom(id string) ConnectorDefinition { + definition, err := s.store.ConnectorDefinitions.Latest(s.ctx, "acme", id) + s.Require().NoError(err) + return definition +} + +// definitionVersion is the xmin of one of acme's revisions, which changes with every write to it. +func (s *StoreSuite) definitionVersion(id string, revision int) string { + var xmin string + s.Require().NoError(s.store.global.QueryRowContext(s.ctx, + "SELECT xmin::text FROM connector_definitions WHERE customer_id = ? AND id = ? AND revision = ?", + "acme", id, revision).Scan(&xmin)) + return xmin +} + func (s *StoreSuite) TestACustomDefinitionIsOnlyItsOwnCustomers() { s.Require().NoError(s.store.ConnectorDefinitions.Seed(s.ctx, providers.FS)) _, err := s.store.ConnectorDefinitions.Revise(s.ctx, "acme", From a44671188993b2739714ca3ee6207089896f8d0b Mon Sep 17 00:00:00 2001 From: Kanat Date: Mon, 23 Nov 2026 22:57:33 +0100 Subject: [PATCH 03/11] Regenerate clients for sync_hash; SDK note --- .claude/skills/sdk/SKILL.md | 1 + .../stream/_generated/models/connector.py | 10 ++++++++ .../models/custom_connector_request.py | 11 +++++++++ .../stream/_generated/models/router_config.py | 10 ++++++++ .../models/router_config_request.py | 11 +++++++++ .../Generated/Models.cs | 24 +++++++++++++++++++ sdks/go/acceleration/generated.go | 12 ++++++++++ sdks/js/src/generated/api.ts | 8 +++++++ sdks/php/src/Generated/Connector.php | 6 +++++ .../src/Generated/CustomConnectorRequest.php | 6 +++++ sdks/php/src/Generated/RouterConfig.php | 6 +++++ .../php/src/Generated/RouterConfigRequest.php | 6 +++++ .../getstream/vision_agents/generated/spec.rb | 8 +++---- sdks/rust/src/types.rs | 12 ++++++++++ 14 files changed, 127 insertions(+), 4 deletions(-) diff --git a/.claude/skills/sdk/SKILL.md b/.claude/skills/sdk/SKILL.md index 346d4368df..4f646e9ef3 100644 --- a/.claude/skills/sdk/SKILL.md +++ b/.claude/skills/sdk/SKILL.md @@ -967,3 +967,4 @@ A device naming a user on a connections call (AI-3412): the router answers every `agent.yaml`'s `greeting` may be its text alone, `greeting: Hello, how can I help?`, read as `{text, mode: variation}`; the mapping still says `exact`, and a mapping without `mode` is now `variation` too, so a folder loader always sends `mode`. The API's own default stays `exact`. Go is done (`GreetingSettings.UnmarshalYAML` in `sdks/go/agents/folder.go`). Other SDKs need to update: the folder loaders of JavaScript (`sdks/js/src/folder.ts`, `greeting()`), Python (`plugins/stream` `folder.py`, `_greeting`), .NET, Ruby, Rust and PHP should take the string form and default a missing `mode` to `variation`. Calls have an id of their own and a `session_id`: a session starts a new call each time voice is started or stopped on it, and an incognito session keeps none, so a session id is no longer a call id. `Call.id` is the call's own id; `Call` gains `session_id` (absent once the session is deleted) and loses `config_id` and `user_id`. `listCalls` (`GET /v1/agents/calls`) takes `session_id` and answers that session's calls newest first. Go is done: `client.Sessions.Timeline` and `Decisions` list the session's calls with `session_id` and `limit=1`, read the newest one's `getCallTimeline` or `getCallEvents`, and fail with `client.ErrNoCall` when the session has none (`sdks/go/client/sessions.go`). Other SDKs need to update: JavaScript, Python (`plugins/stream`), .NET, Ruby, Rust and PHP regenerate their clients, and any helper that passes a session id to `/v1/agents/calls/{id}` (its timeline, events, transcript or tokens) lists the session's calls first; Swift, Kotlin and Dart regenerate `Call` where they have it. STS models list their built-in voices on `Provider.voices` (`ModelVoice`: `id`, `name`, `description`, `gender`, `default`), omitted for non-STS providers, and new voice configs created via `createAgentConfig` or `syncAgent` now default `sts` to `sts-fast` when `sts` is omitted and no cascade settings are provided (explicit `sts: ""` selects the cascade). Go is regenerated (`sdks/go/acceleration/generated.go`). Other SDKs need to update: JavaScript, Python (`plugins/stream`), Swift, Kotlin, Dart, .NET, Ruby, Rust and PHP regenerate their OpenAPI types to pick up `Provider.voices` and `ModelVoice`. +Connectors and router configs carry a `sync_hash`, as agent configs do: `createConnector` (`CustomConnectorRequest.sync_hash`) and `createRouterConfig`/`updateRouterConfig` (`RouterConfigRequest.sync_hash`) take the fingerprint of the file a sync sent, and `Connector.sync_hash` and `RouterConfig.sync_hash` return it. Any write without one clears it; a router config replace with the stored hash and the same content writes nothing, and a connector sent again with the same definition and another hash keeps its revision and records the hash. Every generated client is regenerated in this change; no SDK computes or sends the hash yet. Other SDKs need to update: once the CLI's hash for a connector or router file is settled (AI-3664), a server SDK that syncs those files sends it the same way. diff --git a/plugins/stream/vision_agents/plugins/stream/_generated/models/connector.py b/plugins/stream/vision_agents/plugins/stream/_generated/models/connector.py index baf8e8bcb6..c63d714434 100644 --- a/plugins/stream/vision_agents/plugins/stream/_generated/models/connector.py +++ b/plugins/stream/vision_agents/plugins/stream/_generated/models/connector.py @@ -50,6 +50,8 @@ class Connector: sandbox (ConnectorSandbox | Unset): How code in an agent's sandbox reaches the provider's API with a connection's credential. setup (ConnectorSetup | Unset): What a person does at the provider before the first consent. + sync_hash (str | Unset): The fingerprint of the file the CLI last synced onto this connector. Absent on a built- + in, and on a connector that was never synced or was written since by anything that is not a sync. """ channel: bool @@ -67,6 +69,7 @@ class Connector: redirect_uri: str | Unset = UNSET sandbox: ConnectorSandbox | Unset = UNSET setup: ConnectorSetup | Unset = UNSET + sync_hash: str | Unset = UNSET additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) def to_dict(self) -> dict[str, Any]: @@ -122,6 +125,8 @@ def to_dict(self) -> dict[str, Any]: if not isinstance(self.setup, Unset): setup = self.setup.to_dict() + sync_hash = self.sync_hash + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update( @@ -148,6 +153,8 @@ def to_dict(self) -> dict[str, Any]: field_dict["sandbox"] = sandbox if setup is not UNSET: field_dict["setup"] = setup + if sync_hash is not UNSET: + field_dict["sync_hash"] = sync_hash return field_dict @@ -245,6 +252,8 @@ def _parse_scopes(data: object) -> list[str] | None: else: setup = ConnectorSetup.from_dict(_setup) + sync_hash = d.pop("sync_hash", UNSET) + connector = cls( channel=channel, client=client, @@ -261,6 +270,7 @@ def _parse_scopes(data: object) -> list[str] | None: redirect_uri=redirect_uri, sandbox=sandbox, setup=setup, + sync_hash=sync_hash, ) connector.additional_properties = d diff --git a/plugins/stream/vision_agents/plugins/stream/_generated/models/custom_connector_request.py b/plugins/stream/vision_agents/plugins/stream/_generated/models/custom_connector_request.py index bf23e5b0a3..721127491a 100644 --- a/plugins/stream/vision_agents/plugins/stream/_generated/models/custom_connector_request.py +++ b/plugins/stream/vision_agents/plugins/stream/_generated/models/custom_connector_request.py @@ -33,6 +33,9 @@ class CustomConnectorRequest: authenticates at the token endpoint. description (str | Unset): scopes (list[str] | None | Unset): The scopes a consent asks for, each an RFC 6749 scope token. + sync_hash (str | Unset): The fingerprint of the file this definition was synced from, which the connector then + carries. Absent for a write that is no sync: the connector then carries none. Sending a definition the newest + revision already says with another hash stores no new revision and records the hash on that one. """ endpoint: str @@ -43,6 +46,7 @@ class CustomConnectorRequest: client: ConnectorClient | Unset = UNSET description: str | Unset = UNSET scopes: list[str] | None | Unset = UNSET + sync_hash: str | Unset = UNSET def to_dict(self) -> dict[str, Any]: endpoint = self.endpoint @@ -75,6 +79,8 @@ def to_dict(self) -> dict[str, Any]: else: scopes = self.scopes + sync_hash = self.sync_hash + field_dict: dict[str, Any] = {} field_dict.update( @@ -93,6 +99,8 @@ def to_dict(self) -> dict[str, Any]: field_dict["description"] = description if scopes is not UNSET: field_dict["scopes"] = scopes + if sync_hash is not UNSET: + field_dict["sync_hash"] = sync_hash return field_dict @@ -150,6 +158,8 @@ def _parse_scopes(data: object) -> list[str] | None | Unset: scopes = _parse_scopes(d.pop("scopes", UNSET)) + sync_hash = d.pop("sync_hash", UNSET) + custom_connector_request = cls( endpoint=endpoint, id=id, @@ -159,6 +169,7 @@ def _parse_scopes(data: object) -> list[str] | None | Unset: client=client, description=description, scopes=scopes, + sync_hash=sync_hash, ) return custom_connector_request diff --git a/plugins/stream/vision_agents/plugins/stream/_generated/models/router_config.py b/plugins/stream/vision_agents/plugins/stream/_generated/models/router_config.py index 7456c51403..d760fc2146 100644 --- a/plugins/stream/vision_agents/plugins/stream/_generated/models/router_config.py +++ b/plugins/stream/vision_agents/plugins/stream/_generated/models/router_config.py @@ -44,6 +44,8 @@ class RouterConfig: tts (TtsOptions | Unset): How this config speaks. A provider that cannot express a term refuses the request rather than dropping it silently, since a voice asked to sound urgent and speaking flatly is worse than one that says it cannot. + sync_hash (str | Unset): The fingerprint of the file the CLI last synced onto this config. Absent if it was + never synced, or was written since by anything that is not a sync. """ created_at: datetime.datetime @@ -55,6 +57,7 @@ class RouterConfig: sts: StsOptions | Unset = UNSET stt: SttOptions | Unset = UNSET tts: TtsOptions | Unset = UNSET + sync_hash: str | Unset = UNSET additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) def to_dict(self) -> dict[str, Any]: @@ -86,6 +89,8 @@ def to_dict(self) -> dict[str, Any]: if not isinstance(self.tts, Unset): tts = self.tts.to_dict() + sync_hash = self.sync_hash + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update( @@ -106,6 +111,8 @@ def to_dict(self) -> dict[str, Any]: field_dict["stt"] = stt if tts is not UNSET: field_dict["tts"] = tts + if sync_hash is not UNSET: + field_dict["sync_hash"] = sync_hash return field_dict @@ -161,6 +168,8 @@ def from_dict(cls, src_dict: Mapping[str, Any]) -> Self: else: tts = TtsOptions.from_dict(_tts) + sync_hash = d.pop("sync_hash", UNSET) + router_config = cls( created_at=created_at, id=id, @@ -171,6 +180,7 @@ def from_dict(cls, src_dict: Mapping[str, Any]) -> Self: sts=sts, stt=stt, tts=tts, + sync_hash=sync_hash, ) router_config.additional_properties = d diff --git a/plugins/stream/vision_agents/plugins/stream/_generated/models/router_config_request.py b/plugins/stream/vision_agents/plugins/stream/_generated/models/router_config_request.py index 2204ff1b45..054ed79ec0 100644 --- a/plugins/stream/vision_agents/plugins/stream/_generated/models/router_config_request.py +++ b/plugins/stream/vision_agents/plugins/stream/_generated/models/router_config_request.py @@ -40,6 +40,9 @@ class RouterConfigRequest: tts (TtsOptions | Unset): How this config speaks. A provider that cannot express a term refuses the request rather than dropping it silently, since a voice asked to sound urgent and speaking flatly is worse than one that says it cannot. + sync_hash (str | Unset): The fingerprint of the file this config was synced from, which the config then carries. + Absent for a write that is no sync, which clears it. A replace with the hash the config carries and the same + content writes nothing. """ name: str @@ -48,6 +51,7 @@ class RouterConfigRequest: sts: StsOptions | Unset = UNSET stt: SttOptions | Unset = UNSET tts: TtsOptions | Unset = UNSET + sync_hash: str | Unset = UNSET additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict) def to_dict(self) -> dict[str, Any]: @@ -73,6 +77,8 @@ def to_dict(self) -> dict[str, Any]: if not isinstance(self.tts, Unset): tts = self.tts.to_dict() + sync_hash = self.sync_hash + field_dict: dict[str, Any] = {} field_dict.update(self.additional_properties) field_dict.update( @@ -90,6 +96,8 @@ def to_dict(self) -> dict[str, Any]: field_dict["stt"] = stt if tts is not UNSET: field_dict["tts"] = tts + if sync_hash is not UNSET: + field_dict["sync_hash"] = sync_hash return field_dict @@ -139,6 +147,8 @@ def from_dict(cls, src_dict: Mapping[str, Any]) -> Self: else: tts = TtsOptions.from_dict(_tts) + sync_hash = d.pop("sync_hash", UNSET) + router_config_request = cls( name=name, llm=llm, @@ -146,6 +156,7 @@ def from_dict(cls, src_dict: Mapping[str, Any]) -> Self: sts=sts, stt=stt, tts=tts, + sync_hash=sync_hash, ) router_config_request.additional_properties = d diff --git a/sdks/dotnet/src/GetStream.VisionAgents/Generated/Models.cs b/sdks/dotnet/src/GetStream.VisionAgents/Generated/Models.cs index 7cd3aa78ef..16eaea2f5d 100644 --- a/sdks/dotnet/src/GetStream.VisionAgents/Generated/Models.cs +++ b/sdks/dotnet/src/GetStream.VisionAgents/Generated/Models.cs @@ -5306,6 +5306,12 @@ public partial class Connector [System.Text.Json.Serialization.JsonPropertyName("setup")] public ConnectorSetup? Setup { get; set; } = default!; + /// + /// The fingerprint of the file the CLI last synced onto this connector. Absent on a built-in, and on a connector that was never synced or was written since by anything that is not a sync. + /// + [System.Text.Json.Serialization.JsonPropertyName("sync_hash")] + public string? SyncHash { get; set; } = default!; + private System.Collections.Generic.IDictionary? _additionalProperties; [System.Text.Json.Serialization.JsonExtensionData] @@ -7044,6 +7050,12 @@ public partial class CustomConnectorRequest [System.Text.Json.Serialization.JsonPropertyName("scopes")] public System.Collections.Generic.List? Scopes { get; set; } = default!; + /// + /// The fingerprint of the file this definition was synced from, which the connector then carries. Absent for a write that is no sync: the connector then carries none. Sending a definition the newest revision already says with another hash stores no new revision and records the hash on that one. + /// + [System.Text.Json.Serialization.JsonPropertyName("sync_hash")] + public string? SyncHash { get; set; } = default!; + } [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.7.1.0 (NJsonSchema v11.6.1.0 (Newtonsoft.Json v13.0.0.0))")] @@ -12859,6 +12871,12 @@ public partial class RouterConfig [System.Text.Json.Serialization.JsonPropertyName("stt")] public SttOptions? Stt { get; set; } = default!; + /// + /// The fingerprint of the file the CLI last synced onto this config. Absent if it was never synced, or was written since by anything that is not a sync. + /// + [System.Text.Json.Serialization.JsonPropertyName("sync_hash")] + public string? SyncHash { get; set; } = default!; + [System.Text.Json.Serialization.JsonPropertyName("tts")] public TtsOptions? Tts { get; set; } = default!; @@ -12898,6 +12916,12 @@ public partial class RouterConfigRequest [System.Text.Json.Serialization.JsonPropertyName("stt")] public SttOptions? Stt { get; set; } = default!; + /// + /// The fingerprint of the file this config was synced from, which the config then carries. Absent for a write that is no sync, which clears it. A replace with the hash the config carries and the same content writes nothing. + /// + [System.Text.Json.Serialization.JsonPropertyName("sync_hash")] + public string? SyncHash { get; set; } = default!; + [System.Text.Json.Serialization.JsonPropertyName("tts")] public TtsOptions? Tts { get; set; } = default!; diff --git a/sdks/go/acceleration/generated.go b/sdks/go/acceleration/generated.go index 38b779e035..509e159a6c 100644 --- a/sdks/go/acceleration/generated.go +++ b/sdks/go/acceleration/generated.go @@ -5763,6 +5763,9 @@ type Connector struct { // Setup What a person does at the provider before the first consent. Setup *ConnectorSetup `json:"setup,omitempty"` + + // SyncHash The fingerprint of the file the CLI last synced onto this connector. Absent on a built-in, and on a connector that was never synced or was written since by anything that is not a sync. + SyncHash *string `json:"sync_hash,omitempty"` } // ConnectorAuditAction grant_created: a consent or a credentials write gave the connection a grant. grant_refreshed: the router renewed its credential. grant_revoked: the grant ended, because the provider refused or revoked it or the connection was deleted. token_export: the app's backend exported its access credential. proxy_call: a direct call went to the provider through the connection. tool_reapproved: the app's backend approved tools at the schema the provider lists now (POST .../tools/approve); tools names them. @@ -6504,6 +6507,9 @@ type CustomConnectorRequest struct { // Scopes The scopes a consent asks for, each an RFC 6749 scope token. Scopes *[]string `json:"scopes,omitempty"` + + // SyncHash The fingerprint of the file this definition was synced from, which the connector then carries. Absent for a write that is no sync: the connector then carries none. Sending a definition the newest revision already says with another hash stores no new revision and records the hash on that one. + SyncHash *string `json:"sync_hash,omitempty"` } // CustomModel defines model for CustomModel. @@ -9099,6 +9105,9 @@ type RouterConfig struct { // Stt How this config transcribes, live or from a recording. A field that only means something on one of the two forms says so: a recording has no endpointing to do, and a socket has no file to write subtitles from. A provider that cannot express a term refuses the request rather than dropping it silently. Stt *SttOptions `json:"stt,omitempty"` + // SyncHash The fingerprint of the file the CLI last synced onto this config. Absent if it was never synced, or was written since by anything that is not a sync. + SyncHash *string `json:"sync_hash,omitempty"` + // Tts How this config speaks. A provider that cannot express a term refuses the request rather than dropping it silently, since a voice asked to sound urgent and speaking flatly is worse than one that says it cannot. Tts *TtsOptions `json:"tts,omitempty"` UpdatedAt time.Time `json:"updated_at"` @@ -9121,6 +9130,9 @@ type RouterConfigRequest struct { // Stt How this config transcribes, live or from a recording. A field that only means something on one of the two forms says so: a recording has no endpointing to do, and a socket has no file to write subtitles from. A provider that cannot express a term refuses the request rather than dropping it silently. Stt *SttOptions `json:"stt,omitempty"` + // SyncHash The fingerprint of the file this config was synced from, which the config then carries. Absent for a write that is no sync, which clears it. A replace with the hash the config carries and the same content writes nothing. + SyncHash *string `json:"sync_hash,omitempty"` + // Tts How this config speaks. A provider that cannot express a term refuses the request rather than dropping it silently, since a voice asked to sound urgent and speaking flatly is worse than one that says it cannot. Tts *TtsOptions `json:"tts,omitempty"` } diff --git a/sdks/js/src/generated/api.ts b/sdks/js/src/generated/api.ts index be8e37731d..a55b5c55a0 100644 --- a/sdks/js/src/generated/api.ts +++ b/sdks/js/src/generated/api.ts @@ -6573,6 +6573,8 @@ export type components = { readonly scopes: readonly string[] | null; /** @description What a person does at the provider before the first consent, such as registering an OAuth client. Absent when the manifest says nothing. */ readonly setup?: components["schemas"]["ConnectorSetup"]; + /** @description The fingerprint of the file the CLI last synced onto this connector. Absent on a built-in, and on a connector that was never synced or was written since by anything that is not a sync. */ + readonly sync_hash?: string; }; /** * @description grant_created: a consent or a credentials write gave the connection a grant. grant_refreshed: the router renewed its credential. grant_revoked: the grant ended, because the provider refused or revoked it or the connection was deleted. token_export: the app's backend exported its access credential. proxy_call: a direct call went to the provider through the connection. tool_reapproved: the app's backend approved tools at the schema the provider lists now (POST .../tools/approve); tools names them. @@ -7206,6 +7208,8 @@ export type components = { readonly schemes: readonly string[] | null; /** @description The scopes a consent asks for, each an RFC 6749 scope token. */ readonly scopes?: readonly string[] | null; + /** @description The fingerprint of the file this definition was synced from, which the connector then carries. Absent for a write that is no sync: the connector then carries none. Sending a definition the newest revision already says with another hash stores no new revision and records the hash on that one. */ + readonly sync_hash?: string; }; readonly CustomModel: { readonly base_url: string; @@ -9581,6 +9585,8 @@ export type components = { readonly search?: components["schemas"]["SearchOptions"]; readonly sts?: components["schemas"]["StsOptions"]; readonly stt?: components["schemas"]["SttOptions"]; + /** @description The fingerprint of the file the CLI last synced onto this config. Absent if it was never synced, or was written since by anything that is not a sync. */ + readonly sync_hash?: string; readonly tts?: components["schemas"]["TtsOptions"]; /** Format: date-time */ readonly updated_at: string; @@ -9592,6 +9598,8 @@ export type components = { readonly search?: components["schemas"]["SearchOptions"]; readonly sts?: components["schemas"]["StsOptions"]; readonly stt?: components["schemas"]["SttOptions"]; + /** @description The fingerprint of the file this config was synced from, which the config then carries. Absent for a write that is no sync, which clears it. A replace with the hash the config carries and the same content writes nothing. */ + readonly sync_hash?: string; readonly tts?: components["schemas"]["TtsOptions"]; }; readonly Run: { diff --git a/sdks/php/src/Generated/Connector.php b/sdks/php/src/Generated/Connector.php index 9b3d943204..14181b2c90 100644 --- a/sdks/php/src/Generated/Connector.php +++ b/sdks/php/src/Generated/Connector.php @@ -45,6 +45,8 @@ public function __construct( public ?ConnectorSandbox $sandbox = null, // What a person does at the provider before the first consent, such as registering an OAuth client. Absent wh... public ?ConnectorSetup $setup = null, + // The fingerprint of the file the CLI last synced onto this connector. Absent on a built-in, and on a connect... + public ?string $syncHash = null, ) { } @@ -69,6 +71,7 @@ public static function fromArray(array $data): self redirectUri: array_key_exists('redirect_uri', $data) && $data['redirect_uri'] !== null ? Json::string($data, 'redirect_uri') : null, sandbox: array_key_exists('sandbox', $data) && $data['sandbox'] !== null ? ConnectorSandbox::fromArray(Json::object($data, 'sandbox')) : null, setup: array_key_exists('setup', $data) && $data['setup'] !== null ? ConnectorSetup::fromArray(Json::object($data, 'setup')) : null, + syncHash: array_key_exists('sync_hash', $data) && $data['sync_hash'] !== null ? Json::string($data, 'sync_hash') : null, ); } @@ -105,6 +108,9 @@ public function toArray(): array if ($this->setup !== null) { $out['setup'] = $this->setup->toArray(); } + if ($this->syncHash !== null) { + $out['sync_hash'] = $this->syncHash; + } return $out; } } diff --git a/sdks/php/src/Generated/CustomConnectorRequest.php b/sdks/php/src/Generated/CustomConnectorRequest.php index df5cac0e40..cc1d341044 100644 --- a/sdks/php/src/Generated/CustomConnectorRequest.php +++ b/sdks/php/src/Generated/CustomConnectorRequest.php @@ -29,6 +29,8 @@ public function __construct( // The scopes a consent asks for, each an RFC 6749 scope token. /** @var list|null */ public ?array $scopes = null, + // The fingerprint of the file this definition was synced from, which the connector then carries. Absent for a... + public ?string $syncHash = null, ) { } @@ -46,6 +48,7 @@ public static function fromArray(array $data): self client: array_key_exists('client', $data) && $data['client'] !== null ? ConnectorClient::fromArray(Json::object($data, 'client')) : null, description: array_key_exists('description', $data) && $data['description'] !== null ? Json::string($data, 'description') : null, scopes: array_key_exists('scopes', $data) && $data['scopes'] !== null ? Json::strings($data, 'scopes') : null, + syncHash: array_key_exists('sync_hash', $data) && $data['sync_hash'] !== null ? Json::string($data, 'sync_hash') : null, ); } @@ -73,6 +76,9 @@ public function toArray(): array if ($this->scopes !== null) { $out['scopes'] = $this->scopes; } + if ($this->syncHash !== null) { + $out['sync_hash'] = $this->syncHash; + } return $out; } } diff --git a/sdks/php/src/Generated/RouterConfig.php b/sdks/php/src/Generated/RouterConfig.php index 1d5c199809..feb957926a 100644 --- a/sdks/php/src/Generated/RouterConfig.php +++ b/sdks/php/src/Generated/RouterConfig.php @@ -20,6 +20,8 @@ public function __construct( public ?StsOptions $sts = null, public ?SttOptions $stt = null, public ?TtsOptions $tts = null, + // The fingerprint of the file the CLI last synced onto this config. Absent if it was never synced, or was wri... + public ?string $syncHash = null, ) { } @@ -38,6 +40,7 @@ public static function fromArray(array $data): self sts: array_key_exists('sts', $data) && $data['sts'] !== null ? StsOptions::fromArray(Json::object($data, 'sts')) : null, stt: array_key_exists('stt', $data) && $data['stt'] !== null ? SttOptions::fromArray(Json::object($data, 'stt')) : null, tts: array_key_exists('tts', $data) && $data['tts'] !== null ? TtsOptions::fromArray(Json::object($data, 'tts')) : null, + syncHash: array_key_exists('sync_hash', $data) && $data['sync_hash'] !== null ? Json::string($data, 'sync_hash') : null, ); } @@ -68,6 +71,9 @@ public function toArray(): array if ($this->tts !== null) { $out['tts'] = $this->tts->toArray(); } + if ($this->syncHash !== null) { + $out['sync_hash'] = $this->syncHash; + } return $out; } } diff --git a/sdks/php/src/Generated/RouterConfigRequest.php b/sdks/php/src/Generated/RouterConfigRequest.php index 1a00249fab..10c99d0d11 100644 --- a/sdks/php/src/Generated/RouterConfigRequest.php +++ b/sdks/php/src/Generated/RouterConfigRequest.php @@ -18,6 +18,8 @@ public function __construct( public ?StsOptions $sts = null, public ?SttOptions $stt = null, public ?TtsOptions $tts = null, + // The fingerprint of the file this config was synced from, which the config then carries. Absent for a write... + public ?string $syncHash = null, ) { } @@ -33,6 +35,7 @@ public static function fromArray(array $data): self sts: array_key_exists('sts', $data) && $data['sts'] !== null ? StsOptions::fromArray(Json::object($data, 'sts')) : null, stt: array_key_exists('stt', $data) && $data['stt'] !== null ? SttOptions::fromArray(Json::object($data, 'stt')) : null, tts: array_key_exists('tts', $data) && $data['tts'] !== null ? TtsOptions::fromArray(Json::object($data, 'tts')) : null, + syncHash: array_key_exists('sync_hash', $data) && $data['sync_hash'] !== null ? Json::string($data, 'sync_hash') : null, ); } @@ -60,6 +63,9 @@ public function toArray(): array if ($this->tts !== null) { $out['tts'] = $this->tts->toArray(); } + if ($this->syncHash !== null) { + $out['sync_hash'] = $this->syncHash; + } return $out; } } diff --git a/sdks/ruby/lib/getstream/vision_agents/generated/spec.rb b/sdks/ruby/lib/getstream/vision_agents/generated/spec.rb index dfd46670ad..ae8c7cc52d 100644 --- a/sdks/ruby/lib/getstream/vision_agents/generated/spec.rb +++ b/sdks/ruby/lib/getstream/vision_agents/generated/spec.rb @@ -2288,7 +2288,7 @@ module Generated required: [].freeze, open: false }.freeze, "Connector" => { - properties: %w[category channel client created_at custom description id inputs name redirect_uri revision sandbox schemes scopes setup].freeze, + properties: %w[category channel client created_at custom description id inputs name redirect_uri revision sandbox schemes scopes setup sync_hash].freeze, required: %w[id revision name custom schemes inputs scopes client channel created_at].freeze, open: false }.freeze, "ConnectorAuditCredential" => { @@ -2432,7 +2432,7 @@ module Generated required: %w[items has_more].freeze, open: false }.freeze, "CustomConnectorRequest" => { - properties: %w[category client description endpoint id name schemes scopes].freeze, + properties: %w[category client description endpoint id name schemes scopes sync_hash].freeze, required: %w[id name endpoint schemes].freeze, open: false }.freeze, "CustomModel" => { @@ -2980,11 +2980,11 @@ module Generated required: %w[candidates description id title].freeze, open: false }.freeze, "RouterConfig" => { - properties: %w[created_at id llm name search sts stt tts updated_at].freeze, + properties: %w[created_at id llm name search sts stt sync_hash tts updated_at].freeze, required: %w[created_at id name updated_at].freeze, open: false }.freeze, "RouterConfigRequest" => { - properties: %w[llm name search sts stt tts].freeze, + properties: %w[llm name search sts stt sync_hash tts].freeze, required: %w[name].freeze, open: false }.freeze, "Run" => { diff --git a/sdks/rust/src/types.rs b/sdks/rust/src/types.rs index 14e11a415d..903beb0724 100644 --- a/sdks/rust/src/types.rs +++ b/sdks/rust/src/types.rs @@ -4030,6 +4030,9 @@ pub struct Connector { ///What a person does at the provider before the first consent, such as registering an OAuth client. Absent when the manifest says nothing. #[serde(skip_serializing_if = "::std::option::Option::is_none")] pub setup: ::std::option::Option, + ///The fingerprint of the file the CLI last synced onto this connector. Absent on a built-in, and on a connector that was never synced or was written since by anything that is not a sync. + #[serde(skip_serializing_if = "::std::option::Option::is_none")] + pub sync_hash: ::std::option::Option<::std::string::String>, } ///grant_created: a consent or a credentials write gave the connection a grant. grant_refreshed: the router renewed its credential. grant_revoked: the grant ended, because the provider refused or revoked it or the connection was deleted. token_export: the app's backend exported its access credential. proxy_call: a direct call went to the provider through the connection. tool_reapproved: the app's backend approved tools at the schema the provider lists now (POST .../tools/approve); tools names them. #[derive( @@ -5294,6 +5297,9 @@ pub struct CustomConnectorRequest { ///The scopes a consent asks for, each an RFC 6749 scope token. #[serde(skip_serializing_if = "::std::option::Option::is_none")] pub scopes: ::std::option::Option<::std::vec::Vec<::std::string::String>>, + ///The fingerprint of the file this definition was synced from, which the connector then carries. Absent for a write that is no sync: the connector then carries none. Sending a definition the newest revision already says with another hash stores no new revision and records the hash on that one. + #[serde(skip_serializing_if = "::std::option::Option::is_none")] + pub sync_hash: ::std::option::Option<::std::string::String>, } ///`CustomModel` #[derive(::serde::Deserialize, ::serde::Serialize, Clone, Debug, PartialEq, Default)] @@ -10460,6 +10466,9 @@ pub struct RouterConfig { pub sts: ::std::option::Option, #[serde(skip_serializing_if = "::std::option::Option::is_none")] pub stt: ::std::option::Option, + ///The fingerprint of the file the CLI last synced onto this config. Absent if it was never synced, or was written since by anything that is not a sync. + #[serde(skip_serializing_if = "::std::option::Option::is_none")] + pub sync_hash: ::std::option::Option<::std::string::String>, #[serde(skip_serializing_if = "::std::option::Option::is_none")] pub tts: ::std::option::Option, pub updated_at: ::std::string::String, @@ -10477,6 +10486,9 @@ pub struct RouterConfigRequest { pub sts: ::std::option::Option, #[serde(skip_serializing_if = "::std::option::Option::is_none")] pub stt: ::std::option::Option, + ///The fingerprint of the file this config was synced from, which the config then carries. Absent for a write that is no sync, which clears it. A replace with the hash the config carries and the same content writes nothing. + #[serde(skip_serializing_if = "::std::option::Option::is_none")] + pub sync_hash: ::std::option::Option<::std::string::String>, #[serde(skip_serializing_if = "::std::option::Option::is_none")] pub tts: ::std::option::Option, } From da20427f929bd44d302ff21530872808ef98d6c6 Mon Sep 17 00:00:00 2001 From: Kanat Date: Mon, 23 Nov 2026 22:58:49 +0100 Subject: [PATCH 04/11] Name sync_hash in the add-connector skill --- .claude/skills/add-connector/SKILL.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.claude/skills/add-connector/SKILL.md b/.claude/skills/add-connector/SKILL.md index d72c844022..19ea8623e5 100644 --- a/.claude/skills/add-connector/SKILL.md +++ b/.claude/skills/add-connector/SKILL.md @@ -17,10 +17,12 @@ First decide which kind you need. Connecting an existing connector to an agent i Dashboard: **Library › Connectors › New connector**. API: `POST /v1/agents/connectors` (`CustomConnectorRequest`: `id`, `name`, `endpoint`, `schemes`, optional `scopes`, -`client`, `category`, `description`). +`client`, `category`, `description`, `sync_hash`). - The id starts with `custom_`, for example `custom_crm`. Built-ins never use that prefix. - `endpoint` is the MCP server's https URL. +- `sync_hash` is the fingerprint of the file the CLI synced the connector from. The connector + returns it until a create without one, from the dashboard or the API, clears it. - `schemes` is how a connection signs in: `oauth2_code`, `bearer`, `api_key`, or `none`. - A public server that needs no credential takes `schemes: ["none"]`. Create the connection, then connect it with `PUT /v1/agents/connections/{id}/credentials` and the body From e09e839867dfcf49cfb82847ddb1b0feb04afe9f Mon Sep 17 00:00:00 2001 From: Kanat Date: Mon, 23 Nov 2026 23:05:21 +0100 Subject: [PATCH 05/11] Keep router config fields aligned; wrap long test lines --- acceleration/internal/api/connectors_test.go | 6 ++++-- acceleration/internal/store/router_config.go | 21 ++++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/acceleration/internal/api/connectors_test.go b/acceleration/internal/api/connectors_test.go index 1f3a29dc79..0bbf70c0a2 100644 --- a/acceleration/internal/api/connectors_test.go +++ b/acceleration/internal/api/connectors_test.go @@ -475,7 +475,8 @@ func (s *ConnectorsSuite) TestACreateThatIsNoSyncClearsTheHash() { func (s *ConnectorsSuite) TestAConnectorNoSyncWroteShowsNoHash() { id := s.customID() var created map[string]any - s.Require().Equal(http.StatusOK, s.serverClient.do(http.MethodPost, "/v1/agents/connectors", s.customConnector(id), &created)) + s.Require().Equal(http.StatusOK, + s.serverClient.do(http.MethodPost, "/v1/agents/connectors", s.customConnector(id), &created)) s.NotContains(created, "sync_hash") for _, read := range []string{id, "github"} { var answered map[string]any @@ -485,7 +486,8 @@ func (s *ConnectorsSuite) TestAConnectorNoSyncWroteShowsNoHash() { } func (s *ConnectorsSuite) TestASyncHashThatIsNotPrintableASCIIOrTooLongIsRefused() { - s.Equal(strings.Repeat("f", 128), s.create(s.synced(s.customConnector(s.customID()), strings.Repeat("f", 128))).SyncHash) + longest := strings.Repeat("f", 128) + s.Equal(longest, s.create(s.synced(s.customConnector(s.customID()), longest)).SyncHash) for name, hash := range map[string]string{ "a space": "hash one", "a NUL": "hash\x00", diff --git a/acceleration/internal/store/router_config.go b/acceleration/internal/store/router_config.go index a4393339a8..5b525a7668 100644 --- a/acceleration/internal/store/router_config.go +++ b/acceleration/internal/store/router_config.go @@ -30,18 +30,19 @@ type RouterConfig struct { // The option blocks, one per routed modality. They are the routing package's own // types rather than copies of them, so what is stored and what reaches a provider // cannot drift apart. - STT options.STT `bun:"stt,type:jsonb"` - TTS options.TTS `bun:"tts,type:jsonb"` - LLM options.LLM `bun:"llm,type:jsonb"` - STS options.STS `bun:"sts,type:jsonb"` - Search options.Search `bun:"search,type:jsonb"` + STT options.STT `bun:"stt,type:jsonb"` + TTS options.TTS `bun:"tts,type:jsonb"` + LLM options.LLM `bun:"llm,type:jsonb"` + STS options.STS `bun:"sts,type:jsonb"` + Search options.Search `bun:"search,type:jsonb"` + CreatedAt time.Time `bun:"created_at,notnull"` + UpdatedAt time.Time `bun:"updated_at,notnull"` + DeletedAt *time.Time `bun:"deleted_at"` // SyncHash is a fingerprint of the file the CLI last synced onto this config // (20270201000800_connector_router_sync_hash.sql), as AgentConfig.SyncHash is for a - // directory. Empty if it was never synced, or was written since by anything that is not a sync. - SyncHash string `bun:"sync_hash,notnull"` - CreatedAt time.Time `bun:"created_at,notnull"` - UpdatedAt time.Time `bun:"updated_at,notnull"` - DeletedAt *time.Time `bun:"deleted_at"` + // directory. Empty if it was never synced, or was written since by anything that is not a + // sync. + SyncHash string `bun:"sync_hash,notnull"` } // Validate refuses a config the table would refuse. From 2346939a4920003c1082fdaafc8ddd67274b7c8f Mon Sep 17 00:00:00 2001 From: Kanat Date: Mon, 23 Nov 2026 23:06:41 +0100 Subject: [PATCH 06/11] Move the SDK note to notes/; regenerate schema/global.sql --- .claude/skills/sdk/SKILL.md | 1 - .claude/skills/sdk/notes/2026-11-23-ai-3663.md | 1 + acceleration/schema/global.sql | 2 ++ 3 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 .claude/skills/sdk/notes/2026-11-23-ai-3663.md diff --git a/.claude/skills/sdk/SKILL.md b/.claude/skills/sdk/SKILL.md index 4f646e9ef3..346d4368df 100644 --- a/.claude/skills/sdk/SKILL.md +++ b/.claude/skills/sdk/SKILL.md @@ -967,4 +967,3 @@ A device naming a user on a connections call (AI-3412): the router answers every `agent.yaml`'s `greeting` may be its text alone, `greeting: Hello, how can I help?`, read as `{text, mode: variation}`; the mapping still says `exact`, and a mapping without `mode` is now `variation` too, so a folder loader always sends `mode`. The API's own default stays `exact`. Go is done (`GreetingSettings.UnmarshalYAML` in `sdks/go/agents/folder.go`). Other SDKs need to update: the folder loaders of JavaScript (`sdks/js/src/folder.ts`, `greeting()`), Python (`plugins/stream` `folder.py`, `_greeting`), .NET, Ruby, Rust and PHP should take the string form and default a missing `mode` to `variation`. Calls have an id of their own and a `session_id`: a session starts a new call each time voice is started or stopped on it, and an incognito session keeps none, so a session id is no longer a call id. `Call.id` is the call's own id; `Call` gains `session_id` (absent once the session is deleted) and loses `config_id` and `user_id`. `listCalls` (`GET /v1/agents/calls`) takes `session_id` and answers that session's calls newest first. Go is done: `client.Sessions.Timeline` and `Decisions` list the session's calls with `session_id` and `limit=1`, read the newest one's `getCallTimeline` or `getCallEvents`, and fail with `client.ErrNoCall` when the session has none (`sdks/go/client/sessions.go`). Other SDKs need to update: JavaScript, Python (`plugins/stream`), .NET, Ruby, Rust and PHP regenerate their clients, and any helper that passes a session id to `/v1/agents/calls/{id}` (its timeline, events, transcript or tokens) lists the session's calls first; Swift, Kotlin and Dart regenerate `Call` where they have it. STS models list their built-in voices on `Provider.voices` (`ModelVoice`: `id`, `name`, `description`, `gender`, `default`), omitted for non-STS providers, and new voice configs created via `createAgentConfig` or `syncAgent` now default `sts` to `sts-fast` when `sts` is omitted and no cascade settings are provided (explicit `sts: ""` selects the cascade). Go is regenerated (`sdks/go/acceleration/generated.go`). Other SDKs need to update: JavaScript, Python (`plugins/stream`), Swift, Kotlin, Dart, .NET, Ruby, Rust and PHP regenerate their OpenAPI types to pick up `Provider.voices` and `ModelVoice`. -Connectors and router configs carry a `sync_hash`, as agent configs do: `createConnector` (`CustomConnectorRequest.sync_hash`) and `createRouterConfig`/`updateRouterConfig` (`RouterConfigRequest.sync_hash`) take the fingerprint of the file a sync sent, and `Connector.sync_hash` and `RouterConfig.sync_hash` return it. Any write without one clears it; a router config replace with the stored hash and the same content writes nothing, and a connector sent again with the same definition and another hash keeps its revision and records the hash. Every generated client is regenerated in this change; no SDK computes or sends the hash yet. Other SDKs need to update: once the CLI's hash for a connector or router file is settled (AI-3664), a server SDK that syncs those files sends it the same way. diff --git a/.claude/skills/sdk/notes/2026-11-23-ai-3663.md b/.claude/skills/sdk/notes/2026-11-23-ai-3663.md new file mode 100644 index 0000000000..ad31e5c998 --- /dev/null +++ b/.claude/skills/sdk/notes/2026-11-23-ai-3663.md @@ -0,0 +1 @@ +Connectors and router configs carry a `sync_hash`, as agent configs do: `createConnector` (`CustomConnectorRequest.sync_hash`) and `createRouterConfig`/`updateRouterConfig` (`RouterConfigRequest.sync_hash`) take the fingerprint of the file a sync sent, and `Connector.sync_hash` and `RouterConfig.sync_hash` return it. Any write without one clears it; a router config replace with the stored hash and the same content writes nothing, and a connector sent again with the same definition and another hash keeps its revision and records the hash. Every generated client is regenerated in this change; no SDK computes or sends the hash yet. Other SDKs need to update: once the CLI's hash for a connector or router file is settled (AI-3664), a server SDK that syncs those files sends it the same way. diff --git a/acceleration/schema/global.sql b/acceleration/schema/global.sql index 53b9684181..9fcffe2fad 100644 --- a/acceleration/schema/global.sql +++ b/acceleration/schema/global.sql @@ -535,6 +535,7 @@ TABLE connector_definitions manifest jsonb NOT NULL name text NOT NULL revision integer NOT NULL + sync_hash text NOT NULL DEFAULT ''::text CONSTRAINT connector_definitions_custom_prefix CHECK (((customer_id = ''::text) <> starts_with(id, 'custom_'::text))) CONSTRAINT connector_definitions_pkey PRIMARY KEY (customer_id, id, revision) CONSTRAINT connector_definitions_revision_check CHECK ((revision >= 1)) @@ -1094,6 +1095,7 @@ TABLE router_configs search jsonb NOT NULL DEFAULT '{}'::jsonb sts jsonb NOT NULL DEFAULT '{}'::jsonb stt jsonb NOT NULL DEFAULT '{}'::jsonb + sync_hash text NOT NULL DEFAULT ''::text tts jsonb NOT NULL DEFAULT '{}'::jsonb updated_at timestamp with time zone NOT NULL DEFAULT now() CONSTRAINT router_configs_pkey PRIMARY KEY (id) From 1a7db9ff477a55123948b34d82625195911193f6 Mon Sep 17 00:00:00 2001 From: Kanat Date: Mon, 23 Nov 2026 23:51:32 +0100 Subject: [PATCH 07/11] AI-3663: move the sync_hash migration to slot 20270201001200 main's newest global migration is 20270201001110; goose refuses one lower than the DB version. Co-Authored-By: Claude Opus 5.5 --- acceleration/internal/store/connector_definition.go | 2 +- acceleration/internal/store/router_config.go | 2 +- ...c_hash.sql => 20270201001200_connector_router_sync_hash.sql} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename acceleration/migrations/global/{20270201000800_connector_router_sync_hash.sql => 20270201001200_connector_router_sync_hash.sql} (100%) diff --git a/acceleration/internal/store/connector_definition.go b/acceleration/internal/store/connector_definition.go index 242e33a32a..65630ef9e2 100644 --- a/acceleration/internal/store/connector_definition.go +++ b/acceleration/internal/store/connector_definition.go @@ -64,7 +64,7 @@ type ConnectorDefinition struct { Description string `bun:"description,notnull"` Manifest core.Manifest `bun:"manifest,type:jsonb,notnull"` // SyncHash is a fingerprint of the file the CLI last synced onto this revision - // (20270201000800_connector_router_sync_hash.sql). Empty for a built-in, and for a revision + // (20270201001200_connector_router_sync_hash.sql). Empty for a built-in, and for a revision // that was never synced or was written since by anything that is not a sync. SyncHash string `bun:"sync_hash,notnull"` CreatedAt time.Time `bun:"created_at,notnull"` diff --git a/acceleration/internal/store/router_config.go b/acceleration/internal/store/router_config.go index 5b525a7668..1876c58106 100644 --- a/acceleration/internal/store/router_config.go +++ b/acceleration/internal/store/router_config.go @@ -39,7 +39,7 @@ type RouterConfig struct { UpdatedAt time.Time `bun:"updated_at,notnull"` DeletedAt *time.Time `bun:"deleted_at"` // SyncHash is a fingerprint of the file the CLI last synced onto this config - // (20270201000800_connector_router_sync_hash.sql), as AgentConfig.SyncHash is for a + // (20270201001200_connector_router_sync_hash.sql), as AgentConfig.SyncHash is for a // directory. Empty if it was never synced, or was written since by anything that is not a // sync. SyncHash string `bun:"sync_hash,notnull"` diff --git a/acceleration/migrations/global/20270201000800_connector_router_sync_hash.sql b/acceleration/migrations/global/20270201001200_connector_router_sync_hash.sql similarity index 100% rename from acceleration/migrations/global/20270201000800_connector_router_sync_hash.sql rename to acceleration/migrations/global/20270201001200_connector_router_sync_hash.sql From c18817ed526880a48b6e933935337d2459a6072e Mon Sep 17 00:00:00 2001 From: Kanat Date: Mon, 23 Nov 2026 23:53:51 +0100 Subject: [PATCH 08/11] AI-3663: an import from a release before sync hashes stores none A row or change with no sync_hash key inserted NULL into the NOT NULL column and was refused. Co-Authored-By: Claude Opus 5.5 --- acceleration/internal/store/datamove.go | 4 +++ acceleration/internal/store/datamove_test.go | 31 ++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/acceleration/internal/store/datamove.go b/acceleration/internal/store/datamove.go index dbae7d9890..60cab5d73b 100644 --- a/acceleration/internal/store/datamove.go +++ b/acceleration/internal/store/datamove.go @@ -842,6 +842,10 @@ func (s *Store) importRow(ctx context.Context, db bun.IDB, customerID, table str columns := spec.written(shape) quoted := strings.Join(columns, ", ") picked := slices.Clone(columns) + if i := slices.Index(columns, "sync_hash"); i >= 0 { + // A row from a release before sync hashes carries none, and no sync wrote it here. + picked[i] = "COALESCE(r.sync_hash, '')" + } if i := slices.Index(columns, "usage_id"); spec.name == "requests" && i >= 0 { // The usage id is this deployment's, made from the one the row had where it was first // recorded, or from the source's id for a row from before usage ids. A usage id names a diff --git a/acceleration/internal/store/datamove_test.go b/acceleration/internal/store/datamove_test.go index 7c62f3ed7e..dd79cb7c79 100644 --- a/acceleration/internal/store/datamove_test.go +++ b/acceleration/internal/store/datamove_test.go @@ -2100,6 +2100,25 @@ func (s *DataMoveSuite) TestAReplayedRouterConfigChangeIsServedRightAfterIt() { s.Equal("slow", config.Name) } +// TestARouterConfigFromAReleaseBeforeSyncHashesImportsWithNone: an export from before +// sync_hash has no such key, and its row written over one synced here leaves no hash a sync +// did not write. +func (s *DataMoveSuite) TestARouterConfigFromAReleaseBeforeSyncHashesImportsWithNone() { + id := newID() + _, err := s.destination.GlobalDB().ExecContext(s.ctx, + "INSERT INTO router_configs (id, customer_id, name, sync_hash) VALUES (?, 'moved', ?, 'hash-one')", id, "synced-"+id[:8]) + s.Require().NoError(err) + row := `{"id": "` + id + `", "customer_id": "moved", "name": "old-` + id[:8] + `", "stt": {}, "tts": {}, "llm": {}, "sts": {}, "search": {}, + "created_at": "2026-11-01T00:00:00Z", "updated_at": "2026-11-01T00:00:00Z"}` + + s.Require().NoError(s.destination.ImportRow(s.ctx, "moved", "router_configs", json.RawMessage(row))) + + config, err := s.destination.RouterConfigs.Get(s.ctx, "moved", id) + s.Require().NoError(err) + s.Equal("old-"+id[:8], config.Name) + s.Empty(config.SyncHash) +} + func (s *DataMoveSuite) TestASkillMovedByAReplayLeavesItsOldConfig() { destination := s.cachedDestination() app := "moved-" + newID() @@ -2450,6 +2469,18 @@ func (s *DataMoveSuite) TestAChangeCarryingADefinitionTheAPIWouldRefuseIsRefused s.Zero(s.definitionsNamed(id)) } +// A change recorded by a release before sync hashes carries no sync_hash key. +func (s *DataMoveSuite) TestADefinitionChangeFromAReleaseBeforeSyncHashesApplies() { + id := "custom_" + newID() + manifest := strings.Replace(customAcme, "custom_acme", id, 1) + + err := s.destination.ApplyChanges(s.ctx, "moved", []DataChange{{Table: "connector_definitions", Op: ChangeInsert, + Payload: json.RawMessage(`{"id": "` + id + `", "revision": 1, "name": "Acme", "category": "", "description": "", "created_at": "2026-11-01T00:00:00Z", "manifest": ` + manifest + `}`)}}) + + s.Require().NoError(err) + s.Equal(1, s.definitionsNamed(id)) +} + // customAcme is a manifest the API stores for a custom connector custom_acme: an MCP server // taking a bearer token. const customAcme = `{"id": "custom_acme", "revision": 1, "name": "Acme", "endpoints": {"mcp": "https://mcp.acme.example/mcp"}, From ade0624fb0de666c3508973242934b50ad0e7f80 Mon Sep 17 00:00:00 2001 From: Kanat Date: Mon, 23 Nov 2026 23:57:11 +0100 Subject: [PATCH 09/11] AI-3663: other content under the stored hash clears it A read sent back edited carries the hash, which then named content no sync wrote. Co-Authored-By: Claude Opus 5.5 --- acceleration/internal/api/connectors_test.go | 15 +++++++++++++++ acceleration/internal/api/routerconfigs.go | 5 +++++ acceleration/internal/api/routerconfigs_test.go | 16 ++++++++++++++++ .../internal/store/connector_definition.go | 5 +++++ 4 files changed, 41 insertions(+) diff --git a/acceleration/internal/api/connectors_test.go b/acceleration/internal/api/connectors_test.go index 0bbf70c0a2..d62e7d5122 100644 --- a/acceleration/internal/api/connectors_test.go +++ b/acceleration/internal/api/connectors_test.go @@ -447,6 +447,21 @@ func (s *ConnectorsSuite) TestTheSameDefinitionUnderAnotherHashRecordsTheHashOnT s.Equal("hash-two", s.get(id).SyncHash, "so the next sync of the same file finds it unchanged") } +// A client that copies the read connector into a create, edits it and keeps the hash the read +// carried writes a revision no sync wrote. +func (s *ConnectorsSuite) TestAnEditCarryingTheReadHashClearsIt() { + id := s.customID() + s.create(s.synced(s.customConnector(id), "hash-one")) + edited := s.synced(s.customConnector(id), s.get(id).SyncHash) + edited["name"] = "Renamed" + + revised := s.create(edited) + + s.Equal(2, revised.Revision) + s.Empty(revised.SyncHash) + s.Empty(s.get(id).SyncHash) +} + // A dashboard or API create sends no hash, so the next sync of the file sees a hash it did not // write, whether the definition changed or not. func (s *ConnectorsSuite) TestACreateThatIsNoSyncClearsTheHash() { diff --git a/acceleration/internal/api/routerconfigs.go b/acceleration/internal/api/routerconfigs.go index 53a4fc464e..5bd9758777 100644 --- a/acceleration/internal/api/routerconfigs.go +++ b/acceleration/internal/api/routerconfigs.go @@ -128,6 +128,11 @@ func (s *Server) updateRouterConfig(ctx context.Context, request *updateRouterCo len(auditDiff(routerConfigOf(existing), routerConfigOf(config))) == 0 { return &updateRouterConfigResponse{Body: routerConfigOf(existing)}, nil } + // That body is no sync of the file the hash names, such as a read sent back edited, so + // the hash is not kept on content it does not describe. + if config.SyncHash == existing.SyncHash { + config.SyncHash = "" + } config.ID = existing.ID config.CreatedAt = existing.CreatedAt if err := s.store.RouterConfigs.Update(ctx, &config); err != nil { diff --git a/acceleration/internal/api/routerconfigs_test.go b/acceleration/internal/api/routerconfigs_test.go index 6231a33000..69ac9c5da9 100644 --- a/acceleration/internal/api/routerconfigs_test.go +++ b/acceleration/internal/api/routerconfigs_test.go @@ -200,6 +200,22 @@ func (s *RouterConfigsSuite) TestTheSameHashWithOtherContentIsStillWritten() { read := s.readConfig(created.Id) s.Equal("llm-flow", value(read.Stt.Target), "a body the hash does not describe is not dropped") s.True(read.UpdatedAt.After(created.UpdatedAt)) + s.Empty(read.SyncHash, "nor kept under a hash that names another file") +} + +// A client that reads the config, edits it and sends the whole read back sends the hash too. +func (s *RouterConfigsSuite) TestAReadSentBackEditedClearsTheHash() { + created := s.createConfig(s.syncedClinic("hash-one")) + var read map[string]any + s.Require().Equal(http.StatusOK, s.serverClient.do(http.MethodGet, "/v1/router/configs/"+created.Id, nil, &read)) + s.Require().Equal("hash-one", read["sync_hash"]) + read["stt"] = map[string]any{"target": "llm-flow"} + + s.replaceConfig(created.Id, read) + + after := s.readConfig(created.Id) + s.Equal("llm-flow", value(after.Stt.Target)) + s.Empty(after.SyncHash) } func (s *RouterConfigsSuite) TestTheSameFileUnderAnotherHashRecordsTheNewHash() { diff --git a/acceleration/internal/store/connector_definition.go b/acceleration/internal/store/connector_definition.go index 65630ef9e2..0c11987a0b 100644 --- a/acceleration/internal/store/connector_definition.go +++ b/acceleration/internal/store/connector_definition.go @@ -317,6 +317,11 @@ func (r *ConnectorDefinitions) saveRevision(ctx context.Context, customerID stri return err } manifest.Revision = latest.Revision + 1 + // Another manifest under the latest's hash is no sync of the file that hash names, + // such as a read sent back edited, so the new revision carries none. + if syncHash == latest.SyncHash { + syncHash = "" + } } // Validated as it is stored, with the revision it is stored under. From fd051bf54140f96d5e2ab10499645081eb3dc508 Mon Sep 17 00:00:00 2001 From: Kanat Date: Mon, 23 Nov 2026 23:59:21 +0100 Subject: [PATCH 10/11] AI-3663: pin the sync_hash update to the caller's own revision Co-Authored-By: Claude Opus 5.5 --- acceleration/internal/api/connectors_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/acceleration/internal/api/connectors_test.go b/acceleration/internal/api/connectors_test.go index d62e7d5122..06abcd77e4 100644 --- a/acceleration/internal/api/connectors_test.go +++ b/acceleration/internal/api/connectors_test.go @@ -553,6 +553,26 @@ func (s *ConnectorsSuite) TestAnotherAppMayUseTheSameCustomIdWithoutTouchingThis s.Equal(1, s.get(id).Revision) } +// Another app syncing the same custom id and definition, under its own hash and then under +// none, records each on its own revision only. +func (s *ConnectorsSuite) TestAnotherAppsSyncOfTheSameCustomIdLeavesThisOnesHash() { + id := s.customID() + s.create(s.synced(s.customConnector(id), "hash-ours")) + stranger := s.data.backendOfAnotherApp() + + var theirs, cleared Connector + s.Require().Equal(http.StatusOK, stranger.do(http.MethodPost, "/v1/agents/connectors", + s.synced(s.customConnector(id), "hash-theirs"), &theirs)) + s.Require().Equal(http.StatusOK, stranger.do(http.MethodPost, "/v1/agents/connectors", + s.customConnector(id), &cleared)) + + s.Equal("hash-theirs", theirs.SyncHash) + s.Empty(cleared.SyncHash) + ours := s.get(id) + s.Equal("hash-ours", ours.SyncHash) + s.Equal(1, ours.Revision) +} + func (s *ConnectorsSuite) TestTheListIsTheBuiltInsThenTheAppsOwnEachById() { second, first := "custom_b"+s.suffix(), "custom_a"+s.suffix() s.create(s.customConnector(second)) From 6d47d1660f810421a85c6e91ce7170a0b06a8c76 Mon Sep 17 00:00:00 2001 From: Kanat Date: Tue, 24 Nov 2026 01:11:19 +0100 Subject: [PATCH 11/11] AI-3663: compare a synced router config with the stored row, not the create answer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The create answers with the Go clock (ns on Linux), Postgres keeps µs, so the unchanged-sync test failed on Linux CI at routerconfigs_test.go:189-190. Co-Authored-By: Claude Sonnet 5.5 --- acceleration/internal/api/routerconfigs_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/acceleration/internal/api/routerconfigs_test.go b/acceleration/internal/api/routerconfigs_test.go index 69ac9c5da9..059f9e4100 100644 --- a/acceleration/internal/api/routerconfigs_test.go +++ b/acceleration/internal/api/routerconfigs_test.go @@ -182,16 +182,19 @@ func (s *RouterConfigsSuite) TestASyncedRouterConfigShowsItsHashOnEveryRead() { func (s *RouterConfigsSuite) TestSyncingTheSameFileAgainWritesNothing() { created := s.createConfig(s.syncedClinic("hash-one")) + // The create answers with the Go clock (ns on Linux); Postgres keeps µs. Compare with the stored row. + stored := s.readConfig(created.Id) replaced := s.replaceConfig(created.Id, s.syncedClinic("hash-one")) s.Equal("hash-one", replaced.SyncHash) - s.True(created.UpdatedAt.Equal(replaced.UpdatedAt), "answered with the config as it was") - s.True(created.UpdatedAt.Equal(s.readConfig(created.Id).UpdatedAt), "and nothing was written") + s.True(stored.UpdatedAt.Equal(replaced.UpdatedAt), "answered with the config as it was") + s.True(stored.UpdatedAt.Equal(s.readConfig(created.Id).UpdatedAt), "and nothing was written") } func (s *RouterConfigsSuite) TestTheSameHashWithOtherContentIsStillWritten() { created := s.createConfig(s.syncedClinic("hash-one")) + stored := s.readConfig(created.Id) changed := s.syncedClinic("hash-one") changed["stt"] = map[string]any{"target": "llm-flow"} @@ -199,7 +202,7 @@ func (s *RouterConfigsSuite) TestTheSameHashWithOtherContentIsStillWritten() { read := s.readConfig(created.Id) s.Equal("llm-flow", value(read.Stt.Target), "a body the hash does not describe is not dropped") - s.True(read.UpdatedAt.After(created.UpdatedAt)) + s.True(read.UpdatedAt.After(stored.UpdatedAt)) s.Empty(read.SyncHash, "nor kept under a hash that names another file") }