Skip to content

[AI-3376] Go SDK: a Connections resource - #2095

Merged
kanat merged 18 commits into
mainfrom
kanat/ai-3376-go-connections
Nov 19, 2026
Merged

kanat merged 18 commits into
mainfrom
kanat/ai-3376-go-connections

Conversation

@kanat

@kanat kanat commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

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:

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})
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

kanat and others added 3 commits November 19, 2026 11:36
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Go SDK adds client.Connections() methods to create, authorize, retrieve, list, and delete app-owned or user-owned connections. User-scoped requests use the specified user as the connection owner and set X-Stream-User-Id. Listing supports connector filtering and pagination. Tests cover ownership, access control, request errors, and canceled contexts. The README, SDK skills, and changelog document the API.

Merge Risk: Low · up to 7109b

The Go SDK Connections resource is additive, and the remaining concerns are limited to docs, README examples and test strength. Fixing the README example and wording issues before merge would avoid misleading readers, but nothing here blocks the 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.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 92148e5 and 7109bd1.

Files selected for processing: 2

  • .claude/skills/sdk/SKILL.md
  • CHANGELOG.md

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 2 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nitpick comments: 2

sdks/go/client/connections_test.go: 2

193-193: Trivial · Maintainability & Code Quality · Quick win

Move the connection tests into a testify suite.

The eight standalone tests repeat router and client setup. Put shared setup in SetupTest and use suite assertions. Keep special counting and refusal servers in the tests that need them.

As per coding guidelines: “Group tests in a testify suite (suite.Suite). Shared setup lives in the suite, in one place.”

Source: Coding guidelines


317-328: Trivial · Maintainability & Code Quality · Quick win

Give each listing behavior its own test.

This table combines user pagination, connector filtering and app scope. If the first List returns an error, t.Fatal prevents the other behaviors from running. Split these cases into named tests and share their fixture setup. Apply the same separation to the combined refusal and cancellation cases.

As per coding guidelines: “Avoid table tests” and “Write one test per behaviour, each named for what it proves.”

Source: Coding guidelines

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 8235b40 and 692f353.

Files selected for processing: 7

  • .claude/skills/sdk-go/SKILL.md
  • .claude/skills/sdk/SKILL.md
  • CHANGELOG.md
  • sdks/go/README.md
  • sdks/go/client/client_test.go
  • sdks/go/client/connections.go
  • sdks/go/client/connections_test.go

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 1 remain after this review.

@kanat kanat left a comment

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.

Reviewed at 15ab67df6 merged onto main 072fce4ac. go test -race ./client/..., go test ., go vet ./..., go vet -tags e2e .: pass. CI: go-sdk pass, the rest pass or pending.

Mutations: the author's 30 rerun, all killed; 6 more of mine, 1 non-equivalent survivor (R1.1).

[Should fix] R1.2 also covers CHANGELOG.md:7 and .claude/skills/sdk/SKILL.md:909: api.ForUser("alice").Connections() does not compile in Go, because ForUser returns (*Client, error). That signature is right, like SetUser. The README (sdks/go/README.md:735) already shows it in two steps. The skill note also says "as Python's Client.for_user", which R1.1 contradicts today.

Checked and sound: the shape reads well next to Users(), SpendLimits() and Campaigns() (Create(ctx, struct), value returns, List reading every page, as in limits.go). The owner and X-Stream-User-Id come from one ActingFor value on every request. Connections() on a device client is left unrefused, as in the sibling resources; the router refuses every connection operation without a server-side token. The change is additive only: no spec, generated or router change.

Verdict: request changes, for R1.1 and R1.2.

Comment thread sdks/go/client/connections.go Outdated
return nil, errors.New("client: working for a user needs the user's id")
}
backend := c.backend
backend.ActingFor = userID

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.1 ForUser keeps the parent client's Team and UsageCategories. Probe: New(Backend{..., Team: "finance", UsageCategories: ["project:x"]}).ForUser("alice"), then a create sends X-Stream-Usage-Categories: project:x,team:finance with X-Stream-User-Id: alice. So alice's work is counted against the app client's own team. Python's for_user (plugins/stream/vision_agents/plugins/stream/client.py:174-183, "the parent client's are not carried over") and Go's own SetUser (client.go:96) both drop them, and the six SDKs will copy one of these two precedents. No test pins either behaviour: a mutant that adds the reset survives.

Fix: add backend.Team, backend.UsageCategories = "", nil here and say so in the doc comment (no team option). Add TestForUserCountsNothingAgainstTheParentsTeam: a client with Team finance and category project:x, then ForUser("alice").Connections().Create(...), then expect an empty X-Stream-Usage-Categories on the recorded request. I checked that this test fails on this head and passes with the reset.

@kanat kanat Nov 19, 2026 •

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 3c7efe4: TestForUserCountsNothingAgainstTheParentsTeam (fails with the reset removed: usage categories "project:x,team:finance" sent).

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.

Superseded in 10ca724: the team dropped ForUser (R2.1, #video-ai thread). Every Connections function now takes the user (UserID) per call; the corrected reach docs stay, and TestACallNamingAUserReachesAnAppConnectionButListsOnlyTheUsers pins them. This thread's ForUser code and test are gone.

Comment thread sdks/go/client/connections.go Outdated
return *started.JSON201, nil
}

// Get is one connection of the user this client acts for, or of the app's. Another owner's is

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.2 The router's mayReach (acceleration/internal/api/connections.go:742-745) lets any server-side caller reach an app-owned connection, a backend acting for a user included. A probe on the stand-in router, which mirrors that rule: ForUser("alice").Connections() reads, authorizes and deletes the app's connection, and List on the same handle does not show it. This comment ("Another owner's is not found") and the type docs at :18 and :26-27 ("the connections of the user this client acts for") say otherwise. Fix: say that every backend client reaches an app connection, ForUser's included, and that List on a ForUser client lists only that user's. Also write the Go chain at :18 in two steps (see the review body for the CHANGELOG and the skill note).

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 123950b: docs on Connections, Get and List, README, CHANGELOG, sdk skill note and PR body now say an app connection is reached by every backend client and List on a ForUser client is the user's only; the chain is written as two steps. Pinned by TestAUserClientReachesAnAppConnectionButListsOnlyItsOwn.

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.

Superseded in 10ca724: the team dropped ForUser (R2.1, #video-ai thread). Every Connections function now takes the user (UserID) per call; the corrected reach docs stay, and TestACallNamingAUserReachesAnAppConnectionButListsOnlyTheUsers pins them. This thread's ForUser code and test are gone.

return *created.JSON201, nil
}

// Authorize starts the provider's consent for a connection: a first one for a pending

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.

[Question] R1.3 (ticket, not this PR) A connector that checks its owner's email, such as nessy, ends a user connection's first consent as account_mismatch unless the backend sent X-Stream-User-Email for that user (acceleration/internal/api/authorizations.go:198-200). No SDK sends that header, neither Go's ForUser nor Python's for_user, so a user connection to nessy made through this API cannot connect. This needs a cross-SDK decision on how ForUser names the user's email.

kanat and others added 2 commits November 19, 2026 11:46
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…teps

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Nitpick comments: 1

sdks/go/client/connections_test.go: 1

204-204: Trivial · Maintainability & Code Quality · Quick win

Use the required suite-based test structure.

Move these tests into a testify suite with shared router setup. Use require assertions and separate named tests for the behavior tables. This removes repeated setup and prevents one table case from stopping the remaining behaviors.

As per coding guidelines: “Group tests in a testify suite (suite.Suite)”, “Avoid table tests”, and “Outside a suite, check with require”.

Source: Coding guidelines

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 692f353 and 15ab67d.

Files selected for processing: 5

  • .claude/skills/sdk/SKILL.md
  • CHANGELOG.md
  • sdks/go/README.md
  • sdks/go/client/connections.go
  • sdks/go/client/connections_test.go

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 0 remain after this review.

Comment thread sdks/go/client/connections_test.go Outdated
Comment on lines +400 to +401
{anya, "linear", []string{*third.Id, *first.Id},
url.Values{"owner_type": {"user"}, "connector_id": {"linear"}, "limit": {"200"}}, "anya"},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Trivial · Maintainability & Code Quality · Quick win

Exercise connector filtering across multiple pages.

The filtered case has two matches, which fit one fixture page. It still passes if List drops ConnectorId after the first page.

Add another matching connection and keep a different connector between the matches. Assert the complete filtered result across the cursor boundary.

As per path instructions, flag “tests that would still pass on a broken implementation”.

Source: Path instructions

Comment thread sdks/go/client/connections.go Resolved

@kanat kanat left a comment

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.

VERDICT: GO (delta round 2, 123950b merged onto main 072fce4; no new blocking finding)

Prior findings

  • R1.1 fixed. ForUser now clears Team and UsageCategories before Resolve (sdks/go/client/connections.go:47). I removed the reset: TestForUserCountsNothingAgainstTheParentsTeam failed (project:x,team:finance sent). Reset only Team: it failed (project:x). Reset only UsageCategories: it failed (team:finance).
  • R1.2 fixed. (a) The docs on Connections, Get, List, the README, the CHANGELOG and the sdk skill note now say what the router does: mayReach (acceleration/internal/api/connections.go:742-745) lets every backend client reach an app connection, and a user's only while acting for them. I made List on a user client ask owner_type=app: TestAUserClientReachesAnAppConnectionButListsOnlyItsOwn failed ("alice's list held 1"). (b) No ForUser("x").Connections() one-liner is left outside generated and router text. The README, CHANGELOG, skill note and PR body all write two steps.
  • R1.3 stays a ticket (cross-SDK, not blocking).

Suites on the head merged onto the current base (already up to date): go test -race ./client/..., go test ., go vet ./..., go vet -tags e2e . pass; gofmt -l client is empty.

Nits (no action required): the List doc comment breaks after "newest first,"; the README line at sdks/go/README.md:749-750 is long.

CI at review time: all pending except GitGuardian (pass). The orchestrator waits for CI.

@kanat
kanat marked this pull request as ready for review November 19, 2026 10:49

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 15ab67d and 123950b.

Files selected for processing: 5

  • .claude/skills/sdk/SKILL.md
  • CHANGELOG.md
  • sdks/go/README.md
  • sdks/go/client/connections.go
  • sdks/go/client/connections_test.go

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 0 remain after this review.

Comment thread sdks/go/client/connections_test.go Outdated
connect(t, alice.Connections(), "linear")

sent := backend.heard[len(backend.heard)-1]
if got := sent.Get(stream.UsageCategoriesHeader); got != "" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Assert that ForUser also clears the team.

This test still passes if ForUser clears UsageCategories but retains Team: "finance". Assert that alice.Backend().Team is empty and that api.Backend().Team remains "finance". Keep the categories assertion.

As per path instructions, flag “tests that would still pass on a broken implementation.”

Source: Path instructions

…ections

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 123950b and b8bd182.

Files selected for processing: 1

  • .claude/skills/sdk/SKILL.md

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.

Comment thread .claude/skills/sdk/SKILL.md Resolved
Comment thread .claude/skills/sdk/SKILL.md Outdated

Go `Agent.Sync` stores the config first and then its skills with `config_id` set (AI-3342): the router refuses a skill with no config (`skillComplaint`, `acceleration/internal/api/configs.go:1502`), and skill names are unique per config, so the skills are listed with `config_id` to find the ones to edit. `agents.DefineSkills` takes the `configID`. Other SDKs: Python already does this (`plugins/stream/vision_agents/plugins/stream/config.py:293`); JavaScript (`sdks/js/src/agent.ts:559`), Ruby (`sdks/ruby/lib/getstream/vision_agents/agent.rb:369`), .NET (`sdks/dotnet/src/GetStream.VisionAgents/Agent.cs:509`) and PHP send skills inside the `syncAgent` body and are not affected. **Rust needs the same fix**: `sdks/rust/src/agent.rs:675-690` (`sync_config`) creates or updates skills with `Skill::request()` (`sdks/rust/src/harness.rs:52`, no `config_id`) before it stores the config; store the config first, then list skills with `config_id` and write each with the config's id.
An agent's UI instructions are kept apart from its instructions, so a session can turn UI off: `AgentConfig`, `AgentConfigRequest`, `AgentConfigPatch` and `SyncAgentRequest` have `ui_instructions` (an additive migration), and `CreateSessionRequest` has `ui`, a boolean a device may send. The router tells the model `ui_instructions` after the instructions (a backend's own session instructions included) unless the session was opened with `ui: false`, which reopening or forking it keeps (`agent_sessions.no_ui`). A sync sends the directory whole, so a sync without `ui_instructions` removes them; a PUT that leaves them out keeps them, so a client that does not know the field does not take the UI away. Go's `Load` compiles agent.yaml's `ui:` into `Folder.UIInstructions` and `syncFolder` sends it as `ui_instructions`; the folder's hash takes it in only when there is UI, so a directory without `ui:` is not synced again, and one with it is synced once more, which moves the UI out of the stored instructions. A router older than the field takes the sync and drops it, so `syncFolder` does not trust a stamp covering UI that the stored config lacks, and syncs again, and the router writes a sync of the same hash that declares UI the config lacks rather than finding it unchanged. Deploy the router before releasing an SDK that sends the field. A folder synced by both SDKs flips back: a JavaScript sync writes the UI into `instructions` and removes `ui_instructions`, so a session with `ui: false` is told the UI again; sync a folder with one SDK until JavaScript sends `ui_instructions`. The shared fixtures are unchanged: they are what the model is told, the instructions and the UI joined by a blank line, as the router joins them. Every generated client is regenerated (Go, JavaScript types, Python `plugins/stream`, Swift). Other SDKs need to update: JavaScript (`sdks/js/src/folder.ts`) should send the compiled `ui:` as `ui_instructions` rather than append it to `instructions`, its hash taking it in the same way; Python, .NET, Ruby, Rust and PHP, when they read `ui:`, the same; Swift has `SessionOptions.ui`, which `swift_assistant`'s Settings switch sets, and JavaScript's `sessions.create` passes `ui` through with the regenerated types; Python, Kotlin, Dart and the other server SDKs should offer `ui` on their create-session options, so an app that shows no UI can say so.
Connections (AI-3376): Go has `ForUser(userID)` and `Connections()`, over `createConnection`, `createAuthorization`, `getConnection`, `listConnections` and `deleteConnection`, with no router change. The shape (ForUser returns a client and an error, so two steps in Go): `alice, err := api.ForUser("alice")`, then `alice.Connections().Create(ctx, ConnectionRequest{Connector, Label})`, `Authorize(ctx, id, returnURL)` returning the generated `Authorization` (launch URL, handoff token, expiry), `Get(ctx, id)`, `List(ctx, connector)` reading every page newest first, `Delete(ctx, id)`. `ForUser` (as Python's `Client.for_user`) keeps the app's credential and sets `X-Stream-User-Id`; it is refused on a device client (one holding a user token) and for an empty id, and returns a new client that, like Python's `for_user` and Go's `SetUser`, drops the parent's team and usage categories. The Connections of such a client send that one user as `owner.user_id` (create) and as `X-Stream-User-Id` on every request, reads included; on a client acting for nobody they are the app's (`owner.type: app`, no header, List asks `owner_type=app`). An app connection is reached (Get, Authorize, Delete) by every backend client, a ForUser one included; only List on a ForUser client is the user's alone. Refusals are the SDK's router error; an empty connection id is refused before sending. Other SDKs need to update: JavaScript, Python (plugins/stream), .NET, Ruby, Rust, PHP (AI-3378..AI-3383).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor · Maintainability & Code Quality · Quick win

Limit the router-error claim to refusals the router returns.

ForUser and reach return plain Go errors (errors.New) for local validation: a device client, an empty user ID, and an empty connection ID. These errors are not *stream.RouterError. Only refusals returned by the router are *stream.RouterError. Replace the router-error statement with this wording:

"Router refusals are *stream.RouterError. Local validation refusals (a device client, an empty user ID, or an empty connection ID) are plain errors, and an empty connection ID is refused before any request is sent."

Tools

SkillSpector (2.12.0)

[error] 37: [PE3] Credential Access: Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.

Remediation: Remove references to credential paths. Use environment variables or secrets managers. For docs, use placeholder paths (e.g., /path/to/config). Never load .env or token files in production code paths.

(Privilege Escalation (PE3))


[error] 404: [MP3] Memory Manipulation: Skill manipulates agent memory, state, or stored context. Memory corruption can alter personality, override safety rules, or cause unpredictable behavior.

Remediation: Protect agent memory and state from modification by untrusted content. Use read-only memory for critical instructions and validate all state changes.

(Memory Poisoning (MP3))


[error] 408: [MP3] Memory Manipulation: Skill manipulates agent memory, state, or stored context. Memory corruption can alter personality, override safety rules, or cause unpredictable behavior.

Remediation: Protect agent memory and state from modification by untrusted content. Use read-only memory for critical instructions and validate all state changes.

(Memory Poisoning (MP3))


[error] 544: [PE3] Credential Access: Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.

Remediation: Remove references to credential paths. Use environment variables or secrets managers. For docs, use placeholder paths (e.g., /path/to/config). Never load .env or token files in production code paths.

(Privilege Escalation (PE3))


[error] 544: [PE3] Credential Access: Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.

Remediation: Remove references to credential paths. Use environment variables or secrets managers. For docs, use placeholder paths (e.g., /path/to/config). Never load .env or token files in production code paths.

(Privilege Escalation (PE3))


[error] 562: [PE3] Credential Access: Code accesses credential files (SSH keys, AWS credentials, etc.). This could indicate credential theft attempts.

Remediation: Remove references to credential paths. Use environment variables or secrets managers. For docs, use placeholder paths (e.g., /path/to/config). Never load .env or token files in production code paths.

(Privilege Escalation (PE3))

kanat and others added 2 commits November 19, 2026 12:22
The team decided the user is a parameter of each Connections function, as Chat's
server SDKs pass user_id. Restores the per-call shape, keeps the corrected reach docs.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ach call

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@kanat kanat left a comment

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.

Delta round 3, head 10ca724 (b8bd182 + the per-call user commit + docs). origin/main fa2a6a6 is already merged in. Verdict: GO.

Prior findings

  • R2.1 fixed: no ForUser left (grep of sdks/go, CHANGELOG, sdk skill, PR body); all five calls take the user, flat api.Connections(). api(userID) sets ActingFor on a copy of the backend, so an empty user also clears a client-level ActingFor.
  • R2.2 fixed: UserID in ConnectionRequest, AuthorizeOptions, ConnectionFilter; userID in Get, Delete.
  • R1.2 still holds: docs say an app connection is reached by every backend call and a user's List holds only that user's, which is mayReach (acceleration/internal/api/connections.go:742-745); TestACallNamingAUserReachesAnAppConnectionButListsOnlyTheUsers pins it.
  • R1.1 is moot (ForUser gone). R1.3 stays a ticket.

Checks

  • go test -race -count=1 ./client/... ., go vet ./..., go vet -tags e2e . in sdks/go: pass.
  • 18 mutations, 0 survived: user dropped from the header on create, authorize, get, list, delete (each alone); owner type/user_id on create and list; ActingFor kept or ignored; connector, return URL, label, page loop, empty-id guard, delete status.
  • CI read once: pending, GitGuardian pass.

Two surface nits, not blocking, worth a look before six SDKs copy it (inline).

// connection_id and status added to its query. Empty goes back to the dashboard.
ReturnURL string
// UserID is the user the connection belongs to. Empty is an app connection.
UserID string

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.

[Nit] The user sits in the options of Authorize but is a trailing positional in Get and Delete. A caller (and each of the six SDKs) has two places to look for the same thing, and leaving AuthorizeOptions.UserID empty on a user's connection silently asks as the app and gets a 404. Fine to keep per the R2.2 naming decision; if you want one rule, make it Authorize(ctx, id, userID, options) or say in the sdk skill note that the user is UserID of the call's struct when it has one, else the last string.

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 92148e5: Get and Delete take client.ConnectionOptions{UserID}; the user is always UserID of the call's struct. TestEveryCallSendsTheUserItNamesAsTheActingUser, TestAUsersConnectionIsReachedOnlyAsThem; mutate.py: get/delete user dropped killed

Comment thread sdks/go/client/connections.go Outdated

// Get is one connection of userID's, or of the app's when userID is empty. Another user's is not
// found, the same as one that does not exist. An app's is reached with any user named too.
func (c *Connections) Get(ctx context.Context, id, userID string) (acceleration.Connection, error) {

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.

[Nit] Get(ctx, id, userID string) and Delete(ctx, id, userID string) take two adjacent strings: a swapped (userID, id) compiles and answers a 404 that looks like a missing connection. Same cost for a fixed copy in six SDKs; the doc comment names the order, so non-blocking.

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 92148e5: closed by the same change, no adjacent strings remain (Get/Delete take id, ConnectionOptions). TestEveryCallSendsTheUserItNamesAsTheActingUser, TestAUsersConnectionIsReachedOnlyAsThem; mutate.py: get/delete user dropped killed

kanat and others added 2 commits November 19, 2026 12:29
…r calls' structs

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ll's options struct

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between b8bd182 and 10ca724.

Files selected for processing: 5

  • .claude/skills/sdk/SKILL.md
  • CHANGELOG.md
  • sdks/go/README.md
  • sdks/go/client/connections.go
  • sdks/go/client/connections_test.go

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.

Comment thread sdks/go/client/connections_test.go Outdated
}

created := connectFor(t, api.Connections(), "github", "")
if _, err := api.Connections().Get(t.Context(), *created.Id, ""); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Trivial · Maintainability & Code Quality · Quick win

Assert that connection calls preserve the client's identity.

This test still passes if api changes c.client.backend.ActingFor directly instead of changing a copy. The requests have empty user headers, but the client loses "bob".

After Create and Get, assert that api.backend.ActingFor remains "bob". This protects the identity used by other client operations.

As per path instructions, flag “tests that would still pass on a broken implementation.”

Source: Path instructions

Comment thread sdks/go/README.md
Comment on lines +736 to +737
connection, err := connections.Create(ctx, client.ConnectionRequest{Connector: "linear", UserID: "alice"})
consent, err := connections.Authorize(ctx, *connection.Id, client.AuthorizeOptions{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor · Stability & Availability · Quick win

Check err from Create before dereferencing connection.Id.

Create returns a zero-value acceleration.Connection on every error path. Its Id is nil. The example passes *connection.Id to Authorize without checking err, so a refused or failed creation panics. Readers who copy the example inherit the panic.

Suggested fix

--- "a/sdks/go/README.md"
+++ "b/sdks/go/README.md"
@@ -733,8 +733,11 @@
 
 ```go
 connections := api.Connections()
 connection, err := connections.Create(ctx, client.ConnectionRequest{Connector: "linear", UserID: "alice"})
+if err != nil {
+    return err
+}
 consent, err := connections.Authorize(ctx, *connection.Id, client.AuthorizeOptions{
     ReturnURL: "https://app.example.com/settings", UserID: "alice",
 })
 // Open consent.LaunchUrl in a popup from a page of the return URL's origin, and post it

Comment thread sdks/go/README.md Outdated

connection, err = connections.Get(ctx, *connection.Id, "alice") // Status is pending until alice consents
mine, err := connections.List(ctx, client.ConnectionFilter{UserID: "alice"})
err = connections.Delete(ctx, *connection.Id, "alice")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Separate deletion from the consent flow.

The example deletes the connection immediately after reading it, even when its status is still pending. A reader following the sequence can delete the connection before consent completes. Show deletion as a separate later operation.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 10ca724 and 92148e5.

Files selected for processing: 5

  • .claude/skills/sdk/SKILL.md
  • CHANGELOG.md
  • sdks/go/README.md
  • sdks/go/client/connections.go
  • sdks/go/client/connections_test.go

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 0 remain after this review.

Comment thread CHANGELOG.md

### The Go SDK connects a user's own accounts

`client.Connections()` creates, authorizes, reads, lists and deletes connections: `Create(ctx, client.ConnectionRequest{Connector: "linear", UserID: "alice"})`, then `Authorize(ctx, id, client.AuthorizeOptions{ReturnURL, UserID})` for the launch URL, handoff token and expiry of the consent, and `Get(ctx, id, client.ConnectionOptions{UserID})`, `List(ctx, client.ConnectionFilter{UserID, Connector})`, `Delete(ctx, id, client.ConnectionOptions{UserID})`. Every call takes the user as `UserID` of its options struct and sends it as both the owner and `X-Stream-User-Id`. An empty user is the app's own connection.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor · Functional Correctness · Quick win

Limit the owner claim to creation.

UserID is sent as owner.user_id only on create. A user-scoped Get, Authorize, or Delete can also reach an app-owned connection. The current wording can make readers assume those calls restrict access to the named user's connections. Describe the header behavior separately from create ownership.

@kanat
kanat merged commit ab01365 into main Nov 19, 2026
18 of 19 checks passed
@kanat
kanat deleted the kanat/ai-3376-go-connections branch November 19, 2026 15:41
kanat added a commit that referenced this pull request Nov 20, 2026
…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>
kanat added a commit that referenced this pull request Nov 20, 2026
…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>
kanat added a commit that referenced this pull request Nov 20, 2026
…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>
kanat added a commit that referenced this pull request Nov 20, 2026
…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>
kanat added a commit that referenced this pull request Nov 20, 2026
)

## 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>
kanat added a commit that referenced this pull request Nov 20, 2026
## 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>
kanat added a commit that referenced this pull request Nov 20, 2026
…2100)

## 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_id` and keep it equal to
`owner.user_id`: the router refuses a user connection when the two
differ (`acceleration/internal/api/connections.go` `ownerOf`). The user
is now an optional `user_id` on each call (AI-3387).

The Go reference,
[#2095](#2095), is MERGED.
Siblings: [#2099](#2099) .NET,
[#2101](#2101) PHP,
[#2102](#2102) Ruby,
[#2103](#2103) Python,
[#2110](#2110) JS.

## How it works

```
client.connections()                                 sdks/rust/src/connections.rs
├─ create(&NewConnection{connector, label, user_id})        -> types::Connection
├─ authorize(id, &AuthorizeOptions{return_url, user_id})    -> types::Authorization (launch_url, handoff_token, expires_at)
├─ get(id, user_id: Option<&str>)
├─ list(&ConnectionFilter{connector, user_id})              owner_type user|app, limit=200, every page
└─ delete(id, user_id: Option<&str>)                        no force
```

| `user_id` | owner (create) | `X-Stream-User-Id` |
| --- | --- | --- |
| `Some("alice")` | `{type: user, user_id: alice}` | `alice`, every
call, reads included |
| `None` or `Some("")` | `{type: app}` | 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:742` `mayReach`):
- 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 |
| `README.md`, `CHANGELOG.md`, `.claude/skills/sdk/SKILL.md` | | 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.

| Test | Defect it catches |
| --- | --- |
| `a_users_connection_names_them_as_owner_and_acting_user` | owner and
header differ; label dropped; `auth_scheme`/`inputs` sent |
|
`an_app_connection_names_no_owner_and_leaves_the_clients_own_user_as_it_is`
| `None`/`""` sent as a user; a client's own user cleared by a call
naming nobody |
| `every_call_sends_the_user_it_names_and_only_that_one` | header
missing on a call; header without a user; two headers |
| `behind_the_proxy_a_user_is_named_by_the_header_beside_a_server_token`
| a user token minted instead of the server token plus header |
| `authorizing_answers_where_and_how_long_the_consent_runs` | return URL
dropped; launch URL, token or expiry lost |
| `listing_reads_the_owners_connections_every_page` | one page only;
cursor not sent; wrong `owner_type`; connector or limit dropped |
| `a_list_naming_an_empty_user_is_the_apps_not_a_users` | an empty user
listed as `owner_type=user` or sent as a header |
| `the_apps_list_names_no_connector_unless_asked` | app list sent as
user, or with an unasked connector |
| `listing_stops_at_a_page_that_says_no_more_or_names_no_cursor` | a
cursor followed after `has_more: false` or when empty |
| `deleting_a_connection_sends_no_force` | `force` sent |
| `a_connection_with_no_id_is_refused_before_the_router` | an empty id
sent as a bare collection path |
| `another_users_connection_is_the_routers_not_found` | a refusal not
returned as `Error::Router` |

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.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant