Repository navigation
[app-server] let idle auto-attached threads unload - #1
Draft
freaksdotcom wants to merge 1 commit into
Draft
freaksdotcom wants to merge 1 commit into
freaksdotcom wants to merge 1 commit into
Conversation
This was referenced Jul 26, 2026
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.
TL;DR: Automatic app-server thread attachments now continue delivering events without keeping idle thread runtimes and their MCP processes alive forever. Explicit owners still retain the runtime, the existing 30-minute idle grace remains unchanged, and normal turns or inline reviews atomically establish ownership before work is submitted.
Problem
The app server automatically attaches every initialized connection to internally created threads so those clients can observe events and answer server requests. Those delivery-only attachments were stored in the same set as explicit thread owners. When a TUI exited, its explicit subscription was removed, but another long-lived initialized client could keep the subscriber count nonzero indefinitely, preventing the 30-minute idle-unload timer from ever starting.
This leaves the thread runtime, including per-thread MCP child processes, alive after the interactive client is gone.
Solution
Autoor retainingExplicitownership.AutotoExplicitmonotonically for explicit lifecycle requests, normalturn/start, realtime work, and inline reviews.The explicit ownership distinction is preferable to immediate unload: automatic observers remain functional, transient disconnects retain the existing recovery window, and truly unused runtimes eventually release MCP processes.
Review focus
ThreadEntryattachment bookkeeping and monotonicAutotoExplicitupgrades.try_admit_connection_attachmentlock ordering and its admission-versus-closing race contract.Validation
turn/startupgrade: passed.just fix -p codex-app-server: passed with no findings.just fmt: passed.git diff --check: passed.The broader app-server run completed 1,026 tests: 1,019 passed, 1 skipped, and 7 initially failed. Building the missing companion binaries cleared five failures. The two remaining unrelated tests fail because the copied
codex-linux-sandboxcannot loadlibssl.so.3, after which their image/apply-patch operations time out; all affected lifecycle, ownership, archive, and WebSocket tests passed in that run.Related work
This independently validated patch addresses openai/codex#11324 and overlaps the CLA-blocked draft openai/codex#30985. It additionally covers race-safe ownership admission for normal turns and inline reviews, closing-boundary rejection, real automatic event delivery, and transcript-preserving cold resume.