Skip to content

docs(codex): document Codex through the gateway with a non-enforcing Core - #2687

Merged
hidb4ai merged 1 commit into
oceanbase:masterfrom
Fengzdadi:docs/codex-through-gateway
Nov 17, 2026
Merged

hidb4ai merged 1 commit into
oceanbase:masterfrom
Fengzdadi:docs/codex-through-gateway

Conversation

@Fengzdadi

Copy link
Copy Markdown
Collaborator

Which issue or RFC does this PR close?

Part of #2250 (plan step 2: Codex through the gateway).

Rationale for this change

Step 2 waited for #2420: an enforcing Core withholds every request from an unmodified Codex, because Codex sends no max_output_tokens. #2420 was closed as not planned. The supported path for an unmodified Codex is a non-enforcing Core, which the gateway accepts since #2457. The Codex guide's "Leave prompt-time context to the gateway" section, added by #2453, covered only the two plugin settings and the gateway's Scope. It did not say which Core mode works, how to point Codex at the gateway, or what happens to a thread that already carries the plugin's context.

What changes are included in this PR?

The section in docs/en/docs/integrations/codex.md and docs/zh/docs/integrations/codex.md now has four parts, with the same structure in both languages:

  • Run Core in a non-enforcing mode. Use disabled, shadow, or advisory, with a target for the profile named by PC_GATEWAY_UPSTREAM_PROFILE. The guide explains why an enforcing Core fails every turn: it withholds the request, for example with output_limit_required, and the gateway returns HTTP 400. It says that none of these modes stops delivery for a privacy rule, and that the gateway must be restarted after a mode change because it discovers the mode at startup. It links to the context-protection and inference-protection pages instead of repeating them. Approving provider-default cache retention is optional: a non-enforcing Core does not withhold a request for prompt_cache_key.

  • Point Codex at the gateway. A config.toml provider for /gateway/v1 with wire_api = "responses", which is the only value Codex 0.167 accepts for a custom provider, and env_key = "PC_GATEWAY_KEY". The guide covers three more points:

    • The key: set PC_GATEWAY_API_KEY on the gateway and export the same value as PC_GATEWAY_KEY where Codex starts. Codex 0.167.2 stops with Missing environment variable before any request while PC_GATEWAY_KEY is unset, even for a loopback gateway that checks no key.
    • Per-session routing: the same keys can go in ~/.codex/powercontext-gateway.config.toml, used with codex --profile powercontext-gateway. Codex 0.167.2 rejects a [profiles.<name>] table in config.toml as legacy.
    • The Server URL: in a combined deployment the gateway forwards Core API and MCP requests, so the plugin can keep the gateway's address as its Server URL.
  • Turn the plugin's prompt recall and capture off. The existing settings. New: start a new thread after changing them. Codex resends the thread's history, so a thread that already carries the plugin's block keeps failing after recall is turned off.

  • Configure the gateway. Use the combined deployment, with these settings:

    • PC_GATEWAY_UPSTREAM_URL_RESPONSES and its API key: without the URL, the Responses route returns 501;
    • PC_GATEWAY_API_KEY, the key Codex sends;
    • PC_GATEWAY_CORE_TOKEN when Core enforces authentication;
    • PC_GATEWAY_SEDIMENT=on;
    • PC_GATEWAY_DEFAULT_SCOPE, with a pointer to scope_binding.py for printing the workspace's Scope.

    The part links to the 1 MiB request limit in Deploy the Server, and keeps the existing two differences from plugin recall.

The section's opening now says what happens once the plugin's recall adds context to a thread: Core rejects the check for that request and every later one in the thread with HTTP 422, and the gateway returns HTTP 503 gate_paused. The run reproduced this under a non-enforcing Core.

#2641 edits other sections of the same two files; the hunks do not overlap.

Are there any user-facing changes?

Documentation only. No code, settings, or API changes.

How was this change tested?

Real Codex 0.167.2 (codex exec --json, then codex exec --json resume <thread>), in an isolated HOME and CODEX_HOME:

  • The plugin was installed with powercontext setup codex from this branch.
  • Its four hooks were trusted through Codex's app-server, as the codex-host E2E job does.
  • The Server ran on this branch over a Unix socket, with enforced auth.
  • The Rust gateway, built from this branch, ran in the combined deployment with PC_GATEWAY_SEDIMENT=on.
  • The model upstream was a local fake Responses server, and no real model was called.
  • Recording proxies sat in front of the gateway and between the gateway and Core.

Each setup sent two messages in one thread:

Setup Turns Prepares per message, plugin / gateway Upstream request Captured by
advisory, shadow, and disabled, each with the documented settings complete 0 / 1 one gateway block the gateway, one Source per turn
advisory, the guide's example target (endpoint, model, protocol only; no cache approval) complete 0 / 1 one gateway block the gateway
advisory, plugin defaults (recall and capture on) fail: check 422 (context-binding-required), gateway 503 gate_paused 1 / 1 none the plugin
advisory, documented settings, resuming the previous thread fail: 422, then 503 0 / 1 none none
enforcing, documented settings, provider-default approved fail: withhold output_limit_required, gateway 400 0 / 1 none none
  • In the passing runs, every check was allow with coverage.complete=false.
  • With plugin recall on, Codex puts the plugin's block in a developer message. The second message's request also carried the first message's block.
  • The failing setups ran with Codex's request and stream retries set to 0, so each message sent one request.
  • Codex 0.167.2 rejects wire_api = "chat" at config load.
  • Codex 0.167.2, outside the runs above, with the gateway provider and no listener: with PC_GATEWAY_KEY unset it exits with Missing environment variable before any request. A [profiles.<name>] table is rejected as legacy. The same keys in <name>.config.toml with --profile <name> select the gateway provider.

Checks:

  • make check: passed, ty check included.
  • make docs-test, run locally: lint, the website tests, compilation, and static generation of all 1,408 pages passed. The last step of next build then stopped locally with SecurityFatalError, a Next.js security-advisory check for the pinned Next.js 16.4.1. CI's check-website job runs the same target and passed on master fd16583; this PR's own CI run shows the result there.

Self-review and a separate review: every key, path, default, and behavior that the section states was checked against upstream/master fd16583, either in the code or in the run above. Before any change, the gateway and Core code paths were read for each failure mode the section describes.

AI usage statement

Claude Code (Claude Opus 5.5) ran the real Codex host, gateway, and Server, and wrote the docs change and this description. A separate Claude Code subagent and the coordinating Claude Code session reviewed the diff.

…Core

oceanbase#2420 was closed as not planned: an unmodified Codex sends no
max_output_tokens, so an enforcing Core withholds every request. The
supported path is a non-enforcing Core, which the gateway accepts since
oceanbase#2457.

The "Leave prompt-time context to the gateway" section now covers:
- the Core mode and the gateway restart a mode change needs;
- the Codex provider for /gateway/v1 (wire_api = "responses"), the
  gateway key that Codex needs in PC_GATEWAY_KEY, and a per-session
  profile file;
- the plugin settings, and why a thread that already carries the
  plugin's block keeps failing;
- the gateway settings: the Responses upstream URL, the gateway key,
  the Core token, sediment, and the default Scope.

Approving provider-default cache retention is optional under a
non-enforcing Core.

Checked with a real Codex 0.167.2, the gateway, and the Server from
this branch, against a local fake Responses upstream.

Part of oceanbase#2250.

@PsiACE PsiACE left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks!

@hidb4ai hidb4ai 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.

Reviewed 2e78c65. No blocking findings. The bilingual guide matches the Core/gateway contracts and makes the non-enforcing privacy and single-Scope limitations explicit. No database tables or interfaces are added. Independently verified the documented configuration behavior with Codex 0.167.2 and passed the 33 focused context-check tests. Broader privacy tests could not collect because the local pydantic-ai installation lacks ModelContextWindowExceededError; I did not rerun the full host/gateway/provider workflow. Documentation and website CI are green.

@hidb4ai
hidb4ai merged commit bbd701f into oceanbase:master Nov 17, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.6.0 v1.6.0 release tracking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants