fix(observability): bound websocket trace spans#3
Open
Ankcorn wants to merge 1 commit into
Open
Conversation
Ankcorn
force-pushed
the
tankcorn/bound-websocket-trace-spans
branch
from
July 16, 2026 11:11
e8bb6e6 to
7cfbea0
Compare
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.
Why
A canceled or disconnected hibernatable WebSocket turn can end its Worker invocation before JavaScript stream finalizers run. This left exactly five custom spans open:
chat_interaction,chat_turn,invoke_agent,persist_chat_result, and the activechatspan.What
The tracer now owns bounded span lifetimes. Call sites declaratively choose one of two policies:
There are no
finish()callbacks to thread through the chat lifecycle. The tracer keeps the finished span's async context active, preserving the existing hierarchy:These policies apply only to
ws-chat; RPC and alarm turns retain full-stream span lifetimes and attributes.Evidence
A local Service Trace Worker reproduced both explicit cancellation and hard disconnects:
Completed WebSocket turns remain balanced and raw parent IDs remain unchanged. Agents tracing tests and all AI Chat (646) and Think (910) Worker tests pass.
Stacked on cloudflare#1860.