Skip to content

feat: recognize X-Session-Id header for Tier-1 session identification#687

Merged
BYK merged 1 commit into
mainfrom
feat/x-session-id-support
Jun 11, 2026
Merged

feat: recognize X-Session-Id header for Tier-1 session identification#687
BYK merged 1 commit into
mainfrom
feat/x-session-id-support

Conversation

@BYK

@BYK BYK commented Jun 10, 2026

Copy link
Copy Markdown
Owner

Summary

Adds first-class support for OpenCode v1.17+'s new X-Session-Id header for deterministic Tier-1 session identification, and simplifies the vestigial client-type detection code.

Context

OpenCode v1.17.0 (#31511) added an X-Session-Id header alongside the existing x-session-affinity header for proxy setups that need sticky routing. Both carry the same stable session ID value. The gateway already recognized x-session-affinity, so this was functionally handled — but only through the legacy name. Adding explicit x-session-id recognition future-proofs against OpenCode dropping the legacy header and supports any other client adopting the standard name.

Changes

  • Add x-session-id to KNOWN_SESSION_HEADERS (session.ts): ranked above x-session-affinity so the standard name wins when both are present. Intentionally not added to GATEWAY_MANAGED_HEADERS — the header is forwarded upstream as designed for sticky cache routing.
  • Fix stale x-session-affinity comment: was described as "nanoid, volatile — regenerated on restart" which is no longer accurate (current OpenCode sets it to the stable DB session ID).
  • Replace detectClientType() with isClaudeCodeClient(): the tri-state ClientType (claude-code / opencode / generic) was vestigial — nothing branched on === "opencode". The only behavioral question is "is this Claude Code?" (for max_tokens sizing), which is now a simple boolean. Removes the ClientType type export entirely.
  • Update tests: replaced detectClientType tests with isClaudeCodeClient tests, including coverage for the new x-session-id header returning false (session identity ≠ client identity).

@BYK BYK self-assigned this Jun 10, 2026
@BYK BYK force-pushed the feat/x-session-id-support branch from ca359f6 to f2d936d Compare June 10, 2026 23:33
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.
@BYK BYK force-pushed the feat/x-session-id-support branch from f2d936d to eb59916 Compare June 10, 2026 23:57
@github-actions

Copy link
Copy Markdown
Contributor

Codecov Results 📊

✅ Patch coverage is 100.00%. Project has 5941 uncovered lines.
❌ Project coverage is 59.11%. Comparing base (base) to head (head).

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        +1

Generated by Codecov Action

@BYK BYK merged commit 13bf491 into main Jun 11, 2026
15 checks passed
@BYK BYK deleted the feat/x-session-id-support branch June 11, 2026 00:01
@github-actions

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-06-11 00:02 UTC

@craft-deployer craft-deployer Bot mentioned this pull request Jun 11, 2026
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant