Repository navigation
fix(mcp): exit the MCP bridge once its client is gone - #282
Merged
Merged
Conversation
Problem: the bridge noticed a departed client only when a later write to stdout failed, or after stdin EOF once the app closed the socket. A client that stopped reading, or died while its pipes stayed open, left the bridge running and connected to Chau7 indefinitely. Decision: a watcher thread checks every 2 s whether stdout's reader hung up (poll POLLHUP/POLLERR) or the bridge was reparented to launchd (its parent died), and exits in either case. An idle client that keeps its pipes open keeps its bridge. Rationale: the bridge must not outlive its client, but Codex's app server keeps loaded threads' MCP servers idle on purpose; exiting on idleness would break the next tool call of a resumed thread. Validation: new unit test for the decision and an integration test that runs the real binary against a server that never closes, closes the client's stdout with stdin still open, and requires the bridge to exit (it does in about 2 s; previously it never exited). Clippy and fmt clean. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Exit the MCP bridge when its client goes away; restore traffic lights inside the tab bar
Problem: the bridge noticed a departed client only when a later write to
stdout failed, or after stdin EOF once the app closed the socket. A
client that stopped reading, or died while its pipes stayed open,
left the bridge running and connected to Chau7 indefinitely.
Decision: a watcher thread checks every 2 s whether stdout's reader hung
up (poll POLLHUP/POLLERR) or the bridge was reparented to launchd (its
parent died), and exits in either case. An idle client that keeps its
pipes open keeps its bridge.
Rationale: the bridge must not outlive its client, but Codex's app
server keeps loaded threads' MCP servers idle on purpose; exiting on
idleness would break the next tool call of a resumed thread.
Changes
Checklist
pnpm quality:prepushpasses, orpnpm quality:prepush:fullfor high-impact changescargo test --workspacepasses inapps/chau7-next(if macOS app changes)swift test --package-path apps/chau7-ios/Chau7Corepasses (if Swift changes)Test plan
new unit test for the decision and an integration test that
runs the real binary against a server that never closes, closes the
client's stdout with stdin still open, and requires the bridge to exit
(it does in about 2 s; previously it never exited). Clippy and fmt
clean.
Commits:
Opened by aethyme broker push as a draft.