feat(server): derive org + agent from auth in create_conversation_session#98
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: 47866dc The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
…sion
handle_create_session hard-coded SEED_ORG_ID + a random agent id, which
blocks multi-tenant chat: a relational host (SmooAI) has FKs requiring a
real org + agent, so the stub injected "reference-org" + a random agent.
Derive the session's organization_id from the authenticated request, in
priority order:
1. the agent's widget-auth policy organization_id (new optional
AgentWidgetAuth.organization_id) — widget visitors authenticate via
origin/authContext, not a JWT, so their org rides on the agent policy;
2. the connection's authenticated JWT principal org — now threaded from
the /ws handshake through handle_frame instead of being dropped at the
AccessContext reduction;
3. the seed org as a behavior-preserving fallback for the no-auth/local
flavor.
agent_id continues to come from the inbound agentId payload. Same
JWT-org-then-configured-org derivation applied to the lambda dispatch
create-session path. Existing in-memory/seed flows unchanged.
Adds create_session_org_agent.rs proving authed org X + payload agent Y
land on the persisted conversation/participants/session, plus the
widget-policy-org precedence and the seed-fallback cases.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
brentrager
force-pushed
the
create-session-derive-org-agent
branch
from
June 25, 2026 18:54
282b30f to
47866dc
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
handle_create_sessionhard-codedorganization_id = SEED_ORG_ID("reference-org") and defaulted the agent id to a random UUID. That stub blocks multi-tenant chat: a relational host (SmooAI) has FKs requiring a real org + agent, so the session was being created under a bogus org with a random agent id. This was a known TODO in the handler (// A multi-tenant deployment derives this from auth.).Solution
Derive the session's
organization_idfrom the authenticated request, in priority order:AgentWidgetAuthgains a new optionalorganization_idfield. Widget visitors authenticate via origin +authContext(not a JWT), so their org rides on the agent's embed policy. A host policy service (orWIDGET_AUTH_URL) supplies it.org_idis now threaded from the/wshandshake (resolve_ws_access→connection_loop→handle_frame→handle_create_session) instead of being dropped when thePrincipalis reduced to anAccessContext(which only carriesuser_id+groups).agent_idalready came from the inboundagentIdpayload and is threaded onto the conversation/participants/session — unchanged.The same JWT-org-then-configured-org derivation is applied to the lambda dispatch create-session path (
resolve_frame_org, falling back toconfig.org_id).Why widget-auth carries the org
AgentWidgetAuthpreviously only heldallowed_origins+public_key— it did not carry the agent's org, and widget visitors don't present a JWT. Rather than force it, the change adds an additive, serde-defaultorganization_idso a multi-tenant host can supply it; absent it, derivation falls through to the JWT principal, then the seed org.Tests
New
create_session_org_agent.rs:X(not seed), agent participantinternal_id=Y, sessionagent_id=Y.SEED_ORG_ID(behavior preserved).Gates
cargo build --manifest-path rust/Cargo.toml✅cargo test -p smooai-smooth-operator-server✅ (95 passed, incl. 3 new)cargo test -p smooai-smooth-operator -p smooai-smooth-operator-lambda✅cargo fmt --check✅cargo clippy -p smooai-smooth-operator-server / -lambda / smooth-operator -- -D warnings✅ (No issues found)🤖 Generated with Claude Code