Repository navigation
fix(agents): close rejected sub-agent WebSockets instead of failing the handshake (#2118) - #2401
Merged
threepointone merged 2 commits intoSep 28, 2026
Conversation
🦋 Changeset detectedLatest commit: 64155b9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
threepointone
added this pull request to stack #2407
September 28, 2026 14:47
Contributor
🟢 agents import sizes: 1 entry point changed, no growth
Changed exports (1)
How this worksEach runtime export is bundled on its own, minified, and gzipped. Changes smaller than 100 B, or smaller than 1% and 1 KiB, are ignored. Growth over 10% or 5 KiB is marked 🔴. This report is informational and does not fail CI. The workflow artifact contains every measurement. Compared |
threepointone
marked this pull request as ready for review
September 28, 2026 14:49
threepointone
force-pushed
the
fix/2118-rejected-subagent-socket
branch
from
September 28, 2026 15:46
4c148e0 to
92de61d
Compare
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
…he handshake (#2118) onBeforeSubAgent rejections of an upgrade now accept and close the socket: 4xx maps to 4000+status (terminal), anything else to 1011 (retryable). Browsers hide failed-handshake statuses, so clients used to reconnect forever. useAgent and AgentClient now set connectionError whenever reconnection ends: a terminal code, a declined shouldReconnectOnClose, or spent maxRetries. An explicit close() still reports nothing. Co-authored-by: Cursor <cursoragent@cursor.com>
…s them The #2118 client tests created a call, waited for the close to reject it, and only then attached the assertion. The browser reported the rejection as unhandled, which failed the suite although every test passed. Co-authored-by: Cursor <cursoragent@cursor.com>
threepointone
force-pushed
the
fix/2118-rejected-subagent-socket
branch
from
September 28, 2026 16:54
92de61d to
64155b9
Compare
Merged
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.
Fixes #2118.
Problem
When
onBeforeSubAgentrejected a WebSocket upgrade, the handshake failed with an HTTP status. Browsers hide that status from script, so clients saw a generic close and reconnected forever. Separately,useAgentandAgentClientnever reported that reconnection had ended, even when it had: a terminal close code, ashouldReconnectOnClosethat declined, or exhaustedmaxRetries.Fix
Server:
4000 + status, which is terminal. Anything else maps to1011, which is retryable. The reason isSub-agent connection rejected (<status>).1008whatever the status was.webSocketis passed through untouched.Client:
createCloseClassifierdecides, inshouldReconnectOnClose, whether this close ends reconnection. That is the point where partysocket still exposes enough state to know. When reconnection ends,useAgentandAgentClientsetconnectionErrorand reject pending calls.close()still reports nothing.Edge cases:
shouldReconnectOnCloseeven after an explicitclose(), and before it increments its retry count. The classifier readsshouldReconnect === falseto tell an explicit close apart.shouldReconnecttrue whenmaxRetriesruns out. The classifier compares the retry count withmaxRetriesitself.Tests
maxRetriesexhaustion, ashouldReconnectOnClosethat declines, and an explicitclose()that produces no error.Docs:
docs/agents/sub-agents.mdhas a close-code table.Depends on #2400: before that fix, the nested rejection case hit the depth-limit bug and closed with 1011.