Conversation
This branch has not been deployed
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
Returning early from
BetaToolRunner's iterator skips both its normal completion handler and its error handler. As a result,done()can keep waiting after the iterator has returned;runUntilDone()and directly awaiting the runner also wait on that same unfinished completion promise.This draft proposes rejecting completion with an
AnthropicErrorwhen an iterator that has started is closed early. It does not run pending tools, start another request, or return a message as though the conversation completed normally. The existing stream-abort path and the error path that lets the runner be iterated again after a failed request stay unchanged.Behavior to confirm
Is rejecting completion the desired behavior for an early
breakoriterator.return()? The proposed rule also applies when the last yielded message hasstop_reason: 'end_turn', because the iterator was closed before its normal completion path ran. Closing an iterator before its firstnext()leaves the runner unconsumed.Callers waiting for completion after an early stop would need to handle this rejection. For example, a
runner.done().then(onSuccess)chain with no rejection handler would now reject rather than remain pending. Breaking without observing completion still does not produce an unhandled rejection from the runner itself.I am keeping this as a draft until that completion behavior is agreed.
Test plan
pnpm build,pnpm lint, andpnpm testpassed. Across the main SDK and five subpackages: 2,033 tests passed, 60 skipped. Tests used the repository's local Steady mock server.git diff --checkpassed.