🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

fix(aibridge): recognize hyphenated session-id header from newer Codex releases - #26346

Merged
bpmct merged 1 commit into
mainfrom
fix-codex-session-id-header
Jun 12, 2026
Merged

fix(aibridge): recognize hyphenated session-id header from newer Codex releases#26346
bpmct merged 1 commit into
mainfrom
fix-codex-session-id-header

Conversation

@bpmct

@bpmct bpmct commented Jun 12, 2026

Copy link
Copy Markdown
Member

Codex prompts were showing up as one session per request in the AI Sessions list instead of being grouped into a conversation.

Root Cause

AI Gateway extracts the Codex session key from the session_id request header:

https://github.com/coder/coder/blob/main/aibridge/session.go#L57-L58

Newer Codex releases renamed the header to session-id (hyphen) in codex-rs/codex-api/src/requests/headers.rs:

insert_header(&mut headers, "session-id", &id);

Header.Get is case-insensitive but not underscore/hyphen-insensitive, so no session key is extracted and every request falls back to its own session. Reproduced with Codex CLI 0.139.0.

Changes

  • Check session-id first, fall back to the legacy session_id for older Codex versions
  • Added test cases for the hyphenated header and precedence

Before/After

The same three-prompt Codex conversation ("Write a haiku about Pittsburgh" → "Now make it about Coder" → "Translate it to Spanish", via codex exec + codex exec resume --last) against a local build.

Before: each prompt of the conversation lands as its own session, Threads: 1

before

After: the conversation is a single session with Threads: 3

after

Clicking into the session shows all three threads on the session timeline:

after session detail

Linear: AIGOV-437

🤖 Generated with Coder Agents on behalf of @bpmct

@linear-code

linear-code Bot commented Jun 12, 2026

Copy link
Copy Markdown

AIGOV-437

@bpmct
bpmct marked this pull request as ready for review June 12, 2026 16:43
@tracyjohnsonux

Copy link
Copy Markdown
Contributor

I think the before and after shots are like one of those "spot the difference" visual games but in this case you're getting punked.

bpmct commented Jun 12, 2026

Copy link
Copy Markdown
Member Author

I think the before and after shots are like one of those "spot the difference" visual games but in this case you're getting punked.

@tracyjohnsonux yeah so its def "spot the difference" - under "threads" the latest session has 3 threads from Codex whereas before each new message was its own session.

but heard - i'll update the screenshots to something more obvious

@bpmct

bpmct commented Jun 12, 2026

Copy link
Copy Markdown
Member Author

Updated the before/after with the same three-prompt conversation on both sides so the difference is unmissable: before splits it into 3 sessions (Threads: 1 each), after groups it into 1 session with Threads: 3, plus a shot clicked into the session detail showing all 3 threads on the timeline.

Note on methodology: the "before" was reproduced by replaying the conversation without the session header, which is exactly what the unfixed code path sees (the pre-fix release can't run against the migrated dev database).

🤖 Coder Agents on behalf of @bpmct

@bpmct
bpmct merged commit 61ec5ac into main Jun 12, 2026
59 checks passed
@bpmct
bpmct deleted the fix-codex-session-id-header branch June 12, 2026 17:25
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 12, 2026

@dannykopping dannykopping left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Post-merge ✅

Hyrum's Law strikes again!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants