Skip to content

fix(hook): stdin timeout + stderr logging + bare /agentflare report - #80

Merged
getappz merged 2 commits into
masterfrom
fix/windows-stdin-timeout
Jul 7, 2026
Merged

fix(hook): stdin timeout + stderr logging + bare /agentflare report#80
getappz merged 2 commits into
masterfrom
fix/windows-stdin-timeout

Conversation

@getappz

@getappz getappz commented Jul 7, 2026

Copy link
Copy Markdown
Owner

Changes

  • Add
    ead_stdin_timeout(ms)\ helper using thread+channel+recv_timeout (stdlib only)
  • Replace blocking \stdin().read_to_string()\ in \pre_tool_use\ and \prompt_submit\
  • 1s safety timeout, fail-open: timeout → log to stderr, skip gracefully
  • Bare /agentflare\ or /agentflare status\ reports active state (on/off)

Tickets

References

  • ponytail#214 (upstream Windows stdin hang fix)
  • ponytail#303 (upstream stderr logging)
  • ponytail#99 (upstream bare /ponytail report)

Test

  • 186/186 tests pass

Summary by CodeRabbit

  • New Features

    • Added a status response for /agentflare and /agentflare status to report whether the hook is currently ACTIVE or off.
  • Bug Fixes

    • Prevented indefinite waiting by adding stdin read timeouts for hook handlers.
    • Improved behavior when input is missing or empty by skipping processing and showing clearer feedback.
  • Tests

    • Added a unit test to ensure the timeout-based stdin reader does not panic.

- Add read_stdin_timeout(ms) helper using thread+channel+recv_timeout
- Replace blocking stdin().read_to_string() in pre_tool_use and prompt_submit
- 1s timeout, fail-open: timeout → log to stderr, skip gracefully
- Bare /agentflare or /agentflare status reports active state
- Closes ponytail audit PR tickets #71, #70, #75
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a read_stdin_timeout helper in src/hook.rs that reads stdin with a 1-second timeout via a spawned thread, applies it in pre_tool_use and prompt_submit with early returns on timeout/empty input, adds /agentflare status command handling, and includes a unit test.

Changes

Hook stdin timeout and status command

Layer / File(s) Summary
Stdin timeout helper
src/hook.rs
Introduces read_stdin_timeout(ms) that spawns a thread to read stdin and returns None on timeout or empty input via recv_timeout.
Apply timeout reads in hook entry points
src/hook.rs
Replaces blocking read_to_string calls in pre_tool_use and prompt_submit with read_stdin_timeout(1000), adding early returns with eprintln! messages on timeout/empty input.
/agentflare status command and test
src/hook.rs
Adds /agentflare and /agentflare status handling that returns a JSON hookSpecificOutput reporting ACTIVE/off state, and adds a unit test verifying read_stdin_timeout does not panic.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main hook changes: stdin timeout, stderr logging, and /agentflare reporting.
Description check ✅ Passed Covers the main changes, tickets, and test result; only the template headings and reviewer notes are missing.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/windows-stdin-timeout

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (2)
src/hook.rs (2)

97-103: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicated timeout-handling boilerplate across both call sites.

The match read_stdin_timeout(1000) { Some(s) if !s.is_empty() => s, _ => { eprintln!(...); return; } } block is repeated verbatim (only the log label differs) in pre_tool_use and prompt_submit, and the 1000 ms timeout is a duplicated magic literal. Consider extracting a small helper to reduce duplication and centralize the timeout constant.

♻️ Suggested refactor
+const STDIN_TIMEOUT_MS: u64 = 1000;
+
+fn read_stdin_or_skip(label: &str) -> Option<String> {
+    match read_stdin_timeout(STDIN_TIMEOUT_MS) {
+        Some(s) if !s.is_empty() => Some(s),
+        _ => {
+            eprintln!("[agentflare] {label}: stdin timeout or empty — skipping");
+            None
+        }
+    }
+}

Then in pre_tool_use:

-    let input = match read_stdin_timeout(1000) {
-        Some(s) if !s.is_empty() => s,
-        _ => {
-            eprintln!("[agentflare] PreToolUse: stdin timeout or empty — skipping");
-            return;
-        }
-    };
+    let Some(input) = read_stdin_or_skip("PreToolUse") else { return };

And similarly in prompt_submit with the "UserPromptSubmit" label.

Also applies to: 155-161

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/hook.rs` around lines 97 - 103, Extract the repeated stdin timeout
handling in pre_tool_use and prompt_submit into a small shared helper that wraps
read_stdin_timeout and the empty-input check, so both call sites just pass their
log label. Replace the duplicated 1000 ms magic literal with a central timeout
constant used by that helper, and keep the existing eprintln!/return behavior
for the "PreToolUse" and "UserPromptSubmit" paths.

269-273: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Test doesn't verify meaningful behavior.

read_stdin_timeout_does_not_panic only checks the call doesn't panic; it exercises neither the None (timeout) branch nor a populated-input branch. Given this is the core fix for tickets #71/#70, consider parameterizing the read logic (e.g., accept a generic Read or an injected timeout duration for testing) so the timeout path can be asserted deterministically instead of relying on real stdin timing in tests.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/hook.rs` around lines 269 - 273, The read_stdin_timeout test currently
only proves the call does not panic and does not validate either the timeout
path or the successful input path. Refactor the stdin-reading logic in
read_stdin_timeout to be testable with an injected reader or configurable
timeout so you can deterministically assert the None branch and a
populated-input branch without relying on real stdin timing. Update
read_stdin_timeout and its tests, including read_stdin_timeout_does_not_panic,
to cover the actual behavior of the timeout handling.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/hook.rs`:
- Around line 97-103: Extract the repeated stdin timeout handling in
pre_tool_use and prompt_submit into a small shared helper that wraps
read_stdin_timeout and the empty-input check, so both call sites just pass their
log label. Replace the duplicated 1000 ms magic literal with a central timeout
constant used by that helper, and keep the existing eprintln!/return behavior
for the "PreToolUse" and "UserPromptSubmit" paths.
- Around line 269-273: The read_stdin_timeout test currently only proves the
call does not panic and does not validate either the timeout path or the
successful input path. Refactor the stdin-reading logic in read_stdin_timeout to
be testable with an injected reader or configurable timeout so you can
deterministically assert the None branch and a populated-input branch without
relying on real stdin timing. Update read_stdin_timeout and its tests, including
read_stdin_timeout_does_not_panic, to cover the actual behavior of the timeout
handling.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 5666e382-0309-421e-adc5-5aaff5dc3eac

📥 Commits

Reviewing files that changed from the base of the PR and between 7af46db and a8518f1.

📒 Files selected for processing (1)
  • src/hook.rs

@getappz
getappz merged commit 2924ed1 into master Jul 7, 2026
6 of 7 checks passed
@getappz
getappz deleted the fix/windows-stdin-timeout branch July 7, 2026 17:38
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant