Skip to content

Reduce ProcessRunner to the run methods and teardown its callers use - #196

Merged
lynnswap merged 9 commits into
mainfrom
refactor/process-runner
Nov 20, 2026
Merged

lynnswap merged 9 commits into
mainfrom
refactor/process-runner

Conversation

@lynnswap

@lynnswap lynnswap commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Summary

Reduces ProcessRunner to what its callers use. CommandRunning loses runStreaming, the four run methods share one launch and error-mapping path, and process-group teardown shrinks from a proc_listpgrppids inspection to one waitid and a kill loop. ProcessRunner.swift goes from 1,510 to 926 lines; BoundedProcessOutput and its collector are unchanged.

Details

  • CommandRunning: runStreaming is removed, and runBuffered becomes a requirement instead of defaulting to it. No other method changes, and nothing under Sources/PrivateHeaderKitCLI is touched. The test doubles change only for that: RecordingCommandRunner.runStreaming is renamed to runBuffered (its setStreamingHandler and streamingCommandSnapshot keep their names), and the two private runners in PrivateHeaderKitCLITests.swift drop or rename their runStreaming.
  • The runner still kills the process group itself. swift-subprocess 1.0.0 stops its teardown sequence when the group leader exits and runs none when the leader exits by itself, so a descendant that ignores SIGTERM survives both cancellation and a normal exit. With the kill disabled, six of the existing process-group tests fail.
  • The kill now starts when the leader exits, in a task that runs beside the output handling, instead of after the output has ended. A descendant that keeps writing can no longer hold a run open. The exited leader stays unreaped until that task finishes, as before, so its PID cannot name another group while the group is signaled.
  • runSimple lets the child write to the CLI's standard output directly, which replaces the DispatchIO writer. The child's standard error no longer appears on standard output. It is collected, bounded, and included in the thrown error. The affected commands are simctl bootstatus, simctl delete, tar, the SSH maintenance scripts, and scripts/build-release.sh in a checkout.
  • Output loops read to the end of the stream instead of throwing out of the loop, because swift-subprocess closes the pipe only when the stream ends. A chunk consumer that fails or is cancelled stops the child and the rest of the output is discarded.
  • terminationObservedAtUnixEpochMicroseconds comes from Date; the injected clock and its overflow checks are gone.
  • No longer reported: a kill that fails with EPERM because a live group member runs with other credentials. The old code inspected the group to tell that apart from a group of zombies and threw. Every command the CLI runs executes as the invoking user, and neither they nor the repository's scripts use sudo or a setuid tool.
  • No longer rejected: runSimple when the CLI's standard output is closed. The old writer failed on dup before launching.
  • runInteractive and runWithInputFile now try each PATH candidate like the other methods. Their callers pass /usr/bin/script and ssh.

Testing

  • swift test: all six test bundles pass locally with main merged in, and the package's full test scheme passes through xcodebuild on a second macOS host (** TEST SUCCEEDED **). The runner tests passed in 10 consecutive runs. GitHub CI passed on the head before main was merged in; this PR was merged without waiting for the busy CI queue on the final head.
  • A Foundation generation on macOS 27.2.1 completes (1,025 files), and one through simctl spawn on an iOS 27.2 simulator completes.
  • SIGINT while the host raw helper runs: the CLI exits within 0.2 s with status interrupted and no helper process remains.
  • SIGINT while simctl spawn runs the Simulator helper: the CLI exits within 0.1 s, and neither simctl nor the helper under launchd_sim remains.
  • Eight failed chunk consumers, eight cancelled runBuffered calls, and eight cancelled runCaptureChunks calls leave the number of open descriptors unchanged.
  • Local Codex review, nine rounds: the fixes are the cancellation checks, the read-to-end loops, the concurrent group kill, and reporting a failed terminal restoration on cancellation. Left as is: the two items listed above as no longer reported or rejected, and the blocking waitid on a global queue, which holds one thread per running command while the CLI runs its commands one at a time.
  • Not verified: SSH generation and Ghidra decompilation against real peers and tools.

🤖 Generated with Claude Code

lynnswap and others added 7 commits November 20, 2026 09:29
swift-subprocess ends its teardown sequence when the group leader exits and
runs none when the leader exits by itself, so the runner still kills what is
left of the process group. It now does that with one waitid and a kill loop.

runSimple lets the child write to standard output itself and reports the
child's bounded standard error on failure, which replaces the DispatchIO
writer.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
…the chunk consumer

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
…open

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
swift-subprocess closes a streamed pipe only when its sequence ends. A failed
or cancelled chunk consumer now stops the child and discards the rest.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
…ends

A descendant that keeps writing would otherwise hold the run open. Terminal
state and the input file are now handled around the spawn itself, after the
command has been validated.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
… cancelled

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T04:10:16.309462Z 6a53021 Manual request
🔒 Security Review ✅ Completed 2026-11-20T01:02:04.641497Z a9ce952 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@lynnswap lynnswap left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 6a53021a9b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@lynnswap
lynnswap merged commit 1235f90 into main Nov 20, 2026
4 checks passed
@lynnswap
lynnswap deleted the refactor/process-runner branch November 20, 2026 04:32
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.

Simplify subprocess execution in ProcessRunner

1 participant