fix(sandbox): handle abort signal and early stream close in runCommand#135
Open
pbzona wants to merge 4 commits intovercel:mainfrom
Open
fix(sandbox): handle abort signal and early stream close in runCommand#135pbzona wants to merge 4 commits intovercel:mainfrom
pbzona wants to merge 4 commits intovercel:mainfrom
Conversation
Validates two bugs in the streaming runCommand (wait: true) path:
1. Abort signal hangs forever — the finished promise never settles
because the abort isn't propagated to the jsonlines iterator
2. Abrupt stream close produces ZodError instead of a descriptive
error when iterator.next() returns { done: true, value: undefined }
|
@pbzona is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
When runCommand is called with wait: true, the API returns an ndjson stream with two chunks. If the abort signal fires mid-stream, the jsonlines iterator hangs forever because the abort isn't propagated. If the stream closes before the second chunk, the iterator returns undefined which causes a confusing Zod validation error. Wire the abort signal to destroy the jsonlines stream so pending iterator.next() calls reject immediately. Guard against early stream close by checking iterator.done before parsing. Clean up the abort listener when the stream is fully consumed to avoid retaining references on long-lived signals.
af6f156 to
b04c23f
Compare
marc-vercel
reviewed
Apr 7, 2026
2888ae4 to
cbbb480
Compare
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
When
runCommandis called withwait: true, the API returns an ndjson stream with two JSON chunks (command started, command finished). Two problems with how this stream is consumed:Abort signal hangs forever. If an
AbortSignalfires mid-stream (e.g.AbortSignal.timeout()), the HTTP body closes but thejsonlinestransform stream stays open. Theiterator.next()call waiting for the second chunk blocks indefinitely — it never resolves or rejects.Early stream close throws ZodError. If the stream closes after the first chunk but before the second (e.g. server drops connection),
iterator.next()returns{ done: true, value: undefined }.CommandFinishedResponse.parse(undefined)then throws a Zod validation error instead of a meaningful message.Fix
jsonlinesStream.destroy()so pendingiterator.next()calls reject immediately instead of hangingiterator.donebefore parsing to throw aStreamErrorinstead of a ZodErrorTest plan
throws abort error (not Zod error) when signal aborts before stream finishes— abort mid-stream rejects instead of hangingthrows StreamError when stream closes before finished chunk arrives— early close throws StreamError, not ZodErrorrejects when signal is already aborted before stream starts— pre-aborted signal rejects immediatelyrunCommandand full suite tests still passFirst commit shows the intentionally failing tests to illustrate the behavior. Open to suggestions on the specific error handling behavior, I just don't think it should be a Zod error in these cases. It's technically expected but could be more helpful.