Skip to content

[Bug][Windows] package_tree_changed guard fences /healthz, so ocx restart cannot discover the proxy it tells you to restart (#2459 follow-up) #5496

Closed

Description

@two4mamba

Client or integration

Codex App

Area

Service lifecycle

Summary

The package_tree_changed guard introduced for #2459 fences /healthz alongside /readyz and /v1/*. The CLI's liveness probe treats any non-200 /healthz as "not our proxy". The two combine into a self-lock: once the guard trips, ocx restart can no longer discover the very process the guard is telling the operator to restart.

The guard itself is correct and did its job — it caught a bare npm install -g performed under a live 2.59.0 proxy and refused to serve a mixed module graph. The defect is that the printed remediation ("restart OpenCodex before retrying") is unreachable through ocx restart.

Causal chain, all four links verified against the 2.60.0 source on disk:

  1. src/server/index/serve-options.ts:324-343 — when packageTreeIntegrity.status() is not ok, /healthz, /readyz and /v1/* all return 503. The /healthz body is well-formed and carries status: "restart_required", pid, port and version.
  2. src/server/proxy-liveness.ts:173 — proxyIdentityAt() does const res = await fetchFn(.../healthz); if (!res.ok) return null;. The 503 body is never parsed, so the pid it carries is discarded.
  3. findLiveProxy() therefore returns null even though readAlivePid() resolved a live PID from ocx.pid and runtime-port.json resolved its port. The identity probe is the final gate and it fails closed.
  4. src/cli/index.ts:821 — reportRestartFailure() falls through to the discovery phase and prints Proxy was not running and the fallback start did not become healthy. The graceful stop is skipped entirely and a fallback start is spawned, which cannot bind because the old process still holds the port.

Secondary observation, same run: after the failed ocx restart, ocx.pid was left empty (it held 9172 before — 4 bytes, mtime matching process start). With the pidfile empty, the subsequent ocx stop stopped only the Task Scheduler service, printed Service manager stopped., exited 0, and left the proxy process alive and listening on 10100. That is the #764 shape, reached here through the emptied pidfile rather than independently. Recovery required a manual taskkill.

Expected behavior:

  • A proxy fenced by the package-tree guard should still be discoverable as a live, identity-verified process, so ocx restart and ocx stop can act on it.
  • The remediation string printed by the guard should name a command that actually works in the state the guard creates.

Actual behavior:

  • ocx restart reports the proxy as not running, skips the stop, and fails on a port collision.
  • ocx stop reports success while the proxy keeps answering 503 on the port it still holds.
  • The only way out is to read the PID out of ~/.opencodex/runtime-port.json by hand and kill it.

Note on how the trap is reached: in this instance the bare npm install -g was issued by an agent (Codex Desktop) rather than typed by the operator. Agent-driven upgrades are unlikely to route through ocx update, so the #2459 trigger will keep recurring — which is what makes the unreachable recovery path costly rather than cosmetic.

Reproduction

Reproduced end to end on this machine; the state was then repaired, so the values below are from the captured session.

  1. Have a service-managed proxy running on 10100 from a global npm install (here 2.59.0, Task Scheduler backend, PID 9172, started 14:53:37).
  2. While it is live, run a bare npm install -g @bitkyc08/[email protected] (package files rewritten at 14:59).
  3. curl http://127.0.0.1:10100/healthz returns 503 with "status":"restart_required", "code":"package_tree_changed", "pid":9172, "version":"2.59.0". Codex CLI and Codex App both fail from this point.
  4. Run ocx restart. It prints the two errors below and exits 1. A second bun process is spawned and dies unable to bind 10100.
  5. netstat -ano | findstr 10100 still shows PID 9172 LISTENING. The ocx.pid file is now empty.
  6. Run ocx stop. It prints Service manager stopped. and exits 0, but PID 9172 is still alive and still holding the port.
  7. taskkill /PID 9172 /T then ocx service start recovers cleanly, and /healthz returns 200 with "version":"2.60.0".

Version

Running process at failure time: 2.59.0. Installed package on disk and CLI at failure time: @bitkyc08/[email protected]. The source line references above are from the 2.60.0 tree.

Operating system

Windows 11 Home China, build 10.0.26100. Bundled Bun runtime, service backend scheduler (Task Scheduler).

Provider and model

Not provider-specific. The fence is applied before any provider translation, and /healthz carries no provider state.

Logs or error output

$ curl -s -w "HTTP %{http_code}\n" http://127.0.0.1:10100/healthz
HTTP 503
{"status":"restart_required","service":"opencodex","version":"2.59.0","uptime":1434.5042583,"pid":9172,"port":10100,"error":{"code":"package_tree_changed","message":"OpenCodex package files changed while this proxy was running; restart OpenCodex before retrying."}}

$ ocx restart
Proxy did not become healthy after starting.
Proxy was not running and the fallback start did not become healthy.
(exit 1)

$ netstat -ano | findstr 10100
  TCP    127.0.0.1:10100        0.0.0.0:0              LISTENING       9172

$ ocx stop
Service manager stopped.
Removed opencodex routing from Codex config. Catalog restored to 9 native model(s) (dropped 13 proxy-routed).
Codex/Claude requests through the proxy will fail until it is restarted ('ocx start' or 'ocx service start').
(exit 0 -- but PID 9172 is still alive and still LISTENING on 10100)

$ taskkill /PID 9172 /T
SUCCESS: Sent termination signal to the process with PID 9172.

$ ocx service start
opencodex service started and serving on port 10100.

$ curl -s http://127.0.0.1:10100/healthz
{"status":"ok","service":"opencodex","version":"2.60.0","uptime":10.02,"pid":22104,"port":10100,"restartCapability":"v1"}

The client-side symptom that started it, for searchability:

Falling back from WebSockets to HTTPS transport. unexpected status 503 Service Unavailable: OpenCodex package files changed while this proxy was running; restart OpenCodex before retrying., url: ws://127.0.0.1:10100/v1/responses

unexpected status 503 Service Unavailable: OpenCodex package files changed while this proxy was running; restart OpenCodex before retrying., url: http://127.0.0.1:10100/v1/responses

Screenshots and supporting files

No screenshots. Everything needed is in the log block above, and the source line references are reproducible against any 2.60.0 install.

Redacted configuration

{
  "service-state.json": {
    "version": 2,
    "backend": "scheduler",
    "opencodexHome": "<HOME>\\.opencodex",
    "cliPath": "<NPM_PREFIX>\\node_modules\\@bitkyc08\\opencodex\\src\\cli\\index.ts"
  },
  "runtime-port.json": {
    "pid": 9172,
    "port": 10100,
    "attestationSecret": "<redacted>"
  },
  "config.json": {
    "port": 10100
  }
}

Suggested fix

Any one of these breaks the self-lock; the first two are independent and both look worthwhile.

  1. Do not fence /healthz. It is a diagnostic and identity endpoint, not a traffic or readiness endpoint, and its body already distinguishes ok from restart_required. Keeping /readyz and /v1/* fenced preserves everything [Bug][Windows] Bare npm reinstall can leave a live proxy on a mixed old/new module graph #2459 asked for — no request is served from a mixed module graph — while leaving the proxy discoverable. This is the same lesson as readiness: /readyz returns 503 when Codex OAuth accounts need re-auth, blocking healthy proxy traffic #5179, where fencing readiness on a non-traffic condition took an otherwise working proxy out of service.
  2. Teach proxyIdentityAt() to read a 503 restart_required body. Instead of if (!res.ok) return null, parse the body when it passes isOpencodexHealthz() and return the identity with a degraded flag. ocx restart could then take the graceful path it already implements, and reportRestartFailure() could print an accurate reason instead of "was not running".
  3. Do not clear ocx.pid on a restart attempt that never stopped the process. Clearing it turns one recoverable failure into a second, independent one by disarming ocx stop.

A smaller follow-up regardless of which fix lands: the guard's message could name a command that works in the state it creates. Today it says "restart OpenCodex before retrying", and the most obvious reading of that — ocx restart — is precisely the one that cannot succeed.

Checks

  • I searched existing issues and documentation.
  • I removed secrets, tokens, account details, request credentials, and personal data.

Activity

  1. added
    bug
    cli
    install
    platform
    service
    on Sep 22, 2026
  2. lidge-jun commented on Sep 23, 2026

    @lidge-jun
    Owner

    Landed on dev in 41ba802 via #5643: a proxy fenced after its package tree was replaced stays identifiable to ocx restart through verifiable identity that is separate from readiness, and the automatic drain and restart ends on a single runtime. Merges into dev do not auto-close issues, so closing manually; it ships with the next release cut from dev. Please reopen if it still reproduces there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcliinstallplatformservice

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions