Skip to content

telemetry: session_close covers the whole close - #7322

Draft
davidzhao wants to merge 2 commits into
mainfrom
dz/telemetry-close-span
Draft

davidzhao wants to merge 2 commits into
mainfrom
dz/telemetry-close-span

Conversation

@davidzhao

Copy link
Copy Markdown
Member

What

session_close now spans the whole of AgentSession._aclose_locked: the activity teardown, the close event's handlers, the session host and room io. agent_session ends, and its root context is cleared, only after all of that.

Why

The close span ended after the activity teardown, then agent_session ended, and the close event, session host and room io closed afterwards while the session's context was still current in the closing task. Anything emitted there parented to an already ended span. In a real export, a 103 ms event_loop_blocked from the ai_coustics enhancer's native free during room_io.aclose() showed up 8 ms after agent_session had closed, poking out of it.

With this change that stall nests inside session_close, where it happened, and a close handler's own spans do too.

Tests

test_session_lifecycle_spans_and_events registers a close handler that opens a span and asserts it nests under session_close, that session_close ends after it and agent_session after that, and that the root context is cleared.

🤖 Generated with Claude Code

davidzhao and others added 2 commits September 17, 2026 08:22
…fter room io

The close event's handlers, the session host and room io closed after session_close and
agent_session had ended, still in the session's context, so anything they emitted (a stall in
a plugin's teardown, a handler's spans) parented to an ended span.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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