google-gemini / google-gemini/gemini-cli
bug(cli): readStdin 500ms silent-empty plus destroy() breaks stdin reuse
- Dominant language
- TypeScript
- Stars
- 107k
- Forks
- 14.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 45
Description
## What happened?
`packages/cli/src/utils/readStdin.ts:33-39` resolves piped input as empty after 500ms with no warning, and `:57` destroys stdin after truncation:
```ts
const pipedInputShouldBeAvailableInMs = 500;
let pipedInputTimerId = setTimeout(() => { onEnd(); }, pipedInputShouldBeAvailableInMs);
...
process.stdin.destroy(); // Stop reading further
```
Slow pipes (WSL / networked stdin) arriving after 500ms silently lose context — prompt runs with `""`. `destroy()` also breaks later stdin reuse.
## What did you expect to happen?
Check `process.stdin.isTTY` first; only auto-resolve-empty when TTY, otherwise wait for `end`. Replace `destroy()` with `pause()`+unpipe, and warn on timeout/truncation.
## Client information
- Repo `google-gemini/gemini-cli` @ `main` `9c1b0a610`
- Area `packages/cli/src/utils/readStdin.ts:26-60`
- Platform: WSL2 / piped stdin
## Login information
N/A — repro: `sleep 0.8; echo hello | gemini "summarize"` loses input; 9MB pipe truncates + destroys stdin.
## Anything else we need to know?
Fix direction: TTY-gated timeout, `pause()` instead of `destroy()`, telemetry on truncation. Regression tests with fake timers for slow-pipe and oversize input.
Contributor guide
Research direction
Start in packages/cli/src/utils/readStdin.ts:26-60 and reproduce the slow-pipe command `sleep 0.8; echo hello | gemini "summarize"`. Trace the TTY timeout and oversize-input handling, then add fake-timer regression tests for slow pipes and truncation. Done means non-TTY input waits for end, truncation preserves stdin reuse, and timeout or truncation emits a warning and telemetry.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 74/100