Repository navigation
[codex] Inject memory into Responses WebSocket requests - #3749
diegosouzapw merged 3 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces call history logging and memory context injection for the OpenAI Responses WebSocket proxy. It adds helper functions to extract and inject memory instructions, persists session history (including token usage, status, and duration) via a new internal log endpoint, and includes corresponding unit tests. A review comment highlights a high-severity issue where token usage fields (input_tokens and output_tokens) returned by the Responses WebSocket API need to be normalized to prompt_tokens and completion_tokens to prevent silent logging failures in the database.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| const requestBody = getResponseCreateBody(body); | ||
| const terminalMessage = getTerminalMessage(body); | ||
| const responseBody = getTerminalResponseBody(body); | ||
| const usage = isRecord(responseBody?.usage) ? responseBody.usage : {}; |
There was a problem hiding this comment.
The OpenAI Responses WebSocket API returns token usage using the fields input_tokens and output_tokens instead of the standard OpenAI Chat Completions fields prompt_tokens and completion_tokens.
Since saveCallLog and saveRequestUsage rely on standard token accounting helpers (like getLoggedInputTokens and getLoggedOutputTokens) which expect prompt_tokens and completion_tokens, passing the raw Responses usage object directly will result in 0 tokens being recorded in the database call logs and usage history.
To ensure correct token accounting and prevent silent database logging failures, we should normalize the usage object to map input_tokens to prompt_tokens and output_tokens to completion_tokens.
| const usage = isRecord(responseBody?.usage) ? responseBody.usage : {}; | |
| const rawUsage = isRecord(responseBody?.usage) ? responseBody.usage : {}; | |
| const usage = { | |
| ...rawUsage, | |
| prompt_tokens: rawUsage.prompt_tokens ?? rawUsage.input_tokens, | |
| completion_tokens: rawUsage.completion_tokens ?? rawUsage.output_tokens, | |
| }; |
…onses-ws-history-logging # Conflicts: # src/app/api/internal/codex-responses-ws/route.ts
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
01b1dab
into
cheaper-inference:release/v3.8.24
|
Thanks @kkkayye! 🙌 Merged into |
Code Review SummaryStatus: 1 Issue Found | Recommendation: Address before merge Overview
Issue Details (click to expand)
Files Reviewed (2 files)
Reviewed by step-3.7-flash-20260528 · 506,031 tokens |
…contributor credits - Restructure [3.8.24] into ✨ Features / 🔒 Security / 🐛 Fixed / 📝 Maintenance - Add bullets for every PR landed since v3.8.23 that was missing: marketplace (#3656), strict-mode CC defaults (#3776), emergency-fallback flag (#3752), xhigh effort (#3756), Codex memory WS (#3749), IPv6 egress (#3777), marketplace SSRF (#3774), CodeQL/Dependabot (#3778), anthropic sampling (#3780), thinking passthrough (#3775), mcp dist entry (#3765), streamed tool args (#3762), logs light-mode (#3760), clean-history purge (#3751), quality-gates (#3757), docs gaps (#3453), file-size re-baseline (#3770), E415 publish guard, i18n prune - Move misplaced #3775 bullet out of [Unreleased] into [3.8.24] - Date [3.8.23] header (TBD -> 2026-06-12, the release tag date)
…nce#3749) Inject retrieved OmniRoute memory into Codex Responses-over-WebSocket prepare requests via the instructions field, deriving the retrieval query from the latest user Responses input while skipping tool/reasoning payloads, with a duplicate-safe injection guard. The Responses-WS request-history logging this branch also carried already landed on release; the net change here is the memory-injection parity with the SSE path. Integrated into release/v3.8.24. Co-authored-by: diegosouzapw <diegosouza.pw@gmail.com>
…contributor credits - Restructure [3.8.24] into ✨ Features / 🔒 Security / 🐛 Fixed / 📝 Maintenance - Add bullets for every PR landed since v3.8.23 that was missing: marketplace (cheaper-inference#3656), strict-mode CC defaults (cheaper-inference#3776), emergency-fallback flag (cheaper-inference#3752), xhigh effort (cheaper-inference#3756), Codex memory WS (cheaper-inference#3749), IPv6 egress (cheaper-inference#3777), marketplace SSRF (cheaper-inference#3774), CodeQL/Dependabot (cheaper-inference#3778), anthropic sampling (cheaper-inference#3780), thinking passthrough (cheaper-inference#3775), mcp dist entry (cheaper-inference#3765), streamed tool args (cheaper-inference#3762), logs light-mode (cheaper-inference#3760), clean-history purge (cheaper-inference#3751), quality-gates (cheaper-inference#3757), docs gaps (cheaper-inference#3453), file-size re-baseline (cheaper-inference#3770), E415 publish guard, i18n prune - Move misplaced cheaper-inference#3775 bullet out of [Unreleased] into [3.8.24] - Date [3.8.23] header (TBD -> 2026-06-12, the release tag date)
Summary
instructionsfieldValidation