Skip to content

fix: stop waiting on the silent stdin an agent's shell hands vf - #38

Closed
Bradenream wants to merge 3 commits into
masterfrom
braden/stdin-agent-shell/COR-0
Closed

Bradenream wants to merge 3 commits into
masterfrom
braden/stdin-agent-shell/COR-0

Conversation

@Bradenream

@Bradenream Bradenream commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

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/null instead. 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/null and 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 | vf and 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 output package owns agent detection and imports flagutil, so flagutil cannot import it to ask. Instead output installs IsAgentMode in flagutil when the program starts (internal/output/agentmodecheck.go), and flagutil asks it each time rather than keeping a copy. So the stdin rule follows however agent mode is finally resolved, including an explicit --agent-mode once the separate fix for that flag lands.

Options compared

Each option was measured against the existing stdin tests plus the four new cases:

Option Silent socket no longer stalls Slow piped body still read
Skip stdin when flags satisfy the body only when a body flag is given no: dropped when flags are also given (a README case)
Short window for any stdin, agent mode yes no: slow pipelines dropped in agent mode
Skip stdin that is not yet readable yes no: python3, node and slow producers dropped (5 tests fail)
This PR: short window for a socket, agent mode yes yes (13/13)

Deliberate limit: an idle pipe in agent mode still waits 10s, because a pipe is also how a slow producer | vf arrives. 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:

master this PR
Time 10.0s 0.8s
Result failed to read stdin: timed out…, exit 1 prompt sent, exit 0

Test plan

  • gofmt, go vet ./... and go test ./... pass; go.mod is unchanged.
  • internal/flagutil/stdin_test.go covers the decision rule and the bounded read:
    • a silent reader means no body;
    • a body that starts in time is read;
    • the first bytes, then the rest, are both read;
    • EOF returns at once;
    • a slow body with no limit is read.
  • test/stdin-handling.test.ts has 4 new cases, and the file passes 13/13:
    • a silent socket returns at once, with flags and without (both take 10s and fail on master);
    • a socket that writes at spawn is still read;
    • a slow shell producer merged with flags is still read.
  • Reproduced and verified inside a real Claude Code Bash call.
  • CI

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.

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.
Copilot AI balanced review requested due to automatic review settings October 1, 2026 20:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Explicit --agent-mode overrides are bypassed by early cached detection, producing incorrect stdin behavior.

Review effort: Balanced
Findings: 1 Medium severity

Open (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.

Comment thread internal/output/agentmode.go Outdated
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.

effervescentia commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Merge activity

  • Oct 2, 6:35 PM UTC: The merge label 'merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Oct 2, 6:35 PM UTC: effervescentia added this pull request to the Graphite merge queue.
  • Oct 2, 6:35 PM UTC: CI is running for this pull request on a draft pull request (#47) due to your merge queue CI optimization settings.
  • Oct 2, 6:36 PM UTC: Merged by the Graphite merge queue via draft PR: #47.

@graphite-app graphite-app Bot closed this Oct 2, 2026
@graphite-app
graphite-app Bot deleted the braden/stdin-agent-shell/COR-0 branch October 2, 2026 18:36
@graphite-app graphite-app Bot removed the merge label Oct 2, 2026
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.

3 participants