Skip to content

codex-rs/app-server: graceful websocket restart on Ctrl-C#12517

Merged
maxj-oai merged 9 commits intomainfrom
maxj/sigusr1
Feb 25, 2026
Merged

codex-rs/app-server: graceful websocket restart on Ctrl-C#12517
maxj-oai merged 9 commits intomainfrom
maxj/sigusr1

Conversation

@maxj-oai
Copy link
Copy Markdown
Contributor

@maxj-oai maxj-oai commented Feb 22, 2026

Summary

  • add graceful websocket app-server restart on Ctrl-C by draining until no assistant turns are running
  • stop the websocket acceptor and disconnect existing connections once the drain condition is met
  • add a websocket integration test that verifies Ctrl-C waits for an in-flight turn before exit

Verification

  • cargo check -p codex-app-server --quiet
  • cargo test -p codex-app-server --test all suite::v2::connection_handling_websocket
  • I (maxj) tested remote and local Codex.app

maxj-oai and others added 2 commits February 22, 2026 14:56
Co-authored-by: Codex <noreply@openai.com>
@maxj-oai maxj-oai requested a review from celia-oai February 22, 2026 23:06
@maxj-oai maxj-oai marked this pull request as ready for review February 22, 2026 23:15
Co-authored-by: Codex <noreply@openai.com>
Copy link
Copy Markdown
Contributor

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 11886fcd12

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Co-authored-by: Codex <noreply@openai.com>
@maxj-oai maxj-oai requested a review from bolinfest February 23, 2026 01:58
Copy link
Copy Markdown
Collaborator

@bolinfest bolinfest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to come back to this later, but here are my comments thus far.

maxj-oai and others added 2 commits February 22, 2026 18:32
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Codex <noreply@openai.com>
Copy link
Copy Markdown
Collaborator

@owenlin0 owenlin0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we receive a ctrl-c I believe we'd want to prevent 1) existing clients from triggering new turn/start and 2) new clients from connecting?

ideally if they do they get a JSON-RPC error indicating that the server is shutting down.

from codex: "After the first Ctrl-C, this loop keeps processing IncomingMessage and ConnectionOpened, and the websocket acceptor is only canceled once running_turn_count reaches zero. In practice that means existing clients can still start another turn/start, and brand new websocket clients can still connect, which can bump the running-turn count back up and postpone the restart indefinitely. That defeats the core guarantee of a graceful drain: once shutdown is requested, the server should stop taking new work and wait only for already-running turns to finish."

@maxj-oai
Copy link
Copy Markdown
Contributor Author

That's intended and IMO better behavior. Turns can take a very long time, it would be bad for the server to be "down" for new turns that whole time. At the same time, given that these tend to be used by a single user, it's likely that there will be a "gap" in turns eventually where a restart is safe.

An even better solution is to have another instance ready to accept new turns while existing ones complete on the old instance, but that's complicated enough I'd like to ship this first.

@maxj-oai maxj-oai merged commit 5163850 into main Feb 25, 2026
94 of 115 checks passed
@maxj-oai maxj-oai deleted the maxj/sigusr1 branch February 25, 2026 00:28
@github-actions github-actions bot locked and limited conversation to collaborators Feb 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants