Skip to content

bug(gateway): Codex requests fail or lose their tools through the gateway's Responses ingress #2398

Closed

Description

@jasper-yl

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:

  1. Every Codex request is withheld. Codex always sends stream: true. The gateway forwards it as a streaming request, and the send check returns 409 {"decision":"withhold","reason_codes":["streaming_unsupported"]}, because the protection profile only supports streaming for openai-chat.
  2. From the second turn on, requests are withheld again. Codex replays its earlier reasoning as {"type": "reasoning", "encrypted_content": ...} items (it sets include: ["reasoning.encrypted_content"] and store: false). The send check returns 409 content_unsupported.
  3. 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 only role and content, so the item shrinks from 19,840 bytes to {"role":"system","content":[]} (33 bytes). The model sees no tools.
    • Every developer message is rewritten to role: "system" and loses its type.
    • The top-level fields reasoning, include, prompt_cache_key and parallel_tool_calls are dropped. OpenAiResponsesRequest has no field for them, and serde silently ignores unknown fields. Core's openai-responses request allowlist admits all four.
  4. Prepared context is never injected into Responses requests. inject_context is state.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

  1. 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}}}}'
    
  2. Start the gateway with PC_GATEWAY_UPSTREAM_PROFILE=codex, PC_GATEWAY_UPSTREAM_URL_RESPONSES=http://127.0.0.1:18900/v1/responses and PC_GATEWAY_INJECTION=on. Run a small HTTP server on port 18900 that records the request body and returns a completed Responses object.
  3. POST a request captured from Codex 0.145 (codex exec, first turn, about 47 KB) to /gateway/v1/responses:
    • unchanged (stream: true) → 409 streaming_unsupported;
    • with an appended reasoning item carrying encrypted_content, plus a tool call and its output → 409 content_unsupported;
    • with stream: false → 200, then compare the recorded upstream body with the request (47,589 → 27,504 bytes; the differences are listed above).

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_tools and the type/role of 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_release replay 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_text part of the last user message, and declare its location, as the Chat path does.

Core (needs a maintainer decision):

  • Reasoning ciphertext in openai-responses requests. Codex sends provider-issued encrypted_content back to the same provider. Should the policy admit reasoning items whose only opaque field is encrypted_content for openai-responses targets? 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.

Activity

  1. jasper-yl commented on Nov 2, 2026

    @jasper-yl
    ContributorAuthor

    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-responses target with max_output_tokens and context_window_tokens), injection on, and a scripted upstream that records each request. The upstream is scripted rather than the real API, so the parent calls spawn_agent/wait_agent deterministically and the reasoning ciphertext is a placeholder in the shape the API returns for Codex's include.

    Gateway side, all as intended:

    • stream: true: the upstream request is non-streaming, and Codex accepts the replayed SSE and completes the turn.
    • Tool definitions and results: the additional_tools item (exec, wait, request_user_input, collaboration) and every function_call/function_call_output reach the upstream unchanged, as do include, reasoning, store, text, tool_choice, parallel_tool_calls and prompt_cache_key.
    • Injection: the prepared block is in the last user message, and both before_send and before_release checks accept the declared location.

    Remaining, on the Core side, now tracked in #2420 as you suggested:

    • Codex never sends max_output_tokens, so every unmodified Codex request is withheld with output_limit_required. The run above needed a pass-through shim that added only that field.
    • With a reasoning item carrying encrypted_content in the response, before_release withholds it with content_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.
    • A subagent's task arrives as an agent_message with an encrypted_content part and is withheld with content_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.

  2. frf12 commented on Nov 2, 2026

    @frf12
    Member

    Agreed. This is a clear Responses compatibility defect. Please proceed with the proposed fix.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions