Repository navigation
session: key SSM sessions by client conversation id / first user turn (#209) - #257
Conversation
|
All contributors have signed the CLA. Thank you! |
|
I have read the CLA Document and I hereby sign the CLA |
…Atlas-Inf#209) The first-1024-token session hash was one value for every request sharing a tool set (the template renders the tool JSON first), so separate agent conversations shared one snapshot "session" for eviction, the tail lease and insert_tail's same-session tail replacement. Chat requests now resolve the key in session_key.rs, in priority order: - headers x-session-id / x-session-affinity / x-conversation-id; - Responses `conversation` id; - OpenAI prompt_cache_key, metadata.session_id / metadata.conversation_id (chat and Responses), Anthropic metadata.user_id (Claude Code's session); - OpenAI `user`, folded with the first user turn (an end-user id alone would merge one user's conversations); - the messages through the end of the first user turn (role + content, length-prefixed, capped at 1 MiB), hashed before tool-prompt injection; - the old first-1024-token hash when there is no user message. previous_response_id is deliberately not a key: it changes every turn. Client ids hash with a domain tag through the fixed-key DefaultHasher::new(), on the head only. session_hash is still not sent to the TP worker rank, whose sequences keep session_hash = 0 as before. /v1/completions is unchanged. Each chat request logs `session key: source=<src> hash=0x<hex>`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
7fa0c9c to
a6e3601
Compare
Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
Sparky GB10 gate in progress (job 50a,
The control differs from our older reference, but main has moved 219 commits since that reference was taken (#265–#272, incl. #271's Flash-Next |
|
One-variable baseline (sparky job 50a2: main at this PR's merge base b0df501, same FP4-Local profile):
So the earlier control diff came from main's own changes, not this PR. Merging once the baseline BFCL lands and matches within the subset-level spread. |
|
Gate passed: merging. Sparky GB10, FP4-Local, default recipe profile with prefix caching. One-variable A/B: this PR merged onto b0df501 (job 50a) vs main at b0df501 (job 50a2):
Main has since gained #273/#274. In the files this PR touches they only change unrelated lines (loop-detect steering gate, a test module). Thanks @maplepaladin73. Fixes #209. |
Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Fixes #209 (design agreed with Azeez in the issue thread).
Problem
compute_session_hashkeyed SSM snapshot sessions on the first 1024 prompt tokens. Agent clients (Claude Code, OpenCode, OpenClaw) send a shared system prompt + tool block far longer than 1024 tokens, so every conversation from the same agent collapsed onto one session hash.Design
Session key, highest priority first (new
session_key.rs, computed on rank 0 inapi/chat/inner.rs):x-session-id,x-session-affinity,x-conversation-id(first non-blank); Responsesconversation; OpenAIprompt_cache_key(chat + Responses);metadata.session_id/metadata.conversation_id; Anthropicmetadata.user_id(Claude Code puts its session id there).useris only used combined with the first user turn (on its own it would merge all of one end user's conversations).first_user_turn: hash of all messages through the end of the first user message (past the shared system+tools block), computed from the client messages before server-side tool-prompt injection (no second render/tokenize on 17k+ prompts). Content past 1 MiB ignored.prefix1024: the existing first-1024-token hash (no user message;/v1/completionsis unchanged).Ids are hashed with a domain tag through fixed-key
DefaultHasher::new()(deterministic, pinned by a test); 0 is mapped to 1 because 0 means "untracked".previous_response_idis deliberately not used (changes every turn).TP=2: the hash is computed on rank 0 only from request data; nothing new is broadcast and the worker path is unchanged (worker sequences keep
session_hash = 0as today).One info log line per chat request:
session key: source=<header|conversation|prompt_cache_key|metadata|user|first_user_turn|prefix1024> hash=0x….Open point for review: single-shot prefill (
prefill_a.rs:144) checkssession_matcheson every restore, not only tails. With distinct keys, cross-conversation reuse of a shared system-prompt snapshot on that path is no longer taken (the collision was what allowed it). Making that check tails-only, as suggested in the thread, is in spark-model and left out of this PR; happy to follow up.Tests
cargo fmt --all -- --check,cargo check -p spark-server,cargo clippy -p spark-server --all-targetsclean (ATLAS_NO_RDMA=1 ATLAS_SKIP_BUILD=1).cargo test -p spark-server --bin spark session: 20 passed (same id → same hash; distinct ids with identical prompts → distinct; pinned hash value; header beats body; blank header ignored; same system+tools, different first user msg → distinct; turns appended → same hash; prefix1024 fallback; real 26 KB Claude Code prompt + 70 tools fixture). Fullsparkbin suite: 2797 passed, 0 failed.Pair check (DGX Spark ×2, TP=EP=2, Qwen3.8-Flash-Next FP4, production profile, image built from this branch)
0xd37abd1ee735222bvs0x7f23855313d1ce88, source=first_user_turn); each kept its hash on turn 2.x-session-idagent-x vs agent-y with identical messages → distinct; agent-x kept its hash across turns. Window total: 54 first_user_turn + 3 header keys, 22 distinct.