Context
Current dev handles process shutdown in src/cli.ts:
SIGINT / SIGTERM call a shutdown handler;
- the handler calls
server.stop(true), removes the pid file, restores native Codex when not running as OCX_SERVICE, then exits.
The request paths already have good client-cancel handling in several places (abortSignal, upstream aborts, WebSocket close aborts, etc.). This issue is specifically about the process shutdown path, not normal client disconnects.
Concern
When the proxy is stopped while a long streaming /v1/responses or WebSocket turn is active, it is not obvious what contract users should expect:
- should opencodex wait briefly for active turns to finish?
- should it reject new requests but let existing streams drain up to a deadline?
- should it actively abort in-flight upstream requests and emit/record an incomplete/aborted terminal outcome?
- should
ocx stop behave differently from Ctrl+C or service stop?
Right now the code appears to stop and exit immediately from the CLI shutdown handler. That is simple, but for Codex users a mid-turn stop can look like a random reconnect/stall rather than an intentional proxy shutdown.
Possible approach
A small, bounded policy might be enough:
- Track active HTTP/WebSocket turns in the server.
- On shutdown, stop accepting new work.
- Wait up to a short configurable deadline, e.g. 5-10 seconds, for active streams to finish.
- After the deadline, abort remaining upstream controllers and record/log a terminal shutdown/incomplete outcome where possible.
- Keep
ocx stop --force or service-manager hard kill behavior available for cases where the process must exit immediately.
This does not need to be a big reliability framework; the main value is making shutdown behavior explicit and preventing in-flight turns from being cut off without any diagnostic signal.
Question
Do you think opencodex should support a bounded graceful drain on shutdown, or is immediate shutdown the intended behavior? If you agree with adding a small drain policy, would you prefer to implement it yourself, or should I prepare a focused PR after the current dev merge settles?
Context
Current
devhandles process shutdown insrc/cli.ts:SIGINT/SIGTERMcall ashutdownhandler;server.stop(true), removes the pid file, restores native Codex when not running asOCX_SERVICE, then exits.The request paths already have good client-cancel handling in several places (
abortSignal, upstream aborts, WebSocket close aborts, etc.). This issue is specifically about the process shutdown path, not normal client disconnects.Concern
When the proxy is stopped while a long streaming
/v1/responsesor WebSocket turn is active, it is not obvious what contract users should expect:ocx stopbehave differently from Ctrl+C or service stop?Right now the code appears to stop and exit immediately from the CLI shutdown handler. That is simple, but for Codex users a mid-turn stop can look like a random reconnect/stall rather than an intentional proxy shutdown.
Possible approach
A small, bounded policy might be enough:
ocx stop --forceor service-manager hard kill behavior available for cases where the process must exit immediately.This does not need to be a big reliability framework; the main value is making shutdown behavior explicit and preventing in-flight turns from being cut off without any diagnostic signal.
Question
Do you think opencodex should support a bounded graceful drain on shutdown, or is immediate shutdown the intended behavior? If you agree with adding a small drain policy, would you prefer to implement it yourself, or should I prepare a focused PR after the current
devmerge settles?