Skip to content

fix: reuse sub-agent broadcast bridges - #2006

Closed
Ankcorn wants to merge 1 commit into
cloudflare:mainfrom
Ankcorn:tankcorn/fix-sub-agent-broadcast-rpcs
Closed

fix: reuse sub-agent broadcast bridges#2006
Ankcorn wants to merge 1 commit into
cloudflare:mainfrom
Ankcorn:tankcorn/fix-sub-agent-broadcast-rpcs

Conversation

@Ankcorn

@Ankcorn Ankcorn commented Jul 31, 2026

Copy link
Copy Markdown
Member

A streamed sub-agent chat produced 1,019 _cf_broadcastToSubAgent and 882 setName JSRPC calls because broadcasts that outlived their WebSocket handler resolved the root Agent for every chunk.

Retain the connection bridge with dup() and reuse that capability after the handler returns. This keeps broadcasts on the existing root/facet RPC session instead of creating root DO subrequests, while preserving root resolution as the cold-wake fallback. Retained bridges are replaced on reconnect and disposed on replacement or close.

@changeset-bot

changeset-bot Bot commented Jul 31, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0c149fa

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

@Ankcorn

Ankcorn commented Jul 31, 2026

Copy link
Copy Markdown
Member Author

Local workerd + streaming-tail reproduction found an important constraint: retained reverse-RPC bridge calls avoid durable_object_subrequest spans, but the originating invocation remains open until the duplicated bridge is disposed. Retaining it for the WebSocket lifetime could prevent invocation completion/hibernation, so this draft needs reworking before review.

@Ankcorn

Ankcorn commented Jul 31, 2026

Copy link
Copy Markdown
Member Author

Closing this approach after validating it with a local workerd + streaming-tail reproduction. Retaining the reverse-RPC bridge removes DO subrequests, but keeps the originating invocation open until disposal and could interfere with hibernation/recovery. We need a broader, lifecycle-bounded design.

@Ankcorn Ankcorn closed this Jul 31, 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