Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .claude/skills/add-connector/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .claude/skills/sdk/notes/2026-11-23-ai-3663.md
Original file line number Diff line number Diff line change
@@ -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.
20 changes: 20 additions & 0 deletions acceleration/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3552,6 +3552,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
Expand Down Expand Up @@ -4692,6 +4696,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
Expand Down Expand Up @@ -8718,6 +8728,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:
Expand All @@ -8742,6 +8756,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:
Expand Down
10 changes: 8 additions & 2 deletions acceleration/internal/api/connectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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."`
}

Expand Down Expand Up @@ -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"`
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
}
}
129 changes: 129 additions & 0 deletions acceleration/internal/api/connectors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,115 @@ 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 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() {
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() {
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",
"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))
Expand Down Expand Up @@ -444,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))
Expand Down
16 changes: 16 additions & 0 deletions acceleration/internal/api/routerconfigs.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ 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 &&

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

[Should fix] R1.3 A replace that sends the stored hash with different content is written and keeps the hash, so the hash now describes content no sync wrote. This happens with a client that reads the config and sends it back edited. RouterConfigRequest allows extra properties, so a GET body PUT back whole is accepted, sync_hash included. The CLI's next sync then sees its own hash and cannot see the edit. Probe: create with hash-one, GET as a map, set stt.target, PUT the map back. The stored sync_hash is still hash-one.

Fix: after the early return, add if config.SyncHash == existing.SyncHash { config.SyncHash = "" }. Then assert the cleared hash in TestTheSameHashWithOtherContentIsStillWritten, add the echo row above, and update the PR body row "same hash, other content". After a stale hash, one more sync records it again.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in ade0624: other content under the stored hash now clears it. Tests: TestRouterConfigsSuite/TestTheSameHashWithOtherContentIsStillWritten (now asserts no hash) and TestAReadSentBackEditedClearsTheHash (GET as a map, edit stt, PUT it back). Both fail with the new if turned off.

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 {
Expand Down Expand Up @@ -342,6 +354,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
Expand All @@ -357,6 +370,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,
}
Expand Down Expand Up @@ -549,4 +563,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."`
}
Loading
Loading