fix(cli): "Something went wrong" hang — consume each SSE stream once - #22
Merged
Merged
Conversation
getScriptAndInfo handed two readers over one single-consumption OpenAI SDK stream. Iterating it the second time threw inside readData's detached async IIFE, so the read promise never settled and the rejection reached @Clack's global unhandledRejection handler: the UI froze after 'Your script:' with 'Something went wrong' and nothing else. The same swallow hid mid-stream provider errors. - return one reader from getScriptAndInfo; the explanation always comes from its own request (explainInSecondRequest) - readData rejects through shared normalizeCompletionError, removes its keypress listener and closes readline in finally - add offline stream-consume check to just test; changeset included
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.
Problem
ai '<prompt>'printed◇ Your script:and then died with▲ Something went wrong, leaving the process hanging with no message (reproduced locally, 2026-08-28).Cause
getScriptAndInforeturned two readers (readScript,readInfo) over one OpenAI SDK stream. SDK streams are single-consumption: the second iteration throwsCannot iterate over a consumed streaminsidereadData's detached async IIFE, which had nocatch. The read promise never settled, the rejection went unhandled, and@clack/prompts' spinner — which registers a globalunhandledRejectionhandler — printedSomething went wrong. Any mid-stream provider error was swallowed the same way.The
readInforeader was dead code anyway: the explanation has always come from its own second request (explainInSecondRequest).Fix
getScriptAndInforeturns one reader;prompt.tscallsgetExplanationdirectly for the explanation.readDatanowreject()s through a sharednormalizeCompletionError()(extracted fromgenerateCompletion, so request-time and mid-stream failures produce identical actionableKnownErrors); cleans up itskeypresslistener (previously leaked one per stream) and closes readline infinally.readDatacall sites (getExplanation,getRevision,chat.ts) threadapiEndpoint.Check
New
scripts/stream-consume.check.mjs(offline, fake local SSE server, wired intojust test):FAIL: unhandled rejection(s): Cannot iterate over a consumed stream...+FAIL: readScript-on-error-stream never settledPASSReal PTY smoke of the built binary against the configured provider: script → explanation →
Run this script?→ Yes → command executed, noSomething went wrong.Gate
just build,just lint,just test,just security(gitleaks, actionlint,npm ci --ignore-scripts,npm audit) all green. Changeset included (patch).Co-Authored-By: Claude noreply@anthropic.com