You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
session_hash collides for every request that shares a tool set (first-1024-token hash); snapshot eviction cannot tell agent conversations apart #209
session_manager::compute_session_hash hashes the first min(len, 1024) prompt tokens. With tools, the chat template renders the tool JSON first, so every request with the same tool set gets the same session hash, however different the conversation is.
Measured on sparky (GB10, FP4-Local, main 504063a), from the Session 0x… lines of one serve log:
70 tool requests: one hash, 0x65871a44fdf76528.
Each chat request without tools: its own hash.
Where it matters
Snapshot eviction.SsmSnapshotIndex::session_aware_victim evicts the stalest session first, and the tail lease protects last_lookup_session. With one shared hash, all agent conversations form one "session": eviction can't favour the live one, and the lease covers everyone's tails.
The tail gate in lookup / lookup_tiered (entry.is_tail && entry.session_hash != session_hash) does not separate agent conversations. I checked whether that is a correctness problem; with today's captures it is not:
The default mid-chunk tail capture saves GDN state exactly at tb (midchunk_capture.rs, split kernels).
qwen4_exp's in-pass checkpoints capture PLE/QSA aux at that exact row.
So a tail's physical extent equals its token_count, and a cross-conversation restore of it is as safe as any exact-prefix snapshot.
The "bleeds past its advertised token_count" comment matches the older clamp-based ATLAS_SSM_TAIL_CKPT path. If that path, or any capture that records state past token_count, is used, the gate becomes a real correctness boundary, and a first-1024-token hash cannot carry it.
Suggestion
Key LRU and lease affinity on a request-provided conversation id when present (user / a header), falling back to a hash that excludes the shared preamble, e.g. over the first user turn.
Keep correctness on prefix hashes, as non-tail entries already do.
If any tail capture can record state past its token_count, store and check the hash over the full physical extent rather than the session.
Same picture on our side, on a dual-GB10 serve (FP4-Local, TP=EP=2, same compute_session_hash as main): over the last 24 h, 4,225 of 4,783 tool requests logged one hash, 0xe31efe08175ec982, with prompts from 8,903 to 125,449 tokens (median 37,751). That is hours of separate agent conversations sharing one session.
One more effect, beyond eviction and the lease: the shared hash also makes conversations overwrite each other's tails.
SsmSnapshotIndex::insert_tail (crates/spark-runtime/src/radix_tree/snapshot_insert.rs:101-118) begins by removing and freeing every existing is_tail / is_tail_sibling entry with the same session_hash. Its only production caller is the default-on mid-chunk capture (prefill_b/midchunk_capture.rs:370, finalize_midchunk_capture via insert_tail_snapshot). When every tool request hashes to one value, conversation B's prefill capture frees conversation A's tail and sibling. A's next warm turn then misses its exact restore point, falls back to a coarser checkpoint and replays SSM tokens. With concurrent agent sessions, a conversation's tail survives only until another conversation's next turn.
One thing a fix needs to keep: in single-shot prefill (prefill_a.rs:144), session_matches gates all restores, not only tails, while chunked prefill gates only tails (pc_policy.rs:312-315). Today the collision is what lets a new agent conversation reuse another conversation's preamble snapshot on that path. A fix that separates sessions should make prefill_a tails-only too, or that reuse is lost.
I agree with the correctness analysis. Every restore still checks the prefix hash over tokens[..token_count], and the only is_tail writer registers at key[..tb] with state captured at tb.
A minimal fallback for when no conversation id is supplied: fold the text of the first user message into the chat session hash. It is the earliest span that differs between agent conversations, and it stays fixed as a conversation grows. We have that on a local branch with a unit test: two conversations sharing a 2000-token preamble get distinct hashes, and two turns of one conversation share a hash. Conversations that open with the same user message (a scheduled prompt, for example) would still share a hash, so an explicit key is better when the client has one. Note that OpenAI's user field is an end-user id, not a conversation id. Keying on it alone would still merge all of one user's conversations; prompt_cache_key or a header is a better explicit key.
This comment was prepared with AI assistance (OpenClaw agent) and reviewed by me.
Following up: is anyone working on this one? It's still the biggest cache issue on our agent traffic: one hash covers ~88% of tool requests, so snapshot eviction and the lease treat hours of separate conversations as one session. One possible fix is to hash a prefix that goes past the shared system+tools block (e.g. include the first user turn), or to key on a client-provided conversation id when there is one, and keep the first-1024 hash as the fallback. I'm happy to draft a PR if that approach suits you, or test yours on our pair.
@maplepaladin73 nobody's on it yet, so yes please, draft it. Your approach suits: key on a client-provided conversation id when there is one; otherwise hash past the shared system + tools block through the first user turn, with the first-1024-token hash kept as the fallback. We'll run it on our pair as well (snapshot eviction and lease behaviour under the agentic C4 harness).
Activity
maplepaladin73 commentedon Oct 25, 2026
Same picture on our side, on a dual-GB10 serve (FP4-Local, TP=EP=2, same
compute_session_hashas main): over the last 24 h, 4,225 of 4,783 tool requests logged one hash,0xe31efe08175ec982, with prompts from 8,903 to 125,449 tokens (median 37,751). That is hours of separate agent conversations sharing one session.One more effect, beyond eviction and the lease: the shared hash also makes conversations overwrite each other's tails.
SsmSnapshotIndex::insert_tail(crates/spark-runtime/src/radix_tree/snapshot_insert.rs:101-118) begins by removing and freeing every existingis_tail/is_tail_siblingentry with the samesession_hash. Its only production caller is the default-on mid-chunk capture (prefill_b/midchunk_capture.rs:370,finalize_midchunk_captureviainsert_tail_snapshot). When every tool request hashes to one value, conversation B's prefill capture frees conversation A's tail and sibling. A's next warm turn then misses its exact restore point, falls back to a coarser checkpoint and replays SSM tokens. With concurrent agent sessions, a conversation's tail survives only until another conversation's next turn.One thing a fix needs to keep: in single-shot prefill (
prefill_a.rs:144),session_matchesgates all restores, not only tails, while chunked prefill gates only tails (pc_policy.rs:312-315). Today the collision is what lets a new agent conversation reuse another conversation's preamble snapshot on that path. A fix that separates sessions should makeprefill_atails-only too, or that reuse is lost.I agree with the correctness analysis. Every restore still checks the prefix hash over
tokens[..token_count], and the onlyis_tailwriter registers atkey[..tb]with state captured attb.A minimal fallback for when no conversation id is supplied: fold the text of the first user message into the chat session hash. It is the earliest span that differs between agent conversations, and it stays fixed as a conversation grows. We have that on a local branch with a unit test: two conversations sharing a 2000-token preamble get distinct hashes, and two turns of one conversation share a hash. Conversations that open with the same user message (a scheduled prompt, for example) would still share a hash, so an explicit key is better when the client has one. Note that OpenAI's
userfield is an end-user id, not a conversation id. Keying on it alone would still merge all of one user's conversations;prompt_cache_keyor a header is a better explicit key.This comment was prepared with AI assistance (OpenClaw agent) and reviewed by me.
maplepaladin73 commentedon Oct 29, 2026
Following up: is anyone working on this one? It's still the biggest cache issue on our agent traffic: one hash covers ~88% of tool requests, so snapshot eviction and the lease treat hours of separate conversations as one session. One possible fix is to hash a prefix that goes past the shared system+tools block (e.g. include the first user turn), or to key on a client-provided conversation id when there is one, and keep the first-1024 hash as the fallback. I'm happy to draft a PR if that approach suits you, or test yours on our pair.
AzeezIsh commentedon Oct 29, 2026
@maplepaladin73 nobody's on it yet, so yes please, draft it. Your approach suits: key on a client-provided conversation id when there is one; otherwise hash past the shared system + tools block through the first user turn, with the first-1024-token hash kept as the fallback. We'll run it on our pair as well (snapshot eviction and lease behaviour under the agentic C4 harness).
session: key SSM sessions by client conversation id / first user turn (…
Merge pull request #257 from maplepaladin73/fix/209-session-key
campaign log: Atlas-Inf#208, Atlas-Inf#209