Repository navigation
Description
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:
src/server/index/serve-options.ts:324-343— whenpackageTreeIntegrity.status()is not ok,/healthz,/readyzand/v1/*all return 503. The/healthzbody is well-formed and carriesstatus: "restart_required",pid,portandversion.src/server/proxy-liveness.ts:173—proxyIdentityAt()doesconst res = await fetchFn(.../healthz); if (!res.ok) return null;. The 503 body is never parsed, so thepidit carries is discarded.findLiveProxy()therefore returns null even thoughreadAlivePid()resolved a live PID fromocx.pidandruntime-port.jsonresolved its port. The identity probe is the final gate and it fails closed.src/cli/index.ts:821—reportRestartFailure()falls through to the discovery phase and printsProxy 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 restartandocx stopcan 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 restartreports the proxy as not running, skips the stop, and fails on a port collision.ocx stopreports 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.jsonby 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.
- 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).
- While it is live, run a bare
npm install -g @bitkyc08/[email protected](package files rewritten at 14:59). curl http://127.0.0.1:10100/healthzreturns 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.- Run
ocx restart. It prints the two errors below and exits 1. A second bun process is spawned and dies unable to bind 10100. netstat -ano | findstr 10100still shows PID 9172 LISTENING. Theocx.pidfile is now empty.- Run
ocx stop. It printsService manager stopped.and exits 0, but PID 9172 is still alive and still holding the port. taskkill /PID 9172 /Tthenocx service startrecovers cleanly, and/healthzreturns 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/responsesScreenshots 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.
- Do not fence
/healthz. It is a diagnostic and identity endpoint, not a traffic or readiness endpoint, and its body already distinguishesokfromrestart_required. Keeping/readyzand/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. - Teach
proxyIdentityAt()to read a 503restart_requiredbody. Instead ofif (!res.ok) return null, parse the body when it passesisOpencodexHealthz()and return the identity with a degraded flag.ocx restartcould then take the graceful path it already implements, andreportRestartFailure()could print an accurate reason instead of "was not running". - Do not clear
ocx.pidon a restart attempt that never stopped the process. Clearing it turns one recoverable failure into a second, independent one by disarmingocx 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
fix: keep fenced proxies restartable and failed Windows updates recov…
lidge-jun commentedon Sep 23, 2026
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.