Repository navigation
fix(a2a): propagate userId/sessionId end-to-end across the wire - #3938
Merged
Merged
Conversation
The Session resolved from A2aAgent#call(msgs, RuntimeContext) was local-only: identity was dropped at the serialization boundary and the server's flat metadata lookup could never see it (agentscope-ai#1603). - client: convertFromMsg carries the user id on the envelope-level metadata key `_agentscope_user_id` (written after the per-message wrapping, safe from <msgId, metadata> key collisions) and the session id as the native A2A contextId - server: getUserId reads the envelope key, with the flat legacy `userId` key kept as a deprecated fallback; getSessionId unchanged - runner: BaseReActAgentRunner forwards (userId, sessionId) into the agent's RuntimeContext via streamEvents(msgs, ctx) - adjudication: new A2aContextResolver lets a deployment override the envelope-asserted user id with a transport-verified one (resolver > envelope > none; conflicts WARN; a throwing resolver fails closed); wired via AgentScopeA2aServer.Builder#contextResolver - honoring an envelope-asserted identity without a resolver logs a one-time warning; identity values in logs are bounded and stripped Fixes agentscope-ai#1603
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
jujn
approved these changes
Nov 2, 2026
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.
Fixes #1603
Description
A2aAgent#call(msgs, RuntimeContext)already resolves a first-classSession(userId, sessionId), but that identity was local-only: it was dropped at the serialization boundary, and the server read user/session ids from flat message metadata keys the client never writes flat (convertFromMsgwraps per-message metadata as<msgId, metadata>). As a resultAgentRequestOptions.userIdwas always empty and the built-in runner never forwarded identity into the agent — #1603.This closes the three gaps:
MessageConvertUtil.convertFromMsg(msgs, userId, sessionId)(old overload delegates): user id → envelope-level metadata key_agentscope_user_id; session id → the native A2AcontextId.A2aAgent#exchangepasses the call's session identity.getUserIdreads the envelope key, keeping the flat legacyuserIdkey as a deprecated fallback.getSessionIdis unchanged (#3746 behavior).BaseReActAgentRunnerbuilds the per-callRuntimeContextfrom the options and callsagent.streamEvents(msgs, ctx), so per-user state slots, session logs and tools see the caller's(userId, sessionId).Plus a deployment-side adjudication hook:
A2aContextResolver(new functional interface, wired viaAgentScopeA2aServer.Builder#contextResolver): a transport-verified user id (mTLS cert, OAuth token fromRequestContext#getCallContext()) overrides the envelope-asserted one. Priority:resolver > envelope assertion > none; disagreement logs a WARN (log values bounded and control-char stripped); a resolver that throws fails closed (request rejected, never downgrades to the unverified assertion). A resolver returningnull/blank deliberately keeps the envelope trust.<msgId, metadata>wrapping, so a message whose id collides with the reserved key cannot spoof or suppress the identity (regression-tested).Usage
Compatibility
convertFromMsg(List)overload, 2-arg executor constructor,AgentRunnerinterface untouched;getSessionIdfrom fix(a2a): resolve runner session IDs while preserving legacy metadata #3746 kept byte-identical (its tests unchanged and passing).userIdfallback →"").contextIdis a native field. Anonymous calls send no envelope key.A2aAgentcall now carriescontextId = <agent name>(the client's default session name) instead of letting the server generate a per-request UUID. Slot semantics are equivalent (ReActAgent's default session also falls back to the agent name); deployments grouping server tasks by contextId will see the constant instead.Docs
docs/v2/en/integration/protocol/a2a.mdanddocs/v2/zh/integration/protocol/a2a.md: identity propagation on the client, identity/session resolution precedence, resolver usage, and the delegation trust model on the server.