Fix: Workaround for process stream hanging after completion (Issue #1280)#1281
Fix: Workaround for process stream hanging after completion (Issue #1280)#1281
Conversation
Adding CLAUDE.md with task information for AI processing. This file will be removed when the task is complete. Issue: #1280
--tool claude command execution is stuck just after the success, and I had to manually interrupt ita125364 to
1c75bcf
Compare
Claude Code CLI sometimes hangs indefinitely after sending the final
result event without closing stdout. This fix adds a 30-second timeout
after receiving the result event. If the stream doesn't close within
that time, the process is forcefully terminated with SIGTERM/SIGKILL.
Root Cause Analysis:
- Claude CLI sends {"type":"result","subtype":"success"} event
- But process keeps stdout open and doesn't exit
- for-await loop in streaming code waits forever
- User has to manually CTRL+C to terminate
Solution:
- Track when result event is received
- Set 30s timeout to force-kill process if stream doesn't close
- Use SIGTERM first, then SIGKILL if needed
- Log verbose messages for debugging
Case Study:
- Full timeline reconstruction in docs/case-studies/issue-1280/
- Original log shows 5+ minute hang after successful completion
- Screenshots preserved for reference
- Full log available at gist (too large for git)
Reported upstream:
- anthropics/claude-code#25629
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1c75bcf to
ed87517
Compare
This reverts commit 622f9ea.
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
Now working session is ended, feel free to review and add any feedback on the solution draft. |
|
I don't believe it is the problem with That indicates, that is our solve command code is hanging. Because these lines are added after Please double check our recent releases. Anyway we should apply workaround to successfully terminate Ensure all changes are correct, consistent, validated, tested and fully meet all discussed requirements (check issue description and all comments in issue and in pull request). Ensure all CI/CD checks pass. |
|
🤖 AI Work Session Started Starting automated work session at 2026-02-13T21:51:04.900Z The PR has been converted to draft mode while work is in progress. This comment marks the beginning of an AI work session. Please wait for the session to finish, and provide your feedback. |
…Issue #1280) Root cause: command-stream v0.9.4's stream() async iterator waits for both process exit AND stdout/stderr pipe close before ending. If the CLI process keeps stdout open after sending the result event, pumpReadable() hangs, finish() never fires, and the stream iterator never terminates. This is NOT a Claude CLI bug — it's a command-stream library limitation. Additionally, command-stream stream() does NOT yield {type:'exit'} chunks, making the exit code detection via chunk.type==='exit' dead code (added comment noting this for all 6 affected source files). Changes: - Add configurable timeout: HIVE_MIND_RESULT_STREAM_CLOSE_MS (default 30s) - Improve verbose debug logging with timestamps and process state info - Add detailed root cause comments explaining command-stream behavior - Update case study with corrected analysis (command-stream, not Claude CLI) - Update changeset with accurate description - Filed upstream issue: link-foundation/command-stream#155 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
Now working session is ended, feel free to review and add any feedback on the solution draft. |
Summary
This PR addresses issue #1280 where the
solvecommand using--tool claudegets stuck after successful completion, requiring manual CTRL+C to terminate.Root Cause
The hang is caused by
command-streamv0.9.4'sstream()async iterator behavior:stream()waits for both process exit AND stdout/stderr pipe close before endingpumpReadable()hangs indefinitelyfinish()never fires →'end'event never emitted →for awaitloop never terminatesstream()does NOT yield{type:'exit'}chunks, making exit code detection viachunk.type === 'exit'dead code in 6 source filesThis is NOT a Claude CLI bug — the lines "Cost captured" and "Captured result summary" are printed by our code inside the
for awaitloop after the result event arrives. The hang occurs whencommand-stream'sstream()iterator doesn't terminate because the underlying process keeps stdout open.Evidence from logs — 5 min 26 sec gap after result event:
21:10:17.168Z21:10:17.169Zfor awaitloop stuck incommand-streamstream()21:15:43.123ZSolution
Implemented a configurable timeout workaround in
src/claude.lib.mjs:HIVE_MIND_RESULT_STREAM_CLOSE_MS)Additional Changes
timeouts.resultStreamCloseMstosrc/config.lib.mjs(configurable via env var)command-streamchunk.type === 'exit'dead codedocs/case-studies/issue-1280/ANALYSIS.mdwith corrected root causeUpstream Bug Reports
stream()does not yield exit chunksstream()hangs if stdout stays open after process exitFiles Changed
src/claude.lib.mjs— Timeout workaround + dead code documentationsrc/config.lib.mjs— AddedresultStreamCloseMstimeout config.changeset/issue-1280-claude-cli-hang-workaround.md— Updated changesetdocs/case-studies/issue-1280/ANALYSIS.md— Corrected root cause analysisTesting
Issue Reference
Fixes #1280
This PR was created by the AI issue solver