Skip to content

Test: Capture the Codex TUI's User-Agent live instead of inferring it - #1375

Merged
huang195 merged 2 commits into
mainfrom
fix/codex-tui-capture
Oct 15, 2026
Merged

huang195 merged 2 commits into
mainfrom
fix/codex-tui-capture

Conversation

@Alan-Cha

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

Copy link
Copy Markdown
Member

Recovers a commit pushed to #1337 but not included at merge time — the merge took head 9202dde9 while this landed just after, so it is not in main. Same stale-head race as #1315/#1326, not a code issue. Cherry-picked cleanly onto current main and re-verified there.

What this adds

#1337 fixed its reviewer's second blocker by adding codex-tui and codex_cli_rs to knownClients, but those two strings were inferred — read off Codex's Rust source at rust-v0.160.1 plus strings on the shipped binary. They were the only entries in that map not taken from real traffic, and the reviewer explicitly asked for a live capture.

This is that capture. Driven by allocating a pty directly (this environment has no controlling terminal, so script fails with tcgetattr/ioctl: Operation not supported on socket), exec'ing bare codex, sizing the pty via TIOCSWINSZ, then typing a prompt into the real interactive TUI.

Both tokens confirmed — and codex-tui appears on the TUI's own /backend-api/codex/responses inference requests, not just its chatter, which is the traffic whose tokens and cost get attributed.

Two things the capture gave that inference had not

  • It corrected a detail. The third UA field is the TERM value — unknown under codex exec, xterm-256color under the TUI. The fixtures Feat: Codex support — configure, agent recognition, and docs #1337 shipped said unknown for both. Parsing keys on the product token so nothing was broken, but the fixtures now carry the real strings rather than invented ones.
  • It caught an auto-update mid-session, so the capture holds both 0.160.1 and 0.162.1, parsing identically. That is the only evidence in the suite that the UA shape is stable across Codex releases rather than pinned to the single build everything else was read from — so docs/agents/codex.md's version caveat narrows, and Linux is called out on its own instead of bundled in with it.

Test plan

  • gofmt -l, go vet clean; core/pipeline and core/session suites pass on current main
  • All four real captured strings parse to Name: "codex" with the right version
  • Verified against current main, which now includes Fix: Recognise Claude Code's second product token #1369's claude-code key — no interaction

Related: #942, #1337, #1365 (ticks that issue's live-TUI-capture item).

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

Summary by CodeRabbit

  • Bug Fixes

    • Requests from Codex’s interactive terminal and early startup are now consistently recognized as Codex across the verified versions, improving identification of these requests.
  • Documentation

    • Updated Codex examples to cover additional terminal-specific identifiers and clarify how terminal settings are represented.
    • Clarified which Codex versions, platforms, and environments were verified, including the scope of testing for startup and environment-variable behavior.

#1337 added "codex-tui" and "codex_cli_rs" from Codex's source plus
`strings` on the shipped binary, with no live capture — the only two
entries in knownClients not read off real traffic, and the weakest
part of the fix for that review's second blocker. The reviewer asked
for a capture; this is it.

Driven through the proxy by allocating a pty directly (this
environment has no controlling terminal, so `script` cannot) and
typing a prompt into the real interactive TUI. Both tokens confirmed,
and the first of them on the TUI's own /backend-api/codex/responses
inference requests rather than only on its chatter — which is the
case that matters, since that is the traffic whose cost and tokens
get attributed.

Two things the capture corrected or strengthened:

- The third UA field is the TERM value — "unknown" under `codex exec`,
  the terminal's name under the TUI. The invented fixtures said
  "unknown" for both. Parsing keys on the product token so nothing
  broke, but the fixtures now carry the real shapes.
- The capture caught an auto-update mid-session, so it holds both
  0.160.1 and 0.162.1. Both parse identically, which is the only
  evidence in this suite that the UA shape is stable ACROSS releases
  rather than pinned to the one build everything else was read from.
  The docs' version caveat is narrowed accordingly, and Linux is now
  called out on its own rather than bundled in with it.

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 →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 71bbc69e-d02f-4d0a-a78b-4275d10a34ff
📥 Commits

Reviewing files that changed from the base of the PR and between 09f5578 and 4401bde.

📒 Files selected for processing: 1
  • docs/agents/codex.md
🚧 Files skipped from review as they are similar to previous changes: 1
  • 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 Codex User-Agent map now recognizes codex-tui and codex_cli_rs as codex. Tests and documentation cover token examples from versions 0.160.1 and 0.162.1, and describe the verification scope.

Changes: Codex User-Agent recognition

Layer / File(s) Summary
Recognition and verification
core/pipeline/client.go, core/pipeline/client_test.go, docs/agents/codex.md
The map recognizes the TUI and CLI tokens as codex. Tests cover both tokens for versions 0.160.1 and 0.162.1. Documentation describes variable terminal fields and the evidence and limits of verification.

Priority: ⬇️ Low

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

Change: Other

Suggested reviewers: huang195

Merge Risk: ⚪ Minimal · up to 4401b

This change teaches Cortex to recognize Codex TUI and CLI User-Agent tokens, and it updates the tests and docs to match. No concrete merge-blocking risk is evident.

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 identifies the main change: capturing the Codex TUI User-Agent from live traffic instead of inferring it.
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 1 functions across 2 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 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.

@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.

Replaces the inferred Codex TUI User-Agent fixtures with ones captured from a real TUI session driven through the proxy over a pty — including the TUI's own inference requests and a 0.162.1 mid-auto-update sample — with the knownClients comment and docs updated to match. One docs nit below; nothing blocking.

  • nit docs/agents/codex.md:146 — the codex-tui row omits the trailing (codex-tui; <version>) comment the captured UA carries, while the codex_exec row documents its own.

Reviewed by clawgenti using the github-pr-review skill

Comment thread docs/agents/codex.md Outdated
| `codex-mcp-client/<version>` | its MCP client (`/backend-api/ps/mcp`) |
| `codex-tui/<version> (<os>; <arch>) unknown` | the interactive TUI — i.e. plain `codex` |
| `codex_cli_rs/<version> (<os>; <arch>) unknown` | anything sent before its app-server finishes initializing |
| `codex-tui/<version> (<os>; <arch>) <term>` | the interactive TUI — i.e. plain `codex` — including its inference |

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 captured TUI User-Agents in the new test fixtures carry a trailing comment — e.g. codex-tui/0.160.1 (Mac OS 26.3.0; arm64) xterm-256color (codex-tui; 0.160.1) — but this row doesn't mention it, while the codex_exec row above documents its own optional trailing (codex_exec; <version>) comment. A matching "sometimes with a trailing (codex-tui; <version>) comment" here would keep someone matching live proxy logs against this table from wondering about the suffix.

@Alan-Cha

Copy link
Copy Markdown
Member Author

Correction to this PR's description

I wrote that codex-tui appears on "the TUI's own /backend-api/codex/responses inference requests, not just its chatter, which is the traffic whose tokens and cost get attributed."

That is wrong. Going back over the captured events, every codex-tui request on that path is a WebSocket upgrade attempt that Cortex refused:

{"phase":"request","httpMethod":"GET","httpPath":"/backend-api/codex/responses"}
{"phase":"response","httpMethod":"GET","httpPath":"/backend-api/codex/responses",
 "statusCode":405,"error":{"kind":"backend_error","code":"405"},"bytesDown":31}

GET → 405, four events across two attempts, none carrying a parsed inference payload. Not an inference POST. I read "on the inference path" as "an inference request" and should not have.

What this PR's change still rests on, unchanged

The User-Agent tokens themselves, which is all this PR touches: codex-tui/<version> and codex_cli_rs/<version> are confirmed on real traffic across two Codex versions (0.160.1 and 0.162.1), and the TERM-field correction to the fixtures stands. None of that depended on the requests being inference.

The real open question this surfaced

TUI inference has never been observed through Cortex. The TUI attempts a WebSocket on the inference path, Cortex 405s it, and in five driven runs I never captured the HTTPS fallback completing — 164 events in one session with zero parsed inference. codex exec does fall back and is parsed normally (13,260 tokens, verified repeatedly), so the parser is path-keyed and front-end agnostic; but "the TUI probably falls back too" is inference, which is the exact thing this PR was written to stop doing.

Tracking it on #1365 rather than widening this PR. It may be a harness limitation (I cannot reliably drive a TUI turn to completion non-interactively) or a genuine observability gap for the TUI — and those need different answers.

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

@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.

Replaces two inferred Codex User-Agent fixtures with live-captured ones and corrects a detail the inference got wrong — the third field is the TERM value, not a literal unknown. The parser keys only on the product token, so nothing was broken; the value is that the fixtures now carry real strings, and the incidental mid-session auto-update gives the suite its only cross-release evidence.

What I verified

  • The four new fixtures parse as asserted. Ran all of them, plus the two they replace and codex_vscode, through ParseUserAgent on current main. All seven match their expected Name/Version, including both 0.162.1 strings. The trailing (codex-tui; 0.160.1) comment is correctly ignored.
  • The "key on the product token" reasoning holds. ParseUserAgent cuts at the first space before strings.Cut(token, "/"), so a changed third field cannot reach the parse. That is why swapping unknown for xterm-256color breaks nothing.
  • The recovery premise is real. refs/pull/1337/head is 9202dde, which is in main and matches the head this PR says the merge took. xterm-256color appears nowhere in main's core/pipeline/ or docs/agents/, and main still carries the inferred unknown fixtures at client_test.go:230-231. So the content is genuinely absent from main.
  • Test plan claims. core/pipeline and core/session both pass on this branch; go vet and gofmt -l clean.

Summary

Areas reviewed: Go (fixtures + the knownClients comment), Docs
Commits: 1, signed off, imperative subject at 69 chars
CI: 28/28 passing (Spellcheck skipped)

Three findings, all in the docs table and all cosmetic — the code change itself is correct. The codex_exec row is the one worth fixing: this PR teaches the reader that the third field is TERM, then leaves one row spelling that same field as a literal. The third finding pre-dates this PR; I mention it only because you are editing that exact table.

Comment thread docs/agents/codex.md Outdated
| `codex-mcp-client/<version>` | its MCP client (`/backend-api/ps/mcp`) |
| `codex-tui/<version> (<os>; <arch>) unknown` | the interactive TUI — i.e. plain `codex` |
| `codex_cli_rs/<version> (<os>; <arch>) unknown` | anything sent before its app-server finishes initializing |
| `codex-tui/<version> (<os>; <arch>) <term>` | the interactive TUI — i.e. plain `codex` — including its inference |

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.

suggestion: this PR establishes that the third UA field is the TERM value, and generalizes both TUI rows to <term> — but the codex_exec row two lines above still hardcodes unknown for the same field.

The row is not wrong: codex exec runs with no TTY, so unknown genuinely is its TERM, and your test comment says exactly that. But the table now spells one field two ways with nothing on the page saying they are the same field, so it reads as though exec has a literal there and the TUI has a variable.

Either <term> with a note that exec reports unknown, or keeping the literal and saying why it is fixed for that one, would leave the table self-consistent.

Comment thread docs/agents/codex.md Outdated
| `codex-mcp-client/<version>` | its MCP client (`/backend-api/ps/mcp`) |
| `codex-tui/<version> (<os>; <arch>) unknown` | the interactive TUI — i.e. plain `codex` |
| `codex_cli_rs/<version> (<os>; <arch>) unknown` | anything sent before its app-server finishes initializing |
| `codex-tui/<version> (<os>; <arch>) <term>` | the interactive TUI — i.e. plain `codex` — including its inference |

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.

nit: <term> is introduced here as a placeholder but never expanded anywhere in this page. The explanation — that it is the TERM value, unknown under codex exec and the terminal's name under the TUI — lives only in client_test.go's comment, which a reader of the docs will not see.

One clause after the table would close it, and it is the detail the capture actually corrected, so it seems worth stating where people read it.

Comment thread docs/agents/codex.md Outdated
| `codex-mcp-client/<version>` | its MCP client (`/backend-api/ps/mcp`) |
| `codex-tui/<version> (<os>; <arch>) unknown` | the interactive TUI — i.e. plain `codex` |
| `codex_cli_rs/<version> (<os>; <arch>) unknown` | anything sent before its app-server finishes initializing |
| `codex-tui/<version> (<os>; <arch>) <term>` | the interactive TUI — i.e. plain `codex` — including its inference |

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.

nit, and pre-existing rather than introduced here — I checked main and it reads the same, so this is not a regression from this PR.

The prose above this table says Codex "sends two product tokens" and that the version is "the field after the first slash in both", but the table lists four rows and knownClients claims four tokens (codex_exec, codex-mcp-client, codex-tui, codex_cli_rs).

Flagging it only because this PR is already editing this table, so it is a one-word fix in passing. Equally fine to leave for its own change.

Four review comments on one table, three of them this PR's own doing.

- The `codex_exec` row hardcoded `unknown` for the third field while
  this PR generalised both TUI rows to `<term>`. Same field, spelled
  two ways, with nothing saying they were the same — so it read as
  though exec had a literal and the TUI a variable. Now `<term>` in
  all three.
- `<term>` was introduced as a placeholder and expanded only in
  client_test.go's comment, which no reader of the docs sees. Now
  stated after the table: it is TERM, `unknown` under `codex exec`
  which has no TTY, the terminal's own name under the TUI — plus the
  part that makes it matter, that nothing reads the field, because
  matching is on the product token before the first slash and a
  varying TERM therefore does not split one agent into several rows.
- The `codex-tui` row omitted its trailing `(codex-tui; <version>)`
  comment, which the captured fixtures carry and which the
  `codex_exec` row documents for itself. Added, so someone matching
  live proxy logs against this table is not left wondering.
- "sends two product tokens ... the field after the first slash in
  both" against a four-row table: pre-existing on main rather than a
  regression here, as the reviewer noted, but a one-word fix in a
  table this PR is already editing. Verified against knownClients,
  which has exactly four entries folding to `codex`.

Docs only; no behaviour change.

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

Copy link
Copy Markdown
Member Author

All four applied in 4401bde — thanks, and three of them were this PR's own mess.

@mrsabath's <term> / unknown inconsistency was the real one. I generalised both TUI rows and left codex_exec's literal in place, so the table spelled the same field two ways with nothing saying they were the same. Now <term> in all three rows.

And the undefined placeholder is the one that bothered me most once pointed out: I put <term> in user-facing docs and explained it only in client_test.go's comment. Fixed with a clause after the table — it is TERM, unknown under codex exec which runs without a TTY, the terminal's own name under the TUI. I also added the part that makes it worth knowing rather than trivia: nothing reads that field. Matching is on the product token before the first slash, which is why a varying TERM does not split one agent into several rows.

@clawgenti's trailing-comment nit — added to the codex-tui row, which the captured fixtures do carry and which the codex_exec row already documented for itself.

The "two product tokens" / four-row contradiction — took it, since the table was already being edited. Verified against the code rather than counting rows: knownClients has exactly four entries folding to codex (codex_exec, codex-mcp-client, codex-tui, codex_cli_rs), so "four" is right and "the field after the first slash in all four" now matches. My first grep for this said three — the pattern missed codex-mcp-client's second hyphen — so the count in the doc is from a corrected one.

Docs only, no behaviour change, core/pipeline suite still green.

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

@huang195
huang195 merged commit d27bf8c into main Oct 15, 2026
42 of 43 checks passed
@huang195
huang195 deleted the fix/codex-tui-capture branch October 15, 2026 14:13
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Oct 15, 2026
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.

4 participants