[app-server] Reap orphaned idle threads on websocket disconnect#14997
Closed
cooper-oai wants to merge 3 commits intomainfrom
Closed
[app-server] Reap orphaned idle threads on websocket disconnect#14997cooper-oai wants to merge 3 commits intomainfrom
cooper-oai wants to merge 3 commits intomainfrom
Conversation
…hanged_files] Co-authored-by: Codex <noreply@openai.com>
91641c5 to
2779ade
Compare
Contributor
|
Closing this pull request because it has had no updates for more than 14 days. If you plan to continue working on it, feel free to reopen or open a new PR. |
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.
Summary
Today, switching threads over websocket can leave the previous thread loaded even after it has no subscribers. Because local stdio MCP servers are thread-scoped, those orphaned loaded threads keep their helper processes alive. Repeating that across many threads causes process-count and memory growth, which matches the original report (
31local kepler processes and multi-GB RSS after repeated thread switching).This change keeps the fix intentionally narrow:
Side effect to be aware of: if the last client disconnects from an idle thread, app-server now closes that thread instead of keeping it loaded in memory. If someone opens that thread again later, it still resumes from saved history, but reopening may be a little slower because the thread and its MCP helper processes start again.
Out of scope for this PR:
Validation
bazel test //codex-rs/app-server:app-server-all-testI also ran a manual before/after reproduction of the reported leak using a temporary integration harness with a local stdio MCP helper.
Workload:
thread/loaded/list, live MCP helper count, and helper RSS.Measured results:
origin/main: leaked one loaded thread and one live MCP helper per switch; after 15 switches the server still had15loaded threads and15live helpers, with helper RSS growing to about104.6 MB0and live helper count returned to0; after 15 switches the server finished with0loaded threads and0live helpersThat before/after experiment is the closest reproduction of the original user report, and it shows this scoped change stops the linear thread/process accumulation during left-nav thread switching.
Follow-ups