Skip to content

Commit 3bf4b95

Browse files
committed
fix(cli): report Codex routing in ocx status and name an unused proxy
ocx status greened on process liveness alone, so a proxy answering /healthz read healthy even when ~/.codex/config.toml had no openai_base_url and every routed request went to OpenAI instead. The next line made it worse: native routing is genuinely rebootSafe, so restart safety printed 'no opencodex restart dependency' — a second all-clear for a broken setup. ocx doctor already knew, and printed routing=native, but status is the command people run first. status now prints the routing token doctor prints, and warns when a live proxy is paired with native routing. The proxy line keeps its check. That claim is narrow and true: the listener is up, which the reporter proved by curling it successfully. Turning it yellow would make the one honest signal lie to compensate for a missing one, and it would collide with the not-running branch whose remedy ('ocx start') is wrong here — the proxy does not need restarting, Codex needs re-pointing. Only native warns. custom-local and unknown are equally unused, but startupHealthSummary already renders both as AT RISK with a remedy, and custom-remote is a deliberate choice; warning on all four would train operators to ignore the line that matters. All five routing kinds are pinned in the test. The routing detail is extracted into formatStartupRoutingDetail so status and doctor cannot drift. Two callers computing the same string separately is exactly how #2457 happened. No routing decision, classifier, or restart-safety verdict changes. Closes #2411
1 parent 240ac38 commit 3bf4b95

6 files changed

Lines changed: 90 additions & 5 deletions

File tree

‎src/cli/doctor.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import {
4242
resolveEffectiveUserIdentity,
4343
} from "../codex/user-identity";
4444
import { collectProjectCodexConfigWarnings, formatProjectCodexConfigWarningsForDoctor } from "../codex/project-config-warnings";
45-
import { collectStartupHealth, startupHealthSummary } from "../codex/autostart-health";
45+
import { collectStartupHealth, formatStartupRoutingDetail, startupHealthSummary } from "../codex/autostart-health";
4646
import {
4747
displayCodexRuntimePath,
4848
loadLastEffortClamp,
@@ -983,7 +983,7 @@ export async function runDoctor(args: string[] = []): Promise<void> {
983983
const startup = collectStartupHealth(doctorConfig);
984984
console.log("\nCodex restart safety");
985985
console.log(` ${startup.rebootSafe ? "ok " : "!! "} ${startupHealthSummary(startup)}`);
986-
console.log(` routing=${startup.routingKind}, service=${startup.serviceViable ? "viable" : startup.serviceInstalled ? "installed-but-unhealthy" : "absent"}, shim=${startup.shimHealthy ? "healthy" : startup.shimInstalled ? "stale" : "absent"}`);
986+
console.log(` ${formatStartupRoutingDetail(startup)}`);
987987

988988
console.log("\nCodex runtime selection");
989989
{

‎src/cli/index.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
writePid,
2626
writeRuntimePort,
2727
} from "../config/process-state";
28-
import { collectStatus } from "./status";
28+
import { collectStatus, unusedProxyWarningLines } from "./status";
2929

3030
import {
3131
discoverStableProxyForRestart,
@@ -46,7 +46,7 @@ import { runCli } from "./root";
4646
import { ProxyOwnershipRefusedError, stopProxy } from "../lib/process-control";
4747
import { loadServiceTokenFromFile } from "../lib/service-secrets";
4848
import { diagnoseService, isServiceOwnershipError, serviceCommand, serviceEnvironmentOwnedHere, serviceStartableFromTray, serviceStatusSummary, stopServiceIfInstalled, uninstallServiceIfInstalled } from "../service";
49-
import { startupHealthSummary } from "../codex/autostart-health";
49+
import { formatStartupRoutingDetail, startupHealthSummary } from "../codex/autostart-health";
5050
import { drainAndShutdown, isRecyclingForExit, startServer } from "../server";
5151
import { injectSystemEnv, reconcileShellHook, revertSystemEnv, uninstallShellHook } from "../server/system-env";
5252
import { buildDesktop3pRegistry } from "../claude/desktop-3p";
@@ -848,6 +848,12 @@ async function handleStatus() {
848848
console.log(`❌ Proxy: ${status.proxyLabel}`);
849849
}
850850
console.log(` Health: ${status.healthLabel}`);
851+
for (const line of unusedProxyWarningLines({
852+
proxyUp: Boolean(status.json.proxy.pid || status.json.proxy.health.ok),
853+
routingKind: status.json.startup.routingKind,
854+
})) {
855+
console.log(` ${line}`);
856+
}
851857
if (!(status.json.proxy.pid || status.json.proxy.health.ok)) {
852858
console.log(" ↳ Not running — Codex/Claude requests will fail with connection errors.");
853859
// The service summary a few lines below already tells a registered-but-not-serving
@@ -867,6 +873,7 @@ async function handleStatus() {
867873
console.log(` Default provider: ${status.json.defaultProvider}`);
868874
console.log(` Codex autostart: ${status.json.codexAutostart ? "enabled" : "disabled"}`);
869875
console.log(` Restart safety: ${startupHealthSummary(status.json.startup)}`);
876+
console.log(` ${formatStartupRoutingDetail(status.json.startup)}`);
870877
console.log(` Service: ${status.json.service.summary}`);
871878
console.log(` ${status.json.codexShim.summary}`);
872879
console.log(` Codex runtime: ${status.json.codexRuntime.path}`);

‎src/cli/status.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,29 @@ export function proxyHealthFailureReason(error: unknown, signal: AbortSignal): "
118118
: "unreachable";
119119
}
120120

121+
/**
122+
* `ocx status` greens on process liveness alone, so a proxy that answers
123+
* /healthz reads healthy even when Codex is not pointed at it and every routed
124+
* request goes to OpenAI instead (#2411). The proxy line is not wrong — the
125+
* listener really is up — so it keeps its check, and this supplies the signal
126+
* that was missing rather than corrupting the one that was already honest.
127+
*
128+
* Only `native` warns. `custom-local` and `unknown` are also "this proxy is
129+
* unused", but startupHealthSummary already renders both as AT RISK with a
130+
* remedy command, and `custom-remote` is a deliberate operator choice. Warning
131+
* on all four would teach operators to skip the line that matters.
132+
*/
133+
export function unusedProxyWarningLines(input: {
134+
proxyUp: boolean;
135+
routingKind: StartupHealth["routingKind"];
136+
}): string[] {
137+
if (!input.proxyUp || input.routingKind !== "native") return [];
138+
return [
139+
"⚠️ Codex routing is native — the running proxy is unused.",
140+
" Codex requests go to OpenAI, not this proxy. Re-point with: ocx start",
141+
];
142+
}
143+
121144
async function checkProxyHealth(target: ListenTarget): Promise<HealthCheck> {
122145
const url = target.healthUrl;
123146
const controller = new AbortController();

‎src/codex/autostart-health.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,19 @@ export function startupHealthSummary(health: StartupHealth): string {
154154
if (health.serviceInstalled && !health.serviceViable) return `AT RISK after restart (installed service is disabled, stopped, or unhealthy; run '${command}')`;
155155
return `AT RISK after restart (no viable background service; run '${command}')`;
156156
}
157+
158+
/**
159+
* The routing/service/shim token `ocx doctor` prints under restart safety.
160+
* Extracted so `ocx status` can show the same string rather than growing a
161+
* second copy that drifts (#2411). Two management routes computing the same
162+
* thing separately is exactly how #2457 happened.
163+
*/
164+
export function formatStartupRoutingDetail(health: StartupHealth): string {
165+
const service = health.serviceViable
166+
? "viable"
167+
: health.serviceInstalled ? "installed-but-unhealthy" : "absent";
168+
const shim = health.shimHealthy
169+
? "healthy"
170+
: health.shimInstalled ? "stale" : "absent";
171+
return `routing=${health.routingKind}, service=${service}, shim=${shim}`;
172+
}

‎tests/autostart-health.test.ts‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { describe, expect, test } from "bun:test";
2-
import { deriveStartupHealth, startupHealthSummary } from "../src/codex/autostart-health";
2+
import { deriveStartupHealth, formatStartupRoutingDetail, startupHealthSummary } from "../src/codex/autostart-health";
3+
import { unusedProxyWarningLines } from "../src/cli/status";
34
import { classifyCodexRouting, hasInjectedCodexRouting } from "../src/codex/inject";
45
import { handleManagementAPI } from "../src/server/management-api";
56
import { invalidateStartupHealthCache, markStartupHealthDiagnosticStale } from "../src/server/startup-health-cache";
@@ -231,3 +232,36 @@ describe("Codex startup health", () => {
231232
}, 40_000);
232233
});
233234
import { ManagementRequest as Request } from "./helpers/management-auth";
235+
236+
describe("routing visibility (#2411)", () => {
237+
test("formatStartupRoutingDetail renders the token doctor already prints", () => {
238+
expect(formatStartupRoutingDetail(deriveStartupHealth({ ...base, routingKind: "native" })))
239+
.toBe("routing=native, service=absent, shim=absent");
240+
expect(formatStartupRoutingDetail(deriveStartupHealth({
241+
...base,
242+
serviceInstalled: true,
243+
serviceViable: true,
244+
shimInstalled: true,
245+
shimHealthy: true,
246+
}))).toBe("routing=opencodex-local, service=viable, shim=healthy");
247+
expect(formatStartupRoutingDetail(deriveStartupHealth({ ...base, serviceInstalled: true })))
248+
.toBe("routing=opencodex-local, service=installed-but-unhealthy, shim=absent");
249+
expect(formatStartupRoutingDetail(deriveStartupHealth({ ...base, shimInstalled: true })))
250+
.toBe("routing=opencodex-local, service=absent, shim=stale");
251+
});
252+
253+
// A healthy proxy paired with native routing is the state #2411 reports: the
254+
// process answers /healthz truthfully while no Codex request reaches it.
255+
// custom-local and unknown stay silent on purpose — startupHealthSummary
256+
// already renders both as AT RISK with a remedy, so a second warning would
257+
// train operators to ignore this one.
258+
test("unusedProxyWarningLines fires only for a live proxy on native routing", () => {
259+
expect(unusedProxyWarningLines({ proxyUp: true, routingKind: "native" }).length).toBeGreaterThan(0);
260+
expect(unusedProxyWarningLines({ proxyUp: true, routingKind: "native" }).join(" ")).toContain("unused");
261+
expect(unusedProxyWarningLines({ proxyUp: false, routingKind: "native" })).toEqual([]);
262+
expect(unusedProxyWarningLines({ proxyUp: true, routingKind: "opencodex-local" })).toEqual([]);
263+
expect(unusedProxyWarningLines({ proxyUp: true, routingKind: "custom-remote" })).toEqual([]);
264+
expect(unusedProxyWarningLines({ proxyUp: true, routingKind: "custom-local" })).toEqual([]);
265+
expect(unusedProxyWarningLines({ proxyUp: true, routingKind: "unknown" })).toEqual([]);
266+
});
267+
});

‎tests/cli-help.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ describe("CLI subcommand help", () => {
174174
expect(result.stdout).toContain("Service:");
175175
expect(result.stdout).toContain(join(opencodexHome, "service.log"));
176176
expect(result.stdout).toContain("Codex autostart shim");
177+
// #2411: status must name the routing kind it already computes. The
178+
// proxy is down in this fixture, so the unused-proxy warning must stay
179+
// quiet — that warning is for a LIVE proxy nothing routes through.
180+
expect(result.stdout).toContain("routing=");
181+
expect(result.stdout).not.toContain("the running proxy is unused");
177182
} finally {
178183
rmSync(opencodexHome, { recursive: true, force: true });
179184
}

0 commit comments

Comments
 (0)