Repository navigation
Handle transient stdin reads in the safe-output transport - #65067
Conversation
Co-authored-by: pelikhan <[email protected]>
Co-authored-by: pelikhan <[email protected]>
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
An initial EINTR can still discard implicit piped input instead of retrying.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Improves safe-output stdin handling for transient reads and larger JSON payloads.
Changes:
- Retries transient stdin errors with a bounded wait.
- Adds multi-chunk and near-limit payload tests.
| File | Description |
|---|---|
actions/setup/js/mcp_cli_bridge.cjs |
Adds transient-read retry handling. |
actions/setup/js/mcp_cli_bridge.test.cjs |
Covers varied payload sizes and interrupted reads. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| if (err && typeof err === "object" && (err.code === "EAGAIN" || err.code === "EINTR")) { | ||
| if (totalBytes === 0 && !waitForData) return ""; | ||
| if (Date.now() - idleSince >= 30000) { | ||
| throw new Error("timed out waiting for stdin input", { cause: err }); | ||
| } | ||
| // Pipes may be nonblocking; a temporary lack of data is not EOF. | ||
| Atomics.wait(retryWait, 0, 0, 10); | ||
| continue; | ||
| } |
There was a problem hiding this comment.
Fixed in 965f469: implicit stdin now retries an initial EINTR within the bounded wait; only an initial implicit EAGAIN returns empty immediately. Added a regression test for EINTR followed by EAGAIN before the JSON payload.
|
@copilot Copilot review found an open issue: retry EINTR instead of treating the interrupted stdin read as empty input. Please address the unresolved review feedback and then run the
|
Co-authored-by: gh-aw-bot <[email protected]>
Addressed in |
|
@copilot Please take another pass on this PR. Please refresh the branch if needed, address any outstanding review feedback, and then run the
|
The branch already includes the EINTR fix and regression test in |
|
@copilot Please take another pass on this PR. Please refresh the branch if needed, address any outstanding review feedback, and then run the Generated by PR Sous Chef for #65067: Handle transient stdin reads in the safe-output transport
|
|
/matt |
I rechecked PR #65067: it is open, the head remains |
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /tdd — the fix itself is sound and the prior EINTR/implicit-stdin bug flagged in earlier review comments is correctly resolved in 965f469. Requesting changes only for test coverage gaps on the new retry/timeout paths.
📋 Key Themes & Highlights
Key Themes
- Untested timeout branch: the new 30s
idleSincetimeout (the actual "bounded wait" promised in the PR description) has no test driving it; a regression here would hang the bridge silently. - Untested core behavior change: the PR's headline fix — retrying an initial
EAGAINwhen stdin was explicitly requested (waitForData=true) — isn't directly exercised. Existing tests either don't throwEAGAINon the first read, or test the implicit (waitForData=false) path.
Positive Highlights
- ✅ Correctly narrows the "return empty immediately" fast-path to
EAGAINonly (notEINTR), fixing the real bug called out in prior inline review comments. - ✅ Good size-parameterized coverage (
1,1543,4004,65537, up to near the 10 MiB limit) for chunked reads. - ✅ Preserves existing partial-read-then-error semantics (rethrow vs. empty) without regressing prior tests.
See inline comments for suggested test additions.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · sonnet50 · 87.1 AIC · ⌖ 14.8 AIC · ⊞ 10K
Comment /matt to run again
| } catch (err) { | ||
| if (err && typeof err === "object" && (err.code === "EAGAIN" || err.code === "EINTR")) { | ||
| if (err.code === "EAGAIN" && isFirstRead && !waitForData) return ""; | ||
| if (Date.now() - idleSince >= 30000) { |
There was a problem hiding this comment.
[/tdd] The 30s timeout branch (Date.now() - idleSince >= 30000) is new behavior but has no regression test — none of the added cases drive idleSince stale enough to hit this path.
💡 Suggested test
Use vi.useFakeTimers() with vi.advanceTimersByTime (or mock Date.now) around a persistent EAGAIN/EINTR loop to assert readStdinSync eventually throws /timed out waiting for stdin input/. Without this, a future refactor could silently break the timeout guard and hang the bridge for 30s per invocation without anyone noticing in CI.
@copilot please address this.
| }); | ||
|
|
||
| try { | ||
| expect(parseToolArgs(["."], { body: { type: "string" } }, readStdinSync()).args.body).toBe("x".repeat(bodySize)); |
There was a problem hiding this comment.
[/tdd] None of the new cases cover the core guarantee this PR adds: an explicit stdin request (waitForData=true) that gets EAGAIN on the first read should retry instead of returning "". The size-parameterized tests never throw, and the EINTR test's first failure is EINTR, not EAGAIN.
💡 Suggested test
it("retries an initial EAGAIN when stdin was explicitly requested", () => {
const payload = Buffer.from(JSON.stringify({ body: "explicit stdin" }));
let callCount = 0;
const readSyncSpy = vi.spyOn(fs, "readSync").mockImplementation((_fd, buf, _offset, length) => {
callCount += 1;
if (callCount === 1) throw Object.assign(new Error("resource temporarily unavailable"), { code: "EAGAIN" });
if (callCount === 2) { payload.copy(buf, 0, 0, payload.length); return payload.length; }
return 0;
});
try {
expect(parseToolArgs(["."], { body: { type: "string" } }, readStdinSync(true)).args.body).toBe("explicit stdin");
} finally {
readSyncSpy.mockRestore();
}
});Without this, a regression that re-couples the waitForData early-return to EAGAIN (undoing the very fix this PR makes) would pass the current suite silently.
@copilot please address this.
|
🎉 This pull request is included in a new release. Release: |

Larger safe-output JSON bodies could fail with an EOF parse error and exhaust the retry limit without producing an output.
EAGAINandEINTRreads while receiving stdin, with a bounded wait. Preserve the existing behavior for empty implicit stdin and the 10 MiB input limit.Run: https://github.com/github/gh-aw/actions/runs/37041488340