Skip to content

fix: prevent statusline hook from hanging on stdin#27

Merged
graykode merged 3 commits intograykode:mainfrom
tbouquet:fix/statusline-hang
Apr 4, 2026
Merged

fix: prevent statusline hook from hanging on stdin#27
graykode merged 3 commits intograykode:mainfrom
tbouquet:fix/statusline-hang

Conversation

@tbouquet
Copy link
Copy Markdown
Contributor

@tbouquet tbouquet commented Apr 3, 2026

Summary

Two fixes for abtop-statusline.sh that address #15:

  1. Hang fix: replace INPUT=$(cat) with a read -r -t 5 loop — the script now times out after 5 seconds instead of blocking indefinitely when stdin isn't closed. Uses bash builtins only, works on both macOS and Linux (no coreutils dependency).

  2. Large payload fix: pipe JSON to python via stdin (json.load(sys.stdin)) instead of passing it as a CLI argument (sys.argv[1]). Avoids hitting ARG_MAX on large status payloads and prevents breakage from special characters in the JSON.

Users need to re-run abtop --setup after updating to regenerate the hook script.

Fixes #15

Test plan

  • Valid JSON input → writes correct abtop-rate-limits.json
  • No rate_limits key → exits cleanly
  • Empty stdin → exits immediately (no hang)
  • /dev/null stdin → exits instantly
  • cargo clippy -- -D warnings passes
  • cargo test — 25/25 pass

Two fixes for abtop-statusline.sh:

1. Replace `cat` with `read -t 5` loop — avoids blocking
   indefinitely when stdin isn't closed. Works on both
   macOS and Linux (unlike `timeout` which needs coreutils).

2. Pipe JSON to python via stdin instead of passing as a
   CLI argument — avoids hitting ARG_MAX on large payloads
   and breaking on special characters in the JSON.

Fixes graykode#15
@graykode
Copy link
Copy Markdown
Owner

graykode commented Apr 4, 2026

Thanks for tackling #15! The approach is solid — read -t 5 for timeout and stdin pipe for ARG_MAX are both good calls. A few issues before merging:

  1. echo "$INPUT" is unsafe — if the JSON contains \n, \t, -n, -e, echo may interpret them. Use printf '%s' "$INPUT" instead.

  2. Newlines are strippedINPUT="${INPUT}${line}" joins all lines without newline separators. If Claude ever sends pretty-printed JSON, json.load will fail on the concatenated string. Should be INPUT="${INPUT}${line}\n" or similar.

  3. Minor: timeout is per-line, not globalread -r -t 5 resets the 5s timer on each line. Not a real problem for StatusLine payloads (usually one line), but worth noting.

Could you address 1 and 2?

@tbouquet tbouquet force-pushed the fix/statusline-hang branch from fa28c02 to 6af46b1 Compare April 4, 2026 06:47
Address review feedback:
- Replace echo with printf '%s' to avoid interpreting escapes/flags
- Preserve newline separators when concatenating read lines
@tbouquet tbouquet force-pushed the fix/statusline-hang branch from 6af46b1 to 942b792 Compare April 4, 2026 06:49
Add || [ -n "$line" ] guard so the read loop captures the final
chunk when stdin closes without a trailing newline.
@graykode graykode merged commit db085ca into graykode:main Apr 4, 2026
7 checks passed
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.

abtop-statusline.sh is hanging

2 participants