fix: carry agent identity so TaaS accepts caller session ids - #19
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
TaaS was discarding every caller-supplied session identity and minting its own UUID per request. Production logs showed 76/76 requests with:
Consequences measured in production:
cont:hithad zero keys cluster-wide)Independent evidence that continuation was real: prompt-cache reads averaged 47.6%. A cache read is only possible when a provider recognises a prefix from an earlier request, so upstream providers recognised these conversations while TaaS did not.
Root cause
TaaS trusts a caller identity only when both parts are present:
Two independent gaps meant neither part arrived:
1. The header path never executes for this provider.
X-Session-Idis emitted fromresolveTransportTurnState, but OpenClaw only invokes that hook from the Responses transports. CloudSigma is configuredapi: "openai-completions", andcreateOpenAICompletionsTransportStreamFncontains zeroturnStatereferences. The headers were correct but never attached on our lane.2. The body path that does execute omitted the agent id.
onPayload→patchPayloadMetadataruns on the completions transport and injectedsession_id/sticky_key, butagent_idwas only set whenderiveAgentIdForCapturecould infer it fromagentDir/workspaceDir/env — unavailable in this path, so it returnednull.Fix
Add
resolveAgentIdentity, which prefers the existing directory/env derivation and otherwise extracts the agent segment from OpenClaw's own session key (agent:<agentId>:<scope>). Used at both the wrapper and transport call sites, so the correlation envelope always carries a complete identity.The value only needs to be stable for the conversation, not globally unique. When there is genuinely no session identity, it still returns
nullrather than fabricating one.Verification
Built output, exercising the real code path:
Both flags flip from
falsetotrue— precisely the production failure.test/agent-identity.test.ts)Expected impact
Session affinity should begin pinning conversations to their bound node, which should raise both continuity reporting and real prompt-cache hit rates.