fix: derive agent-scoped session identity when host omits sessionId - #20
Merged
Conversation
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
v0.7.0 injected nothing at all on the transport that carries all agent traffic. Measured in production:
Consecutive requests scattered across 8 different nodes (
jhb-02,fra-03,dub-02,dub-01,zrh-03,zrh-02,mty-04,wdc-04), so session affinity was genuinely not engaging — not merely mis-measured.Root cause
OpenClaw builds the
wrapStreamFncontext inextra-params-cce1g0up.jsas:There is no
sessionId.resolveSessionIdentityrequires eitherctx.sessionIdorOPENCLAW_SESSION_ID(absent from the gateway environment), so it returnednulland the plugin skipped injection entirely.The header path cannot compensate:
X-Session-Idis emitted fromresolveTransportTurnState, which OpenClaw only invokes from the Responses transports. CloudSigma is configuredapi: "openai-completions", andcreateOpenAICompletionsTransportStreamFncontains zeroturnStatereferences.Verified directly against the installed build:
Fix
agentIdis supplied and is stable for the life of an agent conversation — exactly the granularity affinity needs. When no native session id exists, derive a deterministic identity from it, scoped by workspace, under a distinctagent_scopedmode so it can never be mistaken for a native session id.Precedence is unchanged: native
ctx.sessionId→OPENCLAW_SESSION_ID→ agent-scoped fallback →null.Verification
Against the real production context shape:
Invariants confirmed:
test/agent-scoped-session.test.ts)Companion change
Paired with
cloudsigma/taasPR for dual-format identity resolution, so the injectedopenclaw_correlationenvelope is honoured on the OpenAI-compatible endpoint as well as the Anthropic one.