Repository navigation
fix(cli): exit quietly when --completion's reader closes early - #2700
Merged
Merged
Conversation
`mcp-inspector --cli --completion <shell>` wrote its script through awaitableLog with no stdout 'error' listener, so a reader that closed the pipe first (`| head`, bash 3.2's `source <(…)`) crashed the CLI with an unhandled `write EPIPE`. The script write now treats EPIPE as a normal end and rejects any other stdout error into the CLI's error path, reusing the consume-outcome stream's isBrokenPipe. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
There was a problem hiding this comment.
🟢 Approval recommended
The focused fix correctly handles write errors and includes comprehensive regression coverage.
0 open findings
What changed in this PR
Fixes CLI completion output so closed pipes exit quietly while other stdout failures follow the normal error path.
Changes:
- Adds EPIPE-aware completion output handling.
- Reuses the existing broken-pipe predicate.
- Adds unit and subprocess regression coverage.
| File | Description |
|---|---|
clients/cli/src/handlers/consume-outcome.ts |
Exports the shared EPIPE predicate. |
clients/cli/src/completion.ts |
Handles stdout errors during completion writes. |
clients/cli/__tests__/completion.test.ts |
Tests EPIPE, other errors, and listener cleanup. |
clients/cli/__tests__/e2e.test.ts |
Verifies quiet exit with closed stdout. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Member
Author
|
Copilot review loop closed: round 1 came back clean (0 open findings, no inline comments, nothing suppressed), so no further round was requested. |
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.
Closes #2646
What
mcp-inspector --cli --completion <shell>wrote its script throughawaitableLog, which attaches no stdout'error'listener. When the reader closed the pipe first, Node raised an unhandled'error'event (write EPIPE) and printed a stack trace. Both| headand bash 3.2'ssource <(…)close the pipe early.Change
clients/cli/src/completion.ts: the script is now written bywriteCompletion, which attaches aonce('error')listener for the duration of the write. EPIPE resolves as a normal end. Any other stdout error rejects into the CLI's error path. The listener stays attached after a failed write because Node calls the write callback first and emits'error'afterwards; since it is aonce, that emit removes it.clients/cli/src/handlers/consume-outcome.ts: exports the existingisBrokenPipeso both paths use the same EPIPE predicate.Tests
completion.test.ts: EPIPE resolves and leaves no listener behind; a non-EPIPE error rejects; a successful write detaches its listener.e2e.test.ts: spawns the built binary with its stdout read end already closed and asserts exit 0 with empty stderr. Before the fix this test failed withError: write EPIPE; after the fix it passes.node clients/cli/build/index.js --completion bash | head -1) now prints the first line and nothing else.npm run local:gateis green.🤖 Generated with Claude Code