Skip to content

🤖 fix: preserve Codex OAuth prompt cache routing - #4159

Merged
ThomasK33 merged 4 commits into
mainfrom
oauth-cache-root-cause
Sep 9, 2026
Merged

🤖 fix: preserve Codex OAuth prompt cache routing#4159
ThomasK33 merged 4 commits into
mainfrom
oauth-cache-root-cause

Conversation

@ThomasK33

@ThomasK33 ThomasK33 commented Sep 8, 2026

Copy link
Copy Markdown
Member

Summary

Forward a header-safe encoding of Xum's existing stable prompt_cache_key as a missing session-id for Codex OAuth Responses requests. The tested Codex backend uses this header for cache routing; keeping only the body key caused repeated misses.

  • Preserve an explicitly supplied session header and leave callers without a nonempty string cache key unchanged.
  • Reuse the existing project/workspace cache scope; Replace malformed UTF-16 via UTF-8, then URI-encode it so Unicode/control characters in project names cannot make Headers.set() reject the request. No new IDs, persistence, or thread/turn-state headers.
  • Add fetch-boundary coverage for keyless callers, stable routing across turns, Unicode/control characters, lone surrogates, normalization invariants, and explicit-header precedence.
  • Scope: OAuth routing/tests plus the explicitly authorized Codex CI parser fix. No gateway cache-write accounting changes.

Evidence

A controlled diagnostic on 289277eb7 sent 14 byte-identical 6,177-token Astra OAuth bodies. In-phase completion-to-next-request gaps were ~14s (phase boundaries ~30–35s):

Added headers Raw cached input
None, including after a warmed request 0 on all three requests
Stable session + thread 0 cold, then 6,016 twice
Stable session only 6,016 twice (97.4%)
Thread only 0 twice
Client-request only 0
Existing non-UUID mux-v1-… scope as session 0 cold → 6,016

The returned cache key followed session-id even when it differed from the body key. This is a reversible header-only result, not an inference from absent headers or changing response keys alone.

The initial header-forwarding patch was then dogfooded using dev-server-sandbox + agent-browser, a no-tools synthetic project, and existing unexpired OAuth credentials. Normalized instructions/tools/cache key stayed identical; every turn preserved the input prefix and appended two items. Baseline chat turns had 0 cache reads. The patched path went cold → 1,664/1,857 cached tokens (89.6%), visible in Stats.

Sanitized sandbox screenshots and recording

Before:
Baseline OAuth turns: no Cache Read row

After:
Patched OAuth path: Cache Read appears

browser-fix.webm

Validation

  • Fresh after rebasing onto 50b357e67: 353 targeted tests passed (providerModelFactory.test.ts, providerOptions.test.ts), ~1s.
  • Fresh make static-check passed: both TypeScript projects, ESLint, formatting, generated-source/docs checks.
  • During diagnosis, the core regression was red without the implementation; the broader five-file suite passed 438 tests with it.
  • Reused the recorded live evidence rather than spending more OAuth quota: the provider factory, its tests, and provider options were unchanged between the diagnostic base and current main before applying the header-forwarding patch. The final URI-encoding follow-up leaves these ASCII scopes unchanged; Unicode/control-character and lone-surrogate cases were reproduced red at the fetch boundary and are now green. Tests also retain store=false and truncation stripping for these cases.
  • Credential copies and private request bodies were deleted; sandbox/browser stopped. Only source/tests are committed; no credentials or diagnostic logs.

Codex CI parser fix

The user authorized including the narrow CI fix here to unblock the merge. Accept both observed security-review headings (plain and automatically triggered), strip only one heading, and leave the existing exact clean-verdict matching intact. Findings, appended findings, repeated headings, unknown metadata, and incomplete summaries remain blocking; informational metadata still does not count as approval.

  • Real PR dogfood: before the fix, four clean security verdicts were reported as unresolved despite zero unresolved threads. After the fix, ./scripts/check_codex_comments.sh 4159 passes with zero blocking comments.
  • The new plain-heading case was red before the fix; all 12 offline shell-gate regression tests passed (~149s), including pagination/cache/author/approval safety cases.
  • 353 OAuth tests and make static-check passed again on the completed change.
Recorded terminal verification

Live comments gate and fail-closed heading regression pass

Accelerated terminal replay (idle delays removed):

parser-verification-fast.webm

Limits / review focus

This evidence covers one account and Astra over Codex HTTP, not every model/account or a public OpenAI API contract. It does not prove a regression introduced by a particular update; released v0.28.4 has the same omission. Cold-start misses, prefix churn, eviction, and callers without a stable cache scope remain possible. Project-wide scope reuse retains Xum's existing policy; explicit session IDs remain authoritative.

Official Codex rust-v0.153.4 also sends session/thread/client-request headers on HTTP (source); the controlled isolation above shows that thread/client-request headers are unnecessary for this fix. Server-issued x-codex-turn-state is deliberately not replayed across turns.

Merge queue only after all required CI and final review gates pass; no deployment changes.


Generated with mux • Model: openai:gpt-6-astra • Thinking: off • Cost: $108.19

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-09T06:30:44.749573Z 0b8540c Manual request
🔒 Security Review Completed 2026-09-09T06:32:42.583296Z 0b8540c Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ebbd0506af

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/node/services/providerModelFactory.ts Outdated
@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: ebbd0506af

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: e4bf03bf4b

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e4bf03bf4b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/node/services/providerModelFactory.ts Outdated
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: d077fb5e84

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: d077fb5e84

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ThomasK33

Copy link
Copy Markdown
Member Author

Implementation and review are complete at d077fb5e84859777e3da1bd5e948f6202213d806; readiness remains blocked by the unrelated comments gate.

  • Fresh local validation: 353 targeted tests / 837 assertions passed, plus make static-check.
  • Final-head code approval and security no-issues verdict; both findings replied/resolved, all review surfaces audited after a >6-minute quiet interval.
  • Final CI: all 13 test/build/static/visual jobs passed; no real jobs pending. Optional Pixel / Review is not the blocker.
  • Codex Comments and its aggregate Required check fail because the current parser classifies the titled clean security verdict as unresolved. The separate fix #4158 remains open. This PR does not include that CI change or the separate gateway accounting bug.

No merge/deployment performed. Diagnostic credentials were already removed; this implementation reused the bounded recorded live evidence for unchanged ASCII scopes and added offline encoding/normalization regressions.


Generated with mux • Model: openai:gpt-6-astra • Thinking: high • Cost: $68.87

Forward the existing stable prompt cache scope as session-id on Codex OAuth
Responses requests, preserving explicit headers and keyless callers.

---
_Generated with [`mux`](https://github.com/coder/mux) • Model: `openai:gpt-6-astra` • Thinking: `off` • Cost: `$36.74`_

<!-- mux-attribution: model=openai:gpt-6-astra thinking=off costs=36.74 -->
Project scopes include names that may contain Unicode or control characters.
Encode the stable scope rather than letting Headers reject it and skip normalization.

---
_Generated with [`mux`](https://github.com/coder/mux) • Model: `openai:gpt-6-astra` • Thinking: `off` • Cost: `$48.99`_

<!-- mux-attribution: model=openai:gpt-6-astra thinking=off costs=48.99 -->
Replace lone UTF-16 surrogates via UTF-8 before encoding the stable session scope.
Assert that normalization still strips truncation and disables storage.

---
_Generated with [`mux`](https://github.com/coder/mux) • Model: `openai:gpt-6-astra` • Thinking: `off` • Cost: `$61.26`_

<!-- mux-attribution: model=openai:gpt-6-astra thinking=off costs=61.26 -->
@ThomasK33
ThomasK33 force-pushed the oauth-cache-root-cause branch from d077fb5 to 2fb3246 Compare September 9, 2026 05:32
@ThomasK33

Copy link
Copy Markdown
Member Author

Rebased onto 50b357e673e5e4c120a1565b5acbe9faf56bd46b, published as 2fb324663e5363995e96699b547abb713903aedd with an exact-SHA force-with-lease. git range-diff shows all three OAuth commits unchanged, and the provider factory/options files are byte-identical to the previously approved head.

Fresh validation: 353 tests / 837 assertions passed, plus make static-check.

The current-main comments gate still reproduces the false failure: 0 unresolved threads, but 3 clean security verdict comments classified as unresolved. Main strips the ### 🛡️ Codex Security Review · _Automatically triggered_ heading, but these older comments have the plain ### 🛡️ Codex Security Review heading. #4158 remains open. No gate bypass or unrelated CI fix is bundled here.

Requesting fresh reviews for the rewritten head; merge queue remains gated on green checks and clean final review.


Generated with mux • Model: openai:gpt-6-astra • Thinking: high

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 2fb324663e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 2fb324663e

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Accept the plain and auto-triggered security-review headings without
exempting findings, appended findings, or repeated/unknown envelopes.

---
_Generated with [`mux`](https://github.com/coder/mux) • Model: `openai:gpt-6-astra` • Thinking: `high` • Cost: `$108.19`_

<!-- mux-attribution: model=openai:gpt-6-astra thinking=high costs=108.19 -->
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 0b8540c9f2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 0b8540c9f2

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@ThomasK33
ThomasK33 added this pull request to the merge queue Sep 9, 2026
Merged via the queue into main with commit f785403 Sep 9, 2026
35 of 38 checks passed
@ThomasK33
ThomasK33 deleted the oauth-cache-root-cause branch September 9, 2026 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant