Skip to content

Fix stdin message splitting for back-to-back newline-delimited messages#1758

Draft
garrytrinder with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-mock-stdio-response-plugin
Draft

Fix stdin message splitting for back-to-back newline-delimited messages#1758
garrytrinder with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-mock-stdio-response-plugin

Conversation

Copilot AI commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

MockStdioResponsePlugin's @stdin.body.id placeholder fails to resolve when messages arrive in the same stdin.Read buffer — e.g., a JSON-RPC notification (no id) immediately followed by a request (with id). The entire multi-message buffer was passed as a single Body to the plugin pipeline, so JSON parsing would fail or only see the first message.

Changes

  • Split buffered stdin by newlines before processing: ForwardStdinAsync now accumulates data in a StringBuilder, splits on \n, and dispatches each complete line individually through the plugin pipeline.
  • Handle partial messages: Data not terminated by a newline is carried over to the next read.
  • Safe multi-byte UTF-8 handling: Uses a stateful Decoder instead of raw Encoding.UTF8.GetString to avoid corrupting characters split across read boundaries.

Before/After

Before: a single stdin.Read returning {...notification...}\n{...request...}\n produced one StdioRequestArgs with the concatenated content as Body.

After: each newline-delimited message becomes its own StdioRequestArgs, so placeholder resolution sees the correct JSON for each message independently.

Copilot AI added 2 commits July 13, 2026 15:23
When multiple newline-delimited messages arrive in the same buffer read
(e.g., a notification followed by a request), each message is now split
and processed individually through the plugin pipeline. This ensures
that @stdin.body.id placeholders resolve correctly for each message.

Previously, the entire buffer was passed as a single Body to plugins,
causing JSON parsing to fail or only parse the first message when
multiple messages were concatenated.

Closes #1757
Copilot AI changed the title [WIP] Fix placeholder resolution in MockStdioResponsePlugin Fix stdin message splitting for back-to-back newline-delimited messages Jul 13, 2026
Copilot AI requested a review from garrytrinder July 13, 2026 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MockStdioResponsePlugin: @stdin.body.id placeholder fails to resolve when messages arrive back-to-back after an id-less message

2 participants