fix(voice): read rootSpanContext live in AudioRecognition#1246
Draft
mrniket wants to merge 2 commits intolivekit:mainfrom
Draft
fix(voice): read rootSpanContext live in AudioRecognition#1246mrniket wants to merge 2 commits intolivekit:mainfrom
mrniket wants to merge 2 commits intolivekit:mainfrom
Conversation
|
Honour otelContext.active() when starting the agent_session span and when building rootSpanContext, so spans the caller created before session.start() become parents of LiveKit spans. Add a comment to setupCloudTracer explaining that register() uses set-once semantics in the OTel API, so it won't clobber a user's existing context manager or tracer provider. Fixes livekit#924
AudioRecognition was snapshotting rootSpanContext at construction time, so any mutation of session.rootSpanContext after _startSession (e.g. in an Agent.onEnter hook) was invisible to user_turn spans. Store a live reference to the AgentSession instead, and read rootSpanContext fresh on each span creation. Fixes livekit#924
f4feb10 to
fed1dae
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.
Summary
AudioRecognition was snapshotting
rootSpanContextat construction time,so any mutation of
session.rootSpanContextafter_startSession(e.g. inan
Agent.onEnterhook) was invisible touser_turnspans. This stores alive reference to the
AgentSessioninstead, and readsrootSpanContextfresh on each span creation.
Fixes #924
Changes
audio_recognition.ts: ReplacerootSpanContextsnapshot field with alive
agentSessionreference.ensureUserTurnSpananduserTurnContextnow read
this.agentSession?.rootSpanContexton every call.agent_activity.ts: PassagentSession: this.agentSessionto theAudioRecognitionconstructor instead of the snapshottedrootSpanContext: this.agentSession.rootSpanContext.Test plan
audio_recognition_span.test.ts(4 tests) passes — it constructsAudioRecognitionwithout anagentSession, so the?.fallback toundefinedpreserves current behavior.pnpm test,pnpm lint,pnpm format:checkall pass.