Skip to content
2 changes: 2 additions & 0 deletions docs-site/src/content/docs/guides/codex-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,8 @@ Certificates are restricted to TLS server authentication. If status shows `renew
stop the service and close Codex, then renew the older certificate before starting again.
The native API URL must match the proxy's actual listener address and port. IPv4 and IPv6
loopback addresses are not interchangeable here; ambiguous `localhost` aliases are refused.
When experimental context management is enabled, the managed `/backend-api/codex` base path
also qualifies on that listener.
Codex's automatic MCP connection refresh and configuration formatting do not invalidate
observation. Model, authentication, profile and routing changes still require a fresh
observation context; the service does not silently adopt those changes during a trial.
Expand Down
3 changes: 3 additions & 0 deletions docs-site/src/content/docs/ko/guides/codex-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ context_management.experimental_mode = true
시작하세요. 이 기능은 명시적으로 켜야 하며, 사용자 소유 URL과 원격 사용자 지정 provider
주입은 변경하지 않습니다. 컨텍스트 창이나 압축 한도를 덮어쓰지 않습니다.

Windows 데스크톱 호환의 관찰 모드는 이 경로가 현재 OpenCodex 프록시의 주소와 포트를
가리키면 실험적 컨텍스트 관리를 켠 상태에서도 시작할 수 있습니다.

이 backend 접두사는 Responses WebSocket 업그레이드를 포함한 기존 데이터 경로의 별칭입니다.
원래 `/v1` 경로와 realtime sideband 오버라이드도 유지됩니다. 열 개의 네이티브
`alpha/history/v2/*`, `alpha/notes/v2/*` POST 엔드포인트는 `openai-responses` 어댑터와 정식
Expand Down
5 changes: 4 additions & 1 deletion src/codex/desktop-compatibility/routing-preflight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { lstatSync, readFileSync } from "node:fs";
import { createHash } from "node:crypto";
import { join } from "node:path";
import type { OcxConfig } from "../../types";
import { CONTEXT_BACKEND_PREFIX, contextExperimentalEnabled } from "../context-compat";
import { nativeCompatibilityOwner, type NativeCompatibilityOwner } from "./routing-binding";

const record = (value: unknown): value is Record<string, unknown> => !!value && typeof value === "object" && !Array.isArray(value);
Expand Down Expand Up @@ -39,7 +40,9 @@ export function matchesNativeCompatibilityRouting(text: string, owner: NativeCom
if (typeof effective.openai_base_url !== "string") return false;
const url = new URL(effective.openai_base_url);
if (url.protocol !== "http:" || !["127.0.0.1", "[::1]"].includes(url.hostname) || url.username || url.password
|| url.search || url.hash || !["/v1", "/v1/"].includes(url.pathname) || !url.port) return false;
|| url.search || url.hash || !url.port) return false;
const basePath = url.pathname.replace(/\/$/, "");
if (basePath !== "/v1" && (basePath !== CONTEXT_BACKEND_PREFIX || !contextExperimentalEnabled(text))) return false;
const port = Number(url.port), matchesPort = (value: number | undefined) => Number.isInteger(value) && Number(value) > 0 && value === port;
// The companion always binds IPv4. localhost can resolve to another address family.
if (matchesPort(owner.loopbackPort) && url.hostname === "127.0.0.1") return true;
Expand Down
1 change: 1 addition & 0 deletions structure/clients/codex-desktop.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ described in the [transport inventory](../transports/inventory.md#native-desktop
Invalid proxy routes refuse rather than falling back to direct egress.
Native routing verification binds both the actual listener address family and port; the companion
is IPv4-only. Ambiguous localhost aliases cannot qualify, and listener identity changes revoke observation.
It accepts the native `/v1` base path and the `/backend-api/codex` alias when experimental context management is enabled.

`relay-listener.ts` forwards HTTP with the existing upstream-header filter, cookies and
streaming bodies, and pipes upgraded TLS sockets without decoding their frames. The
Expand Down
21 changes: 21 additions & 0 deletions tests/clients/desktop-compatibility-routing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { afterEach, beforeEach, expect, test } from "bun:test";
import { mkdtempSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { contextCompatibleBaseLine } from "../../src/codex/context-compat";
import { createNativeRoutingVerifier, matchesNativeCompatibilityRouting } from "../../src/codex/desktop-compatibility/routing-preflight";
import { bindNativeCompatibilityOwner, nativeCompatibilityOwner, type NativeCompatibilityOwner } from "../../src/codex/desktop-compatibility/routing-binding";
import { removeTreeWithRetry } from "../helpers/remove-tree";
Expand Down Expand Up @@ -56,6 +57,26 @@ test("the actual bound listener and companion port are accepted, not a stale con
expect(matchesNativeCompatibilityRouting(text, { ...owner, config: { ...owner.config, codexDesktopAuthless: true } })).toBe(false);
expect(matchesNativeCompatibilityRouting(text, { ...owner, config: { ...owner.config, runtimeRole: "client" } })).toBe(false);
});
test("the injected context-management base URL qualifies on the active listener", () => {
const baseLine = 'openai_base_url = "http://127.0.0.1:12001/v1"';
const optedIn = text + '[features.context_management]\nexperimental_mode = true\n';
const injected = optedIn.replace(baseLine, contextCompatibleBaseLine(optedIn, baseLine));
expect(injected).toContain('openai_base_url = "http://127.0.0.1:12001/backend-api/codex"');
expect(matchesNativeCompatibilityRouting(injected, owner)).toBe(true);
expect(matchesNativeCompatibilityRouting(injected.replace('/codex"', '/codex/"'), owner)).toBe(true);
});

test("the context-management alias still requires opt-in and a valid local route", () => {
const alias = text.replace("/v1", "/backend-api/codex");
const optedIn = alias + '[features]\ncontext_management = true\n';
expect(matchesNativeCompatibilityRouting(optedIn, owner)).toBe(true);
for (const candidate of [alias, optedIn.replace("= true", "= false"),
optedIn.replace(":12001", ":10100"), optedIn.replace("127.0.0.1", "example.test"),
optedIn.replace("/codex", "/codex/extra"), optedIn.replace("/codex", "/codex?x=1")]) {
expect(matchesNativeCompatibilityRouting(candidate, owner)).toBe(false);
}
});

test("foreign providers, destinations, credentials and unknown profiles cannot qualify", () => {
for (const candidate of [text.replace('"openai"', '"custom"'), text.replace("127.0.0.1", "example.test"),
text.replace("http://", "https://"), text.replace("127.0.0.1", "user:pass@127.0.0.1"), text.replace("/v1", "/v1?x=1"),
Expand Down
Loading