Skip to content

fix(openai-codex): avoid stale Responses replay state#76832

Merged
steipete merged 3 commits into
openclaw:mainfrom
MkDev11:fix/issue-76413-codex-replay-state
May 4, 2026
Merged

fix(openai-codex): avoid stale Responses replay state#76832
steipete merged 3 commits into
openclaw:mainfrom
MkDev11:fix/issue-76413-codex-replay-state

Conversation

@MkDev11

@MkDev11 MkDev11 commented May 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Problem: native ChatGPT Codex Responses turns could carry session-scoped request/cache/replay state across Telegram turns after tool calls.
  • Why it matters: stale prior assistant/tool-call state can make a fresh user message receive an old assistant reply.
  • What changed: turn-scope native Codex request identity, strip native Codex prompt_cache_key, and avoid replaying prior Responses reasoning/message/function item IDs for native Codex.
  • What did NOT change (scope boundary): custom/proxy Codex-compatible endpoints still keep compatible cache/replay behavior; lossless-claw memory reconciliation is not changed here.

Change Type

  • Bug fix

Scope

  • Gateway / orchestration
  • API / contracts

Linked Issue/PR

Root Cause

  • Root cause: native ChatGPT Codex Responses reused session-scoped request identity, prompt_cache_key, and prior Responses item IDs across turns.
  • Missing detection / guardrail: tests covered native Codex metadata stripping but still expected prompt_cache_key and replay IDs to survive.
  • Contributing context: the private ChatGPT Codex backend does not behave like the public OpenAI Responses API for these replay/cache fields.

Regression Test Plan

  • Coverage level that should have caught this:
    • Unit test
  • Target test or file:
    • extensions/openai/transport-policy.test.ts
    • src/agents/openai-transport-stream.test.ts
  • Scenario the test should lock in:
    • native ChatGPT Codex stream turns use turn-scoped x-client-request-id
    • native ChatGPT Codex payloads strip prompt_cache_key
    • native ChatGPT Codex does not replay prior Responses reasoning/message/function item IDs
    • custom Codex-compatible routes keep existing replay behavior
  • Why this is the smallest reliable guardrail:
    • the bug lives in request construction and transcript-to-Responses payload conversion, so unit tests can verify the exact payload shape without live Telegram or private backend access.

User-visible / Behavior Changes

Native openai-codex/* ChatGPT backend sessions should no longer send stale request/cache/replay state that can cause prior tool-call replies to reappear on unrelated later turns.

Diagram

N/A

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • OS: local Linux workspace
  • Runtime/container: Node/pnpm repo checkout
  • Model/provider: openai-codex/openai-codex-responses payload construction
  • Integration/channel: Telegram issue path, unit-tested at transport boundary
  • Relevant config: native ChatGPT Codex base URL https://chatgpt.com/backend-api

Steps

  1. Build a native Codex Responses payload after a prior assistant tool-call turn.
  2. Inspect request headers and Responses input items.
  3. Compare native ChatGPT Codex behavior against custom Codex-compatible route behavior.

Expected

  • native ChatGPT Codex uses turn-scoped request identity
  • native ChatGPT Codex strips prompt_cache_key
  • native ChatGPT Codex omits prior reasoning/message/function item IDs
  • custom Codex-compatible routes preserve existing compatible behavior

Actual

Before this PR, native ChatGPT Codex preserved session-scoped request/cache/replay state.

Evidence

  • Failing test/log before + passing after

Human Verification (required)

  • Verified scenarios:
    • targeted transport policy regression
    • targeted native Codex payload sanitizer regression
    • targeted native/custom Codex replay-item regression
    • changed-file type/lint/check gate
  • Edge cases checked:
    • payload-hook mutation
    • custom Codex-compatible base URL
    • prior reasoning item replay
    • prior function-call item ID replay
  • What you did not verify:
    • live Telegram + ChatGPT Codex + lossless-claw end-to-end reproduction

AI Assistance

  • AI-assisted PR; I reviewed the generated diff and understand the code path being changed.
  • Testing level: targeted unit/regression tests plus changed-file checks.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Risks and Mitigations

  • Risk: native Codex backend might rely on some prior item replay for niche continuations.
    • Mitigation: scope suppression only to native ChatGPT Codex Responses; custom/proxy compatible routes retain existing replay behavior and tests lock that boundary.

@clawsweeper

clawsweeper Bot commented May 3, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

Summary
The PR updates OpenAI Codex transport policy, Responses payload construction, tests, docs, and changelog to use turn-scoped native Codex request IDs, strip native prompt_cache_key, and suppress native Codex replay item IDs while preserving custom proxy behavior.

Reproducibility: yes. for the transport payload path: current main can be inspected to show session-scoped native Codex request IDs, prompt_cache_key, and prior Responses item IDs crossing turns. I did not establish a live Telegram plus ChatGPT Codex replay in this read-only review.

Next step before merge
No repair job is queued because the PR already contains the narrow implementation; the remaining action is maintainer review plus normal validation.

Security
Cleared: The diff changes transport headers, payload serialization, tests, docs, and changelog only; it adds no dependencies, workflow changes, permissions, lifecycle scripts, or secret-handling paths.

Review details

Best possible solution:

Land this transport-scoped fix after normal maintainer review and keep the linked bug report available for any remaining lossless-claw or live-channel validation.

Do we have a high-confidence way to reproduce the issue?

Yes for the transport payload path: current main can be inspected to show session-scoped native Codex request IDs, prompt_cache_key, and prior Responses item IDs crossing turns. I did not establish a live Telegram plus ChatGPT Codex replay in this read-only review.

Is this the best way to solve the issue?

Yes for the core transport portion: the PR changes only native ChatGPT Codex cache/replay identity while preserving custom Codex-compatible proxy behavior and adding focused regression coverage. Remaining lossless-claw reconciliation, if still needed, should stay a separate follow-up.

Acceptance criteria:

  • pnpm test extensions/openai/transport-policy.test.ts src/agents/openai-transport-stream.test.ts -- --reporter=verbose
  • pnpm check:changed

What I checked:

Likely related people:

  • steipete: Recent commits and current blame show repeated maintenance of src/agents/openai-transport-stream.ts, including OpenAI reasoning, maxTokens, attribution, and Codex Responses payload behavior near this surface. (role: recent maintainer and adjacent owner; confidence: high; commits: 11e05e86a233, 399d7f61783f, bc21f500d4c1; files: src/agents/openai-transport-stream.ts, extensions/openai/transport-policy.ts)
  • keshavbotagent: Commit 388019f changed the same OpenAI Codex Responses transport path to preserve Codex OAuth transport and scope native Codex payload sanitization to the ChatGPT backend. (role: adjacent Codex OAuth transport contributor; confidence: medium; commits: 388019f5b693; files: src/agents/openai-transport-stream.ts)
  • obviyus: Commit 3624dda refactored the OpenAI base URL helpers that transport-policy.ts uses to distinguish native ChatGPT Codex routes from proxy routes. (role: adjacent OpenAI base-url helper maintainer; confidence: medium; commits: 3624dda67d70; files: extensions/openai/base-url.ts, extensions/openai/transport-policy.ts)

Remaining risk / open question:

  • This read-only review did not live-test the private ChatGPT Codex backend or the Telegram end-to-end sequence.
  • The linked bug report also calls out lossless-claw ignore-session-pattern behavior, which this PR intentionally leaves outside its transport boundary.

Codex review notes: model gpt-5.5, reasoning high; reviewed against ab032675ce09.

@MkDev11

MkDev11 commented May 4, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper

@steipete steipete force-pushed the fix/issue-76413-codex-replay-state branch 2 times, most recently from 06b4ffd to b82f4e5 Compare May 4, 2026 22:45
@steipete steipete force-pushed the fix/issue-76413-codex-replay-state branch from b82f4e5 to cc76c2f Compare May 4, 2026 23:08
@steipete steipete merged commit 29eb47e into openclaw:main May 4, 2026
108 checks passed
@steipete

steipete commented May 4, 2026

Copy link
Copy Markdown
Contributor

Landed via rebase onto main.

  • Gate: exact-head GitHub CI for ee7e7f690b75c6309caf1eb87b04bcc9796611c1 completed with no failures; local targeted proof: pnpm test src/agents/openai-transport-stream.test.ts extensions/openai/transport-policy.test.ts and git diff --check.
  • Source head: ee7e7f6
  • Landed commits: 27e467a, 15d3fd8, 29eb47e

Thanks @MkDev11!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation extensions: openai size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants