Repository navigation
Description
Describe the bug
Codex CLI talks to the gateway through /gateway/v1/responses (wire_api = "responses"). On master e03f54ee, with inference protection in enforcing mode, a real Codex 0.145 request does not get through:
- Every Codex request is withheld. Codex always sends
stream: true. The gateway forwards it as a streaming request, and the send check returns409 {"decision":"withhold","reason_codes":["streaming_unsupported"]}, because the protection profile only supports streaming foropenai-chat. - From the second turn on, requests are withheld again. Codex replays its earlier reasoning as
{"type": "reasoning", "encrypted_content": ...}items (it setsinclude: ["reasoning.encrypted_content"]andstore: false). The send check returns409 content_unsupported. - With
stream: false, the request reaches the upstream, but changed:- Codex puts its tool definitions in an input item
{"type": "additional_tools", "role": "developer", "tools": [...]}. The ingress keeps onlyroleandcontent, so the item shrinks from 19,840 bytes to{"role":"system","content":[]}(33 bytes). The model sees no tools. - Every
developermessage is rewritten torole: "system"and loses itstype. - The top-level fields
reasoning,include,prompt_cache_keyandparallel_tool_callsare dropped.OpenAiResponsesRequesthas no field for them, and serde silently ignores unknown fields. Core'sopenai-responsesrequest allowlist admits all four.
- Codex puts its tool definitions in an input item
- Prepared context is never injected into Responses requests.
inject_contextisstate.inject_context && matches!(format, Format::Chat)(gateway/crates/pc-gateway-app/src/ingress.rs:235).
This blocks moving Codex onto the gateway (see #2055).
Steps to reproduce
- Start a Server from master with a Responses target in enforcing mode:
POWERCONTEXT_SERVER_INFERENCE='{"protection":{"mode":"enforcing","policy_version":"t1","targets":{"codex":{"endpoint":"http://127.0.0.1:18900/v1/responses","model":"gpt-5.6-sol","protocol":"openai-responses","allowed_cache_retention":["provider-default"],"context_window_tokens":400000,"max_output_tokens":32000,"validated_utf8_token_bound":true}}}}' - Start the gateway with
PC_GATEWAY_UPSTREAM_PROFILE=codex,PC_GATEWAY_UPSTREAM_URL_RESPONSES=http://127.0.0.1:18900/v1/responsesandPC_GATEWAY_INJECTION=on. Run a small HTTP server on port 18900 that records the request body and returns a completed Responses object. - POST a request captured from Codex 0.145 (
codex exec, first turn, about 47 KB) to/gateway/v1/responses:- unchanged (
stream: true) → 409streaming_unsupported; - with an appended
reasoningitem carryingencrypted_content, plus a tool call and its output → 409content_unsupported; - with
stream: false→ 200, then compare the recorded upstream body with the request (47,589 → 27,504 bytes; the differences are listed above).
- unchanged (
Expected behavior
A Codex request passes the gateway unchanged, apart from the gateway's own declared injection, and Codex works through the gateway in enforcing mode.
Actual behavior
See above. Codex cannot complete a single turn in enforcing mode. Without streaming and reasoning replay, it runs without any tools.
Suggested fix
Gateway (we can open a PR for these):
- Responses item fidelity. Forward every input item that is not a plain user message verbatim, including typed items such as
additional_toolsand thetype/roleof developer messages. Only user messages need the canonical form for injection. - Request fields. Pass through the Responses request fields the ingress does not model, and let Core's request allowlist decide. Today they are dropped without any error.
- Streaming. Request a non-streaming response upstream, and after
before_releasereplay it to a streaming client as Responses SSE events (response.created,response.output_item.added/done,response.completed). This keeps the "nothing released before the release check" semantics and does not need streaming support in the protection profile. - Injection for Responses. Insert the prepared context as a separate first
input_textpart of the last user message, and declare its location, as the Chat path does.
Core (needs a maintainer decision):
- Reasoning ciphertext in
openai-responsesrequests. Codex sends provider-issuedencrypted_contentback to the same provider. Should the policy admitreasoningitems whose only opaque field isencrypted_contentforopenai-responsestargets? Or should the gateway drop those items, at the cost of the model losing its earlier reasoning?
Additional context
We ran about 150 Codex SWE-bench Pro sessions through #2307 with local patches for the gateway items above (plus a local relaxation for reasoning ciphertext), so the approach is exercised end to end. The patches were written against an earlier revision of #2307 and need porting to master.
- PowerContext: master
e03f54ee - Codex CLI 0.145.0,
wire_api = "responses"
Are you willing to submit a PR to fix this bug?
- Yes, I would like to submit a PR.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
feat(gateway): inject prepared context into Responses requests
fix(gateway): replay Responses text events, failure status and degrad…
feat(gateway): inject prepared context into Responses requests
fix(gateway): forward Responses requests intact and replay streams af…
feat(gateway): inject prepared context into Responses requests (#2400)
jasper-yl commentedon Nov 2, 2026
Acceptance check on master
44bba6b7d, with an unmodified Codex CLI 0.145.0 (@openai/codex@0.145.0), a master Server in enforcing mode (openai-responsestarget withmax_output_tokensandcontext_window_tokens), injection on, and a scripted upstream that records each request. The upstream is scripted rather than the real API, so the parent callsspawn_agent/wait_agentdeterministically and the reasoning ciphertext is a placeholder in the shape the API returns for Codex'sinclude.Gateway side, all as intended:
stream: true: the upstream request is non-streaming, and Codex accepts the replayed SSE and completes the turn.additional_toolsitem (exec, wait, request_user_input, collaboration) and everyfunction_call/function_call_outputreach the upstream unchanged, as doinclude,reasoning,store,text,tool_choice,parallel_tool_callsandprompt_cache_key.before_sendandbefore_releasechecks accept the declared location.Remaining, on the Core side, now tracked in #2420 as you suggested:
max_output_tokens, so every unmodified Codex request is withheld withoutput_limit_required. The run above needed a pass-through shim that added only that field.reasoningitem carryingencrypted_contentin the response,before_releasewithholds it withcontent_unsupported, so the first turn already fails; Codex retries the 409 five times, each a billed upstream call. The same items in the next request's input are the request-side case listed here as item 2.agent_messagewith anencrypted_contentpart and is withheld withcontent_unsupported.Since the gateway scope of this issue is done and the rest is in #2420, I'm closing this one. Please reopen if you'd rather keep it open until #2420 is decided.
frf12 commentedon Nov 2, 2026
Agreed. This is a clear Responses compatibility defect. Please proceed with the proposed fix.