Skip to content

Add stream inactivity timeout to prevent mid-session hangs (Issue #1444)#1445

Open
konard wants to merge 5 commits into
mainfrom
issue-1444-252ab210c5a7
Open

Add stream inactivity timeout to prevent mid-session hangs (Issue #1444)#1445
konard wants to merge 5 commits into
mainfrom
issue-1444-252ab210c5a7

Conversation

@konard

@konard konard commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #1444/hive command stuck on completion requiring CTRL+C interruption.

Root Cause

The Claude CLI stopped producing output mid-session while processing issue #299 from suenot/machine-learning-for-trading, likely due to hitting the Anthropic API 7-day rate limit (utilization: 0.85, overage-status: rejected).

The existing Issue #1280 fix (30s force-kill timeout) only activates after a result event is received. Since the Claude CLI never emitted a result event (it was stuck waiting for an API response), the timeout was never started, and the process hung indefinitely.

Solution

  • Add a configurable stream inactivity timeout (HIVE_MIND_STREAM_INACTIVITY_TIMEOUT_MS, default: 5 minutes) that force-kills the Claude CLI process if no output chunks are received for the configured duration
  • The inactivity timer resets on every chunk received from the stream
  • When a result event is received, the inactivity timer is cleared and the existing Issue --tool claude command execution is stuck just after the success, and I had to manually interrupt it #1280 timer takes over
  • Added verbose logging for inactivity timeout events

Timeline from Log Analysis (156,197 lines)

Time Event
09:50:52Z Issue #299 solve started (last of 11 issues, 10 completed successfully)
09:54:39Z API rate limit warning: 7d-utilization: 0.85, overage-status: rejected
09:55:55Z Last output: tool_result for file creation
74s gap No output — Claude CLI stuck waiting for API
09:57:09Z User CTRL+C — process was stuck

Files Changed

How the Two Timeouts Work Together

Scenario Which Timeout Fires
Session completes, stream hangs Issue #1280 (30s after result event)
Session stuck mid-work, no output Issue #1444 (5min inactivity)
Normal operation Neither — both reset/cleared properly

Test plan

  • All existing tests pass (npm test)
  • Lint passes (npx eslint)
  • Manual test: run /hive against a repo and verify inactivity timeout fires if API becomes unresponsive
  • Verify HIVE_MIND_STREAM_INACTIVITY_TIMEOUT_MS env var override works

🤖 Generated with Claude Code

Adding .gitkeep for PR creation (default mode).
This file will be removed when the task is complete.

Issue: #1444
@konard konard self-assigned this Mar 19, 2026
The /hive command got stuck when Claude CLI stopped producing output
mid-session (likely due to API rate limiting). The existing Issue #1280
timeout only triggers after a `result` event, which never arrived in
this case. This adds a configurable inactivity timeout (default 5 min)
that force-kills the process if no output is received for too long.

- Add HIVE_MIND_STREAM_INACTIVITY_TIMEOUT_MS config (default 300000ms)
- Reset inactivity timer on each stream chunk received
- Clear inactivity timer when result event received (Issue #1280 takes over)
- Add case study with full timeline reconstruction and root cause analysis

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@konard konard changed the title [WIP] /hive command stuck on completion and I had to do interruption Add stream inactivity timeout to prevent mid-session hangs (Issue #1444) Mar 19, 2026
@konard
konard marked this pull request as ready for review March 19, 2026 10:36
konard and others added 3 commits March 19, 2026 10:37
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move the stream timeout management (Issue #1280 + #1444) into a
separate claude.stream-timeout.lib.mjs module to keep claude.lib.mjs
under the CI file line limit of 1500 lines.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@konard

konard commented Mar 19, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $14.520235
  • Calculated by Anthropic: $8.848934 USD
  • Difference: $-5.671300 (-39.06%)

🤖 Models used:

  • Tool: Claude
  • Requested: opus
  • Main model: Claude Opus 4.6 (ID: claude-opus-4-6, Anthropic, cutoff: 2025-05)
    📎 Log file uploaded as Gist (4380KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard

konard commented Mar 19, 2026

Copy link
Copy Markdown
Contributor Author

✅ Ready to merge

This pull request is now ready to be merged:

  • All CI checks have passed
  • No merge conflicts
  • No pending changes

Monitored by hive-mind with --auto-restart-until-mergeable flag

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.

/hive command stuck on completion and I had to do interruption

1 participant