Repository navigation
Feat: Read Codex's session header so its traffic groups by conversation - #1379
Conversation
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]>
|
Warning Review limit reachedYou'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. View limit details
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
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]>
…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
left a comment
There was a problem hiding this comment.
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" countsX-Session-Idas dedicated, though the same file'sSessionIDHeadercomment calls it "the generic request header".
Reviewed by clawgenti using the github-pr-review skill
| // 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 |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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" countsX-Session-Idas 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
| // 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 |
There was a problem hiding this comment.
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.
| session.ClaudeCodeSessionHeader, | ||
| session.BobSessionHeader, | ||
| session.SessionIDHeader, | ||
| session.CodexSessionHeader, |
There was a problem hiding this comment.
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.
| | | 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 | |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
Verified the code paths and the load-bearing claims:
CodexSessionHeadersits 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.mdmatches thepricing.EndpointConfig/TierRatesschema (hosts globs, four*_cost_per_milliontiers), andchatgpt.comcorrectly excludes theab.chatgpt.comtelemetry host. The "bundled table is Anthropic-only by design" claim matchespricegen.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.
| // 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 |
There was a problem hiding this comment.
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.
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
Authorizationtoken reached the log; probe reverted, binary checksum-verified):Cortex's laptop list held
X-Claude-Code-Session-Id,X-Task-IdandX-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:
Session-IdThread-IdX-Client-Request-IdAll three carry the same value today. This reads
Session-Idbecause its name matches the intent: if Codex later makesX-Client-Request-Idper-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-Idis the least namespaced of the four names, so it is:X-Session-Idis and for the reason documented there: in a cluster a workload may send a bareSession-Idfor 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 -diffclean; fullcoresuite passesTestIDFromHeaders_Codex: the id alone is used;X-Session-Iddoes not match a bareSession-Id; every dedicated header outranks it; canonical casingTestSessionConfig_SessionIDHeadersForto assert the laptop list in order, since the order is a precedence ruleX-Session-Id, each make their test failcodex execruns produced two sessions under their real UUIDs withagent=codexand 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
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.codex execonly; the TUI's startup chatter carriesOriginatorbut 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, anddocs/agents/codex.mdsays so. If it does not,codex execstill gets named sessions.Refs #1365, #942. Stacked conceptually on #1375 (independent branch, no overlap).
Assisted-By: Claude (Anthropic AI) [email protected]
Summary by CodeRabbit
Session-Idrequest header. Existing session headers take precedence when present.