fix: propagate input stream errors through ndJsonStream#111
Merged
benbrandt merged 3 commits intoagentclientprotocol:mainfrom Apr 8, 2026
Merged
Conversation
The readable stream returned by ndJsonStream used try/finally, which swallowed errors from the underlying input stream. When the input errored (e.g. a child process crash), the readable stream would close cleanly instead of erroring, causing the Connection to treat it as a normal shutdown rather than propagating the error to pending requests. Changed to try/catch/finally so that input stream errors are forwarded via controller.error(), allowing Connection.#receive() to capture the error and reject all pending requests with the original error message. Added two tests: - Verifies ndJsonStream propagates immediate input stream errors - Verifies pending requests are rejected when input stream errors Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
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.
Problem
ndJsonStreamusestry/finallyto read from the input byte stream. When the input stream errors (e.g. a child process crashes and theReadableStreamcontroller callscontroller.error()), thefinallyblock callscontroller.close()on the output message stream, swallowing the error. This causesConnection.#receive()to see a clean EOF instead of the actual error.As a result, when a process crashes mid-connection:
sendRequest()calls hang forever (before v0.18.0) or get a generic "ACP connection closed" error (v0.18.0+) instead of the actual crash errorsignal.reason/closedpromise don't carry the original errorFix
Replace
try/finallywithtry/catch/finally:catch: callscontroller.error(err)to propagate the error to the message-levelReadableStream, then returns earlyfinally: always callsreader.releaseLock()controller.close()only runs on the success path (after the try block)Tests
Added two tests: