Skip to content

Allow idle threads to prewarm and repair WebSocket connections - #47701

Merged
copyberry[bot] merged 1 commit into
mainfrom
copyberry/codex-internal-to-codex-oss/aa164b91a399de2375eda3bf28397725439fce93
Sep 24, 2026
Merged

copyberry[bot] merged 1 commit into
mainfrom
copyberry/codex-internal-to-codex-oss/aa164b91a399de2375eda3bf28397725439fce93

Conversation

@copyberry

@copyberry copyberry Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Allow idle threads to prewarm and repair WebSocket connections

Why

A previously used WebSocket can close while a thread is idle. Hosts need a way to prepare the connection before the next turn without repeating warmup on a healthy connection.

What changed

  • Expose CodexThread::prewarm() using the existing startup warmup and next-turn handoff.
  • Reuse healthy connections and pending warmups, retry failed warmups, and repair closed connections. Treat a finished WebSocket reader task as a closed connection.
  • Skip scheduling during an active turn or shutdown, and stop warmup admission before shutdown takes the pending task.
  • Expose active_turn_environment_selections() so hosts can inspect the environments captured by the active turn, including those still starting or failed, when authorizing steering.

Testing

Add regression coverage for repeated idle prewarm calls, healthy connection reuse with preserved response continuation, reconnection with generate: false, and warmup rejection after shutdown. Update delayed MCP discovery coverage to verify prewarm repairs an eagerly closed socket and the first turn reuses it.

## Why

A previously used WebSocket can close while a thread is idle. Hosts need a way to prepare the connection before the next turn without repeating warmup on a healthy connection.

## What changed

- Expose `CodexThread::prewarm()` using the existing startup warmup and next-turn handoff.
- Reuse healthy connections and pending warmups, retry failed warmups, and repair closed connections. Treat a finished WebSocket reader task as a closed connection.
- Skip scheduling during an active turn or shutdown, and stop warmup admission before shutdown takes the pending task.
- Expose `active_turn_environment_selections()` so hosts can inspect the environments captured by the active turn, including those still starting or failed, when authorizing steering.

## Testing

Add regression coverage for repeated idle prewarm calls, healthy connection reuse with preserved response continuation, reconnection with `generate: false`, and warmup rejection after shutdown. Update delayed MCP discovery coverage to verify prewarm repairs an eagerly closed socket and the first turn reuses it.

GitOrigin-RevId: aa164b91a399de2375eda3bf28397725439fce93
@copyberry
copyberry Bot force-pushed the copyberry/codex-internal-to-codex-oss/aa164b91a399de2375eda3bf28397725439fce93 branch from 95c63e0 to d838c23 Compare September 24, 2026 00:38
@github-actions

Copy link
Copy Markdown
Contributor


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@copyberry
copyberry Bot merged commit d838c23 into main Sep 24, 2026
1 check failed
@copyberry
copyberry Bot deleted the copyberry/codex-internal-to-codex-oss/aa164b91a399de2375eda3bf28397725439fce93 branch September 24, 2026 00:38
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 24, 2026
@ytcheng
ytcheng deployed to issue-triage September 24, 2026 00:47 — with GitHub Actions Active
@ytcheng
ytcheng deployed to issue-triage September 24, 2026 00:47 — with GitHub Actions Active
@ytcheng
ytcheng deployed to issue-triage September 24, 2026 00:47 — with GitHub Actions Active

This branch was successfully deployed

1 active deployment
issue-triage — d838c234 Deployed Sep 24, 2026 by ytcheng via Identify potential duplicates (all issues) #47841
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.

2 participants