Skip to content

[Graphite MQ] Draft PR GROUP:spec_c00243 (PRs 38) - #47

Closed
graphite-app[bot] wants to merge 1 commit into
masterfrom
gtmq_spec_c00243_1790966144850-d53d03ac-ca33-45a5-9443-69cc852ef8e7
Closed

graphite-app[bot] wants to merge 1 commit into
masterfrom
gtmq_spec_c00243_1790966144850-d53d03ac-ca33-45a5-9443-69cc852ef8e7

Conversation

@graphite-app

@graphite-app graphite-app Bot commented Oct 2, 2026

Copy link
Copy Markdown

This draft PR was created by the Graphite merge queue.
Trunk will be fast forwarded to the HEAD of this PR when CI passes, and the original PRs will be closed.

The following PRs are included in this draft PR:

## 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
- [x] `gofmt`, `go vet ./...` and `go test ./...` pass; `go.mod` is unchanged.
- [x] `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.
- [x] `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.
- [x] 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.
@graphite-app graphite-app Bot closed this Oct 2, 2026
@graphite-app
graphite-app Bot deleted the gtmq_spec_c00243_1790966144850-d53d03ac-ca33-45a5-9443-69cc852ef8e7 branch October 2, 2026 18:36
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.

1 participant