fix(voice): report e2e_latency for the first reply after a handoff - #7167
Merged
Conversation
The user turn metrics live in a local of the reply task, so the first reply after an agent handoff never reports e2e_latency, and a tool reply after an inline AgentTask reports the whole sub-conversation as one latency. Keep the latest unanswered user turn on the session, set where the reply task commits the user message and cleared where a speech reports it. The tool reply and any say() or generate_reply() from on_enter read it. The fake VAD now shares one clock across streams so a spoken turn after a handoff has timing anchors in tests. Closes #7157
Concurrent say() and generate_reply() from on_enter each read the same unanswered turn at creation, so both reported its e2e_latency. A borrowed turn now belongs to the first speech that reports it. say(add_to_chat_ctx=False) left the turn pending after its audio played, so the next stored reply reported a stale value. The audio answers the turn whether or not a message is stored.
A user turn that produced no speech stayed pending until the next user turn, so a later handoff nothing in the conversation caused reported a latency from long before. The turn now ends when the reply chain ends without a tool reply or a handoff, and when an on_enter returns without speaking. Speeches created inside on_enter claim the turn when created, so the on_enter end clear cannot take it from them and concurrent speeches report it once.
Contributor
There was a problem hiding this comment.
Devin Review found 2 new potential issues.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
A user turn committed while on_enter was still running was cleared when on_enter returned, so a tool-only handoff from that turn lost its greeting latency. on_enter now clears the pending turn only if it is still the one that existed when on_enter started.
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.
Problem:
e2e_latencyis computed from the user turn's metrics held in a local of the reply task, so the first reply after an agent handoff never gets it, and a tool reply after an inlineAgentTaskreports the whole sub-conversation as one latency. The slowest turns of a call are the ones missing from the message, thelk.e2e_latencyspan attribute, and the OTel histogram.Fix: The session keeps the latest user turn no speech has answered, set where the reply task commits the user message. The tool reply reads it, a
say()orgenerate_reply()created insideon_enterclaims it, and it ends when a speech reports it, when the reply chain ends without a tool reply or a handoff, or when anon_enterreturns without speaking.Closes #7157. Supersedes #7161.
Context for reviewing and coding agents