Skip to content

fix: stderr is complete when a command completes, including after a deadline - #40

Merged
flyingrobots merged 4 commits into
mainfrom
fix/9-stderr-drain
Dec 1, 2026
Merged

flyingrobots merged 4 commits into
mainfrom
fix/9-stderr-drain

Conversation

@flyingrobots

Copy link
Copy Markdown
Member

Closes #9

What was already fixed on main

#30 made every runner (Node, Bun, Deno) complete through ProcessDeadline.settle, which waits for the leader's exit and for both output pipes to end, and each runner then awaits its stderr collector. So on main a normal completion already returns complete stderr even when Node delivers it after exit. The new tests prove this and stay as regression guards.

What this PR changes

After a deadline, ProcessDeadline.settle resolved on the leader's exit alone, while the pipes it had just released could still be closing. It now also waits for each released pipe's drained, which releasing makes certain (a helper holding the other end cannot hold it), and still reports timedOut: true.

Tests (test/StderrCompleteness.test.js, also wired into the Deno entry)

  • Node runner with an injected child: stderr written after exit and before close is complete, for run() and open(). Passed on main.
  • Settlement once: spawn error then exit/close; exit then a late error. Passed on main.
  • Deadline: SIGKILL to the group, leader exits while a pipe is still closing; completion waits for the close and reports timedOut: true. Failed on main (expected 1 to be +0: it settled at exit).
  • Shared contract on StoppableNodeStream (Node) and StoppableWebStream (Bun, Deno): settle does not resolve until late stderr has ended. Passed on main; fails if settle stops waiting for drained (mutation checked).
  • Real processes on each runtime: 4 rounds of 32 concurrent git rev-parse failures outside a repository, and 4 rounds of 32 sh children writing 8 KiB to stderr just before exit 128. Stderr must match exactly.

Docs: docs/CUSTOM_RUNNERS.md now states that stderr must be complete when exitPromise resolves. CHANGELOG entry under Unreleased / Fixed.

Covers #9. A Node child whose stderr arrives after its
exit event, settlement once across error, exit and close, the shared
ProcessDeadline contract on Node and Web stream views, and a real-process
stress run of concurrent short failures. Only the deadline case fails:
after a timeout the completion resolves before the killed child's pipes
have closed.

Refs #9
ProcessDeadline already waited for both pipes to end before resolving a
normal completion, so stderr was complete when exitPromise resolved on
Node, Bun and Deno. After a deadline it resolved on the leader's exit
alone, while the pipes it had just released could still be closing. It
now waits for each released pipe to close too, which releasing makes
certain, and still reports timedOut: true.

Documents that stderr must be complete when exitPromise resolves.

Closes #9
@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: ee8a5f9c-9fc0-44bb-a1b2-d5cb416604f4
Commits

Reviewing files that changed from the base of the PR and between 950f143 and 6e32282.

Files selected for processing: 5

  • CHANGELOG.md
  • docs/CUSTOM_RUNNERS.md
  • src/infrastructure/ProcessDeadline.js
  • test/StderrCompleteness.test.js
  • test/deno_entry.js
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@flyingrobots

Copy link
Copy Markdown
Member Author
  1. R1 · P2 · test/StderrCompleteness.test.js:286-291 — Pin the locale before asserting Git’s exact stderr.
    The test expects an English diagnostic, but EnvironmentPolicy preserves inherited LANG, LC_ALL, and LC_MESSAGES, and this invocation supplies no locale override. On a machine with a supported non-English locale and Git translations installed, Git returns its complete, correctly translated stderr and the test fails. Pass env: { LC_ALL: 'C' } to this invocation so the expected bytes are independent of the host’s locale.

  2. R2 · P2 · test/StderrCompleteness.test.js:65-68 — Bound the condition polling so a settlement regression fails instead of hanging Deno.
    until() polls forever, and the new tests await it both for deadline teardown at line 183 and for completion at line 225. The Deno entry imports these tests through deno_shim.js, which supplies no per-test timeout. If a regression prevents stop() from initiating destruction or prevents drained from settling, the test keeps scheduling timers indefinitely and the Deno run never finishes. Add a bounded failure deadline with a useful diagnostic and clean up outstanding controlled streams in finally. The expected outcome can remain condition-based; the bound should terminate a broken implementation.

Reviewed git diff origin/main...HEAD and the surrounding implementation needed to assess that change. No tests were run. I found no additional concrete production correctness defect introduced by the runtime change.

VERDICT: CHANGES_REQUIRED

@flyingrobots

flyingrobots commented Dec 1, 2026 •

Copy link
Copy Markdown
Member Author

Footprint

5 files, +346/-6 · origin/main...origin/fix/9-stderr-drain

Structural, as graft struct review reads it: 0 files changed shape (+0/-0/~0 symbols), 2 labelled formatting.

  • graft's label, not footprint's claim: it saw no symbol added, removed or changed in src/infrastructure/ProcessDeadline.js, test/deno_entry.js. A changed value inside an existing symbol (a rule table, a constant) can carry that label, so read the diff.

  • No symbol was added, removed or changed. Nothing's public shape moved.

Composition
pie showData
    title Changed lines by file kind
    "source" : 19
    "test" : 325
    "docs" : 8
Loading
Kind Files +/- Share
source 1 +15/-4 5.4%
test 2 +325/-0 92.3%
docs 2 +6/-2 2.3%
total 5 +346/-6 100%
Files (5)

docs

  • CHANGELOG.md +1/-0
  • docs/CUSTOM_RUNNERS.md +5/-2

source

  • src/infrastructure/ProcessDeadline.js +15/-4

test

  • test/StderrCompleteness.test.js +324/-0
  • test/deno_entry.js +1/-0

Figures computed from git diff --numstat. Composition is a sanity check, not a verdict.

Before merge

  • 1 changed file match the guard rule: CHANGELOG.md (version).

After merge

No landing steps are declared: RELEASE.md is absent; AGENTS.md is absent. footprint states none rather than inventing them.

After-merge steps are read from this repository's own RELEASE.md and AGENTS.md, never invented. The guard rule is path patterns, documented in footprint's docs/topics/landing/README.md.

Blast radius

+0 added / -0 removed / ~0 signature-changed exported symbols · 950f1438554b4914f0c85fa5179e805960db3e81 → 6e32282a3529ae8b1cec083e4a1e53e71aafbdb9 · graft struct exports reads this as a none change

  • No exported symbol was added, removed or re-signed.

Exported symbols from graft struct exports --json (graft.cli.struct_exports 1.0.0). Whatever graft parses counts as an export surface, including fields in config and lock files.

Call sites are footprint's own whole-word identifier scan, not graft's: every whole-word occurrence of the name in the tracked, non-binary files of the working tree (grep -w's boundary -- a letter, digit or underscore in any script). It counts the declaration itself and a mention in a comment, a string or prose, and it cannot see a call through dynamic dispatch or a re-export under another name. Evidence to check, not a call graph.

The grouping. A system is the first path segment of a call site's repository-relative path: the directory immediately under the repository root, however deep the file sits inside it. A file at the repository root has no such segment and is grouped under (unassigned), which is listed last and never dropped. Systems are ordered by name so the grouping follows the tree rather than the order the scan found the sites in. The mitigations. Every row's mitigation is derived from two reported facts about that call site and nothing else: whether it is in the very file the symbol is exported from, and what classify() calls that file. A call site in the symbol's own declaring file, or in a test file, is "None needed"; any other call site states the system it is in, or that it is outside every known system. No mitigation is a judgement about importance, risk or coverage, and none is advice: footprint reports and does not judge (AGENTS.md).

Every changed source file was in a language footprint recognises graft's grammars can parse.

Open pull requests

No other pull request is open, so nothing can overlap this change.

Proposed merge order (1 wave)

Wave 1 — #40

No two open pull requests change the same file, so they can land in any order.

Pull requests from gh pr list; their files from gh pr diff --name-only; the symbols of a shared file from git diff -U0 against each side's merge base and the top-level symbols of graft read outline at both ends (0 of at most 24 outline calls this run). Merge waves are greedy first-fit over the conflict graph: a proposal, not a minimum, and not a gate.

Changelog
Timestamp SHA Change Reason Remarks
2026-12-01T08:12:26Z d7bd080 First report: 5 files, +333/-6; no export added, removed or re-signed Pull request opened No call sites to assess: no export moved
2026-12-01T08:17:01Z 6e32282 Test-only changes: locale pinned; git case compared with a baseline; still no export moved Review fix No call sites to assess: no export moved

@flyingrobots

Copy link
Copy Markdown
Member Author

Response to automated review round 1

R1 (P2, locale): accepted, fixed. The git stress case now passes env: { LC_ALL: 'C' } (LC_ALL is an allowed per-call override in EnvironmentPolicy), so the expected English message no longer depends on the host locale. RED could not be shown in the Docker images: they generate no non-English locale, so git falls back to its untranslated text there; the defect is real on a developer host with translations installed.

R2 (P2, unbounded until()): rebutted. The repository deliberately waits on conditions, never on durations, so that a regression hangs a test rather than passes it on a timing guess. The same unbounded helper is already used in test/NodeProcessGroupSignals.test.js (until) and test/ProcessGroupDeadline.test.js (untilExited, untilExists, whose header says "a process that survives hangs the test"). Under vitest and bun test the 5 s default per-test timeout bounds every one of these; under Deno the run is bounded by the CI job timeout. Adding a wall-clock bound to only these new tests would diverge from that convention without adding coverage; if per-test bounds on Deno are wanted, that belongs in test/deno_shim.js for every test, as a separate change.

The runner passes LANG and LC_* through, so a host with git translations
would return a translated, complete message and fail the exact match.

Refs #9
@flyingrobots

Copy link
Copy Markdown
Member Author

Correction to my R2 rebuttal: ci.yml sets no timeout-minutes, so on Deno a hang is bounded only by GitHub's 6-hour job default, not a tight CI bound. The rebuttal still stands on the repository's convention (condition waits shared by NodeProcessGroupSignals and ProcessGroupDeadline tests); a bound for Deno belongs in test/deno_shim.js or the workflow, for every test, as its own change.

The expected text no longer depends on how git discovers a repository
from the temporary directory (a tmpfs mount changes the message). A
failing read in a fresh repository takes no lock, so every concurrent
failure must match the stderr of one run alone.

Refs #9
@flyingrobots

Copy link
Copy Markdown
Member Author
  • R3 · P2 · test/StderrCompleteness.test.js:293 — The expected Git diagnostic depends on the temporary directory’s filesystem.
    Failure scenario: On a machine where os.tmpdir() is on a separate filesystem, such as /tmp mounted as tmpfs, Git stops repository discovery at that mount boundary. It reports “not a git repository (or any parent up to mount point …)” followed by the filesystem-boundary explanation, rather than the exact string asserted here. All concurrent commands can return complete, correct stderr and the test still fails. LC_ALL=C fixes localization but does not fix this separate dependency on filesystem layout. Use a command with deterministic diagnostics independent of parent-directory discovery, or validate the diagnostic while comparing its complete output against an independently captured baseline.

Reviewed git diff origin/main...HEAD at 01b458fdf8117ee3f7b8f80895af3a9c609e52a8. No test suite was run. No additional runtime correctness findings identified. R1 is fixed; R2 is not re-raised.

🎬 plumbing review 🟡 100% (1/1) [plumbing:🟡]
→ no change

VERDICT: CHANGES_REQUIRED

@flyingrobots

Copy link
Copy Markdown
Member Author

Response to automated review round 2

R3 (P2, git diagnostic depends on tmpdir filesystem): accepted, fixed. The git stress case now runs git show-ref --verify refs/stunts/missing inside a fresh repository, so no parent-directory discovery is involved, and compares every concurrent failure with the stderr of one run alone (asserted nonzero exit and that it names the ref). A guarded update-ref was considered and rejected: concurrent runs race on the ref's lock file and can legitimately report a different diagnostic. Not reproducible in the Docker images (/tmp is on the overlay root there), so no RED run; the fix removes the dependency.

@flyingrobots

Copy link
Copy Markdown
Member Author

No findings requiring changes in git diff origin/main...HEAD.

The deadline path now waits for the leader’s exit and both output drained promises after stopping the pipes. The built-in Node and Web stream wrappers support that sequence, and the runners await stderr collection before returning the completion record. I found no introduced settlement race, stream or process leak, hang, unhandled error, or API contract break.

The added tests cover late stderr for commands and sessions, competing process events, delayed pipe closure after a deadline, Node and Web stream completion, and concurrent subprocess failures. R1 and R3 are addressed by the locale override and fresh-repository baseline. I found no new argument for reopening R2. The documentation and CHANGELOG match the changed behavior.

Review was static. I did not run the test suite. git diff --check origin/main...HEAD passed, and the working tree remained unchanged.

🎬 plumbing review 🟢 100% (1/1) [plumbing:🟢]
→ no change

VERDICT: APPROVE

@flyingrobots
flyingrobots merged commit bd1d2a7 into main Dec 1, 2026
3 checks passed
@flyingrobots
flyingrobots deleted the fix/9-stderr-drain branch December 1, 2026 08:18
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.

NodeShellRunner can resolve before stderr drains

1 participant