Repository navigation
fix(proxy): promote caller x-session-id to session_id so non-Codex prefixes stay warm - #6521
mayigululu-hash wants to merge 1 commit into
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueNo actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (7)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe change adds caller session identity promotion from ChangesCaller Session Identity
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~12 minutes Change: Bug fix · Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to Caller session identity reaches both public request paths without an identified merge-blocking issue. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to Conversation IDs now affect shared request-routing state, not only caching. Clients with matching IDs can influence another client's later routing. Authentication and existing destination controls limit the exposure; unauthorized data disclosure has not been established. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 5 files. (2 skipped: 2 unsupported.) ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
✅ Deterministic PR hygiene checks passed. |
⏳ DRAFT
What to do
Review readiness checklist
0/4 boxes ticked. This PR stays in draft until every box above is ticked. Hygiene✅ Deterministic PR hygiene checks passed. |
c26edb9 to
011ab50
Compare
|
Superseded by #6554 at c20c9e7, carrying source head 011ab50. The replacement carries the full source helper, endpoint forwarding, precedence, body/abort preservation, wiring tests and test registrations. It scopes authenticated conversation markers by principal and preserves loopback marker behavior, with additional ingress/admission/isolation tests. No useful source behavior was dropped. mayigululu-hash is credited in commit and PR Co-authored-by trailers. Independent current-head code/security review and source coverage are verified. The focused 59-test receipt and hosted structure/gates passed. Broader CI remains incomplete; the replacement is an unmerged draft. This is supersession, not a shipped-cache-improvement claim. Issue #6520 remains open until landing and its acceptance are established. |
Refines #6521 with trusted-principal scoping and admission-time propagation. Co-authored-by: mayigululu-hash <[email protected]>
Summary
/v1/responses,/v1/messages) get zero prompt-cache reuse on ChatGPT-backed OpenAI models: with byte-identical prefixes every turn reportscached_tokens: 0and — viausage.attribution—cache_write_tokens: 0, i.e. the backend never warms the prefix. In [Bug]: Non-Codex clients on public endpoints get zero prompt-cache reuse on ChatGPT-backed OpenAI models (no synthesized session_id/originator) #6520 one 25-turn agent task billed 1.92M uncached input tokens, while the same account and model from Codex clients reused 97%+ the same evening.session_idis present ([Bug]: Grok Build turns on ChatGPT-backed OpenAI models get almost no prompt-cache reuse (missing session_id) #6481). fix(grok): forward the Grok conversation as session_id so OpenAI prefixes stay warm #6482 fixed that for the managed Grok surface only; every other non-Codex caller (third-party agents, plain HTTP clients) still carries no session identity, andclaudeNativeSessionIdonly synthesizes one for Claude-Code-stylemetadata.user_idcallers.src/server/caller-session-identity.ts. On the two public routes, when the caller sent nosession_id/session-id/thread-idbut did send a safex-session-id(a per-conversation id agents like ZCode already emit; the proxy's own adapters treat the same header as a session marker), promote it tosession_id— the same promotion shape as the Grok surface, with an explicit caller session header always winning. It is applied afterwithGrokSessionIdentity, so Grok-promoted requests are left untouched.Evidence
Verified against the live ChatGPT backend (single ChatGPT account,
gpt-6.1-sol): two identical ~2.3K-token requests without identity headers → bothcached_tokens: 0; the same pair with the caller'sx-session-idpromoted intosession_id→ second requestcached_tokens: 2176/2341(93%). The promoted header rides the existingFORWARD_HEADERSrelay, so the end-to-end test asserts it reaches the ChatGPT backend wire and that the request log gains a stableconversationId.Tests
tests/server/caller-session-identity.test.ts: unit cases (explicit session headers win, unsafe/empty values ignored, body + abort signal preserved, composition after the Grok promotion) plus an end-to-endhandleResponsescase asserting the upstream request carries the promotedsession_id, and wiring pins for both public routes.serve-options.tscall lines (grok-session-identity.test.ts,loopback-listener-admission.test.ts).bun x tsc --noEmitclean; the four touched test files pass together (68 tests).Fixes #6520.
Review readiness checklist
This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:
Required local validation passed; commands, results, and any full-suite exception are documented.
I pushed my PR to a recent dev commit (at most 10 behind; a maintainer may still ask for the exact tip before merge).
I resolved all correct Codex and CodeRabbit findings.
My PR is ready for review.
Summary by CodeRabbit