Fix shellper processes dying when Tower restarts (#324)#340
Merged
waleedkadous merged 5 commits intoFeb 16, 2026
Conversation
Root cause: shellper stderr was piped to Tower. When Tower exited, the pipe broke and async EPIPE errors on process.stderr (which has no error handler by default) crashed the shellper. Two-part fix: 1. session-manager: redirect shellper stderr to a log file (not a pipe), eliminating the parent→child pipe dependency 2. shellper-main: add defensive error handlers on process.stdout and process.stderr to swallow EPIPE/EBADF Also adds regression test that verifies shellper survives with both the file-based stderr approach and the error handler approach.
Force a post-break stderr write by connecting/disconnecting from the shellper socket after destroying the stderr pipe. This ensures the error handler is actually exercised. Addresses Codex review feedback on PR #340.
…lessons learned
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
process.stdout/process.stderrin shellper-main to swallow EPIPE/EBADF errorsRoot Cause
Shellper was spawned with
stdio: ['ignore', 'pipe', 'pipe']. The stderr pipe connected shellper fd 2 to Tower. When Tower exited viaprocess.exit(0), the pipe broke. On macOS,process.stderrconnected to a pipe uses async writes — the resulting EPIPE errors surfaced as unhandled'error'events on the stream, crashing the shellper process.Changes
session-manager.ts:socketPath.replace('.sock', '.log')) instead of'pipe'.logcompanion files inunlinkSocketIfExistsandcleanupStaleSocketslogStderrTail)shellper-main.ts:stream.on('error', () => {})handlers onprocess.stdoutandprocess.stderrat startup as a defensive measureshellper-survive-parent-exit.test.ts(new):session-manager.test.ts:Test plan
Closes #324
🤖 Generated with Claude Code