Repository navigation
Conversation
…acting-user wire A Connections call that names a user on a client holding a user's token (AsUser, or Token with UserId) now throws ConfigurationException before any request (AI-3412). Tests pin that a user given replaces the user the client was made for with a server token behind the proxy, which is what the router needs; Go differs (AI-3410). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
kanat
left a comment
There was a problem hiding this comment.
Round-1 review of #2155 at 124b857d4, merged onto main at 2d236ed89 (the base had not moved).
Checks run:
- .NET suite in Docker, LiveTests left out, 3 runs on the head: 328/328 each time.
- The same 3 runs on the base: 2 passed (322/322). Run 3 failed 1 test,
DispatchTests.AWorkerReconnectingSaysWhatItIsStillHandling(TimeoutException,DispatchTests.cs:298). That test flakes on the base too; this PR does not touch it. - Controls: the new
ConnectionsTests.csrun against the base code. Only the two device-refusal cases fail there. The no-user, server-token and customer-id tests pass on the base, so a call that names no user sends the same request as before. - Mutations: 11 checked, 0 survived. They include removing the guard, moving it above the no-user branch, keying it on
Token/ApiSecret/UserId, throwing a different exception type, andActingkeepingUserId(the Go behaviour). At the call site, a named call sent on_clientwithoutActingForwas also killed.
[Question] R1.5 Go behaviour: CONFIRMED, but the request is refused somewhere else than the PR says. A throwaway probe on client.New(stream.Backend{APIKey, APISecret, UserID: "ada", Authenticate: true}).Connections().Get(..., ConnectionOptions{UserID: "alice"}) sent claims {user_id: ada}, Stream-Auth-Type: jwt and X-Stream-User-Id: alice. Source: sdks/go/stream/backend.go:250-253 and :273-275, plus client/connections.go:187-190, which sets only ActingFor and keeps UserID. Stream's proxy refuses this request before it reaches the router: a user_id token is kind jwt, and a header naming somebody else gets a 403 "only a server-side caller may name another user" (GetStream/chat projects/stream-accelerate/proxy.go, the jwt-kind switch and the userHeader check). The router's server_side_only (server.go:1257-1275) would answer only if the header repeated the token's own user. auth.go:435-444 is the keyed (no-proxy) authenticator. There, Go's stream-auth-type: jwt makes every Go caller non-server whatever its claims, so those lines do not show the proxied path. Either way Go needs its own fix: drop UserID on a call that names a user, as .NET, JS, Python, PHP, Ruby and Rust do. That fix belongs in a Go PR.
[Nit] R1.2 (ticket, existing code). Backend.cs:297 and :254: a client given both ApiSecret and Token (with Authenticate) counts as ServerSide, so it gets past the new guard. A probe naming alice sent Authorization: Bearer ada-token with X-Stream-User-Id: alice. That is a user's token, which the proxy refuses with a 403, and it contradicts the new doc line "the request keeps the server credential". The base sends the same request. Fix: refuse a Token beside an ApiSecret in the constructor, or have Acting drop the token when a secret is held.
[Nit] R1.4 (ticket). CHANGELOG.md:17: the new sentence has no PR number. AGENTS.md («Changelog») asks for (#2155).
Verdict: NO-GO, for R1.1 (the docs say the router answers Go's request with 403 server_side_only; the proxy refuses it first). R1.2 to R1.5 go to tickets. The guard (Connections.cs:167) is correct and pinned by tests. A call that names no user sends the same request as on the base, and the customer-id path is unchanged.
| Ruby connections and the user parameter (AI-3380, AI-3387): `Client#connections` has `create(connector, label:, user_id:)`, `authorize(id, return_url:, user_id:)`, `get(id, user_id:)`, `list(connector:, user_id:)` (every page, `owner_type` app or user) and `delete(id, user_id:)`; a `user_id` is the owner on create and `X-Stream-User-Id` on every call, none is the app's connection with no header. `Client#get`, `post`, `put`, `patch`, `delete` and `socket` take an optional `user_id:` last (nil keeps whoever the backend acts for, empty drops it), and `Backend#acting_for` keeps working with a `@deprecated` tag pointing at it; `Dispatch#answer` acts through `Backend#acting` (`@api private`). Other SDKs follow the same rule (AI-3378..AI-3383). | ||
| A screened turn carries its guardrail check: `TimelineEntry.guardrail` and the `guardrail` field of the session socket's `turn` frame, a `GuardrailCheck` (`kind`, `model`, `probability`, `threshold`, `allowed`, `latency_ms`, `held_ms`, `mode`, `failed`), absent when no check ran; a written aside (`Agent.Ask`) is no turn, so its check is not recorded. A `type: decision_model` guardrail.md takes a `question:` key, and a guardrail webhook's body has `conversation`, the lines said before the turn. Go has the regenerated client and `agents.GuardrailAsk.Conversation`. The generated clients are regenerated for Go, JavaScript types and Python `plugins/stream`. Other SDKs need to update: Ruby, PHP, .NET and Rust should regenerate for `GuardrailCheck`, and add `conversation` to their guardrail webhook body where they have one; Swift, Kotlin and Dart read `guardrail` off the `turn` frame once they show one (Swift's client was not regenerated here: its generator needs the chat repo's `tools/openapi`). | ||
| Acting for a user (AI-3396): Go deprecated `Backend.ActingFor`: name the user on the call where it takes one (`UserID` of `client.Connections()` options, `XStreamUserId` of a generated call's params such as `CreateScheduledTaskParams`, or an `X-Stream-User-Id` set on one request with an `acceleration.RequestEditorFn`); `client.Agent(...)` calls take no per-call user yet, so `ActingFor` stays how they act for one. `ActingFor` keeps working and sends what it always did. Other SDKs need to update: JavaScript (#2110), Python (#2103), Ruby (#2102) and PHP (#2101) deprecate their own helper in their open PRs, each with an optional per-call user; .NET (#2099) and Rust (#2100) add the per-call user and have no public helper to deprecate. Until those merge, none of them is deprecated. | ||
| Acting for another user in .NET connections (AI-3410, AI-3412): a `Connections` call that names a user sends the client's server credential and `X-Stream-User-Id`, and drops the user the client was made for (`Backend.Acting` sets `UserId` to empty, `Backend.cs:254`). Behind the proxy that is a `server: true` token, as Python (`_backend.py:463`), JavaScript (`speakingFor`, `backend.ts:575`), PHP (`Backend.php:198`), Ruby (`backend.rb:301`) and Rust (`client.rs:174`) send; **Go differs**: a `Backend` with `UserID` and `ActingFor` signs `{"user_id": <UserID>}` and adds the header (`stream/backend.go:250-253`, `:273`), a user token the router answers as a device (403 `server_side_only`), so a Go client made for a user cannot name another on a connections call; Go should drop `UserID` for the call, as the others do. A client holding a user's token (a device: `AsUser`, or `Token` with `UserId`) naming a user on a connections call throws `ConfigurationException` before any request, as JavaScript's `connections.ts:137-146` does; a customer-id client (`ServerSide` true) is unchanged. Other SDKs need to update: Go (the call's user replaces `UserID`), Python, Ruby and Rust (refuse a device's user before sending, AI-3412). |
There was a problem hiding this comment.
[Should fix] R1.1 This note says Go's request is "a user token the router answers as a device (403 server_side_only)". A probe on the base confirms what Go sends: claims {user_id: ada} with X-Stream-User-Id: alice. But Stream's proxy refuses that request before the router sees it: a user_id token is kind jwt, and a header naming another user gets a 403 "only a server-side caller may name another user" (GetStream/chat projects/stream-accelerate/proxy.go, the userHeader check; NotAllowedError is a 403). server_side_only (acceleration/internal/api/server.go:1257-1275) would answer only if the header repeated the token's own user. The Go fixer will read this note, so it should name the right refusal. Fix: "...a user token, which Stream's proxy refuses with a 403 (only a server-side caller may name another user)". Correct the PR body's "Answer to AI-3410" section the same way.
| device. It cannot act for another user, so a call naming one throws a `ConfigurationException` | ||
| before any request, and a call naming none is sent as before. The Go SDK differs here: a | ||
| `client.Client` made for a user (`UserID` with the secret) keeps signing that user's own token | ||
| when a call names another, which the router answers as the device it is. |
There was a problem hiding this comment.
[Should fix] R1.1 (same finding) "which the router answers as the device it is": behind the hosted router it is the proxy that refuses this request, with a 403, before the router sees it (see the SKILL.md comment). Suggest: "which Stream's proxy refuses with a 403, as it refuses a device naming another user".
There was a problem hiding this comment.
Fixed in 6cf1e07 (wording; test: none, prose only). The Go sentence now says Stream's proxy refuses the call with a 403, not the router.
| A user given replaces the one the client was made for (`VisionAgentsOptions.UserId`), and the | ||
| request keeps the server credential: behind the proxy it is a server token, not a token for the | ||
| client's own user, which is what the router needs to let a backend act for somebody. A client | ||
| that holds a user's token instead of the secret (`AsUser`, or `Token` with `UserId`) is a |
There was a problem hiding this comment.
[Nit] R1.3 (ticket) "AsUser ... is a device ... throws": AsUser on a customer-id client is ServerSide and is not refused. Your own ACustomerIdClientMadeForAUserStillNamesAnotherOnATrustingRouter pins that. The same wording is in CHANGELOG.md:17 and the Connections remarks (Connections.cs:49). Say "a client with an API key that holds a user's token".
There was a problem hiding this comment.
Fixed in 7db125d (wording; test: none, prose only). The paragraph now says a client with an API key holding a user's token; AsUser of a customer-id client is not refused, pinned by ACustomerIdClient in ConnectionsTests.cs.
SKILL.md and the README said the router answers Go's request with 403 server_side_only. Stream's proxy refuses it first (proxy.go:277, a user token naming another user, 403), so the router never sees it.
…User AsUser of a customer-id client is not refused (ServerSide is true, pinned by ACustomerIdClient), so 'AsUser throws' was wrong in the README, CHANGELOG, the Connections doc comment and the sdk skill. The refusal is for a client with an API key holding a user's token.
AGENTS.md Changelog: every entry references its PR.
proxy.go:430 and errors.go:223-225 on chat master; the earlier :277 was a line of another branch.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#2156 changes the Go behaviour this sentence described. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Go, Ruby and Rust (#2156) ## Why The router answers every connections call made with a user token with `403 server_side_only`: these operations carry no `x-client-accessible`, so `refuseClientSide` stops them before the handler (`acceleration/internal/api/server.go:1262`). A device that names a `userId` on a connections call therefore always failed, after a request, with a generic router error. The JavaScript and PHP SDKs already refuse it before sending. Python, Go, Ruby and Rust did not (AI-3412). Go had a second bug. A `Backend` built for one user with the API secret, naming another user on a connections call, signed a token for its own user plus `X-Stream-User-Id: <named>`. Stream's proxy refuses that pair with 403 (`chat projects/stream-accelerate/proxy.go:425-431`). The other SDKs act for the named user with the app's token. ## How it works ``` device (user token, no secret) backend (API key + secret) connections.get(id, "a") connections.get(id, "a") | | was: request -> router 403 request as "a" (app token) now: SDK error, nothing sent (unchanged in Python, Ruby, Rust) Go backend built for "ada", naming "a": was: token for "ada" + X-Stream-User-Id: a -> proxy 403 now: server token + X-Stream-User-Id: a (the wire of Python's acting_for) ``` A device is a client holding a user's token. Python, Ruby and Rust key it on the SDK's own `server_side`. Go keys it on `Authenticate` with a `UserID` and a `Token`, because `SetUser` keeps the API secret and sets the token (`sdks/go/client/client.go:96-98`). Left as they were, each with a control test: - a call naming no user, or an empty one, on any client - a backend naming a user in Python, Ruby and Rust - a client on a router that trusts the customer id (`as_user` or `SetUser` with a customer id and no API key): it sends no token, works against a dev router today, and is out of scope ## Changes | SDK | Where | Result | | --- | --- | --- | | Python | `Connections._client` | a device naming a user raises `ValueError` (as `Client._acting`) | | Go | `Connections.api` | a device naming a user returns a `client:` error; a backend built for a user and naming another drops its own `UserID` for that call and sends the app's token with `X-Stream-User-Id` | | Ruby | `Connections#named` | a device naming a user raises `ConfigurationError` | | Rust | `Connections::acting` | a device naming a user returns `Error::Configuration`; `acting` now returns `Result<Client>`, public signatures unchanged | `sdks/go/stream` (`backend.go`, Dispatch) and `client.Agent` are unchanged: the Go fix is a local copy of the backend inside `Connections.api`. Also: one CHANGELOG entry and one note at the bottom of `.claude/skills/sdk/SKILL.md`. .NET follows in #2155 (AI-3410). ## Validation - Python `plugins/stream`: `uv run --no-sync pytest plugins/stream -m "not integration"`: 683 passed. - Go `sdks/go`: `gofmt -l` empty, `go vet ./...`, `go test ./client ./stream` ok, `-race -cpu 1 -count=3` on the new and device tests ok. - Ruby: `rake` in Docker: 259 runs, 0 failures. - Rust: `cargo test`, `clippy --workspace --all-targets -D warnings`, `fmt --all --check`: ok. - Tests per SDK: a device naming a user is refused on every connections call, with nothing sent; a device naming no user sends the same request as before; a customer-id client still names a user. Go adds a backend built for a user that names another user and acts for the named one, with the wire checked against Python's `acting_for`. - Each new rule has a mutation check. Round 1: 13 mutants, 0 survived. Round 2: 8 mutants, 1 survivor that is equivalent (`|| APISecret == ""` on the Go token guard: `Resolve` already refuses a backend with neither secret nor token, `backend.go:229`). - CI: green on `71e72b8ef` (CodeQL, go, sdks, unit Lint and Test "not integration", Analyze). ## Review rounds | Round | Head | Verdict | Findings | Outcome | | --- | --- | --- | --- | --- | | R1 | `a7e82f8ad` | GO, with an orchestrator Should fix | X0.1 (Should fix): a Go backend built for a user, naming another user, is refused locally. Confirmed by #2155's review. R1.1 (Nit): the Ruby generic verbs (`get`, `post`, `put`, `patch`, `delete`, `socket`) do not refuse a device naming a user | Fixer r1 fixed X0.1 in `989bd9235`. Fixer r1 disputed R1.1: `getSession` is client-accessible and a device may name itself | | R2 | `71e72b8ef` | GO | X0.1 fixed; R1.1 withdrawn (no gap: `getSession` is `x-client-accessible`, so a refusal would break a working call) | 8 mutants, 1 equivalent survivor | ## Related - AI-3412 (this PR) - [#2155](#2155): the .NET part of the device refusal, AI-3410 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Why
AI-3410: a .NET client made for one user (secret +
UserId, behind the proxy) naming another user on a connections call: does it lose its user token, and does Go do the same? AI-3412 (.NET part): a device client naming a user on a connections call got the router's generic 403; it should be refused before sending, as JavaScript does (sdks/js/src/connections.ts:137-146).How it works
X-Stream-User-Idmakes the router's principal a backend acting for that user (acceleration/internal/auth/auth.go:468). A token carrying auser_idis a user, never server side (auth.go:435-444).chat/projects/stream-accelerate/proxy.go:430,chat/lib/core/errors/errors.go:223-225, both on chat master).Changes
Connections.SendAsync(sdks/dotnet/src/GetStream.VisionAgents/Connections.cs): a call naming a user on a client that is notServerSidethrowsConfigurationExceptionbefore anything is sent. The customer-id path (ServerSidetrue, header-trusting dev router) is unchanged. No change toBackendorActingFor.Connections.cs(the class remarks andSendAsync).sdks/dotnet/README.md: a paragraph on naming a user on a connections call..claude/skills/sdk/SKILL.md: one note at the bottom (Go differs; Go, Python, Ruby and Rust to follow).CHANGELOG.md: one sentence in the .NET entry, with(#2155).ConnectionsTests.cs: four new tests (see Validation).4626f6ae4, which brings8e68a6c5c(test(api): fix four integration tests that fail at random #2150, acceleration tests only). It changes no .NET code.UserIDon a call that names a user ([AI-3412] Refuse a userId on a device's connections calls in Python, Go, Ruby and Rust #2156); Python, Ruby and Rust refusing a device's user (AI-3412, other PRs).Validation
ConnectionsTests: 20/20 on head (reviewer-1.md:11).UserId=adabehind the proxy: a call naming alice sendsserver: true, nouser_idclaim andX-Stream-User-Id: alice; a call naming none sendsuser_id: adaand no header.ApiKey+Token+UserId, andAsUserof a secret client), direct and proxied: all five calls throwConfigurationException, and the router sees 0 requests.Bearer <its token>,Stream-Auth-Type: jwt, no user header.AsUser, naming alice: still sendsX-Customer-IdandX-Stream-User-Id.ConnectionsTests:Token != ""ActingkeepsUserId(the Go behaviour)ServerSideignores customer-idServerSidetrue for a tokendotnet formatofConnectionsTests.cs: applied in 41a0dea; CI had caught the format difference.ci.txt: SDK checks, CodeQL, GitGuardian, labeler, Analyze). Commit 2999041 changes only a README sentence; its CI was pending when this body was written.DispatchTests.AWorkerReconnectingSaysWhatItIsStillHandlingtimed out once in three runs on base2d236ed89(DispatchTests.cs:298). Ticketed separately; not in this PR.Review rounds
proxy.go:425-431, not the router'sserver_side_only. Wording fixed in 6cf1e07; cite in ead1ee5.ApiSecretandTokencounts asServerSide, so it gets past the guard and sends the user's token withX-Stream-User-Id. The base sends the same request. Ticket: refuse aTokenbeside anApiSecret, or drop the token when a secret is held.AsUserthrows; a customer-id client'sAsUseris not refused. Now "a client with an API key holding a user's token". 7db125d.(#2155)added in ce1d826.user_id: adawithX-Stream-User-Id: alice, which the proxy refuses. Go fix in #2156.8e68a6c5c(acceleration tests only).dotnet formatofConnectionsTests.cs; CI had caught it.Answer to AI-3410
.NET already sends what the router needs: the server token plus
X-Stream-User-Id, as Python, JavaScript, PHP, Ruby and Rust do. Go was the odd one on base: it signs the client's own user (user_id: ada) with the header, and Stream's proxy refuses that user's token with a 403 when it names another user. Go is fixed in #2156. The .NET README no longer mentions Go (commit 2999041).Wire for a client built with secret +
UserId=ada, proxy on, one call namingalice(all at2d236ed89; Go measured with a throwaway test onstream.Backend.Credentials()):X-Stream-User-Iduser_id: adaalicesdks/go/stream/backend.go:250-253,273;client/connections.go:187-190keepsUserIDserver: truealiceBackend.cs:254(UserId = ""),Backend.cs:273-275server: truealice_backend.py:463server: truealicebackend.ts:573-581server: truealiceBackend.php:198server: truealicebackend.rb:301server: truealiceclient.rs:172-176Without the secret (a device:
ApiKey+Token), .NET keeps the token, as Go does. That call is now refused before sending (see How it works).🤖 Generated with Claude Code