Skip to content

fix(shell_exec): write small command input to a pipe, not a temp file - #4519

Merged
max-sixty merged 2 commits into
mainfrom
fix/empty-stdin-null
Oct 20, 2026
Merged

max-sixty merged 2 commits into
mainfrom
fix/empty-stdin-null

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Since v0.80.0, an unusable TMPDIR broke every command that passes input to a child: background hooks never spawned ("Failed to prepare detached input"), wt step for-each failed, wt list lost the working-tree diff of a worktree with untracked files (git add --pathspec-from-file=- failed), and background wt remove exited 1 after already removing the worktree. #4400 moved this input from a pipe to an anonymous temp file, even when it was empty.

The temp file exists so that no writer thread can block on a child that doesn't read its input. A pipe meets that requirement when the whole input fits in its buffer, so on Unix buffered_stdin now writes the input into a fresh pipe with a nonblocking writer before spawn and closes the writer. Only input larger than the pipe buffer (64 KiB on macOS and Linux) falls back to the temp file, and that case still needs a usable TMPDIR. Windows keeps the temp file.

Verified with the release-review repros: with TMPDIR=/nonexistent/dir, the post-start hook runs, for-each succeeds, wt list shows the dirty worktree, and wt remove exits 0, matching v0.80.0. The existing list TMPDIR test now adds an untracked file and requires empty stderr, and a new remove test covers the detached cleanup; both fail without the fix. The existing test_cmd_with_stdin covers empty input and a 1.7 MB input that takes the temp-file path.

This was written by Claude Code on behalf of max-sixty

Since #4400 (cd6732e), buffered_stdin put every command's input in an
anonymous file from tempfile::tempfile(), including empty input. With an
unusable TMPDIR, background hooks failed to spawn ("Failed to prepare
detached input"), wt step for-each failed, wt list lost the working-tree
diff of a worktree with untracked files (git add
--pathspec-from-file=-), and background wt remove exited 1 after
removing the worktree. v0.80.0 wrote input to a pipe and handled all of
these.

#4400 moved to a file so that no writer thread can block on a child that
does not read its input. A pipe meets the same requirement when the
whole input fits in its buffer: on Unix, buffered_stdin now writes the
input into a fresh pipe through a nonblocking writer before spawn and
closes the writer, so the child reads the bytes and then EOF. Only input
larger than the pipe buffer (64 KiB on macOS and Linux) falls back to
the anonymous file. Empty input is the empty-pipe case of the same path.
Windows keeps the file.

The list TMPDIR test now adds an untracked file and requires empty
stderr, and a new remove test covers the detached cleanup with empty
input; both fail without the fix.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ilure

A fresh pipe whose reader we hold fails a write only with WouldBlock, so
the separate error arm was unreachable.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 6826904 into main Oct 20, 2026
38 checks passed
@max-sixty
max-sixty deleted the fix/empty-stdin-null branch October 20, 2026 15:39
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.

2 participants