named-gate child that exits early is misreported as EPIPE (flaky named-gate-diagnostics test)

Closed
RA
2mo ago
+19-1

Summary

Closes #598

Fix word_count_bounds diagnostics incorrectly reporting EPIPE when the child process exits non-zero after closing stdin.

Problem

When wc exits before consuming all of its stdin, Node's spawnSync can set result.error to EPIPE even though the child process has a valid exit status.

Previously, result.error was checked first, so a child that exited with code 2 could incorrectly produce:

word_count_bounds: could not run wc -w: EPIPE

This masked the actual child exit status.

Changes

  • Check result.signal first to preserve signal diagnostics.
  • Check result.status before result.error.
  • Only use result.error when the child has no exit status (status === null).
  • Added a regression test where the stub wc exits with code 2 without reading stdin.
  • The test uses 100,000 bytes of input to trigger the EPIPE condition.

Verification

  • npx vitest run tests/named-gate-diagnostics.test.ts
    • 18/18 tests passed
  • npm run build passed
  • npm run typecheck passed
  • npm run typecheck:tests passed
  • Mutation verification confirmed that reverting the production fix causes the new regression test to fail with EPIPE.

Expected Behavior

With the fix, a child that exits with code 2 is reported as:

word_count_bounds: wc -w exited 2

instead of incorrectly reporting:

word_count_bounds: could not run wc -w: EPIPE

[!NOTE]
Low Risk
Narrow change to error-message ordering for one named gate plus a test; no auth, data, or API surface impact.

Overview
Fixes word_count_bounds gate diagnostics so a wc -w child that exits with a real status is not mislabeled as could not run wc -w: EPIPE when Node also sets spawnSync’s error after stdin is closed early.

The lowered gate command now checks signal, then non-null exit status (including nonzero), and only falls back to result.error when status === null. A regression test stubs wc to exit 2 with large input to reproduce the flaky EPIPE case and expects exited 2 without EPIPE in stderr.

Reviewed by Cursor Bugbot for commit 48e94b2e386641044989ef2dfe98b0d30ae09b20. Bugbot is set up for automated code reviews on this repo. Configure here.


Summary by cubic

Fixes word_count_bounds diagnostics misreporting EPIPE when a child process exits non-zero after closing stdin. The fix checks signal first, then the exit status, and only uses spawnSync's error when the child has no exit status.

  • A child exiting with code 2 is now reported as wc -w exited 2 instead of could not run wc -w: EPIPE.
  • Adds a regression test using a stub wc that exits 2 without reading 100,000 bytes of stdin.