fix: stop waiting on the silent stdin an agent's shell hands vf - #38
Closed
Bradenream wants to merge 3 commits into
Closed
Bradenream wants to merge 3 commits into
Bradenream wants to merge 3 commits into
Conversation
Claude Code runs any Bash command that contains a heredoc with stdin connected to a Unix socket that it never writes to and never closes. vf took that for a piped body, waited the full 10s stdin deadline and failed, even when its flags held the whole request. Every body command an agent ran in such a call lost 10s and had to be retried with </dev/null. In agent mode, a socket on stdin that delivers nothing within 250ms is now taken to carry no body. Pipes and files keep the full deadline in every mode. Shells hand vf a pipe for `producer | vf` and a file for redirects and heredocs, never a socket, so a slow producer is still read. A socket comes from a program that spawned vf, and a program that means to send a body writes it as it starts vf: a Node parent's first byte lands in under a millisecond, even with a hundred spawns at once. The three alternatives each failed a case, measured against the stdin tests plus the four new ones: - Skipping stdin when flags satisfy the body still stalls when no body flag is given. It also drops a slow piped body merged with flags, which the README documents. - A short window for any stdin in agent mode drops slow pipelines there. - Skipping stdin that is not yet readable drops python3, node and slow producers, as the bounded-read fix (#18) found. The new cases: a silent socket returns at once, with flags and without them; a socket that writes at spawn, and a slow shell producer merged with flags, are still read.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Explicit --agent-mode overrides are bypassed by early cached detection, producing incorrect stdin behavior.
Review effort: Balanced
Findings: 1
What changed in this PR
Prevents agent-mode commands from waiting on silent stdin sockets while preserving normal pipe behavior.
Changes:
- Adds socket-specific 250ms silence handling.
- Synchronizes agent mode with stdin handling.
- Adds Go and integration regression tests.
| File | Description |
|---|---|
internal/flagutil/stdin.go |
Implements bounded socket handling. |
internal/flagutil/metadata.go |
Routes body reads through new logic. |
internal/output/agentmode.go |
Propagates agent-mode state. |
internal/flagutil/stdin_test.go |
Tests bounded reads and classification. |
test/stdin-handling.test.ts |
Tests real socket and pipe behavior. |
Files not reviewed (2)
- internal/flagutil/metadata.go: Generated file
- internal/output/agentmode.go: Generated file
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
flagutil kept its own copy of agent mode, refreshed from InitAgentMode. The copy was written after InitAgentMode's early return for repeat calls, so a later change of mode, such as an explicit --agent-mode once flags are parsed, would never reach it. Copilot raised this in review. output now installs IsAgentMode in flagutil when the program starts, and flagutil asks it each time. There is one answer, so the stdin rule follows however agent mode is finally resolved. This PR no longer edits the generated agentmode.go.
This was referenced Oct 1, 2026
effervescentia
approved these changes
Oct 2, 2026
Contributor
Merge activity
|
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
Claude Code runs any Bash command that contains a heredoc with stdin connected to a Unix socket. It never writes to that socket and never closes it; commands without a heredoc get
/dev/nullinstead. vf took the socket for a piped body. Every body command in such a call waited the full 10s stdin deadline and then failed, even with every field given as a flag. An agent then had to retry with</dev/nulland remember to add it to every later write.In agent mode, a socket on stdin that delivers nothing within 250ms is now taken to carry no body. Pipes and files keep the full 10s in every mode. Shells hand vf a pipe for
producer | vfand a file for redirects and heredocs, never a socket. So slow producers (curl … | vf) and the README's "pipe a body, override fields with flags" still work. A socket comes from a program that spawned vf, and a program that means to send a body writes it as it starts vf: a Node parent's first byte arrives within 0.1ms, even with 100 spawns at once.The
outputpackage owns agent detection and importsflagutil, soflagutilcannot import it to ask. InsteadoutputinstallsIsAgentModeinflagutilwhen the program starts (internal/output/agentmodecheck.go), andflagutilasks it each time rather than keeping a copy. So the stdin rule follows however agent mode is finally resolved, including an explicit--agent-modeonce the separate fix for that flag lands.Options compared
Each option was measured against the existing stdin tests plus the four new cases:
Deliberate limit: an idle pipe in agent mode still waits 10s, because a pipe is also how a slow
producer | vfarrives. Claude Code does not hand vf one.Before and after
vf agent update --prompt x, run in an agent's Bash call that contains a heredoc:failed to read stdin: timed out…, exit 1Test plan
gofmt,go vet ./...andgo test ./...pass;go.modis unchanged.internal/flagutil/stdin_test.gocovers the decision rule and the bounded read:test/stdin-handling.test.tshas 4 new cases, and the file passes 13/13:The 4 vitest cases that already fail on master (
docs-command×2,flag-errors,flag-raw-text) are fixed by #37. With both PRs applied to current master, the suite passes 82/82.