Skip to content

Feat: Read Codex's session header so its traffic groups by conversation - #1379

Merged
Alan-Cha merged 4 commits into
mainfrom
feat/codex-session-header
Oct 14, 2026
Merged

Alan-Cha merged 4 commits into
mainfrom
feat/codex-session-header

Conversation

@Alan-Cha

@Alan-Cha Alan-Cha commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Closes the largest remaining parity gap from #942 / #1365: Codex's traffic landed in a per-process bucket (pending:codex@<pid>.<start>) rather than a session — so two conversations in one long-lived process merged, and one spanning a restart split in two.

Codex does send a session id. Cortex was reading the wrong name.

Found by temporarily logging every header name Codex sends (values only for session-shaped names, so no Authorization token reached the log; probe reverted, binary checksum-verified):

Session-Id: 01a136c3-9708-7242-9934-9e5ab2568b41

Cortex's laptop list held X-Claude-Code-Session-Id, X-Task-Id and X-Session-Id. Codex sends the bare name, so the header already read for OpenCode missed it by one prefix.

Verified usable before relying on it

Forced a tool-using turn so one session produced nine inference requests:

Header Within one session Across two sessions
Session-Id one value, stable differs ✅
Thread-Id identical differs
X-Client-Request-Id identical differs

All three carry the same value today. This reads Session-Id because its name matches the intent: if Codex later makes X-Client-Request-Id per-request as its name implies, a bucket keyed on that would split one session into one per request and nothing would announce the change.

Placement is the careful part

Session-Id is the least namespaced of the four names, so it is:

  • last in precedence — every client sending a dedicated header still wins its bucket;
  • read only on a loopback-only install, exactly as X-Session-Id is and for the reason documented there: in a cluster a workload may send a bare Session-Id for its own purposes, and filing its calls by it would take them away from the session holding its user's intent. TestSessionConfig_InClusterDefaultDoesNotReadGenericHeaders (renamed from ...DoesNotReadXSessionID) now covers both generic names.

Test plan

  • gofmt -l, go vet, go mod tidy -diff clean; full core suite passes
  • New TestIDFromHeaders_Codex: the id alone is used; X-Session-Id does not match a bare Session-Id; every dedicated header outranks it; canonical casing
  • Updated TestSessionConfig_SessionIDHeadersFor to assert the laptop list in order, since the order is a precedence rule
  • Both guards mutation-tested — dropping the header from the laptop list, and collapsing it onto X-Session-Id, each make their test fail
  • Live-verified: two codex exec runs produced two sessions under their real UUIDs with agent=codex and their tokens attached, where before both would have merged into one process bucket. Claude Code's own session grouping unchanged. Binary reverted, checksum-verified.

Two honest caveats, both documented

  • Codex's pre-inference chatter carries no Session-Id, so a run leaves a small per-process bucket beside its named session — 15 events against 113 on a measured run. All the tokens and cost are in the named one.
  • Unconfirmed on the interactive TUI. The evidence is codex exec only; the TUI's startup chatter carries Originator but had not reached an inference request before the capture window closed. The two share one HTTP client so it very likely sends this too, but that is inference rather than evidence, and docs/agents/codex.md says so. If it does not, codex exec still gets named sessions.

Refs #1365, #942. Stacked conceptually on #1375 (independent branch, no overlap).

Assisted-By: Claude (Anthropic AI) [email protected]

Summary by CodeRabbit

  • New Features
    • On loopback-only installations, Codex inference requests can now be grouped into sessions using the Session-Id request header. Existing session headers take precedence when present.
  • Documentation
    • Updated Codex guidance to explain session grouping and its limitations: some non-inference activity may remain in a separate pending group, and session grouping for interactive TUI traffic is unconfirmed.

Codex's traffic landed in a per-process bucket (pending:codex@<pid>)
rather than a session, which was the largest remaining parity gap from
#942/#1365: one bucket per process, so two conversations in one
long-lived process merged and one spanning a restart split in two.

It turns out Codex does send a session id — Cortex was reading the
wrong name. Found by temporarily logging every header name Codex sends
(values only for session-shaped names, so no Authorization token
reached the log):

  Session-Id: 01a136c3-9708-7242-9934-9e5ab2568b41

Cortex's laptop list held X-Claude-Code-Session-Id, X-Task-Id and
X-Session-Id. Codex sends the BARE name, so the header already read for
OpenCode missed it by one prefix.

Verified usable before relying on it. Across one multi-turn session's
nine inference requests the value is constant, and differs in the next
session. Codex also sends Thread-Id and X-Client-Request-Id carrying
the same value; this reads Session-Id because its NAME matches the
intent — if Codex later makes X-Client-Request-Id per-request as its
name implies, a bucket keyed on that would split one session into one
per request and nothing would announce it.

Placed LAST in the precedence order and read only on a loopback-only
install, exactly as X-Session-Id is and for the reason given there: a
bare Session-Id is the least namespaced of the four, so every client
sending a dedicated header still wins its bucket, and an in-cluster
workload sending one for its own purposes does not get its calls filed
away from the session holding its user's intent. The in-cluster guard
test now covers both generic names rather than only X-Session-Id.

Live-verified: two `codex exec` runs produced two sessions under their
real UUIDs with agent=codex and their tokens attached, where before
both would have merged into one process bucket; Claude Code's own
session grouping is unchanged. Binary reverted and checksum-verified.

Both guards mutation-tested — dropping the header from the laptop list,
and collapsing it onto X-Session-Id, each make their test fail.

One honest consequence, now documented: Codex's pre-inference chatter
carries no Session-Id, so a run leaves a small per-process bucket
beside its named session (15 events against 113 on a measured run).
All the tokens and cost are in the named one.

Unconfirmed on the interactive TUI — its startup chatter carries
Originator but had not reached an inference request when the capture
window closed. The two share one HTTP client so it very likely sends
this too, but that is inference, not evidence, and the doc says so.

Refs #1365, #942.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Alan Cha <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 13 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 06edd45c-5e39-42ac-8d6c-985f66d6f74d
📥 Commits

Reviewing files that changed from the base of the PR and between 7f2d6e1 and 07601a6.

📒 Files selected for processing: 3
  • cmd/cortex/local.go
  • core/session/idheader.go
  • docs/agents/codex.md

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: be454a09-44cd-4115-97c5-0044ece9cf51
📥 Commits

Reviewing files that changed from the base of the PR and between 3455fe3 and 7f2d6e1.

📒 Files selected for processing: 5
  • core/config/config.go
  • core/config/config_test.go
  • core/session/idheader.go
  • core/session/idheader_test.go
  • docs/agents/codex.md

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

The change adds recognition for Codex’s Session-Id header and includes it in session header defaults for loopback-only deployments. Explicit header lists and non-loopback defaults remain unchanged. Tests cover header resolution and default selection. Codex documentation describes the behavior and its limitations.

Changes: Codex Session Header

Layer / File(s) Summary
Define and recognize the Codex header
core/session/idheader.go, core/session/idheader_test.go
Adds CodexSessionHeader for Session-Id. Tests cover header resolution, precedence, distinction from X-Session-Id, and canonical casing.
Enable the header in loopback defaults
core/config/config.go, core/config/config_test.go, docs/agents/codex.md
Loopback-only defaults include Session-Id after existing headers. Tests verify ordering and exclusion from in-cluster defaults. The documentation describes the header, pending traffic, and unconfirmed TUI support.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Feature · Severity of issue fixed: Medium

Suggested reviewers: huang195

Merge Risk: ⚪ Minimal · up to 7f2d6

Codex inference requests can be grouped by session on loopback-only installs. No actionable issue remains before merge.

Pre-merge checks: Passed 5
Passed Passed checks: 5 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: reading Codex's session header to group traffic by conversation.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 4 files. (1 skipped: 1 …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Two corrections to what docs/agents/codex.md claimed.

It said Cortex "ships no rate for the model Codex uses" and that there
"may be no public per-token rate to apply". The first is true but
framed as Codex-specific when it is not: the bundled table is
Anthropic-only by design (its generator keeps only
litellm_provider == "anthropic", for a documented reason), so ANY
agent on a non-Anthropic model reports priceable-but-unpriced. The
second is simply wrong — BerriAI/litellm, the same upstream the
bundled table is generated from, carries a first-party openai entry
for gpt-6-luna with all four tiers.

So the page now gives the rates as a copyable pricing: block rather
than describing cost as unavailable.

With two caveats it did not have. The figure is an ESTIMATE: those are
per-token API list prices, while Codex on a ChatGPT subscription bills
a flat fee, so the number is "what this would have cost via the API".
That is a subscription-vs-API distinction Cortex does not model for
any agent — Claude Code on Pro/Max has the same gap and is priced
today without comment — so the caveat is stated as general rather than
as a Codex quirk. And the model name must be checked before copying:
Codex picks its own and it moves between releases (gpt-6.1-sol has
also been observed).

Refs #1365.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Alan Cha <[email protected]>
CI caught what the live test could not. The laptop config writes
session.id_headers out EXPLICITLY, and an explicit list is used as
written rather than merged with the built-in default — so adding
Session-Id to config.SessionIDHeadersFor reached nothing on a freshly
installed Cortex. TestBuiltinConfig_IDHeadersEqualTheCoreDefault
exists to keep the two in sync and failed exactly as intended.

My live verification passed only because this machine's config
predates the explicit list, so the default still applied there. A new
install would not have read the header at all.

Also documents the consequence for anyone already installed: their
config keeps the old three names until they add the entry or drop the
id_headers block. Nothing can migrate it for them, since an explicit
list is exactly the thing an operator is entitled to pin.

Refs #1365.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Alan Cha <[email protected]>
@Alan-Cha Alan-Cha added the ready-for-ai-review Request automated AI code review from clawgenti label Oct 13, 2026
…rry it

The previous commits left this unconfirmed because the interactive TUI
blocks on two modal dialogs before its composer is usable, and clicking
through them was unreliable — the update nag reappeared. Suppressing
both at source works where dismissing them did not:

  codex -c check_for_update_on_startup=false \
        -c features.api_key_model_discovery=false

With those, no dialog appears and the TUI reaches a prompt. Tested
through the FEATURE rather than a debug probe: with sessions cleared
first, the TUI's traffic landed in a real UUID session tagged
agent=codex instead of a pending:codex@<pid> bucket, which can only
happen if a request carried the header.

It also corrected a claim these commits shipped. "Only Codex's
inference requests carry it" held for `codex exec` but not for the
TUI: that session was named with ZERO inference events in it, every
request being plugin-list and MCP chatter. So the practical
consequence is the opposite of what was documented — the TUI leaves
ONE row, not two, because its chatter is already named, while `codex
exec` still leaves a small chatter bucket beside its conversation.

The doc now states that per front-end rather than as one rule, and
adds the caveat that client_affinity files header-less requests into a
named session too — so a row's presence there is not by itself proof
that that request carried the header.

Refs #1365.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Alan Cha <[email protected]>

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Adds Codex's bare Session-Id header to the loopback-only default and the laptop installer template, last in precedence, with thorough tests and a docs rewrite — the pricing-override example matches the core/cost/pricing schema, and the Anthropic-only bundled-table claim checks out. One terminology nit below; nothing blocking.

  • nit core/session/idheader.go:83 — "the three dedicated headers" counts X-Session-Id as dedicated, though the same file's SessionIDHeader comment calls it "the generic request header".

Reviewed by clawgenti using the github-pr-review skill

Comment thread core/session/idheader.go
// reason given there: on a laptop the only clients are the user's own agents,
// while in a cluster an agent sending this for its own purposes would have its
// calls filed away from the session holding its user's intent. It also sits LAST
// in that list, so any client sending one of the three dedicated headers still

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: "one of the three dedicated headers" counts X-Session-Id as dedicated, but the taxonomy used elsewhere in this change differs: SessionIDHeader's own comment ~25 lines up calls it "the generic request header" and "UNNAMESPACED", and config.go's SessionIDHeadersFor comment describes X-Session-Id and Session-Id together as "the two generic names". Since the ordering rule is the point of this change, one consistent framing would help — e.g. "any client sending one of the three more-namespaced headers still wins". (The docs paragraph's "after the three dedicated names" has the same wrinkle.)

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

07601a6 confirms the TUI behavior with a live measurement and the docs table now reflects it; placement, installer/core parity (pinned by TestBuiltinConfig_IDHeadersEqualTheCoreDefault), and the pricing example all check out. Findings, all minor:

  • nit core/session/idheader.go:83 — carried over from the previous review, still present: "one of the three dedicated headers" counts X-Session-Id as dedicated, though the same file calls it the generic request header.
  • nit cmd/cortex/main.go (~L965) — the per-session bucketing comment still describes the loopback-only default as "plus X-Session-Id"; it is now plus two generic names.
  • nit PR description — the "Unconfirmed on the interactive TUI" caveat is superseded by this head's measurement; the docs table states it as fact.
  • suggestion docs/laptop-service.md — the "How traffic is grouped into sessions" narrative covers Claude Code, Bob, and OpenCode but not Codex, which now groups on laptop installs.

Reviewed by clawgenti using the github-pr-review skill

Comment thread core/session/idheader.go
// reason given there: on a laptop the only clients are the user's own agents,
// while in a cluster an agent sending this for its own purposes would have its
// calls filed away from the session holding its user's intent. It also sits LAST
// in that list, so any client sending one of the three dedicated headers still

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit — carried over from the previous review and still present at this head: "one of the three dedicated headers" counts X-Session-Id as dedicated, but the taxonomy used elsewhere in this change differs — SessionIDHeader's own comment above calls it "the generic request header" and UNNAMESPACED, and config_test.go now says "the two generic names come last". The installer comment in cmd/cortex/local.go avoids the clash with "any client sending one of the names above"; something like that would work here too.

Comment thread core/config/config.go
session.ClaudeCodeSessionHeader,
session.BobSessionHeader,
session.SessionIDHeader,
session.CodexSessionHeader,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit (cross-file): the caller comment in cmd/cortex/main.go (~L965) still describes the default as "the supported agents' session headers, plus X-Session-Id on a loopback-only install" — with this entry the loopback-only additions are two generic names. Worth a touch-up so the comment doesn't drift from SessionIDHeadersFor.

Comment thread docs/agents/codex.md
| | Carries `Session-Id` | Rows per run |
|---|---|---|
| `codex exec` | its **inference** requests; the plugin-list and MCP chatter does not | **two** — the conversation under its real id, plus a small `pending:codex@<pid>.<start>` bucket for the chatter that arrived before anything named the session (15 events against 113, measured) |
| the TUI (plain `codex`) | **also its chatter** — a TUI session was named with *zero* inference requests in it | **one** — everything lands in the named session, no pending bucket |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: the PR description still lists "Unconfirmed on the interactive TUI" as a caveat (and phrases the pre-inference-chatter caveat without the codex exec scope), but this row states the TUI behavior as measured per 07601a6. Updating the description would keep it from contradicting the docs.

Comment thread docs/agents/codex.md
traffic attributed to *that* agent's session — observed directly: the same `codex exec`
run filed its events under the Claude Code session that spawned it before the entry
existed, and into its own `pending:codex@…` bucket after.
**It groups into named sessions.** Codex sends its session id in a header named

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

suggestion: docs/laptop-service.md's "How traffic is grouped into sessions" section walks through Claude Code (X-Claude-Code-Session-Id), Bob (X-Task-Id), and OpenCode (X-Session-Id) but not Codex, which now groups on laptop installs via this header. A sentence there would keep the laptop doc's grouping narrative complete.

@mrsabath mrsabath left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verified the code paths and the load-bearing claims:

  • CodexSessionHeader sits last in the loopback-only default and is absent from the in-cluster default (both asserted by tests, order included); the renamed in-cluster guard test now covers both generic names.
  • Installer/core parity is pinned by TestBuiltinConfig_IDHeadersEqualTheCoreDefault — the gap commit 3 closed is exactly the one that test exists to catch.
  • The pricing example in docs/agents/codex.md matches the pricing.EndpointConfig/TierRates schema (hosts globs, four *_cost_per_million tiers), and chatgpt.com correctly excludes the ab.chatgpt.com telemetry host. The "bundled table is Anthropic-only by design" claim matches pricegen.go's filter and its documented reason.
  • Test quality is strong: precedence, name-distinctness, and canonical casing all asserted; mutation-tested per the description.

Findings, all minor (1 inline nit; the rest on lines this PR didn't touch, so noted here):

  • cmd/cortex/main.go:965 (nit) — the per-session bucketing comment still says the loopback-only default is "plus X-Session-Id"; it is now plus two generic names.
  • docs/laptop-service.md:74 (suggestion) — "How traffic is grouped into sessions" covers Claude Code, Bob, and OpenCode but not Codex, which now groups on laptop installs; line 138's "Agents other than Claude Code, Bob and OpenCode need to be named" is now stale for Codex.
  • PR description (nit) — the "Unconfirmed on the interactive TUI" caveat is superseded by the final commit's TUI measurement.

No blocking issues — approving.

Comment thread core/session/idheader.go
// reason given there: on a laptop the only clients are the user's own agents,
// while in a cluster an agent sending this for its own purposes would have its
// calls filed away from the session holding its user's intent. It also sits LAST
// in that list, so any client sending one of the three dedicated headers still

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Minor wording: "one of the three dedicated headers" counts X-Session-Id as dedicated, but SessionIDHeader's own comment (line 46) calls it "the generic request header" — and the least-namespaced reasoning given here for Session-Id applies to X-Session-Id too, just less strongly. Consider "the three headers above it" or "the three more-namespaced names". The subtest name every dedicated header outranks it in idheader_test.go repeats the same framing.

@Alan-Cha
Alan-Cha merged commit bd66e5f into main Oct 14, 2026
28 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Oct 14, 2026
@evaline-ju
evaline-ju deleted the feat/codex-session-header branch November 18, 2026 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants