Make StdioTransport accept Flow<String> + suspend writer#100
Merged
Conversation
anna239
requested changes
May 20, 2026
Promote the Flow-based pair to the primary constructor and keep the existing Source/Sink one as a back-compat secondary, marked @deprecated: the blocking variant pins a dispatcher thread per readLine and would saturate the I/O pool under high agent concurrency. Fix close() to cancel childScope. Previously close() only closed the channels and invoked closeHandler; the Source/Sink path worked because closing the underlying streams unblocked readLine, but the Flow path has no equivalent unblock — close() would leave the read job parked inside input.collect and the transport stuck in CLOSING. Cancelling childScope cooperatively unwinds the collect, the read job exits, joinAll returns, and the finally block sets state to CLOSED. The Source/Sink path is unaffected (the cancel is a no-op once the job has already exited). Add StdioTransportFlowTest covering the new primary path: round-trip send/receive, JSON-skip behaviour, input-flow completion, input-flow errors, the output exception contract (IOException = clean, anything else = onError), parent-scope cancellation, and the close-deadlock regression itself. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
anna239
approved these changes
May 20, 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.
Promote the Flow-based pair to the primary constructor and keep the existing Source/Sink one as a back-compat secondary, marked @deprecated: the blocking variant pins a dispatcher thread per readLine and would saturate the I/O pool under high agent concurrency.
Fix close() to cancel childScope. Previously close() only closed the channels and invoked closeHandler; the Source/Sink path worked because closing the underlying streams unblocked readLine, but the Flow path has no equivalent unblock — close() would leave the read job parked inside input.collect and the transport stuck in CLOSING. Cancelling childScope cooperatively unwinds the collect, the read job exits, joinAll returns, and the finally block sets state to CLOSED. The Source/Sink path is unaffected (the cancel is a no-op once the job has already exited).
Add StdioTransportFlowTest covering the new primary path: round-trip send/receive, JSON-skip behaviour, input-flow completion, input-flow errors, the output exception contract (IOException = clean, anything else = onError), parent-scope cancellation, and the close-deadlock regression itself.