Files
opencode2api/internal
Jason Xu 9aa2133f84 fix(identity): scope derived upstream sessions to the calling server key
Two callers whose conversations began identically were mapped onto the
same upstream session. Without a client session signal the session was
hashed from the first user turn alone, ignoring the server key and the
system prompt, so two users opening with "你好", or two Codex users in the
same working directory (whose first user turn is the boilerplate
<environment_context> block), shared one x-opencode-session, one sticky
upstream provider, one preferred key and one anonymous proxy exit. Every
caller without a client project also shared one constant project id.

- Mix the authenticated caller (server key fingerprint; Playground gets
  its own bucket) into every session and default project the gateway
  derives. Official OpenCode ses_ sessions sent by the client are kept
  verbatim because the client minted them uniquely.
- Read the session signals mainstream agents already send before falling
  back to a content seed: Codex's session_id / conversation_id headers
  and the session UUID inside Claude Code's metadata.user_id (underscore
  or JSON form). The per-user remainder of user_id is never used as a
  session.
- Seed from the system prompt (Anthropic system, Responses instructions,
  leading system/developer messages) plus the first user turn instead of
  the first user turn alone.
- Correct stale comments: x-opencode-request and the project header do
  reach upstream, rendered per lane.

Upgrading re-derives every gateway-made session once, so in-flight
conversations may move to another key or proxy and start with a cold
upstream cache. Conversations under one key that share both the system
prompt and the opening turn can still share affinity; the READMEs now
recommend separate server keys for users who must stay isolated.
2026-10-18 22:04:54 +08:00
..