Skip to content

fix(examples): bound stdin read so statusline/title scripts can't hang on a held-open pipe - #1499

Closed
ai-engineer-devansh-singh wants to merge 1 commit into
google-antigravity:mainfrom
ai-engineer-devansh-singh:fix/example-scripts-stdin-timeout
Closed

ai-engineer-devansh-singh wants to merge 1 commit into
google-antigravity:mainfrom
ai-engineer-devansh-singh:fix/example-scripts-stdin-timeout

Conversation

@ai-engineer-devansh-singh

@ai-engineer-devansh-singh ai-engineer-devansh-singh commented Nov 11, 2026 •

Copy link
Copy Markdown

Fixes #698

Problem

examples/statusline/statusline.sh (via jq) and examples/title/title.sh (via cat) read stdin with no timeout. If the CLI holds the pipe open without writing or closing it, which #698 traces to resume/auth warm-up, the script blocks until the runner kills it (statusline: command failed: signal: killed). After repeated kills, the statusline auto-disables.

There's a second, related failure: if stdin is empty, jq prints nothing and exits 0, so the first read -r STATE fails, and set -e makes statusline.sh exit 1. That also counts as a runner failure.

Change (both scripts)

INPUT=""
IFS= read -r -d '' -t 2 INPUT || true   # read until EOF, give up after 2s
exec 0</dev/null                        # nothing later can block on stdin
[ -n "$INPUT" ] || INPUT='{}'           # timeout/empty -> all fields use defaults

statusline.sh then passes $INPUT to its existing single jq pass with <<<. Apart from that, the parsing and rendering code is unchanged.

The 2s timeout is well under the runner's ~5–10s kill. When the CLI writes the payload and closes the pipe (the normal case), read returns at EOF straight away, so there's no added latency.

Testing

Case Before After
stdin held open, never written (FIFO repro from #698) both scripts killed by an 8s outer timeout (exit 124) exit 0 after 2.0s, default output
Normal JSON payload – byte-identical output to main for both scripts
Payload arrives after 1s, then pipe closes – byte-identical to main
Payload without trailing newline – byte-identical to main
Empty stdin statusline.sh exit 1 exit 0, defaults
Malformed JSON – exit 0, defaults
/dev/null stdin – exit 0
bash 3.2.57 (macOS /bin/bash), in Docker – normal, empty and held-open cases all pass

shellcheck warning count is unchanged for both files.

#699 targets the same issue in statusline.sh only. It uses timeout, or a background sleep + kill fallback, around cat with a 0.25s window. This PR differs in a few ways:

  • It only uses the read -t builtin, so there are no helper processes and nothing depends on timeout being installed.
  • The 2s window gives a slow writer more time; 0.25s could drop a payload that arrives late.
  • It also covers title.sh.
  • It fixes the empty-stdin set -e exit.

🤖 Generated with Claude Code

@google-cla

google-cla Bot commented Nov 11, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Both example scripts read stdin with no timeout (`jq` / `cat`). If the
CLI holds the pipe open without writing or closing it (e.g. during resume
or auth warm-up), the script blocks until the runner kills it. Repeated
kills count as failures and auto-disable the statusline.

Read stdin with `read -t 2`, detach stdin afterwards, and fall back to
'{}' on timeout or empty input so every field takes its default. This
also stops statusline.sh from exiting 1 on empty stdin, where `set -e`
tripped on a failed `read`.

Fixes google-antigravity#698
@ai-engineer-devansh-singh
ai-engineer-devansh-singh force-pushed the fix/example-scripts-stdin-timeout branch from 9058420 to f0766e2 Compare November 11, 2026 03:26
@ai-engineer-devansh-singh

Copy link
Copy Markdown
Author

@googlebot I signed it!

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.

[Bug]: Custom statusline script can hang indefinitely on blocked stdin, gets SIGKILL'd, and auto-disables after repeated failures

1 participant