Relaunch the Codex app-server automatically after an unexpected exit - #14
Merged
Merged
Conversation
When the app-server child died on its own (OOM kill, a stray `kill -9`, a crash), the runtime only flagged itself degraded and every turn failed with "Codex app-server is not running … Send /restart to recover it" until an operator noticed. Docker's restart policy does not help here because the wirebot process itself keeps running. CodexRuntimeService now reacts to an unexpected exit by relaunching the server under the runtime lock with a short back-off (1s, 2s, 5s, 10s, 30s). Turns are paused during each attempt and resumed afterwards so a failed attempt surfaces an error instead of hanging. A manual /restart or reload that lands first ends the loop, and stop() waits for an in-flight recovery. Once all attempts fail the previous behaviour returns: degraded status with the manual-restart hint. The status text shown while relaunching says so instead of asking for /restart.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When the Codex app-server child exits on its own — kernel OOM-killer, a stray
kill -9, or a crash — Wirebot keeps running but only marks the runtime degraded. Every following turn fails with:and the bot stays unusable until a human sends
/restart. Docker'srestart: unless-stoppeddoes not help because the Wirebot process itself never died.Fix
CodexRuntimeService.handleExitnow starts a background recovery loop for unexpected exits:1s, 2s, 5s, 10s, 30s(about 50 seconds in total);rpc.start()and the fresh-serverreconcile, then resumes turns so a failed attempt yields an error instead of a hang;/restartor/reloadthat succeeds first ends the loop (checked viarestartRequired), andstop()awaits an in-flight recovery;While a relaunch is in progress the runtime status text reads "the app-server is being relaunched automatically" instead of asking for
/restart.Expected exits (
stop(), manual/restart) are untouched.Verification
bun run checkandbun testpass on Bun 1.4.0. No new tests, per maintainer request.Docs
CHANGELOG
[Unreleased] → Fixedand a short README paragraph next to the/restartdescription.🤖 Generated with Claude Code