Skip to content

fix: wait for a plugin command's pipes to close after its exit - #6818

Merged
janicduplessis merged 1 commit into
mainfrom
fix/6803-host-exec-close
Dec 2, 2026
Merged

janicduplessis merged 1 commit into
mainfrom
fix/6803-host-exec-close

Conversation

@janicduplessis

@janicduplessis janicduplessis commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Plugin host.exec calls could return code 0 with empty stdout on Linux. In exact-offload-worker.integration.test.ts, that turned Exact's git rev-parse HEAD on its pinned checkout into an exact-tools "not at commit" refusal. The test failed the 2.3.0 release gate and Full suite on 450fd2f, even after #6815.

host.exec runs with cleanupOnExit: at the leader's exit event Stim kills its process group and then destroys the pipes. Node often sees exit before it has read what the child already wrote. #6815 put a drain before the destroy that reads event-loop turns until one turn delivers nothing. A Linux CI run with every plugin git call, drain and finish logged (run 46922914607) shows that rule doesn't hold. Every failing call logged drain turns=1 read=0 closed=false and then finish status=0 out=0B: the first turn ran before any poll had read git's 41-byte answer, so the drain stopped with the data still in the pipe.

Solution

At an exit cleanup, wait for the pipes to actually close, up to 1 s, instead of counting turns (exec.ts). The group has already been killed, so in the normal case the pipes reach EOF at once and everything the child wrote is read. One setImmediate turn after the wait lets the poll phase read what is left if the event loop stalled past the second.

host.exec keeps cleanupOnExit. Without it, a plugin command whose leader leaves a child holding its stdout would wait for that child until its timeout, even after succeeding. The new test row covers that.

Known limit: a process that escaped the group (its own session) and still holds a pipe can add its writes from that second to the output. It also makes every cleanupOnExit caller, spawnManagedCapture.finish() included, wait out that second. Shipped plugins don't do this. Exact runs only short git, bun and rustup probes, exact.mjs help and its sweep's clean through host.exec, and Godot uses none. This PR removes the #6815 test row that asserted a detached descendant's late write is left out, because the close-wait accepts it. #6816 tracks the exact-bytes question, with two designs that would return only what the leader wrote.

This is the second fix for #6803 after #6815 didn't hold on Linux, so #6815 and this PR count as one review chain under the step-back rule. A Fable consult recommended this close-wait over another drain mechanism for 2.3.0, with the detached-writer case tracked in #6816 rather than fixed here.

Test plan

  • exact-offload-worker.integration.test.ts on the Linux test (node 22) and test (node 24) jobs is the regression check. It failed 1 to 4 of its 8 tests per job with fix: keep a child's buffered output when cleanup starts at its exit #6815's drain: release gate run 46908610161, Full suite run 46908685305 and diagnostic run 46922914607.
  • exec.integration.test.ts "cleanup at leader exit": one row keeps 16 KiB that was still unread at exit, and another returns ready in well under its timeout when the leader left a child holding stdout. Both fail on the code before fix: keep a child's buffered output when cleanup starts at its exit #6815. Neither reproduces the Linux turn race on macOS.
  • Locally on macOS, the 13 test files that exercise plugin host.exec, exec.integration.test.ts, report-listing.test.ts and offload-worker-pod-rekey.integration.test.ts pass (283 tests). pnpm run lint passes.

Fixes #6803

@janicduplessis janicduplessis added area: cli packages/stim-cli, including its README and guide ci-full run the macOS, Windows, Desktop and license jobs on this pull request labels Dec 2, 2026
@janicduplessis
janicduplessis force-pushed the fix/6803-host-exec-close branch 2 times, most recently from 1761b56 to 57f536b Compare December 2, 2026 16:36
@janicduplessis janicduplessis changed the title fix: let plugin host.exec calls finish when their pipes close fix: wait for a plugin command's pipes to close after its exit Dec 2, 2026
@janicduplessis

Copy link
Copy Markdown
Collaborator Author

Review outcome for 80d074c, which has the same tree as the reviewed 57f536b. It was re-pushed only because the GitHub Actions incident dropped the first pull_request event.

@janicduplessis
janicduplessis marked this pull request as ready for review December 2, 2026 17:06
@janicduplessis
janicduplessis enabled auto-merge (squash) December 2, 2026 17:06
@janicduplessis
janicduplessis merged commit a741bbe into main Dec 2, 2026
123 of 131 checks passed
@janicduplessis
janicduplessis deleted the fix/6803-host-exec-close branch December 2, 2026 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli packages/stim-cli, including its README and guide ci-full run the macOS, Windows, Desktop and license jobs on this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

exact-offload-worker integration tests fail intermittently on test (node 24) on main

1 participant