Repository navigation
fix: bind grok-shell sessions via x-grok-session-id so compression state stops forking - #1038
Conversation
…ate stops forking grok-shell (xAI CLI) stamps a per-session UUID on every model request as x-grok-session-id (x-grok-conv-id carries the same value). The whitelist did not know them, so every request was anonymous and fell to prefix-affinity — which forked a fresh session every turn because grok-shell reorders its replayed history head between turns, leaving compression state unable to accumulate (every session ended with 0 blocks).
[bot] 🏷 Reviewed — correct, minimal, well-tested, and independently verified. Ready to merge once the branch is brought up to current master (details below). I did not merge — that's human-only per repo rules. What I checked
Code correctness
TestsThree integration cases against the real One action before mergeThe branch is currently behind master by 7 commits (incl. #1033, #1034, #1037). It's an external fork, so please use GitHub's "Update branch" button (or rebase + force-push your branch). I verified the resulting tree is green, so it should land cleanly. VerdictPasses the auto-merge criteria on scope/diff/tests/greenness, with one deliberate exception: §7.4's "must stay human" list explicitly covers identity/session-binding logic, which is precisely what this touches — so the merge itself is a human call. Everything on the correctness side is done and confirmed. 中文摘要:修复正确且已独立验证(rebase 到最新 master 后 typecheck/全量测试/构建全绿,CI 全绿)——把 |
|
Reviewed — LGTM. Filed the companion issue #1042 (repo rule: fixes reference an issue; please add Code review:
Verification on the rebased head (rebased onto current master One ask per repo convention: every fix carries a CHANGELOG entry (see CHANGELOG.md head). Suggested text, feel free to paste/adapt:
|
Problem
grok-shell (xAI's CLI) stamps a per-session UUID on every model request as
x-grok-session-id(the parallelx-grok-conv-idcarries the same value). The identity whitelist did not know either name, so every grok request fell through to anonymous prefix-affinity — and grok-shell reorders its replayed history head between turns (message order/composition changes, not pure append), which breaks the byte-exact hash chain and forks a brand-new session on every request.Net effect: compression state never accumulates (every session ends with 0 blocks; nudges re-evaluate from scratch forever), exactly the failure mode
session-id.tswarns about for identity-less clients.Captured from grok-shell 1.0.34 (headless, one turn — identity headers on both the main and the turn-summary request):
Fix
Add
x-grok-session-id(withx-grok-conv-idas fallback) to the header whitelist, placed with the other client-specific headers — same trust class asx-claude-code-session-id: a client-specific name no other agent sends, so it can never collide with or displace a stronger signal (x-bili-plugin-conversationstill outranks everything).Testing
tests/grok-session-identity.test.ts(3 cases, all green): verbatim session binding, two concurrent session ids stay two sessions,x-grok-conv-idfallback.claude-nativeinstaller round-trip ×2,isMitmHostwhitelist ×1) reproduce identically on a cleanorigin/mastercheckout in the same environment — they touch real~/.claudestate and are unrelated to this diff.npm run typecheckclean; diff touches nopackage.jsonversion field.Verified end-to-end
Proxy running this build, two independent real grok-shell sessions driven through it: each routes to its own UUID-named session, messages accumulate per session, zero anonymous
pfa-forks, and compression blocks persist across requests (previously: ~20 forks in 15 minutes, every session 0 blocks).