You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[AI-3383] Rust SDK: a connections resource and an optional user_id - #2100
A backend that connects its users' accounts (Linear, GitHub) had only generated operations in the Rust SDK (AI-3375). It had to build a whole client with ClientOptions::user_id and keep it equal to owner.user_id: the router refuses a user connection when the two differ (acceleration/internal/api/connections.goownerOf). The user is now an optional user_id on each call (AI-3387).
none from the call; a client's own ClientOptions::user_id stays as built (as Go)
Options structs (Default) rather than adjacent Option<&str>, so a label cannot be swapped for a user.
A user named goes through the existing pub(crate) Client::acting_for (dispatch's path, dispatch.rs:374): it clones the client, sets acting_for and clears ClientOptions::user_id.
An empty id is refused before any request.
What the router answers (connections.go:742mayReach):
every backend call reaches an app connection, even one naming a user;
list with a user holds only that user's;
another user's connection is a 404, as for one that does not exist.
Changes
Piece
Before
After
Client::connections()
none
Connections with create, authorize, get, list, delete
NewConnection, AuthorizeOptions, ConnectionFilter
none
Default structs with user_id, re-exported in lib.rs
Backend.acting_for, Client::acting_for
pub(crate)
unchanged: no public helper, so nothing to deprecate and no #[deprecated] (backend.rs:189)
Existing public wrappers
none changed: searched sdks/rust, README, examples/, docs. connections is the only wrapper taking user_id, so no backward-compatibility test
a section "A user's own accounts", one entry, one note
Validation
cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings, cargo run -p generate -- --check and cargo test, in rust:1 per the sdk-rust skill: pass (round-2 reviewer, all 12 test targets and doctests). The tests use the axum stand-in router (tests/support), which records method, path, query, body and headers.
Mutations: the fixer's 22 killed (fix-1-mutate.log); round 2 reran them plus 4 more: 26 checked, 0 survived.
Live on the staging router, test user, connector linear, booleans and statuses only (live/live-2.log): create (owner user, pending), authorize (https launch URL, token, expiry set), get, get as another user and as the app are 404, list holds it and the app list does not, delete; cleanup found 0 leftovers.
Review rounds
Round
Verdict
Findings
Sha
1
NO-GO
R1.1 options structs, R1.2 surviving list mutant, R1.3 changelog form, R1.4 None keeps the client's own user: all fixed
bbf74b9fd
2
GO
no new findings
b2083269b
Head eca728e67 adds a main merge and restores main's CHANGELOG lines on top of the GO sha.
The reason will be displayed to describe this comment to others. Learn more.
Reviewed bbf74b9fd merged onto mainfa2a6a66d (base is already an ancestor). In rust:1: cargo fmt --check, generate -- --check, clippy -D warnings and cargo test all pass. CI was pending when read. Mutations: 31 checked (the author's 25 plus 6 of mine), 1 survived (R1.2).
[Question] R1.4 An empty or None user ignores a ClientOptions::user_id the client was built with: Client::acting_for clears it (client.rs:158-160). That matches the shape (absent means an app connection, no header). Go #2095 at 92148e5fe behaves differently: Connections.api sets only ActingFor, so Backend.token() (sdks/go/stream/backend.go:242) still mints a user token for UserID behind the proxy. Nothing to change here; the Go side should decide.
Checked and sound: the doc comments match the router (mayReach, connections.go:742; a user list with the header holds only that user's, connections.go:411). delete sends no force (pinned by a test). The generated delete_connection keeps force because the generator owns it. No public acting helper exists to deprecate: Backend is not re-exported and Client::acting_for is pub(crate). The change is additive only, with no logging and no dependency added.
Verdict: request changes, for R1.1 (positional Option<&str> arguments that can be swapped) and R1.2 (the surviving list mutant).
The reason will be displayed to describe this comment to others. Learn more.
[Should fix] R1.1 Three methods take two Option<&str> arguments side by side: create(connector, label, user_id), authorize(id, return_url, user_id) and list(connector, user_id). Swapping them compiles without any warning. create("linear", Some("alice"), None) stores an app connection labelled alice. Every backend call reaches that connection (mayReach, connections.go:742), and any of the app's agents may bind it. list(Some("alice"), None) lists the app's connections to a connector named alice. Go #2095 uses structs here (ConnectionRequest, AuthorizeOptions, ConnectionFilter), and this SDK already uses Default option structs (LimitFilter in limits.rs:73, which has user_id, and Query in sessions.rs:84). Fix: use Default structs, for example NewConnection { connector, label, user_id }, AuthorizeOptions { return_url, user_id } and ConnectionFilter { connector, user_id }. get and delete can keep (id: &str, user_id: Option<&str>), because their argument types differ and cannot be swapped. Update the README, the doc example, CHANGELOG, the sdk skill note and the tests to match.
The reason will be displayed to describe this comment to others. Learn more.
Fixed in b208326 (code in 030f309): NewConnection, AuthorizeOptions and ConnectionFilter (Default structs) replace the adjacent Option<&str> pairs; get and delete keep (id, user_id). README, doc example, CHANGELOG, sdk note and tests are moved to them. Mutants of every field (label, connector, return_url, user_id) fail in tests/connections.rs.
The reason will be displayed to describe this comment to others. Learn more.
[Should fix] R1.2 A mutant survives here. I deleted let user_id = named(user_id); in list, and all 11 tests still pass. Under that mutant, list(None, Some("")) sends owner_type=user with no X-Stream-User-Id. The router answers that request from a backend with every user's connections (connections.go:411-418, everyUser). Test row for the_apps_list_names_no_connector_unless_asked (tests/connections.rs:273): also call list(None, Some("")) and assert query == "owner_type=app&limit=200" and no x-stream-user-id. I checked this row in a scratch copy: it passes on the head and fails under the mutant (left owner_type=user&limit=200). If R1.1 changes the signature, keep the same row with user_id: Some("") in the filter.
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 030f309: a_list_naming_an_empty_user_is_the_apps_not_a_users lists Some("") and expects owner_type=app&limit=200 with no header. Mutant "list call site keeps empty as a user" (removing named in list) now fails it and every_call_sends_the_user_it_names_and_only_that_one.
The Rust SDK connects a user's own accounts: `Client::connections()` has `create(connector, label, user_id)`, `authorize(id, return_url, user_id)` (the consent's launch URL, handoff token and expiry), `get(id, user_id)`, `list(connector, user_id)` (every page) and `delete(id, user_id)`; a user given goes out as both the owner and `X-Stream-User-Id`, and `None` is the app's own connection.
The reason will be displayed to describe this comment to others. Learn more.
[Nit] R1.3 This entry is a bare paragraph directly under ## Features, above the ### entries. The other entries are a ### heading followed by a paragraph. This goes to a ticket and is not needed for this PR.
Reviewing files that changed from the base of the PR and between ce7511f and ee01282.
Files selected for processing: 7
.claude/skills/sdk/SKILL.md
CHANGELOG.md
sdks/rust/README.md
sdks/rust/src/client.rs
sdks/rust/src/connections.rs
sdks/rust/src/lib.rs
sdks/rust/tests/connections.rs
Walkthrough
The Rust SDK adds a Client::connections() accessor and a Connections API. The API supports create, authorize, get, list, and delete operations for app-owned and user-owned connections. It adds request option types, ownership and acting-user handling, pagination, and validation for empty connection IDs. The README, changelog, skill note, and integration tests were updated to document and test the API.
Merge Risk: Low · previous review ce751
The Rust connections API looks sound and its router ownership checks hold. The README walkthrough deletes the connection before consent completes, which would mislead readers. Documentation of owner and header behavior and of empty user IDs needs correcting. Listing connections has no page limit against a faulty router. These are small fixes to make before or soon after merge.
- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
…eps the client's own user
R1.1 NewConnection, AuthorizeOptions and ConnectionFilter replace adjacent Option<&str> parameters.
R1.2 a test for list naming an empty user.
R1.4 a call naming no user leaves ClientOptions::user_id as it is.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
R1.1 fixed. NewConnection, AuthorizeOptions and ConnectionFilter replace the adjacent Option<&str> parameters (connections.rs:9-37); get and delete keep (id, user_id). They are re-exported (lib.rs:42), and the README, doc example, CHANGELOG and sdk skill note follow.
R1.2 fixed. a_list_naming_an_empty_user_is_the_apps_not_a_users checks owner_type=app&limit=200 with no header. The mutant "list keeps an empty user as a user" now fails it.
R1.3 fixed. The CHANGELOG entry uses the ### heading and a paragraph.
R1.4 fixed. acting() returns client.clone() for no user, so the client's own ClientOptions::user_id stays. A named user replaces it. Both directions are tested, including the proxy token claims (bob when unnamed, no user_id when ada is named). Both mutants fail.
Q0.3: the public delete(id, user_id) has no force. Only the generated DeleteConnectionQuery has it, and connections.rs sends its default. Mutant "force sent" is killed.
Q0.4: an empty user_id is the same as none. Closed.
CI steps run locally in rust:1 (the rust job in ci.yml): generate --check, fmt --check, clippy --all-targets -D warnings and cargo test all exit 0. All 12 test targets and the doctests pass. The PR's own rust check is green; other jobs were still running when I read them.
Mutations: 26 checked (the fixer's 22 rerun, plus 4 of mine), 0 survived. No new findings in the changed hunks.
## Why
A backend that connects its users' accounts (Linear, GitHub) has only
the generated operations in the Go SDK. It sets `X-Stream-User-Id` by
hand and must keep it equal to `owner.user_id`: the router refuses a
user connection whose two values differ
(`acceleration/internal/api/connections.go:765`).
This is the first of the seven server SDKs (AI-3375). Its shape was
decided in #video-ai on 2026-11-19:
- flat `api.Connections()`, with no `agents.` level;
- the user is a per-call parameter, as Chat's server SDKs pass
`user_id`;
- no per-user client.
The other six copy it, and merge after this PR:
- JavaScript [#2110](#2110)
- Python [#2103](#2103)
- Ruby [#2102](#2102)
- PHP [#2101](#2101)
- .NET [#2099](#2099)
- Rust [#2100](#2100)
## How it works
```
api.Connections()
├─ Create(ctx, ConnectionRequest{Connector, Label, UserID})
│ UserID set -> owner {type: user, user_id: UserID} + X-Stream-User-Id: UserID
│ UserID empty -> owner {type: app} + no X-Stream-User-Id
├─ Authorize(ctx, id, AuthorizeOptions{ReturnURL, UserID}) -> launch URL, handoff token, expiry
├─ Get(ctx, id, ConnectionOptions{UserID})
├─ List(ctx, ConnectionFilter{Connector, UserID}) owner_type user|app, reads every page
└─ Delete(ctx, id, ConnectionOptions{UserID})
```
```go
conn, err := api.Connections().Create(ctx, client.ConnectionRequest{Connector: "linear", UserID: "alice"})
auth, err := api.Connections().Authorize(ctx, conn.ID, client.AuthorizeOptions{ReturnURL: returnURL, UserID: "alice"})
conn, err = api.Connections().Get(ctx, conn.ID, client.ConnectionOptions{UserID: "alice"})
```
The user is always the `UserID` of the call's options struct. No two
strings sit side by side, so a call cannot swap them.
| Call | `X-Stream-User-Id` | What the router answers |
| --- | --- | --- |
| `UserID: "alice"` | `alice`, also on reads | alice's connection; an
app connection is reached too (`mayReach`, `connections.go:742-745`) |
| `UserID` empty | none: only the acting-for user is cleared, and a
client's own `UserID` stays | the app's connections |
| `List` with `UserID` | `alice` | only alice's connections |
A per-call copy of the client's `stream.Backend` gets `ActingFor =
userID` (`client/connections.go:187-191`). Results are the generated
`acceleration.Connection` and `acceleration.Authorization`. Refusals are
`*stream.RouterError`.
The change is additive only, per Chat's "deprecate, never break" rule.
Go had no public acting-for helper, so nothing is deprecated here; the
other SDKs deprecate theirs (AI-3387).
## Changes
- `sdks/go/client/connections.go`: the resource.
- `client/client_test.go`: the stand-in router now records each
request's headers. It serves the connection routes with the router's own
owner rules (`ownerOf`, `mayReach`).
- `sdks/go/README.md`: new section "A user's own accounts".
- `CHANGELOG.md`: one entry.
- `.claude/skills/sdk/SKILL.md`: a note for the other SDKs. In each, the
user is an optional named parameter (`userId` / `user_id`) and the
optional parts are an options object. Also, "connections" leaves the
sdk-go known-gaps list.
## Validation
`go test -race ./client/... && go test . && go vet ./... && go vet -tags
e2e .` in `sdks/go`: pass. CI: green on `92148e5fe`.
| Test | Defect it catches |
| --- | --- |
| `TestAUsersConnectionNamesThemAsOwnerAndActingUser` | owner and header
differ, or one has no user |
| `TestAnAppConnectionNamesNoUser` | an app connection sent with a
`user_id`, or with the client's acting user |
| `TestACallNamingAUserReachesAnAppConnectionButListsOnlyTheUsers` |
docs and code disagree on reach |
| `TestEveryCallSendsTheUserItNamesAsTheActingUser` | owner and header
differ on any call, reads included; an app call sends a header |
| `TestAuthorizingAnswersWhereAndHowLongTheConsentRuns` | return URL or
user dropped; launch URL, token or expiry lost |
| `TestAUsersConnectionIsReachedOnlyAsThem` | get, authorize or delete
sent with no user or the wrong one |
| `TestListingReadsTheOwnersConnectionsEveryPage` | only one page read,
wrong `owner_type`, connector dropped |
| `TestDeletingAConnectionRemovesIt` | delete not sent, sent as someone
else, or `force` sent |
| `TestAConnectionWithNoIDIsRefusedBeforeTheRouter` | an empty id sent
as `/v1/agents/connections/` |
| `TestAConnectionRefusalIsTheRoutersError` | a refusal or a cancelled
request returned as success |
Mutations: 30 of 30 killed (`mutate.py`). They cover every condition,
branch and constant in `connections.go`, including the user dropped from
each of the five calls.
Review rounds:
- Round 1 NO-GO, fixed:
- `ForUser` kept the parent client's team;
- the docs disagreed with the router on reach.
- The team then dropped `ForUser` for a per-call user (R2.1, `UserID`
naming R2.2).
- Round 3 GO; its two nits (`Get` and `Delete` took a bare `userID`
string) are fixed by `ConnectionOptions`.
- Follow-up: AI-3385 (the user's email for connectors that check it).
Live run on the staging router with the final signatures, as user
`e2e-ai3376` and connector `linear`. The id is shortened to a prefix.
The deferred delete found nothing, so nothing was left behind.
```
create: id=afa8b1… connector=linear owner=user/e2e-ai3376 status=pending
authorize: kind=consent launch_url_https=true handoff_token_set=true expires_in_10m=true
get: status=pending
get as another user: refused=true
list: count=1 contains=true
list app: contains=false
delete: ok; get after delete: refused=true
list after delete: count=0
delete (deferred): no such connection
```
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
…2128)
## Why
The other server SDKs are adding a per-call user. JavaScript, Python,
Ruby and PHP deprecate their per-user helper in open PRs (#2110, #2103,
#2102, #2101); .NET (#2099) and Rust (#2100) add the per-call user and
have no public helper to deprecate. Go still recommends
`Backend.ActingFor`, a field that fixes one user for every request a
backend makes. `client.Connections()` (#2095) already takes the user as
`UserID` per call. This deprecates `ActingFor` and moves the two
examples off it. It keeps working: only a `Deprecated:` paragraph is
added. The note names what exists today: `UserID` on
`client.Connections()` calls, `XStreamUserId` on
`CreateScheduledTaskParams`, a per-call `acceleration.RequestEditorFn`;
`client.Agent(...)` calls take no per-call user yet, so `ActingFor`
stays their way.
## How it works
```
before example ──> Backend{ActingFor: user} ──> X-Stream-User-Id
after example ──> per-call user ───────────────> X-Stream-User-Id
(UserID of the call, or the header on the call)
SDK itself (Dispatch.Answer, Connections.api)
──> still sets ActingFor on a copy of the backend, each line with
//nolint:staticcheck // SA1019 (golangci-lint's form, as acceleration/cmd/usage)
```
No public API is added: every call site the examples needed already had
a per-call user. The SDK's own two writes send exactly what they sent on
base.
| Call site | Now | Request change |
| --- | --- | --- |
| `crew_assistant` create | `Backend{}`;
`CreateScheduledTaskParams.XStreamUserId` (already set) | none |
| `crew_assistant` run, delete | `Backend{}`; a backend reaches a task
of its customer without naming the user (`session.Owner.Reaches`, server
kind) | `X-Stream-User-Id` no longer sent on run and delete |
| `swift_assistant` list Gmail | `client.Connections().List(ctx,
ConnectionFilter{UserID, Connector})` | adds `limit=200` and follows
every page (the old call read the first 25) |
| `swift_assistant` proxy POST | `Backend{}.Resolve()`, then
`credentials.Set(stream.UserHeader, user)` on the raw request; kept raw
so the 1 MiB read cap stays | none |
Other readers of `ActingFor` (grep over `sdks/go`, `examples`, `tui`,
`.claude/skills`, READMEs): `stream/backend.go` (`Credentials`, the
field), `agents/dispatch.go`, `client/connections.go` (both write it,
with a nolint), `client/connections_test.go` (reads it, with a nolint),
`.claude/skills/sdk/SKILL.md:447` (a note about every SDK, left as
written, with one line appended). The Go README and `sdk-go` skill never
recommended it.
## Validation
- `cd sdks/go`, `GOWORK=off`: `gofmt -l`, `go mod tidy -diff`, `go vet
./...`, `go vet -tags e2e .`, `go test -race ./...` all pass. Each
touched example: `go build ./... && go vet ./...` pass; `crew_assistant`
tests pass.
- staticcheck (via `golangci-lint -E staticcheck`): no SA1019 in
`sdks/go`, either example or `tui`; the six findings left are in files
this PR does not touch.
- Backward compatibility:
`TestABackendBuiltWithActingForSendsWhatItAlwaysDid` pins method, path
and headers of three `ActingFor` backends (local router, behind the
proxy, team and categories). The expected values were read off a client
built the same way on the base commit (ab01365). It fails if the
header is dropped, sent only in one mode, or read from another field.
- `TestActingForAUserKeepsTheServersToken`: the user goes in the header,
never into the token, and the token keeps its server claim.
- `Dispatch.Answer` and `Connections` keep their existing header tests
(`TestAMessageWrittenToARunningSession...`, the connections suite); each
fails with its `ActingFor` write removed.
- New example tests (run locally; CI runs neither example's tests):
`TestGmailCallsNameTheUser` (swift: the Gmail list and the proxy POST
name the user) and `TestTheAgentSpeaksFirstInTheUsersConversation`
(crew: the task is created naming the user).
- Examples: a throwaway probe test recorded every request of both
examples on base and on this branch; the diffs are the two rows above
and nothing else. The probe is not committed; the two example tests
above pin the user on those requests.
- Mutants over the changed lines (the two SDK writes dropped; the token
losing its server claim; `Credentials` dropping or mode-limiting the
header; the swift list and proxy and the crew create dropping the user):
all killed.
Not checked: nothing run against a real router, as no request changes
for existing callers.
## Review rounds
| Round | Verdict | Findings | Sha |
| --- | --- | --- | --- |
| 1 | NO-GO | R1.1 exported `Backend.Acting` removed (internal writes
keep `//nolint:staticcheck` with the reason); R1.2 deprecation note
names only what exists; R1.3 four surviving mutants now killed (swift
list/proxy, crew create, token server claim); R1.4 skill note links the
open SDK PRs: fixed. R1.5 example `go.sum`: ticket AI-3399; per-call
user on `client.Agent`: ticket AI-3398 | `8ca1c3635` |
| 2 | NO-GO | R1.1-R1.3 verified, 10/10 mutants killed; R2.1 skill note
claimed .NET and Rust deprecate a helper (they have none public): fixed
| `ecab56d1b` |
| 3 | GO | R2.1 closed; claims checked against each SDK PR's diff
([review](#2128 (review)))
| `0526b858c` |
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
The PR's own patch is unchanged (delta-kind.sh: merge of base only). The one conflict is the use block in sdks/rust/src/client.rs; both lines are kept, Connections and Dispatch. Main's Tools/with_tools merged clean. No main line is reverted: against 46f24fc the head adds 694 lines and removes none, all in the Rust SDK, CHANGELOG.md and .claude/skills/sdk/SKILL.md. Against current main the head merges clean (main has since gained only #2128, Go).
Rust CI steps in rust:1: cargo fmt --check, cargo clippy --all-targets -D warnings and cargo test pass (connections 12, dispatch 18, session 61, doctests 9).
cargo run -p generate -- --check (ci-sdks.yml:212) fails here with "types.rs is out of date with the spec", and it fails the same way on a pure origin/main checkout (36d5e34). The cause is #2138, which changed acceleration/api/openapi.yaml without regenerating sdks/rust/src/types.rs. It is a base failure, not this PR's.
Prior findings R1.1 to R1.4 stay fixed (round 2). Nit, not blocking: the blank line this PR adds before the "Connections in Rust" line in .claude/skills/sdk/SKILL.md is not needed.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
⚠️ Outside diff range comments (1)
Major · Bound connection pagination. · connections.rs:146
sdks/rust/src/connections.rs:146 Major · Stability & Availability · Quick win
Bound connection pagination.
If the router repeatedly returns the same nonempty cursor with has_more=true, list requests it indefinitely and keeps appending items. The call can exhaust memory. Detect repeated cursors and bound pagination; return an error when a bound is reached.
As per coding guidelines, router input must be read “within bounds.”
Reviewing files that changed from the base of the PR and between eca728e and ce7511f.
Files selected for processing: 4
.claude/skills/sdk/SKILL.md
CHANGELOG.md
sdks/rust/README.md
sdks/rust/src/client.rs
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Major · Functional Correctness · Quick win
Do not delete the connection before consent completes.
The example deletes the connection immediately after it starts consent. Alice may still be in the popup, so deletion can prevent her from completing the connection. Move deletion to a separate cleanup example or wait until the connection is no longer needed.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Data Integrity & Integration · Quick win
Limit the owner claim to create. get, authorize, delete and list send no user owner.
Only create sends the user as the connection owner. list sends owner_type with the X-Stream-User-Id header. get, authorize and delete send only the header. Replace the absolute claim with the exact wire behavior. The None case with ClientOptions::user_id is already explained in the next sentences, so do not repeat it here. Apply the same correction to the Connections rustdoc at sdks/rust/src/connections.rs:41-42.
README.md
-Each call names its user once, as `user_id`, and the SDK sends it as the owner and as-`X-Stream-User-Id`, so the two never differ. Another user's connection is not found, the same+A call that names its user sends that user as `X-Stream-User-Id`. `create` also sends it as the+owner, and `list` sends the owner type with it. `get`, `authorize` and `delete` have no owner, so+they send only the header. Another user's connection is not found, the same
CHANGELOG.md
-`Client::connections()` creates, authorizes, reads, lists and deletes connections: `create(&NewConnection { connector, label, user_id })`, `authorize(id, &AuthorizeOptions { return_url, user_id })` (the consent's launch URL, handoff token and expiry), `get(id, user_id)`, `list(&ConnectionFilter { connector, user_id })` (every page) and `delete(id, user_id)`. A user given goes out as both the owner and `X-Stream-User-Id`; `None` is the app's own connection and leaves the client's own `ClientOptions::user_id` as it is.+`Client::connections()` creates, authorizes, reads, lists and deletes connections: `create(&NewConnection { connector, label, user_id })`, `authorize(id, &AuthorizeOptions { return_url, user_id })` (the consent's launch URL, handoff token and expiry), `get(id, user_id)`, `list(&ConnectionFilter { connector, user_id })` (every page) and `delete(id, user_id)`. A user given goes out as `X-Stream-User-Id` on every call, and as the owner on `create`; `None` is the app's own connection and leaves the client's own `ClientOptions::user_id` as it is.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Security & Privacy · Quick win
Document that an empty user_id selects app ownership.
The README tells callers to pass None for the app's own connection. It does not say that an empty string does the same. A user_id taken from input can be Some(""). create then makes an app-owned connection, which any of the app's agents can use. Add the rule to the README next to the None instruction.
Suggested README change
-`None` for the app's own connection, which any of its agents may be bound to; the client then-keeps acting for whoever `ClientOptions::user_id` names, if anyone.+`None` for the app's own connection, which any of its agents may be bound to. An empty string+also selects the app's own connection, so check a user ID from input for emptiness before the+call. The client then keeps acting for whoever `ClientOptions::user_id` names, if anyone.
…2103)
## Why
A backend that connects its users' accounts (Linear, GitHub) had only
generated operations in the Python SDK (AI-3375). It had to set
`X-Stream-User-Id` by hand and keep it equal to `owner.user_id`: the
router refuses a user connection whose two values differ
(`acceleration/internal/api/connections.go:765`). The user is now an
optional `user_id` on each call (AI-3387).
The Go reference,
[#2095](#2095), is MERGED.
Siblings: [#2099](#2099) .NET,
[#2100](#2100) Rust,
[#2101](#2101) PHP,
[#2102](#2102) Ruby,
[#2110](#2110) JS.
## How it works
```
api.connections (one flat resource, server side only)
├─ create(connector_id, *, label=None, user_id=None) -> Connection
├─ authorize(id, *, return_url=None, user_id=None) -> Authorization (launch_url, handoff_token, expires_at)
├─ get(id, *, user_id=None) -> Connection
├─ list(*, connector_id=None, user_id=None) -> every page
└─ delete(id, *, user_id=None)
```
| `user_id` | owner (create) | `X-Stream-User-Id` | list |
| --- | --- | --- | --- |
| `"alice"` | `{type: user, user_id: alice}` | `alice`, every call,
reads included | `owner_type=user` |
| `None` | `{type: app}` | none; a client built for a user still names
that user | `owner_type=app` |
- A call naming a user replaces whoever the client acts for and the user
it was built for (behind the proxy, that user would get a token of their
own).
- Every option is keyword-only, so a user id cannot land in a label's or
connector's slot.
- A device client (user token) naming a user is refused with
`ValueError` before any request, as `for_user` already was.
What the router answers (`connections.go:742-748` `mayReach`):
- a call naming a user still reaches the app's connections;
- a user's list holds only that user's connections.
```
before (deprecated, still works) after
api.for_user("u", team="finance") -> stream.Client(team="finance")
.router("clinic") -> .router("clinic", user_id="u")
.agent("docs") -> .agent("docs", user_id="u")
```
## Changes
Callers found with `grep -rn "for_user\|acting_for"` over
`plugins/stream`, its README, `examples/` and `docs/`:
| Piece | Before | After |
| --- | --- | --- |
| `Client.connections` | none | `Connections`: `create`, `authorize`,
`get`, `list`, `delete`; `Connections`, `Connection`, `Authorization`
exported |
| `Client.agent` | no user | keyword-only `user_id=None`, last |
| `Client.router` | no user | keyword-only `user_id=None`, last |
| `Client.for_user` | public | public, `DeprecationWarning` (attributed
to the caller) + docstring pointing at `user_id` |
| `_backend.py` `acting_for(backend, user_id)` | | the internal path;
`dispatch.py:293` and `accelerated.py:170` keep using it |
| `plugins/stream/README.md`, `teams.py` docstring | `for_user` |
`user_id=` on `agent`/`router` |
| `tests/test_teams.py:240,249` (integration) | `for_user` | unchanged:
deprecated calls still work |
| `CHANGELOG.md`, `.claude/skills/sdk/SKILL.md` | | one entry, one note
|
## Validation
`uv run --no-sync pytest plugins/stream -m "not integration"`: 673
passed (647 on base), by the round-2 reviewer on `d03a0634b`. `ruff
check`, `ruff format --check` and `mypy plugins/stream/vision_agents`:
clean.
| Test | Defect it catches |
| --- | --- |
| `test_a_users_connection_names_them_as_owner_and_acting_user` | owner
and header differ, label lost |
| `test_an_app_connection_names_no_user` | app connection sent with a
user, or its header dropped for a client built for a user |
| `test_every_call_sends_the_user_it_names_and_an_app_call_sends_none` |
a call (reads too) without its user; an app call with a header |
| `test_the_user_named_on_the_call_replaces_whoever_the_client_acts_for`
| behind the proxy, a token signed for the client's own user |
|
`test_a_call_naming_a_user_reaches_an_app_connection_but_lists_only_theirs`
| wrong `owner_type`, reach rule broken |
| `test_a_users_connection_is_reached_only_as_them` |
get/authorize/delete with no user or the wrong one |
| `test_authorizing_answers_where_and_how_long_the_consent_runs`,
`test_authorizing_without_a_return_url_sends_none` | return URL dropped
or sent empty; launch URL, token or expiry lost |
| `test_listing_reads_every_page_of_one_connector`,
`test_listing_the_apps_asks_for_the_apps_of_every_connector` | one page
only; connector or limit dropped |
| `test_a_page_marked_more_without_a_cursor_ends_the_list`,
`test_a_page_marked_last_ends_the_list_whatever_cursor_it_carries` | a
loop on a broken page |
| `test_deleting_a_connection_removes_it` | delete not sent, or `force`
sent |
| `test_a_connection_with_no_id_is_refused_before_the_router` | empty id
sent as a bare collection path |
| `test_every_option_is_named_never_positional` | a user id accepted in
the label, return URL or connector slot, on connections, `agent`,
`router` |
| `test_a_refusal_is_the_routers_error` | a refusal returned as success
|
| `test_an_agent_for_a_user_names_them_on_every_request`,
`test_a_router_for_a_user_names_them_whoever_the_client_acts_for` |
`user_id` not sent as `X-Stream-User-Id` |
| `test_an_agent_without_a_user_sends_what_it_sent_before`,
`test_a_router_without_a_user_opens_as_it_did_before` | backward
compatibility: paths, bodies and `X-` headers equal those probed on base
`fa2a6a66d` |
|
`test_an_agent_without_a_user_keeps_the_user_the_client_was_built_for`,
`test_agent_and_router_without_a_user_keep_the_proxy_token_user_of_the_client`
| `agent()`/`router()` with no user drop the client's own user |
| `test_a_device_cannot_name_a_user` | a device acting for another user,
incl. `user_id=""` |
| `test_a_user_named_on_the_call_is_what_for_user_was` | the replacement
signs other claims than `for_user`; wrong warning, stacklevel |
Mutations: the author's 37 killed (every condition, constant, user
hand-off, the deprecation warning and each keyword-only `*`). Round 2
reran the reviewer's 10: 8 killed, 2 equivalent (`mutate_r1.py`,
delta-2.md).
Live on the staging router, test user, connector `linear`: create (owner
user, pending), authorize (https launch URL, handoff token, 10 minute
expiry), get, get as another user is 404, list holds it and the app list
does not, delete; list after delete is 0.
## Review rounds
| Round | Verdict | Findings | Sha |
| --- | --- | --- | --- |
| 1 | not a GO (two Should fix) | R1.1 a no-user call cleared the
client's own user, R1.2 three surviving mutants: fixed; N2 cursor type,
N3 README wording: fixed; N1 stale `for_user(team=)` line in the sdk
skill: ticket | `9f8751678` |
| 2 | GO | no new findings | `d03a0634b` |
| 4 | GO | base merge of #2122 resolved in `__init__.py` (main's import
without `ensure_agent` + `Connections`); patch unchanged; ruff, mypy,
674 tests pass
([review](#2103 (review)))
| `452a64e77` |
Head `359f79d31` adds main merges and restores main's CHANGELOG lines on
top of the GO sha.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…2102)
## Why
A backend that connects its users' accounts (Linear, GitHub) has only
generated operations in the Ruby SDK (AI-3375). It would set
`X-Stream-User-Id` by hand and keep it equal to `owner.user_id`. The
user is now an optional `user_id:` on each call (AI-3387).
The Go reference,
[#2095](#2095), is MERGED.
Siblings: [#2099](#2099) .NET,
[#2100](#2100) Rust,
[#2101](#2101) PHP,
[#2103](#2103) Python,
[#2110](#2110) JS.
## How it works
```
client.connections (flat, no agents. level)
.create(connector, label:, user_id:) POST /v1/agents/connections
.authorize(id, return_url:, user_id:) POST /v1/agents/connections/{id}/authorizations -> launch_url, handoff_token, expires_at
.get(id, user_id:) GET /v1/agents/connections/{id}
.list(connector:, user_id:) GET /v1/agents/connections?owner_type=user|app&limit=200 (every page)
.delete(id, user_id:) DELETE /v1/agents/connections/{id}
```
| Call | Owner | `X-Stream-User-Id` |
| --- | --- | --- |
| `user_id: "alice"` | `{type: user, user_id: alice}` | `alice`, on
every call, reads included |
| `user_id` omitted or `""` | `{type: app}` | none from `user_id`; an
empty one drops the `acting_for` user |
| client built with its own `user_id:` | unchanged from base | still
sent (left as base behaves, as in Go) |
What the router answers (`acceleration/internal/api/connections.go`
`mayReach`, `ownerOf`):
- an app's connection is reached by any backend call, whatever `user_id`
it sends;
- a user's connection is reached only naming that user;
- `list` with a user holds only that user's connections.
## Changes
| Piece | Before | After |
| --- | --- | --- |
| `Client#connections` | none | `create` / `authorize` / `get` / `list`
/ `delete`, each with optional `user_id:` |
| `Client#get`, `post`, `put`, `patch`, `delete`, `socket` | the
backend's user only | optional `user_id:` last; `nil` keeps the
backend's user, `""` drops it |
| `Backend#acting_for` | public | still works, `@deprecated`, points at
`user_id:` |
| `Dispatch#answer` | `backend.acting_for` | `backend.acting` (`@api
private`), same requests |
| `Backend#headers` | no argument | optional `acting_for:` keyword |
| `README.md`, `CHANGELOG.md`, `.claude/skills/sdk/SKILL.md` | | a
section, one line, one note for the other SDKs |
Wrappers callers used `acting_for` for: `git grep -n acting_for --
sdks/ruby examples docs '*.md'` finds one caller, `Dispatch#answer`.
README, examples and docs name none. So `user_id:` sits on every request
level (the six `Client` verbs) and on each `connections` method.
## Validation
`docker run --rm -v "$PWD:/repo" -v va-ruby-bundle:/usr/local/bundle -w
/repo/sdks/ruby ruby:4.0 sh -c "bundle install && bundle exec rake"`:
249 runs, 1074 assertions, 0 failures (base: 230). Run on head
`ed95799c9` by the round-2 reviewer. The later commits only merge main
and restore main's CHANGELOG lines.
The stand-in `LocalRouter` records every request's method, path, body
and headers.
| Test | Defect it catches |
| --- | --- |
| `test_a_user_s_connection_names_the_user_as_owner_and_header` | owner
and header differ, or one has no user |
| `test_no_user_is_the_app_s_connection_with_no_header` | an app
connection sent with a user |
| `test_the_user_given_wins_over_whoever_the_client_acts_for` | the
deprecated acting user overrides the parameter |
| `test_authorize_without_a_user_on_an_acting_client_names_nobody` |
authorize keeps the acting user (`.to_s` dropped) |
| `test_list_without_a_user_on_an_acting_client_names_nobody` | list
keeps the acting user |
| `test_delete_without_a_user_on_an_acting_client_names_nobody` | delete
keeps the acting user |
| `test_create_sends_the_connector_given` | connector hard-coded |
| `test_authorize_sends_the_return_url_and_answers_the_consent` | return
URL dropped; launch URL, token or expiry lost |
| `test_get_and_delete_name_the_user_only_when_given` | get/delete
header missing or sent without a user |
| `test_list_reads_every_page_of_the_user_s_connections` | one page
read; header missing on a page |
| `test_list_without_a_user_is_the_app_s_and_names_nobody` | wrong
`owner_type`, or a header on the app list |
| `test_list_stops_on_a_page_that_has_no_more_or_no_cursor` | endless
paging |
| `test_an_empty_id_is_refused_before_sending` | an empty id sent as a
bare collection path |
| `test_another_user_s_connection_is_the_router_s_not_found` | a refusal
returned as success |
| `test_a_user_given_is_named_with_the_client_s_own_credential` | user
sent with the wrong credential, on each verb and the socket |
| `test_an_empty_user_names_nobody_even_on_a_client_acting_for_one` | an
empty `user_id:` keeps the acting user |
| `test_a_user_that_is_not_text_is_sent_as_text` | `headers` fails on a
non-String user |
| `test_a_request_without_a_user_is_the_one_sent_before` | backward
compatibility: every verb, the socket and `Backend#headers` send what
base `fa2a6a66d` sent |
| `test_dispatch_answers_for_the_writer_and_for_nobody_as_before` |
`Dispatch#answer` changes its requests |
Mutations: the author's 35 mutants, all killed (`mut/run-1.log`); the 5
survivors of round 1 are killed by the round-1 fix, 0 of 5 survive in
round 2. Two round-1 mutants are equivalent (reviewer-1.md).
Live on the staging router (`live/run-1.log`): create (pending, user
owner), authorize (launch URL, handoff token, expiry), get, get without
the user and as another user (`connection_not_found`), list (the user's
one, not in the app's list), delete. Nothing left behind.
## Review rounds
| Round | Verdict | Findings | Sha |
| --- | --- | --- | --- |
| 1 | NO-GO | R1.1 (five surviving mutants, tests added), R1.2 (docs on
empty `user_id:` fixed) | `3e01c84b6` |
| 2 | GO | no Blocker, no Should fix; Nit: test count in this body
(updated above) | `ed95799c9` |
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…Id (#2110)
## Why
A backend that connects its users' accounts (Linear, GitHub) had only
generated operations in the JS SDK (AI-3375, AI-3378). It would set
`X-Stream-User-Id` by hand and keep it equal to `owner.user_id`. The
user is now an optional `userId` on each call, never a client of its own
(AI-3387).
The Go reference,
[#2095](#2095), is MERGED.
Siblings: [#2099](#2099) .NET,
[#2100](#2100) Rust,
[#2101](#2101) PHP,
[#2102](#2102) Ruby,
[#2103](#2103) Python.
## How it works
```
api.connections (server side only)
├── create(connectorId, { label?, userId? }) POST /v1/agents/connections
├── authorize(id, { returnUrl?, userId? }) POST /v1/agents/connections/{id}/authorizations
├── get(id, { userId? }) GET /v1/agents/connections/{id}
├── list({ connectorId?, userId? }) GET /v1/agents/connections (every page, 200 a page, newest first)
└── delete(id, { userId? }) DELETE /v1/agents/connections/{id}
```
| `userId` | body / query | header | credential |
| --- | --- | --- | --- |
| given | `owner: {type: user, user_id}`, `owner_type=user` |
`X-Stream-User-Id` on every call, reads included | the app's server
token |
| left out or `""` | `owner: {type: app}`, `owner_type=app` | none added
| the client's own |
- A client built with `BackendOptions.userId` still sends that user on a
call without `userId`, as on its other calls.
- A client built on the deprecated `actingFor` drops its user on a call
naming none: the call is the app's.
- `userId` on a client that is not server side (a device, or a page on a
customer-id router) is a `ConfigurationError` before any request. A
server reached by customer id may name a user.
What the router answers (`acceleration/internal/api/connections.go`
`mayReach`, `ownerOf`, `listConnections`):
- the app's connections are reached whatever `userId` a call names;
- another user's is not found;
- `list({ userId })` holds only that user's.
No `force`, `auth_scheme`, `inputs` or all-users list.
## Changes
| Piece | Before | After |
| --- | --- | --- |
| `api.connections` | none | `create`, `authorize`, `get`, `list`,
`delete`, each with an optional `userId` in the options object |
| `Backend.actingFor` | public | public and working, `@deprecated`,
points at `userId` |
| `Backend.speakingFor` | none | `@internal`: the old `actingFor` body;
used by `connections` and `Dispatch.answer` (`src/dispatch.ts:264`) |
| Public wrappers that used `actingFor` | | none: `git grep -n
actingFor` over `sdks/js`, `examples/`, `docs` finds only
`Dispatch.answer` (internal) and tests. Every new parameter is optional
and last |
| `README.md`, `CHANGELOG.md`, `.claude/skills/sdk/SKILL.md` | | a
section, one entry, one note |
## Validation
`cd sdks/js && npm ci && npm test` (the SDK's real HTTP test router,
with a stand-in for the router's owner rule that records every request):
745/745 pass at `eaee43956` (fixer 2). Round 2 on `246c2dab7`: `npm ci`,
`types --check`, `npm test` 744/744, build: all exit 0.
| Test (`tests/connections.test.ts`) | Defect it catches |
| --- | --- |
| `names a user's connection as its owner and as the user acted for, so
the router takes it` | owner and header differ |
| `still speaks as the app's backend for a user, since a user's own
token is refused here` | a user token sent instead of the server one |
| `sends the user on every call about their connection, reads included`
| a call without its user |
| `names no user for the app's own connection, on any call` | a header
on an app call |
| `reads an empty user id as the app, rather than as a user nobody is` |
`""` taken as a user |
| `reaches the app's connection whoever it names, and only a user's own`
| reach rule broken |
| `lists every page of one user's connections, newest first, and not the
app's or another user's` | one page only; wrong owner |
| `stops at a page that says it is the last, or that gives no cursor to
go on from` | endless paging |
| `keeps one connector's when asked, and asks for every connector's
otherwise`; `asks for the connector it was given, and every connector's
for an empty one` | connector dropped or hard-coded |
| `leaves a label out of the request when none is given`; `sends the
label it was given` | label sent empty or lost |
| `sends the return URL it was given, and the user without one` | return
URL lost |
| `refuses a call naming no connection before asking the router` | an
empty id sent |
| `leaves a client built for a user sending that user when a call names
none, as its other calls do`; `keeps a client's own user when a call
names the empty user` | the client's own user cleared |
| `drops the deprecated actingFor user on a call naming none, so the
call is the app's` | the deprecated user leaks into an app call |
| `refuses to name a user on a device, which holds its own user's token`
| a device or page acting as a backend |
| `lets a server reached by customer id name a user, since it holds no
user's token` | the refusal widened to customer-id servers |
| `is still reached through the deprecated actingFor, sending what it
sent before userId` | backward compatibility: four backend shapes send
what base `fa2a6a66d` sent |
The existing dispatch test still asserts `answer`'s request unchanged.
Mutations: the author's 28 killed (`mutations.log`, `mutate.py`; three
paging ones by the 20 s test timeout). Round 2 reran the round-1 set:
all killed but two surviving mutants that are moved base code or
equivalent. Round 2's M3 survived, then was killed by the new row.
Live on the staging router, test user: connection to `linear`: create,
authorize, get (pending), list, delete; nothing left behind.
## Review rounds
| Round | Verdict | Findings | Sha |
| --- | --- | --- | --- |
| 1 | NO-GO | R1.1 `userId` refused off a server, R1.2 deprecated user
dropped on a no-user call, R1.3 six surviving mutants, R1.5 changelog
`(#2110)`: fixed; R1.4 `@internal` not stripped from dist, X1 cross-SDK
device check: tickets | `3fefe3055` |
| 2 | NO-GO (R2.1 Should fix) | R2.1 customer-id server refusal pinned
(`d96b127d7`), R2.2 changelog blank line (`eaee43956`): fixed |
`246c2dab7` |
| 3 | GO | R2.1 and R2.2 closed; M3 re-run and killed by the new row; no
new findings
([review](#2110 (review)))
| `77b528d78` |
Head `77b528d78` adds a main merge and restores main's CHANGELOG lines.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
)
## Why
A backend that connects its users' accounts (Linear, GitHub) has only
generated operations in the .NET SDK (AI-3375). It would set
`X-Stream-User-Id` by hand and keep it equal to `owner.user_id`. The
user is now an optional `userId` on each call (AI-3387).
The Go reference,
[#2095](#2095), is MERGED.
Siblings: [#2100](#2100) Rust,
[#2101](#2101) PHP,
[#2102](#2102) Ruby,
[#2103](#2103) Python,
[#2110](#2110) JS.
## How it works
```
VisionAgentsClient.Connections (flat, no agents level)
├─ CreateAsync(connectorId, NewConnectionOptions?{Label, UserId}) POST /v1/agents/connections
├─ AuthorizeAsync(id, AuthorizeOptions?{ReturnUrl, UserId}) POST /v1/agents/connections/{id}/authorizations
├─ GetAsync(id, userId?) GET /v1/agents/connections/{id}
├─ ListAsync(ConnectionFilter?{ConnectorId, UserId}) GET /v1/agents/connections (every page, limit 200)
└─ DeleteAsync(id, userId?) DELETE /v1/agents/connections/{id}
```
| `userId` / `UserId` | `owner` (create) | `X-Stream-User-Id` | list
`owner_type` |
| --- | --- | --- | --- |
| `"alice"` | `{type: user, user_id: alice}` | `alice`, every call,
reads included | `user` |
| `null` or `""` | `{type: app}` | none from the parameter; a client's
own `UserId` option is left as it is | `app` |
- Create, authorize and list take sealed options records, so a user
cannot land where a label or connector belongs. Get and delete take
`string? userId` last, before the `CancellationToken`.
- A user goes through the internal `ActingFor` that Dispatch already
uses: the server credential plus `X-Stream-User-Id`.
- An empty connection id is refused before any request is sent.
What the router answers (`acceleration/internal/api/connections.go:742`
`mayReach`):
- a backend reaches app connections whatever user it sends;
- a user's connection is reached only with that user;
- a list with a user holds only that user's connections.
## Changes
| Piece | Before | After |
| --- | --- | --- |
| `VisionAgentsClient.Connections` | none | `CreateAsync`,
`AuthorizeAsync`, `GetAsync`, `ListAsync`, `DeleteAsync` |
| `NewConnectionOptions`, `AuthorizeOptions`, `ConnectionFilter` | none
| sealed records with `UserId` (Go's `ConnectionRequest`,
`AuthorizeOptions`, `ConnectionFilter`) |
| `Backend.Acting`, `VisionAgentsClient.ActingFor` | internal |
unchanged, still internal: no public helper, so nothing to deprecate and
no `[Obsolete]` |
| Existing public wrappers | | none built on an acting helper (grep of
`sdks/dotnet`, its README, `examples/`, `docs/`), so none got a `userId`
|
| `README.md`, `CHANGELOG.md`, `.claude/skills/sdk/SKILL.md` | | a
section "A user's own accounts", one entry, one note |
`Backend` is `internal sealed class` (`Backend.cs:143`); `ActingFor` is
`internal` (`VisionAgentsClient.cs:125`), its only caller is Dispatch
(`Dispatch.cs:218`). The backward-compatibility test of the brief
therefore does not apply (decision Q0.1).
## Validation
Full suite in Docker: 323 total, 316 passed, 7 skipped (live), 0 failed
(base: 309, 302, 7). `ConnectionsTests` runs on the existing Kestrel
`TestRouter`, which records method, path, query, headers and body of
every request, reads included.
| Test | Defect it catches |
| --- | --- |
| `AUserGivenIsTheOwnerAndTheHeaderOnEveryCallReadsIncluded` | owner and
header differ, or a call drops the user; list query not
`owner_type=user` |
| `NoUserIsTheAppsOwnConnectionAndSendsNoHeader` (null and `""`) | app
connection sent with a user or header; authorize body not `{}` |
| `EmptyOptionalStringsAreLeftOutAndTheOwnerIsTheUserGiven` | empty
label or return URL sent; owner `user_id` hard-coded |
| `ABackendActingForAUserKeepsItsServerCredential` | user token replaces
the server token, direct or behind the proxy |
| `AUserGivenReplacesTheOneTheClientWasMadeForAndNoneLeavesItAsItIs` |
the given user ignored; an empty one changes the client's own user |
| `AListReadsEveryPageWithTheSameFilter` (and a theory on stop
conditions) | one page read; filter lost on later pages; endless paging
|
| `AFilterWithAConnectorAndNoUserListsTheAppsConnectionsOfThatConnector`
| connector dropped, or wrong `owner_type` |
| `AConnectionIdIsOnePathSegment` | an id not escaped into one path
segment |
| `AnEmptyConnectionIdIsRefusedBeforeAnythingIsSent` | an empty id sent
as a bare collection path |
| `AnotherUsersConnectionIsTheRoutersNotFound` | a 404 or 409 returned
as success instead of `RouterException` |
Mutations: 17 mutants on `Connections.cs` plus 16 on the options and
empty-string rules (author, round 1 and fix 1); round 2 reran 11, 0
survived. One fix-1 mutant did not build, a rerun was killed
(`mut-fix1.log`).
Live on staging with a test user: create linear (pending, owner `user`),
authorize (https launch URL, handoff token, 10 minute expiry), get, list
with the user holds it and the app list does not, get as another user
and with no user are 404 `connection_not_found`, delete; the user ends
with 0 linear connections, as before (`live/live-fix1.log`).
## Review rounds
| Round | Verdict | Findings | Sha |
| --- | --- | --- | --- |
| 1 | not a GO | R1.1 options records (adjacent strings), R1.2 three
surviving mutants, R1.4 changelog `(#2099)`: fixed; R1.3 (a client made
for one user loses its user token when a call names another) is a ticket
| `67c72f990` |
| 2 | NO-GO | R2.1 Blocker: `dotnet format --verify-no-changes` red;
fixed by `c05d9159e`, whitespace only | `a8f964d20` |
| 3 | GO | R2.1 closed (`dotnet format --verify-no-changes` exits 0; the
old lines fail it); no new findings
([review](#2099 (review)))
| `a8991f844` |
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
## Why
A backend that connects its users' accounts (Linear, GitHub) had only
generated operations in the PHP SDK (AI-3375). It would set
`X-Stream-User-Id` by hand and keep it equal to `owner.user_id`. The
user is now an optional `userId` on each call (AI-3387).
The Go reference,
[#2095](#2095), is MERGED.
Siblings: [#2099](#2099) .NET,
[#2100](#2100) Rust,
[#2102](#2102) Ruby,
[#2103](#2103) Python,
[#2110](#2110) JS.
## How it works
```
$client->connections
├─ create(NewConnection) POST /v1/agents/connections
├─ authorize($id, AuthorizeOptions) POST /v1/agents/connections/{id}/authorizations
├─ get($id, ?string $userId = null) GET /v1/agents/connections/{id}
├─ list(ConnectionFilter) GET /v1/agents/connections (every page, limit 200)
└─ delete($id, ?string $userId = null) DELETE /v1/agents/connections/{id}
```
`NewConnection($connectorId, $label, $userId)`,
`AuthorizeOptions($returnUrl, $userId)` and `ConnectionFilter($userId,
$connectorId)` are readonly option objects (Go's `ConnectionRequest`,
`AuthorizeOptions`, `ConnectionFilter`). A string where an object goes
is a `TypeError` before anything is sent, so a user id cannot land in a
label, return URL or connector slot.
| `userId` | owner (create) | `X-Stream-User-Id` | list asks |
| --- | --- | --- | --- |
| `'ada'` | `{type: user, user_id: ada}` | `ada`, every call, reads
included | `owner_type=user` |
| left out or `''` | `{type: app}` | none, whoever the backend otherwise
acts for | `owner_type=app` |
- Behind the proxy the user is a header beside the server token, never a
user token.
- A device backend (`asUser`) and an empty id are refused before a
request is sent.
What the router answers (`acceleration/internal/api/connections.go:742`
`mayReach`):
- an app connection is reached by every backend call, one naming a user
included;
- a user's list holds only theirs.
## Changes
| Piece | Before | After |
| --- | --- | --- |
| `Client::$connections` | none | `Connections`: `create`, `authorize`,
`get`, `list`, `delete` |
| `NewConnection`, `AuthorizeOptions`, `ConnectionFilter` | none |
readonly options objects with `userId` |
| `Backend::onBehalfOf` | public | public and working, `@deprecated` in
favour of the `userId` parameter; calls `writingFor` |
| `Backend::speakingFor($userId)` | none | `@internal`: server
credential plus the header, none when empty (drops the backend's own
user); used by `Connections` |
| `Backend::writingFor($userId)` | none | `@internal`: the old
`onBehalfOf` body; used by `Worker/Dispatch.php:193`, so an empty writer
on a backend built with a user still sends that user, as on base |
| `Backend::actingFor` | signs a user token | unchanged: the device
path, not deprecated |
| Public wrappers that used `onBehalfOf` | | none: `grep -rn onBehalfOf`
over `sdks/php`, README, `examples/`, docs finds only `Dispatch::answer`
(internal) and the sdk skill |
| `README.md`, `CHANGELOG.md`, `.claude/skills/sdk/SKILL.md` | | a
section, one entry, one note |
## Validation
Round-3 reviewer on the head merged onto main, in Docker: `phpunit
--testsuite unit` OK (360 tests, 945 assertions); `phpstan analyse`
(max) no errors; `bin/generate.php ... --check` up to date (round 2).
`ConnectionsTest` runs on the `php -S` stand-in router and checks
method, path, query, body and headers of every request.
| Test | Defect it catches |
| --- | --- |
| `testAUsersConnectionNamesThemAsOwnerAndActingUser` | owner and header
differ, label or user dropped |
| `testAnAppConnectionNamesNoUser` | app connection with a user, or with
the backend's own user |
| `testEveryCallNamingAUserSendsItReadsIncluded` | a call without its
user |
| `testBehindTheProxyTheUserIsAHeaderBesideTheServersToken` | a user
token minted behind the proxy |
| `testWithNoProxyTheCustomerHeaderStaysBesideTheUser` | the customer
header lost |
| `testAuthorizingAnswersWhereAndHowLongTheConsentRuns` | return URL
dropped; launch URL, token or expiry lost |
| `testAStringWhereTheOptionsObjectGoesIsRefusedBeforeSending` | the old
string signature, where a user lands in a label |
| `testListingReadsEveryPageOfOneConnector` | one page only; connector
dropped |
| `testListingStopsOnACursorItAlreadyFollowedOrAnEmptyOne` | endless
paging |
| `testAnAppListByConnectorSendsNoUser`,
`testAnAppAuthorizationWithAReturnUrlSendsNoUser`,
`testAnAppConnectionWithALabelIsOwnedByTheApp` | a user swapped with
connector, return URL or label inside the objects |
| `testAnotherUsersConnectionIsTheRoutersNotFound` | a refusal returned
as success |
| `testRefusedBeforeSending` | a device backend or an empty id sent |
|
`ClientTest::testOnBehalfOfAnEmptyUserKeepsTheUserTheBackendWasBuiltWith`
| `onBehalfOf('')` changes the base request |
| `ClientTest::testADeviceBackendCannotActOnBehalfOfAUser` | the device
refusal of `onBehalfOf` removed |
|
`WorkerTest::testAnswerForAWriterWithoutAnIdKeepsTheUserTheBackendWasBuiltWith`
| `Dispatch::answer` request differs from base for an empty writer |
Backward compatibility: no public wrapper gained a parameter. The
existing `onBehalfOf` tests (`ClientTest`) and `Dispatch::answer` tests
(`WorkerTest`) pass unchanged.
Mutations: the author's 22, 21 killed and 1 equivalent (`mut/run1.log`);
the fixer's N1, N3 and O1-O6 killed; round 2 reviewer's 10 killed; round
3 rerun: 6 checked, 0 survived. Two mutants (an empty label or connector
sent) are equivalent, as the router trims or skips them.
Live on the staging router through the proxy, test user: create linear
(pending, owner user), authorize (consent, launch URL and handoff token
set, 600 s), get, get as another user and as the app are 404
`connection_not_found`, list holds it and the app list does not, delete
then get is 404; 0 left.
## Review rounds
| Round | Verdict | Findings | Sha |
| --- | --- | --- | --- |
| 0 (author question) | decision | R0.1 an empty writer must keep the
backend's own user as on base: fixed | `9fd8394f0` |
| 1 | NO-GO | R1.1 options objects, R1.2 two surviving mutants, R1.3
stale skill note: fixed | `9fd8394f0` |
| 2 | NO-GO | R2.1 three swap mutants (tests added), R2.2 named
`userId:` in docs: fixed | `81c2213cb` |
| 3 | GO | none | `9f649ea85` |
Head `ee224c707` adds main merges and restores main's CHANGELOG lines on
top of the GO sha.
## Questions
- PHP's `Backend::actingFor` signs a user token (the device path). In Go
and JavaScript `actingFor` names the server-side helper, so the same
name differs across SDKs. Left as the brief says.
- `Folder/Connector.php` (`fixedConnection`) has its own page loop over
`GET /v1/agents/connections`. It could call
`$client->connections->list(...)`. Not changed here.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
A backend that connects its users' accounts (Linear, GitHub) had only generated operations in the Rust SDK (AI-3375). It had to build a whole client with
ClientOptions::user_idand keep it equal toowner.user_id: the router refuses a user connection when the two differ (acceleration/internal/api/connections.goownerOf). The user is now an optionaluser_idon each call (AI-3387).The Go reference, #2095, is MERGED. Siblings: #2099 .NET, #2101 PHP, #2102 Ruby, #2103 Python, #2110 JS.
How it works
user_idX-Stream-User-IdSome("alice"){type: user, user_id: alice}alice, every call, reads includedNoneorSome(""){type: app}ClientOptions::user_idstays as built (as Go)Default) rather than adjacentOption<&str>, so a label cannot be swapped for a user.pub(crate) Client::acting_for(dispatch's path,dispatch.rs:374): it clones the client, setsacting_forand clearsClientOptions::user_id.What the router answers (
connections.go:742mayReach):listwith a user holds only that user's;Changes
Client::connections()Connectionswithcreate,authorize,get,list,deleteNewConnection,AuthorizeOptions,ConnectionFilterDefaultstructs withuser_id, re-exported inlib.rsBackend.acting_for,Client::acting_forpub(crate)#[deprecated](backend.rs:189)sdks/rust, README,examples/, docs.connectionsis the only wrapper takinguser_id, so no backward-compatibility testREADME.md,CHANGELOG.md,.claude/skills/sdk/SKILL.mdValidation
cargo fmt --all --check,cargo clippy --workspace --all-targets -- -D warnings,cargo run -p generate -- --checkandcargo test, inrust:1per the sdk-rust skill: pass (round-2 reviewer, all 12 test targets and doctests). The tests use the axum stand-in router (tests/support), which records method, path, query, body and headers.a_users_connection_names_them_as_owner_and_acting_userauth_scheme/inputssentan_app_connection_names_no_owner_and_leaves_the_clients_own_user_as_it_isNone/""sent as a user; a client's own user cleared by a call naming nobodyevery_call_sends_the_user_it_names_and_only_that_onebehind_the_proxy_a_user_is_named_by_the_header_beside_a_server_tokenauthorizing_answers_where_and_how_long_the_consent_runslisting_reads_the_owners_connections_every_pageowner_type; connector or limit droppeda_list_naming_an_empty_user_is_the_apps_not_a_usersowner_type=useror sent as a headerthe_apps_list_names_no_connector_unless_askedlisting_stops_at_a_page_that_says_no_more_or_names_no_cursorhas_more: falseor when emptydeleting_a_connection_sends_no_forceforcesenta_connection_with_no_id_is_refused_before_the_routeranother_users_connection_is_the_routers_not_foundError::RouterMutations: the fixer's 22 killed (
fix-1-mutate.log); round 2 reran them plus 4 more: 26 checked, 0 survived.Live on the staging router, test user, connector
linear, booleans and statuses only (live/live-2.log): create (owner user, pending), authorize (https launch URL, token, expiry set), get, get as another user and as the app are 404, list holds it and the app list does not, delete; cleanup found 0 leftovers.Review rounds
Nonekeeps the client's own user: all fixedbbf74b9fdb2083269bHead
eca728e67adds a main merge and restores main's CHANGELOG lines on top of the GO sha.🤖 Generated with Claude Code