fix: prevent readStdin() from hanging indefinitely on Windows - #74
fix: prevent readStdin() from hanging indefinitely on Windows#74myselfsiddharth wants to merge 1 commit into
Conversation
|
Vorflux skipped this auto review because this account has reached its Auto Review daily review limit (40/40). You can change this in Auto Review Settings: https://us1.vorflux.com/supermemory/settings?section=pull-requests |
|
@myselfsiddharth can you resolve the conflicts? |
On Windows, piped stdin never emits the 'end' event for hook subprocesses spawned by Claude Code, so readStdin() waited forever and every hook burned its full timeout before doing any work. Fixes supermemoryai#25 Changes to readStdin(): - Parse eagerly on each data chunk: hooks receive a single JSON object, so resolve as soon as the accumulated input parses, without waiting for 'end' or any timeout - Add a 3 second timeout fallback that resolves with an empty object when no complete input arrives; all callers already handle empty input gracefully - Pause and unref stdin once settled so the open pipe cannot keep the process alive Unix behavior is unchanged: 'end' still resolves normally and malformed JSON with a closed stdin still rejects with the same error message. Bundles in plugin/scripts were rebuilt with npm run build.
aaab6bb to
00c9526
Compare
|
@ishaanxgupta done — rebased onto All the conflicts were in the generated That also shrinks the diff. The earlier bundle churn was from building with a different esbuild version; with the pinned one,
Re-verified on macOS after the rebase — behavior is unchanged from the original test plan:
|
Summary
Fixes #25
On Windows, piped stdin never emits the
endevent for hook subprocesses spawned by Claude Code.readStdin()insrc/lib/stdin.jswaited for that event with no timeout, so every hook (SessionStart,UserPromptSubmit,PreToolUse,Stop) hung at its very first line and burned the full hook timeout before any authentication or API work began.Changes to
readStdin(){}instead of hanging. All four hook callers already handle empty input gracefully (they fall back toprocess.cwd()and skip work that needssession_idortranscript_path).pause()plusunref()so the still-open pipe cannot keep the Node process alive after the promise settles, which is the underlying mechanism of the hang.Unix behavior is unchanged:
endstill resolves normally, and malformed JSON with a closed stdin still rejects with the same error message as before.Bundles in
plugin/scripts/were rebuilt withnpm run build(the bundle diff churn is from esbuild output formatting; the only source change issrc/lib/stdin.js).Test plan
Verified on Windows 11 by spawning child processes against both the source module and the built bundles:
{}after 3 srecall-hook.cjswith stdin held opennpx biome checkandnpm run buildboth pass.