Fix: Add error handler to streaming onFinish promise chain#1539
Open
kernel-systems-bot wants to merge 1 commit intobrowserbase:mainfrom
Open
Fix: Add error handler to streaming onFinish promise chain#1539kernel-systems-bot wants to merge 1 commit intobrowserbase:mainfrom
kernel-systems-bot wants to merge 1 commit intobrowserbase:mainfrom
Conversation
|
Contributor
Greptile SummaryThis PR fixes a bug where the streaming agent's result promise would hang indefinitely if
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant V3AgentHandler
participant LLMClient
participant ensureClosed
Client->>V3AgentHandler: stream(options)
V3AgentHandler->>LLMClient: streamText(options)
LLMClient-->>V3AgentHandler: fullStream
V3AgentHandler-->>Client: AgentStreamResult (with result promise)
Note over LLMClient: Streaming completes
LLMClient->>V3AgentHandler: onFinish callback
V3AgentHandler->>ensureClosed: ensureClosed()
alt ensureClosed succeeds
ensureClosed-->>V3AgentHandler: closeResult
V3AgentHandler->>V3AgentHandler: resolveResult(result)
V3AgentHandler-->>Client: result promise resolves
else ensureClosed fails (NEW FIX)
ensureClosed-->>V3AgentHandler: Error
V3AgentHandler->>V3AgentHandler: rejectResult(err)
V3AgentHandler-->>Client: result promise rejects
end
|
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.
Fix: Streaming onFinish Promise Chain Missing Error Handler
Summary
Adds missing
.catch()handler to theensureClosed().then()promise chain in streaming mode'sonFinishcallback. Without this handler, ifensureClosed()fails, thestreamResult.resultpromise hangs forever instead of rejecting with an error.Problem
In
v3AgentHandler.ts, the streaming modeonFinishcallback callsensureClosed()and chains.then()to resolve the result promise, but has no.catch()handler:Solution
Add a
.catch()handler that properly rejects the result promise:Impact
ensureClosed()fails during streaming,streamResult.resulthangs indefinitely, causing memory leaks and unrecoverable stateTest Plan
streaming-onfinish-error-handling.test.tsnpm testto verify all tests passFiles Changed
packages/core/lib/v3/handlers/v3AgentHandler.ts- Added.catch()handlerpackages/core/tests/streaming-onfinish-error-handling.test.ts- New regression testFeedback? Email p0@kernel.dev
Summary by cubic
Fixes a hang in streaming results by adding an error handler to the onFinish ensureClosed() promise chain. Errors now reject streamResult.result instead of hanging, so callers can handle failures.
Written for commit e20e06e. Summary will update on new commits.