Skip to content

fix(openai): normalize additional Codex context on HTTP Responses - #8769

Merged
Wei-Shaw merged 1 commit into
Wei-Shaw:mainfrom
Undertone0809:codex/fix-codex-http-context
Nov 16, 2026
Merged

Wei-Shaw merged 1 commit into
Wei-Shaw:mainfrom
Undertone0809:codex/fix-codex-http-context

Conversation

@Undertone0809

Copy link
Copy Markdown
Contributor

Codex 0.169.0 can send additional context as standalone agent function outputs without a model-issued call_id. With v0.2.21 / current main, browser_info, goal_objective and untrusted_context are rejected locally with HTTP 400, before an upstream account is selected. This extends the existing page-context normalization from #8622 to those three observed names.

Reproduction

Send this to POST /v1/responses, substituting a configured model and the usual authorization header:

{
  "model": "<configured-model>",
  "stream": true,
  "input": [
    {"role": "user", "content": "Reply with the diagnostic marker in external context."},
    {
      "type": "function_call_output",
      "namespace": "agent",
      "name": "browser_info",
      "output": "CONTEXT_MARKER_123"
    }
  ]
}

The response is 400 invalid_request_error: function_call_output requires call_id on HTTP requests; continuation via previous_response_id is only supported on Responses WebSocket v2. The same rejection reproduces with goal_objective or untrusted_context. Ordinary text succeeds.

Codex's v0.169.0 additional-context constructor emits call_id: None, namespace agent, and a name supplied explicitly or derived from the caller's context key. openai/codex#60487 enables untrusted_as_tool_output by default. These three names are a bounded observed set, not the complete set of possible names.

Configuration investigation

We checked the server's rectifier, account passthrough/protocol options, model/header mappings, retry/fallback, error passthrough and WebSocket settings against the request path. None of the investigated server settings changes this pre-routing HTTP validation for the same incoming request. Merely enabling a server WebSocket option does not switch a client's HTTP request to WebSocket.

There is a working client workaround: untrusted_as_tool_output=false. A fresh official Codex 0.169.0 session completed two turns through the public gateway with that setting; codex --disable untrusted_as_tool_output also worked. That requires changing each affected client. The proposed gateway fallback handles the tested inputs while leaving the client feature enabled.

Change and boundaries

  • Normalize only the exact three additional names, namespace agent, a missing or blank string call_id, and nonblank textual output.
  • Convert them to user input_text with <external_NAME>…</external_NAME> delimiters, following the existing Pages compatibility strategy. Preserve text, ordering, unrelated history, previous_response_id and numeric precision. Existing Pages formatting is unchanged.
  • Preserve nonblank real call IDs and leave null/numeric IDs, unknown names, wrong/missing namespaces, encrypted arrays, malformed/duplicate JSON and other unsupported inputs to existing validation.

This deliberately changes the representation and role of recognized context. Text delimiters are not equivalent to native untrusted-context semantics. It is a narrow compatibility fallback, not a wildcard acceptance of arbitrary function outputs.

Relationship to #8680

#8680 proposes preserving native context instead of converting it to user messages. At its current head (19b0c17477d2), its allowlist recognizes browser_tabs and untrusted_content, but not the browser_info and untrusted_context inputs above; goal_objective overlaps.

Our directly tested API-key upstream paths rejected these original shapes with missing-call-ID errors while ordinary text succeeded; another upstream accepted them. This does not imply that every API-key or OAuth upstream rejects native context. This PR offers a minimal extension of #8622 for the observed HTTP compatibility gap; maintainers may prefer to incorporate its cases into #8680 with an appropriate compatibility strategy.

Validation

On this upstream-based branch:

  • go test -tags=unit ./internal/handler -count=1 -timeout=180s
  • go test -tags=unit ./internal/handler -run '^TestNormalizeCodex' -count=1 -timeout=120s after adding boundary cases
  • go test -tags=unit ./internal/service -run '^TestValidateFunctionCallOutput' -count=1 -timeout=120s
  • gofmt and git diff --check

Regression tests cover the three names, blank call IDs, mixed contexts, idempotence, real/malformed outputs, duplicate members, Pages behavior and history/numeric preservation.

Separately, the same backend implementation was tested through a deployed public gateway using official Codex 0.169.0 on macOS: feature enabled, HTTP 400 before; two completed HTTP 200 turns after, with changing context markers preserved. Public SSE probes for all three names, existing Pages and ordinary text completed. A model-generated tool call followed by its actual call_id output plus standalone context also completed; an unrelated missing-ID ordinary output still returned 400. This validates the tested protocol path, not recovery of any pre-existing affected session.

Refs #8609. Follow-up to #8622; alternative/overlapping work: #8680.

@Wei-Shaw
Wei-Shaw merged commit d31a87a into Wei-Shaw:main Nov 16, 2026
8 of 9 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants