From 53491a7fd85dad4d000d5c8329dcfac9f2d9e261 Mon Sep 17 00:00:00 2001 From: yunseong kim Date: Tue, 24 Nov 2026 14:30:19 +0900 Subject: [PATCH] fix(codex): accept the context route in Desktop observation Allow the opted-in context-management alias on the verified local OpenCodex listener. Cover the injected URL and rejected alternatives with routing preflight tests. --- .../content/docs/guides/codex-integration.md | 2 ++ .../docs/ko/guides/codex-integration.md | 3 +++ .../routing-preflight.ts | 5 ++++- structure/clients/codex-desktop.md | 1 + .../desktop-compatibility-routing.test.ts | 21 +++++++++++++++++++ 5 files changed, 31 insertions(+), 1 deletion(-) diff --git a/docs-site/src/content/docs/guides/codex-integration.md b/docs-site/src/content/docs/guides/codex-integration.md index c3f8cd44ed5..47eec96a7b0 100644 --- a/docs-site/src/content/docs/guides/codex-integration.md +++ b/docs-site/src/content/docs/guides/codex-integration.md @@ -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. diff --git a/docs-site/src/content/docs/ko/guides/codex-integration.md b/docs-site/src/content/docs/ko/guides/codex-integration.md index 3cfa116ec0b..9571420e8ad 100644 --- a/docs-site/src/content/docs/ko/guides/codex-integration.md +++ b/docs-site/src/content/docs/ko/guides/codex-integration.md @@ -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` 어댑터와 정식 diff --git a/src/codex/desktop-compatibility/routing-preflight.ts b/src/codex/desktop-compatibility/routing-preflight.ts index 97b66a54fb2..5a588df9750 100644 --- a/src/codex/desktop-compatibility/routing-preflight.ts +++ b/src/codex/desktop-compatibility/routing-preflight.ts @@ -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 => !!value && typeof value === "object" && !Array.isArray(value); @@ -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; diff --git a/structure/clients/codex-desktop.md b/structure/clients/codex-desktop.md index 89b204d5657..9ec63e172ff 100644 --- a/structure/clients/codex-desktop.md +++ b/structure/clients/codex-desktop.md @@ -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 diff --git a/tests/clients/desktop-compatibility-routing.test.ts b/tests/clients/desktop-compatibility-routing.test.ts index 8eaaaf69706..5c8d07e9035 100644 --- a/tests/clients/desktop-compatibility-routing.test.ts +++ b/tests/clients/desktop-compatibility-routing.test.ts @@ -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"; @@ -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"),