Repository navigation
fix: add x-openclaw-session header for stable agent-scoped HTTP sessions - #69060
JustInCache wants to merge 3 commits into
Conversation
Greptile SummaryThis PR adds a new Confidence Score: 5/5Safe to merge; the only finding is a P2 hardening suggestion that mirrors a pre-existing gap in the user field path. No P0 or P1 issues found. The logic is correct, agent-scoped, and consistent with existing patterns. The single P2 comment (no length/char validation on the header value) is consistent with the treatment of the user field and represents a hardening opportunity rather than a blocking defect. No files require special attention. Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/gateway/http-utils.ts
Line: 307
Comment:
**No length or character validation on session hint**
The header value is only `.trim()`-ed before being embedded in the session key. Agent IDs are validated against `VALID_ID_RE = /^[a-z0-9][a-z0-9_-]{0,63}$/i` (max 64 chars), but `sessionHint` has no equivalent guard. A caller could send a value containing internal spaces (`"foo bar"`) or embedded colons (`"a:b"`), producing session keys like `agent:{id}:{prefix}-session:foo bar` that may behave unexpectedly in storage backends or key-comparison code. Consider rejecting or sanitizing values that fail `VALID_ID_RE` (or a dedicated session-hint regex), consistent with how agent IDs are treated.
```suggestion
const rawHint = getHeader(params.req, "x-openclaw-session")?.trim();
const sessionHint = rawHint && /^[a-z0-9][a-z0-9_-]{0,127}$/i.test(rawHint) ? rawHint : undefined;
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix: add x-openclaw-session header for s..." | Re-trigger Greptile |
|
Codex review: found issues before merge. Reviewed June 5, 2026, 1:13 AM ET / 05:13 UTC. Summary PR surface: Source +25, Tests +89, Docs +28. Total +142 across 4 files. Reproducibility: yes. from source inspection: current Review metrics: 1 noteworthy metric.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review findings
Review detailsBest possible solution: Land this only after the new header's endpoint scope, precedence, and same-session concurrency semantics are explicit and covered for every affected HTTP endpoint. Do we have a high-confidence way to reproduce the issue? Yes, from source inspection: current Is this the best way to solve the issue? Unclear: the new stable hint is a plausible fix for voice clients, but putting it in the shared resolver broadens the API surface before the Responses endpoint, precedence, and concurrency semantics are settled. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model gpt-5.5, reasoning high; reviewed against e0018382eb00. Label changesLabel justifications:
Evidence reviewedPR surface: Source +25, Tests +89, Docs +28. Total +142 across 4 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
|
Addressed all review feedback in commit 84407e9484: Greptile P2 — no length/character validation on session hint Added a regex guard on the raw header value before it is used: ```ts Values containing colons, spaces, or other special characters are silently rejected and the request falls through to the random-UUID fallback — consistent with the treatment of agent IDs. Max length capped at 128 chars (slightly more generous than agent IDs but still bounded). Codex P3 — document the new header Expanded the
Also listed the header alongside the other optional headers in Codex P3 — changelog entry Added a single-line Codex P3 — session header precedence tests Added five focused cases to
|
Closes openclaw#68920 Every /v1/chat/completions call that omits the OpenAI `user` field receives a fresh random UUID session key, triggering a full QMD re-index on each request and inflating TTFB by several seconds. Voice/realtime stacks (LiveKit, Twilio, etc.) cannot easily inject a `user` field per-request. This change adds support for a new `x-openclaw-session` request header that produces a deterministic, agent-scoped session key — `{prefix}-session:{hint}` — without overriding the full session key the way x-openclaw-session-key does. Priority order remains: 1. x-openclaw-session-key (explicit full override, unchanged) 2. user field (agent-scoped, unchanged) 3. x-openclaw-session (NEW — agent-scoped stable hint) 4. random UUID (per-call fallback, unchanged) Callers that need one session per voice channel can now pass x-openclaw-session: call-id-abc123 and the gateway will reuse the same warm session across the call, avoiding repeated QMD sync startup overhead. Made-with: Cursor
- Greptile P2: validate the x-openclaw-session header value against
/^[a-z0-9][a-z0-9_-]{0,127}$/i before embedding it in a session key.
Invalid values (colons, spaces, oversized) are silently ignored and
the request falls through to the random-UUID fallback, preventing
malformed storage keys.
- Codex P3: document x-openclaw-session in docs/gateway/openai-http-api.md
with the full 4-level priority table, usage example, and format
constraints; expand the Session behavior section accordingly.
- Codex P3: add a focused CHANGELOG entry under Unreleased/Fixes that
references openclaw#68920 as partially addressed.
- Codex P3: add five regression tests for x-openclaw-session precedence:
valid hint → stable agent-scoped key; user field priority over hint;
x-openclaw-session-key priority over both; same hint on two agents
produces different keys (agent scoping); invalid hint (colon) falls
back to random UUID.
Co-authored-by: Cursor <[email protected]>
84407e9 to
3819bde
Compare
|
ClawSweeper PR egg 🔥 Warming up: real-behavior proof passed; findings, security review, or rank-up moves are still in progress. Hatch commandComment Hatchability rules:
What is this egg doing here?
|
|
@clawsweeper hatch |
|
🦞👀 I queued a comment sync for this PR. If the egg is hatchable, ClawSweeper will generate the image once and update the existing review comment. |
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
1 similar comment
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
@osolmaz Could you please review this PR ? Let me know in case anything is required from my side. |
|
This assigned pull request has been automatically marked as stale after being open for 27 days. |
|
Closing due to inactivity. |
Summary
Partially addresses #68920 (the QMD re-index overhead component).
Every
/v1/chat/completionscall that omits the OpenAIuserfield receives a fresh random-UUID session key. This triggers a full QMD re-index on each request, which accounts for a significant portion of the 10-15s TTFB reported by voice/realtime callers (LiveKit, Twilio, etc.).Voice stacks cannot always inject the
userfield per-request. This PR adds a newx-openclaw-sessionheader that produces a deterministic, agent-scoped session key without clobbering the existing full-override behaviour ofx-openclaw-session-key.Priority order (unchanged except for the new entry)
x-openclaw-session-keyheaderuserrequest fieldx-openclaw-sessionheader (new)Usage
Voice/realtime callers can now pass a stable call identifier:
The gateway resolves this to
{prefix}-session:livekit-room-abc123scoped to the agent, so warm-session cache hits apply and QMD sync is skipped on subsequent requests in the same call.What this does NOT fix
The core 15-20K-token framework system prompt assembly still runs on every request. A
lightContext/x-openclaw-light-contextmode that bypasses the full context pipeline is a separate, larger architectural change.Test plan
x-openclaw-session: behaviour unchanged — new UUID session per callx-openclaw-session: my-id: same stable session key across calls (verify no QMD re-index on second call)userfield still takes priority overx-openclaw-sessionx-openclaw-session-keystill takes highest priority, overriding bothx-openclaw-sessionvalue get different session keys (agent scoping confirmed)Real behavior proof
Behavior or issue addressed:
/v1/chat/completionscalls without the OpenAIuserfield each received a fresh random UUID session key, triggering a full QMD re-index on every request and inflating TTFB to 10-15s for voice/realtime callers.Real environment tested: Local OpenClaw gateway (
openclaw start),gateway.http.endpoints.chatCompletions.enabled: true, macOS 14.7, Node 22.4, auth modetoken.Exact steps or command run after fix:
Evidence after fix:
Terminal capture — gateway debug log showing session key resolution and TTFB:
Observed result after fix: Calls 1 and 2 with the same
x-openclaw-session: livekit-room-abc123header resolve to the identical session keyagent:main:openai-session:livekit-room-abc123. Call 2 skips QMD re-index and returns in ~350ms vs ~11s for the cold call. Without the header the key stays random-UUID and every call is cold.What was not tested: Load behaviour under concurrent voice sessions; LiveKit/Twilio SDK integration beyond curl.