Skip to content

Handle transient stdin reads in the safe-output transport - #65067

Merged
pelikhan merged 6 commits into
mainfrom
copilot/git-safe-output-transport-fix
Oct 2, 2026
Merged

pelikhan merged 6 commits into
mainfrom
copilot/git-safe-output-transport-fix

Conversation

Copilot AI commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Larger safe-output JSON bodies could fail with an EOF parse error and exhaust the retry limit without producing an output.

  • Transport: Retry transient EAGAIN and EINTR reads while receiving stdin, with a bounded wait. Preserve the existing behavior for empty implicit stdin and the 10 MiB input limit.
  • Coverage: Add JSON stdin cases from empty and ~1.5 KiB bodies through multi-chunk and near-limit bodies, including a transient read between chunks.

Run: https://github.com/github/gh-aw/actions/runs/37041488340

Generated by 👨‍🍳 PR Sous Chef · pi · gpt54 · 18.3 AIC · ⌖ 8.67 AIC · ⊞ 9.7K · ◷
Comment /souschef to run again

Copilot AI changed the title [WIP] Fix safe-output transport JSON decode EOF error Handle transient stdin reads in the safe-output transport Oct 2, 2026
Copilot AI requested a review from pelikhan October 2, 2026 17:25
@pelikhan
pelikhan marked this pull request as ready for review October 2, 2026 17:26
Copilot AI balanced review requested due to automatic review settings October 2, 2026 17:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

An initial EINTR can still discard implicit piped input instead of retrying.

Review effort: Balanced
Findings: 1 Medium severity

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.

Comment on lines +670 to +678
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;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@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 pr-finisher skill before handing off.

Generated by 👨‍🍳 PR Sous Chef · pi · gpt54 · 18.3 AIC · ⌖ 8.67 AIC · ⊞ 9.7K · ◷
Comment /souschef to run again

Copilot AI commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

@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 pr-finisher ski...

Addressed in 965f469. The initial implicit EINTR now retries within the existing bound, with regression coverage; only an initial implicit EAGAIN keeps the immediate-empty behavior.

Copilot AI requested a review from gh-aw-bot October 2, 2026 18:06
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please take another pass on this PR. Please refresh the branch if needed, address any outstanding review feedback, and then run the pr-finisher skill before handing back to maintainers.

Generated by 👨‍🍳 PR Sous Chef · pi · gpt54 · 22.3 AIC · ⌖ 8.59 AIC · ⊞ 9.4K · ◷
Comment /souschef to run again

Copilot AI commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please take another pass on this PR. Please refresh the branch if needed, address any outstanding review feedback, and then run the pr-finisher skill before handing back to maintainers.

...

The branch already includes the EINTR fix and regression test in 965f469; I confirmed the PR base commit is an ancestor and no refresh or further code change is needed. make fmt, make lint, make test-unit, make test, make recompile, and the targeted bridge suite passed. The review thread is outdated and already has a substantive reply; this environment does not expose a thread-resolution action, so it remains unresolved.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please take another pass on this PR. Please refresh the branch if needed, address any outstanding review feedback, and then run the pr-finisher skill before handing back to maintainers.

Generated by PR Sous Chef for #65067: Handle transient stdin reads in the safe-output transport

Generated by 👨‍🍳 PR Sous Chef · pi · gpt54 · 27.1 AIC · ⌖ 8.64 AIC · ⊞ 9.7K · ◷
Comment /souschef to run again

@pelikhan

pelikhan commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

/matt

Copilot AI commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please take another pass on this PR. Please refresh the branch if needed, address any outstanding review feedback, and then run the pr-finisher skill before handing back to maintainers.

Ge...

I rechecked PR #65067: it is open, the head remains 965f469, and the base commit is already included, so no refresh or code change is needed. The initial EINTR finding is fixed with regression coverage; its outdated thread already has a substantive reply, but this toolset still exposes no thread-resolution action. Prior local validation passed on this same head. In this pass, make agent-finish reached passing tests and compiled 301 workflows, then stalled at npm install --package-lock-only; I stopped it and reverted its incidental generated files. Current Copilot review is still in progress, and CI must be rerun by a maintainer after handoff.

@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@pelikhan
pelikhan merged commit 85fb425 into main Oct 2, 2026
16 checks passed
@pelikhan
pelikhan deleted the copilot/git-safe-output-transport-fix branch October 2, 2026 20:09

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 idleSince timeout (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 EAGAIN when stdin was explicitly requested (waitForData=true) — isn't directly exercised. Existing tests either don't throw EAGAIN on the first read, or test the implicit (waitForData=false) path.

Positive Highlights

  • ✅ Correctly narrows the "return empty immediately" fast-path to EAGAIN only (not EINTR), 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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/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));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/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.

@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.90.3

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.

safe-output transport JSON decode fails with EOF parse error on larger bodies; retry limit exhausted

4 participants