Skip to content

fix(agents): route WebSockets through sub-agents nested past one level - #2400

Merged
threepointone merged 1 commit into
fix/2252-facet-broadcast-rpcsfrom
fix/nested-subagent-websockets
Sep 28, 2026
Merged

threepointone merged 1 commit into
fix/2252-facet-broadcast-rpcsfrom
fix/nested-subagent-websockets

Conversation

@threepointone

@threepointone threepointone commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Problem

I found this while testing #2118; there was no issue for it. WebSockets to a sub-agent three or more levels deep failed with "Facet nesting depth limit exceeded".

The root forwards the x-cf-agents-subagent-url header, which is meant only for the root-owned socket, to every child in meta.requestHeaders. A second-level child's onConnect wrapper copied it into its outer-URL flag and resolved its own connection from the top of the chain. The third hop then routed back into the second level, recursively, until the depth limit threw.

Fix

#resolveConnection drops that header from the headers it forwards to the child.

Tests

sub-agent-routing.test.ts connects two clients through three and four levels of sub-agents. Both see the leaf's identity, a state frame from one is broadcast to the other, and neither sees an error frame. The test fails without the fix.

@changeset-bot

changeset-bot Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3ffc90a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
agents Patch
@cloudflare/agent-think Patch

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
threepointone added this pull request to stack #2407 September 28, 2026 14:47
@agent-think

agent-think Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

✅ agents import sizes: no significant changes (52853b12 → 3ffc90a3, workflow run)

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@pkg-pr-new

pkg-pr-new Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@2400

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@2400

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@2400

hono-agents

npm i https://pkg.pr.new/hono-agents@2400

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@2400

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@2400

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@2400

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@2400

commit: 3ffc90a

@threepointone
threepointone force-pushed the fix/nested-subagent-websockets branch from 9ba029f to e3556a3 Compare September 28, 2026 15:46
The outer-URL header meant for the root-owned socket was forwarded to every
child. A second-level child copied it into its connection flag and resolved
its connection from the top of the chain, routing back into the first level
until the facet depth limit threw.

Co-authored-by: Cursor <cursoragent@cursor.com>
@threepointone
threepointone force-pushed the fix/nested-subagent-websockets branch from e3556a3 to 3ffc90a Compare September 28, 2026 16:54
@threepointone
threepointone merged commit 498bc29 into main Sep 28, 2026
24 of 30 checks passed
@threepointone
threepointone deleted the fix/nested-subagent-websockets branch September 28, 2026 18:04
threepointone added a commit to AntoniTok/agents that referenced this pull request Sep 29, 2026
Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions github-actions Bot mentioned this pull request Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant