app-server daemon: auto-update force-kills active turns after a 60s drain budget, and cannot be disabled
app-server daemon: auto-update force-kills active turns after a 60s drain budget, and cannot be disabled
Summary
On a long-lived codex remote-control daemon, the auto-updater restarts the app-server as soon as a new release lands. The app-server implements a correct graceful drain that waits for running assistant turns — but the daemon only grants it 60 seconds before sending SIGKILL. For any workload where a turn routinely lasts minutes (agents running build/test suites), the drain can essentially never complete, so every auto-update destroys in-flight work across every thread on the host.
There is also no supported way to turn auto-update off, so an operator cannot opt out of the behavior.
Environment
- codex-cli / app-server 0.149.0 → 0.150.0 (standalone managed install), Debian 13 x86_64
- daemon started via
codex remote-control start; multiple TUI clients attached over an SSH-forwarded unix socket - workload: 13 long-lived threads; typical turn runs a Go build/test suite lasting 3–30 minutes
What happened
2026-08-26, unattended:
20:16— updater installed0.150.0(symlink~/.codex/packages/standalone/currentre-pointed).20:16 → 20:17:51— app-server restarted; every attached client connection dropped simultaneously; turns that were mid-execution were terminated. The ~90s gap matches the grace period elapsing before the forced kill.- Recovery required reconnecting each client and interrupting/continuing each thread; turns that were awaiting an exec at kill time exhibited the hang described in #40306.
Mechanism (source refs, rust-v0.150.0)
The graceful path exists and is well-implemented:
app-server/src/lib.rs:250-253— on SIGTERM the server logs "received shutdown signal; entering graceful restart drain (connections=…, runningAssistantTurns=…, requests still accepted until no assistant turns are running)".app-server/src/lib.rs:257-262—update()returnsShutdownAction::Finishonly whenself.forced || running_turn_count == 0, and otherwise logs "waiting for N running assistant turn(s) to finish".
The daemon then overrides it:
app-server-daemon/src/backend/pid.rs:520—stop()sendsSIGTERM.app-server-daemon/src/backend/pid.rs:23-24—STOP_GRACE_PERIOD = 60s,STOP_TIMEOUT = 70s.app-server-daemon/src/backend/pid.rs:253-277— afterSTOP_GRACE_PERIODelapses,force_terminate_process(pid)→SIGKILL(pid.rs:535).
Restart eligibility is version-only and has no turn awareness:
app-server-daemon/src/lib.rs:804-818—restart_decisioncomparesinfo.app_server_versionagainst the managed version.app-server-daemon/src/lib.rs:363-372— theRestartIfRunningOutcome::Busybranch reflects the daemon operation lock, not running turns.
Auto-update cannot be disabled:
app-server-daemon/src/settings.rs:11-13—DaemonSettingshas exactly one field,remote_control_enabled;settings.jsoncannot express an update preference.app-server-daemon/src/lib.rs:608-612— bootstrap unconditionally startspid_update_loop_backend; there is no gate.app-server-daemon/src/lib.rs:619—auto_update_enabled: truein the status payload is a hardcoded literal, not a setting, which makes the reported field misleading.
No CLI flag or environment variable appears to control it. The only working workaround is to kill the codex app-server daemon pid-update-loop process after every daemon start (it does not respawn on its own, and killing it does not disturb the running app-server), or to bypass codex app-server daemon entirely and supervise codex app-server directly.
Requests
- Make the drain budget configurable, and allow it to be unbounded. A server operator should be able to say "never
SIGKILLan app-server that is still draining turns" (or set a budget in the tens of minutes). The 60s default is sensible for an interactive desktop session and unusable for turns that run build/test suites. The forced path should remain available explicitly (e.g. a second signal /--force), ason_signalalready models. - Provide a supported way to disable auto-update — a
DaemonSettingsfield pluscodex app-server daemon disable-auto-update(mirroring the existingenable-remote-control/disable-remote-controlpair) would fit the current surface. Operators running unattended fleets need updates to be a deliberate, scheduled action. - Optionally: defer rather than kill. Since the updater already loops with
RESTART_RETRY_INTERVALonBusy, treating "turns are running" as a retryable condition — rather than starting a drain that will be killed — would make auto-update safe by default without any configuration.
Also worth fixing regardless: autoUpdateEnabled in the status output currently reports a constant, so tooling cannot detect the actual state.
Related
- #40306 — turns awaiting an exec hang indefinitely when their client connection dies; the forced kill in this issue is one way to trigger that state.
Verified your source refs against current main (37a5149822, 2026-08-27) — they all hold. Updated line numbers (your rust-v0.150.0 refs → main):
| Your ref (v0.150.0) | Current main | Symbol |
|---|---|---|
pid.rs:23-24 |
pid.rs:23-24 |
STOP_GRACE_PERIOD = 60s, STOP_TIMEOUT = 70s |
pid.rs:520 |
pid.rs:240 |
PidBackend::stop() — SIGTERM via terminate_process (pid.rs:517) |
pid.rs:253-277 |
pid.rs:255, 274 |
grace deadline + force_terminate_process → SIGKILL (pid.rs:532) |
lib.rs:804-818 |
lib.rs:804 |
restart_decision — version-only comparison, no turn awareness |
lib.rs:363-372 |
lib.rs:363 |
try_restart_if_running — Busy = operation lock only |
lib.rs:608-612, 619 |
lib.rs:587, 619 |
bootstrap always starts the update loop; auto_update_enabled: true literal (unchanged) |
app-server/lib.rs:250-262 |
app-server/lib.rs:235, 251, 256, 276 |
ShutdownState::on_signal / update() drain |
Two additions to the mechanism picture, both relevant to your request 3 (defer rather than kill):
- The daemon currently has no running-turn visibility.
ProbeInfo(client.rs:38-41) carries onlyapp_server_version— the restart decision literally cannot see turns. "Turns running → defer" therefore needs a small additive protocol change: expose the running-turn count over the control socket. The good news is the app-server already maintains exactly this number for the drain —ThreadWatchManager::running_turn_count_tx(thread_status.rs:22, 235) →subscribe_running_assistant_turn_count(thread_processor.rs:3514,message_processor.rs:819) → consumed atapp-server/src/lib.rs:918. Extending the probe (or adding a status request) to surface it is straightforward. - The retry cadence in the update loop can't support a minutes-long defer.
update_once(update_loop.rs:109-135) installs the new standalone before the restart decision and only re-loops withRESTART_RETRY_INTERVAL = 50msonBusy. A turn-drain defer needs its own longer interval (e.g. 30–60s) so the daemon doesn't spin at 20 Hz against the control socket for the whole drain.
Design notes:
- Unbounded drain is safe only because of the second-signal force path.
ShutdownState::on_signalsetsforcedon a second SIGTERM andupdate()returnsShutdownAction::Finishimmediately (app-server/src/lib.rs:235-245, 261-271). So "no automatic SIGKILL" should still keep an explicit force — a second SIGTERM (not SIGKILL) for the operator, with the daemon'sSTOP_TIMEOUTas a final fallback. This matters because of the #40306 hang class (a turn awaiting exec with a dead client never completes): an unbounded drain on such a turn would otherwise wedge the daemon forever. - A configurable grace affects user-initiated
stoptoo —Daemon::stopand the update path sharePidBackend::stop(). Keeping the default at 60/70s leaves behavior unchanged unless the operator opts in.
Implementation gotcha for your request 2: DaemonSettings (settings.rs:9-12) derives Deserialize without #[serde(default)], so adding a non-Option field would break loading of existing settings.json files (missing-field error). New fields (auto_update_enabled, grace/timeout) need #[serde(default)] or Option for backward compatibility — and the same applies to the stop_grace_period/stop_timeout fields in request 1.
Happy to implement this. The smallest high-value slice (mirroring requests 1+2, both low-risk and fully testable in the daemon crate):
- configurable
stop_grace_period_secs/stop_timeout_secsinDaemonSettings(null= never auto-SIGKILL), plumbed intoPidBackend, default 60/70 unchanged; auto_update_enabledsetting +enable-auto-update/disable-auto-updatemirroring the existing remote-control pair, gating the update loop at bootstrap and replacing the hardcodedautoUpdateEnabledstatus literal.
Defer-on-by-default (your request 3) is the nicer long-term behavior but needs the probe extension above; happy to take that on as a follow-up once maintainers confirm the intended default semantics.
I've prepared an implementation for requests 1 + 2 (configurable/unbounded drain budget + auto-update toggle). Design summary:
Settings (settings.json, daemon-managed)
| field | meaning |
|---|---|
stopGracePeriodSecs |
seconds after SIGTERM before force-terminating (SIGKILL). Absent → 60 (unchanged); 0 → unbounded (never auto-SIGKILL while draining); n → n seconds |
stopTimeoutSecs |
total stop budget before giving up. Absent → 70 (unchanged); 0 → wait indefinitely |
autoUpdateEnabled |
false → update loop not started at bootstrap; running loop stopped by the toggle |
0 = "no limit" follows the systemd TimeoutStopSec=0 convention. New fields are optional with skip_serializing_if — existing settings.json files keep working unchanged, and the default behavior (60/70, auto-update on) is bit-for-bit today's.
Design decisions worth confirming
- Unbounded drain stays interruptible: the app-server's existing second-SIGTERM force path (
ShutdownState::forced→ immediateShutdownAction::Finish) is preserved, so an operator can still force-exit an unbounded drain explicitly. This matters because of the #40306 hang class — a turn awaiting exec with a dead client never completes on its own, so a truly unkillable drain would wedge the daemon. disable-auto-updatestops the running update loop immediately (mirrors your workaround of killing the pid-update-loop process, but as a supported command pairenable-auto-update/disable-auto-update).- No re-bootstrap resurrection:
is_bootstrappedis extended to also treat a running app-server backend as bootstrapped, socodex app-server daemon startafter disabling auto-update won't re-bootstrap and silently restart the update loop. - Configurable grace applies to user-initiated
stoptoo (both paths sharePidBackend::stop()), default unchanged.
Scope
Touch: DaemonSettings (settings.rs), PidBackend::stop() policy (backend/pid.rs), BackendPaths plumbing (backend/mod.rs), bootstrap gating + set_auto_update (lib.rs), CLI subcommand pair (cli/main.rs). Request 3 (defer rather than kill by default) is intentionally out of this slice — it needs the probe protocol change from my earlier comment and is a natural follow-up.
I can push this as a PR — I have the patch ready. (Note: my fork push has been intermittently blocked by a local sandbox restriction; will land as soon as it clears.)
Implementation update — requests 1 + 2 are now built and tested on a fork branch (no PR yet; still waiting on the invitation gate for PR creation).
Branch: argszero/codex:fix/app-server-daemon-stop-policy-and-auto-update-toggle @ 293a744e9a
What's in it:
Configurable stop policy (settings.json, absent = current behavior, 0 = unbounded):
{
"remoteControlEnabled": false,
"stopGracePeriodSecs": 0,
"stopTimeoutSecs": 0,
"autoUpdateEnabled": false
}
stopGracePeriodSecs— grace after SIGTERM before SIGKILL; default 60,0= never auto-SIGKILL while draining. Second-signal force is preserved, so an operator can still interrupt an unbounded drain.stopTimeoutSecs— total stop budget; default 70,0= wait indefinitely.autoUpdateEnabled— default true. Disables the update loop at bootstrap;codex app-server daemon disable-auto-update/enable-auto-updatestop/start a running loop and persist the setting.
Key semantics
bootstrap_lockedloads existing settings instead of replacing them → a disabled auto-update survives re-bootstrap (this was the trap in the currentupdater.start()unconditional path).is_bootstrappedtreats a running app-server backend as bootstrapped →ensure_remote_control_startedwon't re-bootstrap and resurrect the update loop.- The update-loop process always uses the default stop policy (no turns to drain) so an unbounded drain setting can never wedge
disable-auto-update. PidBackend::new/new_update_loopsignatures unchanged (zero test churn); onlywith_stop_policyis added.
Tests: cargo test -p codex-app-server-daemon 36 passed; cargo test -p codex-cli --bin codex 279 passed (new parse tests included); clippy + fmt clean.
Request 3 ("defer rather than kill") still needs the probe-protocol change (expose running-turn count in the daemon's probe) so the daemon can choose to defer restart — separate follow-up.
Design for request 3 — "defer rather than kill" on auto-update (follow-up to my P1 implementation comment)
Key facts that shape the design
- The app-server's graceful drain has no internal timeout: on first SIGTERM it enters graceful-restart drain and waits indefinitely for running turns (
ShutdownState::update→ShutdownAction::Noopuntilrunning_turn_count == 0; only a second signal forces). So with P1'sstopGracePeriodSecs: 0, auto-update already stops killing — the app-server drains on the old binary, exits on its own when idle, and the daemon then restarts with the new binary. - What request 3 still needs on top of P1:
- Visibility: the daemon silently waits while turns drain — no signal that an update is pending.
- Bounded defer: a stuck turn (the #40306 hang class — turn awaiting exec with a dead client never completes) would wedge the update forever with unbounded drain. Operators need "wait for idle, but not forever", with a fallback to the configured stop policy.
Proposed design
1. Probe protocol — expose the running-turn count
- Add an optional field to
InitializeResponse:#[serde(default, skip_serializing_if = "Option::is_none")] running_turn_count: Option<usize>(camelCase:runningTurnCount). - Plumbing is cheap: the app-server already publishes this via
message_processor::subscribe_running_assistant_turn_count()→watch::Receiver<usize>. Pass a cloned receiver intoInitializeRequestProcessor(it derivesClone, andwatch::Receiver::borrow()gives the latest value per request). - Backward compatible: older app-servers omit the field → the daemon treats it as "unknown".
2. Daemon side — bounded defer on restart
ProbeInfogainsrunning_turn_count: Option<usize>;probe()parses it.- New optional setting
deferRestartTimeoutSecs(absent → 0 → no defer, current P1 behavior):> 0and auto-update restart is pending withrunningTurnCount > 0→ poll the probe every ~2–5 s until the count reaches 0 or the deadline; log awarn!per poll ("auto-update deferred: waiting for N running assistant turn(s)") so the pending update is visible.- On deadline:
warn!("deferred restart timed out with N running assistant turn(s); proceeding with configured stop policy")and fall through to the normal graceful stop (SIGTERM → drain →stopGracePeriodSecs→ SIGKILL).
3. Escape hatches compose, not conflict
deferRestartTimeoutSecsonly delays the start of the graceful stop; it is orthogonal tostopGracePeriodSecs/stopTimeoutSecs.- Stuck-turn recovery stays as-is: second SIGTERM forces the app-server to exit;
stopGracePeriodSecs: 0still means "never auto-SIGKILL".
Why this shape
- One optional protocol field, no new JSON-RPC method (the probe already does
initialize). - Old binaries + default settings → behavior identical to today (and to P1).
- The defer window is bounded by default opt-in, avoiding the unbounded-wedge regression while still giving long-turn operators the "finish on the old binary" behavior they asked for.
I can implement this on the same branch pattern as P1 (fork branch + tests) once it looks reasonable — happy to adjust the knob shape or naming if you'd prefer waitForIdleTimeoutSecs or similar.
Reproduced again on macOS with the current standalone release transition 0.152.0 -> 0.152.1. This affected every active CLI/TUI client attached to the shared remote-control app-server on the host.
Environment
- macOS 26.6.2 (25G83), arm64
- Standalone managed Codex CLI/app-server: 0.152.0 -> 0.152.1
- Shared socket:
unix:///<home>/.codex/app-server-control/app-server-control.sock - Managed processes included
codex app-server daemon pid-update-loopandcodex app-server --remote-control --listen unix://
Observed timeline (2026-09-01, CST / UTC-6)
- 17:07:13 - the 0.152.1 standalone release was staged locally.
- 17:08:04 - last observed log activity from the 0.152.0 app-server (PID 51151).
- 17:08:13.945 - macOS unified logs recorded the old app-server exiting.
- 17:08:14.065 - replacement app-server PID 7055 started as 0.152.1; its PID file and socket were recreated at 17:08:14.
- 17:08:16 - the replacement briefly received
409 Remote app server already online. - 17:08:17 - the replacement connected successfully.
At the replacement boundary, multiple clients failed simultaneously with:
remote app server at `unix:///<home>/.codex/app-server-control/app-server-control.sock`
transport failed: WebSocket protocol error: Connection reset without closing handshake
Disconnected from this task. Work may still be running.
One interrupted session had been running for approximately 4h45m. This was not caused by an operator-initiated update: codex update was only run later, around 17:25, after the disconnects had already occurred. The pid-update-loop supervisor had remained alive since Aug 30 while its app-server child was replaced.
Current mitigation gap
check_for_update_on_startup = false can disable the ordinary client startup check, but it is not a daemon auto-update control. On 0.152.1, codex app-server daemon --help still exposes no disable-auto-update command or daemon drain policy. Therefore users cannot reliably prevent this host-wide interruption through the supported daemon interface.
Required behavior
A device-wide shared daemon must not be replaced while active clients or turns depend on it. The updater should do at least one of the following:
- Defer installation/restart until no active turns remain.
- Run old and new daemons side-by-side, allowing existing connections to drain on the old version.
- Transparently reconnect clients and preserve active turn/event-stream state.
- Require explicit operator confirmation before force-terminating active work.
The safe default should be defer, never force-kill active turns for an unattended update. A bounded force path may exist for explicit operator actions, but it should not be the automatic update policy. Resumable task metadata is not an adequate substitute for uninterrupted execution and session continuity.
This also corroborates #23954's exact Unix-socket WebSocket-reset symptom, but with a version transition and process timestamps that identify the managed update/restart path directly.
Reproduced on Linux, 12 November 2026. Installed CLI: 0.167.0; managed server updated to 0.167.2 during an active interactive conversation.
Updater log, UTC:
08:45:37.558 package_selected: 0.167.2, trigger=scheduled
08:45:37.714 restart_requested: shutdownGraceSeconds=60
08:46:37.752 shutdown_forced
08:46:37.888 replacement spawned
08:46:38.219 readiness succeeded
The conversation was interrupted and subsequently resumed. No update was requested during the session.
Please provide a persistent manual-only update setting and prevent scheduled updates from forcibly terminating active turns.
This issue covers one side of the problem: a fixed 60 s budget kills active turns. The other side shows up when nothing kills the drain, and both point to the same missing feature: suspend running turns when a drain starts and resume them after the update, under a policy the user controls.
Today a restart for an update handles running turns in one of two ways, and neither fits long agent work:
- The managed daemon allows a 60 s drain, then force-kills active turns (this issue, #56474). In-flight work is lost.
- A server run without that budget (for example
codex app-server --remote-controlin a supervising terminal, drained by a console Ctrl+C or SIGHUP) waits for every running turn to finish. Meanwhile it refuses new connections andturn/steer, so nobody can reach the threads that are holding it up.
Observed 2026-11-18 (0.171.0-alpha.11 → alpha.13, Windows): one turn had been started from the phone and was running a multi-stage installer acceptance test. It held the drain for 53 minutes. During that time:
- every other TUI got
turn/start failed: Server is draining; retry after reconnecting (code -32600) {"reason":"serverShuttingDown"}; - the phone app showed "can't load task right now" for that thread;
- the turn had asked the user a question (
request_user_input_async), which no client could display; turn/steerasking the agent to reach a checkpoint was refused with the same draining error.
The only lever left was turn/interrupt. It ended the turn but killed the tool process mid-stage, which left the test's sandbox VM running without cleanup.
Proposal: a native suspend/resume path for server restarts, with a policy the user controls.
- Suspend at drain start. The server tells each running turn that a restart is pending, as a system message on the turn, and gives it a bounded window to reach a checkpoint: finish or record the current tool call, then end the turn. A turn waiting on user input is suspended immediately, and its pending question is persisted with the thread.
- Resume after the update. The new server lists suspended threads to every client that connects. Depending on policy, it either resumes them with a "resumed after server update" turn or leaves them for the user, and it re-surfaces pending questions in both cases.
- Keep control reachable while draining. Refuse new turns, but keep accepting connections for
thread/read, answering pending questions,turn/steerandturn/interrupt. Then the phone and TUIs can still see and steer the threads the drain waits on. - Configuration, for example:
[app_server.restart]
# what happens to running turns when the server restarts for an update
on_running_turns = "suspend" # suspend | wait | interrupt
checkpoint_window = "10m" # suspend: time a turn gets to reach a checkpoint before it is suspended anyway
resume = "ask" # ask | auto: what the new server does with suspended threads
plus a per-thread override, settable from the TUI or the app (e.g. /restart-policy wait or a thread setting), for threads that must not be interrupted. Example: a long migration or install that must run to completion. An update then waits for that thread while the others suspend.
This covers both preferences: users who want sessions to finish cleanly first can choose wait, and users who want updates to land promptly can choose suspend. It also replaces the hard-coded budget this issue describes.
Related: #56474 (update forces active-turn shutdown, TUIs stranded).