Skip to content

fix(gateway): Send the conversation ID as the AI Gateway session ID - #2590

Merged
thomasjiangcy merged 1 commit into
mainfrom
fix/gateway-session-id
Nov 3, 2026
Merged

thomasjiangcy merged 1 commit into
mainfrom
fix/gateway-session-id

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Junior sends no session ID to AI Gateway. The gateway then groups requests by a fingerprint of the system prompt, tools, and first user message, so many Conversations land in one session. In production, one gateway session (c4324a46b68384ee1ed53430177616b2) held about 2,000 requests over 6 hours from many Conversations.

The agent now passes its Conversation ID to Pi as sessionId. resolveGatewayModel enables Pi's sendSessionAffinityHeaders on every gateway model, so Pi sends it as x-session-affinity, which the gateway reads as an explicit session ID. Every gateway model in Pi's catalog and in our overrides uses anthropic-messages, so one flag covers all of them. Direct completeText calls pass no sessionId, so they still send no header. A child agent has its own Conversation ID and gets its own session.

Conversation IDs are opaque (slack:<channel>:<ts>, hashed agent:/local: IDs) and already go into telemetry, so they are sent as-is, not hashed.

The model message history integration test now checks that every request over two Turns carries the Conversation ID in x-session-affinity. It fails on main with [null, null, null].

--

View Session [Sentry]

@vercel

vercel Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Nov 3, 2026 6:43am UTC

Request Review

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

4 screenshot changes — 4 changed · 0 added · 0 removed

Review screenshots in Frameshift

Conversation Attachment · Desktop
Conversation Attachment · Desktop
Changed
Conversation Attachment · Mobile
Conversation Attachment · Mobile
Changed
Conversation Attachment Modal · Desktop
Conversation Attachment Modal · Desktop
Changed
Settings Mcp · Desktop
Settings Mcp · Desktop
Changed

@sentry-junior
sentry-junior Bot marked this pull request as ready for review November 3, 2026 06:46
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 3, 2026
@thomasjiangcy thomasjiangcy self-assigned this Nov 3, 2026
@thomasjiangcy
thomasjiangcy merged commit 2335942 into main Nov 3, 2026
49 checks passed
@thomasjiangcy
thomasjiangcy deleted the fix/gateway-session-id branch November 3, 2026 07:06
sentry-junior Bot added a commit that referenced this pull request Nov 8, 2026
The agent sends its Conversation ID as x-session-affinity (#2590), but
warmups went through completeText with no session ID. Pass the same
session ID, so a warmup reaches the same gateway session as the request
that it refreshes.

Co-Authored-By: BYK <[email protected]>

This branch was successfully deployed

1 active deployment
Preview – junior-docs — 20fd5691 Deployed Nov 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant