fix: prevent readStdin() from hanging indefinitely on Windows#74
Open
myselfsiddharth wants to merge 1 commit into
Open
fix: prevent readStdin() from hanging indefinitely on Windows#74myselfsiddharth wants to merge 1 commit into
myselfsiddharth wants to merge 1 commit into
Conversation
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.
|
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.