feat: recognize X-Session-Id header for Tier-1 session identification#687
Merged
Conversation
ca359f6 to
f2d936d
Compare
Add x-session-id to KNOWN_SESSION_HEADERS (above x-session-affinity) so the gateway deterministically identifies sessions from clients that send the new standard header (e.g. OpenCode v1.17+). The header is NOT added to the managed-headers strip-set — it is forwarded upstream for sticky routing as designed by OpenCode. Also simplify client-type detection: collapse the tri-state ClientType (claude-code / opencode / generic) into a boolean isClaudeCodeClient(). The opencode vs generic distinction was vestigial — nothing branched on it.
f2d936d to
eb59916
Compare
Contributor
Codecov Results 📊✅ Patch coverage is 100.00%. Project has 5941 uncovered lines. Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 59.13% 59.11% -0.02%
==========================================
Files 100 100 —
Lines 14534 14531 -3
Branches 9951 9947 -4
==========================================
+ Hits 8594 8590 -4
- Misses 5940 5941 +1
- Partials 1117 1118 +1Generated by Codecov Action |
Contributor
|
6 tasks
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.
Summary
Adds first-class support for OpenCode v1.17+'s new
X-Session-Idheader for deterministic Tier-1 session identification, and simplifies the vestigial client-type detection code.Context
OpenCode v1.17.0 (#31511) added an
X-Session-Idheader alongside the existingx-session-affinityheader for proxy setups that need sticky routing. Both carry the same stable session ID value. The gateway already recognizedx-session-affinity, so this was functionally handled — but only through the legacy name. Adding explicitx-session-idrecognition future-proofs against OpenCode dropping the legacy header and supports any other client adopting the standard name.Changes
x-session-idtoKNOWN_SESSION_HEADERS(session.ts): ranked abovex-session-affinityso the standard name wins when both are present. Intentionally not added toGATEWAY_MANAGED_HEADERS— the header is forwarded upstream as designed for sticky cache routing.x-session-affinitycomment: was described as "nanoid, volatile — regenerated on restart" which is no longer accurate (current OpenCode sets it to the stable DB session ID).detectClientType()withisClaudeCodeClient(): the tri-stateClientType(claude-code/opencode/generic) was vestigial — nothing branched on=== "opencode". The only behavioral question is "is this Claude Code?" (formax_tokenssizing), which is now a simple boolean. Removes theClientTypetype export entirely.detectClientTypetests withisClaudeCodeClienttests, including coverage for the newx-session-idheader returning false (session identity ≠ client identity).