Harden sample replay JSON-RPC framing and move shim logs off stdout#37528
Merged
Conversation
Co-authored-by: dsyme <7204669+dsyme@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix apply_samples.cjs crash when parsing stdout
Harden sample replay JSON-RPC framing and move shim logs off stdout
Jun 7, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the deterministic sample replay driver (apply_samples.cjs) against non-protocol stdout output during MCP JSON-RPC exchanges, and adjusts the GitHub Actions core.* shim so diagnostic logging won’t corrupt JSON-RPC framing when MCP servers speak over stdout.
Changes:
- Redirected shimmed
core.*logging inactions/setup/js/shim.cjsfromconsole.*(stdout-mixed) toprocess.stderr.write(...)to keep stdout protocol-safe. - Made
apply_samples.cjs::sendJsonRpcmore defensive by skipping non-JSON lines and surfacing targeted parse errors. - Added focused unit tests for
sendJsonRpcbehavior around interleaved debug lines and malformed JSON frames.
Show a summary per file
| File | Description |
|---|---|
| actions/setup/js/shim.cjs | Routes shim core.* logs to stderr to avoid stdout protocol corruption for JSON-RPC-speaking processes. |
| actions/setup/js/apply_samples.cjs | Makes JSON-RPC response parsing more resilient to non-JSON stdout lines and improves parse error reporting. |
| actions/setup/js/apply_samples.test.cjs | Adds unit tests covering the new sendJsonRpc framing/parse defenses. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 3/3 changed files
- Comments generated: 1
Comment on lines
+183
to
+193
| if (!line.startsWith("{")) { | ||
| core.debug(`apply_samples: ignoring non-JSON stdout line: ${line}`); | ||
| continue; | ||
| } | ||
| try { | ||
| return JSON.parse(line); | ||
| } catch (err) { | ||
| throw new Error( | ||
| `apply_samples: failed to parse MCP JSON-RPC response for request id=${request.id}: ${getErrorMessage(err)} (line: ${line})` | ||
| ); | ||
| } |
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.
apply_samples.cjscould crash during sample replay when the safe-outputs MCP path emitted[debug] ...lines on stdout, causingsendJsonRpcto parse non-JSON text as a protocol frame. This blocked--use-samplesreplay for PR-creating tools.Protocol-safe logging for shimmed actions context
actions/setup/js/shim.cjsso shimmedcore.*logging writes tostderrviaprocess.stderr.write(...)instead of console stdout paths.Defensive JSON-RPC parsing in replay driver
actions/setup/js/apply_samples.cjs::sendJsonRpcto read line-by-line until a JSON object frame is found.Focused regression coverage
sendJsonRpcunit tests inactions/setup/js/apply_samples.test.cjsfor: