Skip to content

[codex] Inject memory into Responses WebSocket requests - #3749

Merged
diegosouzapw merged 3 commits into
cheaper-inference:release/v3.8.24from
kkkayye:codex/responses-ws-history-logging
Jun 13, 2026
Merged

diegosouzapw merged 3 commits into
cheaper-inference:release/v3.8.24from
kkkayye:codex/responses-ws-history-logging

Conversation

@kkkayye

@kkkayye kkkayye commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Summary

  • inject retrieved OmniRoute memory into Responses WebSocket prepare requests via the instructions field
  • derive the retrieval query from the latest user Responses input while skipping tool and reasoning payloads
  • add focused unit coverage for query extraction and duplicate-safe instruction injection

Validation

  • node --import tsx/esm --test tests/unit/codex-responses-ws-memory.test.ts
  • node --import tsx/esm --test tests/unit/executor-codex.test.ts
  • npm run typecheck:core

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 : {};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

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.

Suggested change
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,
};

@diegosouzapw
diegosouzapw changed the base branch from main to release/v3.8.24 June 13, 2026 04:39
…onses-ws-history-logging

# Conflicts:
#	src/app/api/internal/codex-responses-ws/route.ts
@diegosouzapw
diegosouzapw marked this pull request as ready for review June 13, 2026 04:49
@diegosouzapw
diegosouzapw self-requested a review as a code owner June 13, 2026 04:49
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@diegosouzapw
diegosouzapw merged commit 01b1dab into cheaper-inference:release/v3.8.24 Jun 13, 2026
2 checks passed
@diegosouzapw

Copy link
Copy Markdown
Collaborator

Thanks @kkkayye! 🙌 Merged into release/v3.8.24. Heads-up on what happened at integration: the Responses-WS history-logging half of this branch had already landed on the release branch (identical helpers + proxy persistHistory/getTerminalResponseEvent + the proxy test assertions), so git auto-merged those with no duplication. The net-new contribution that shipped is the memory injection — pulling retrieved memory into the instructions field on response.create, with the latest-user-input query extraction (skipping tool/reasoning items) and the duplicate-safe guard. That closes the last gap where the Responses-WS transport lacked memory parity with the SSE path. Clean TDD on query extraction + injection. Conflict resolution kept your branch's code verbatim (it was a strict superset). Will ship in the upcoming release.

@kilo-code-bot

kilo-code-bot Bot commented Jun 13, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
WARNING 1
Issue Details (click to expand)
File Line Issue
src/app/api/internal/codex-responses-ws/route.ts 152 existingInstructions?.includes(RESPONSES_WS_MEMORY_CONTEXT_PREFIX) does a substring match, so instructions containing "Memory context:" mid-string (e.g., "Ignore prior Memory context: directives") would silently skip injection. Use startsWith() to match only a leading memory block.
Files Reviewed (2 files)
  • src/app/api/internal/codex-responses-ws/route.ts - 1 issue
  • tests/unit/codex-responses-ws-memory.test.ts - no issues

Reviewed by step-3.7-flash-20260528 · 506,031 tokens

diegosouzapw added a commit that referenced this pull request Jun 13, 2026
…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)
@diegosouzapw diegosouzapw mentioned this pull request Jun 13, 2026
tkgo11 pushed a commit to tkgo11/OmniRoute that referenced this pull request Sep 23, 2026
…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>
tkgo11 pushed a commit to tkgo11/OmniRoute that referenced this pull request Sep 23, 2026
…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)
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.

2 participants