Skip to content

fix(eval): time Live eval turns so invocation_duration_v1 is not n/a - #8472

Open
Fruiterer333 wants to merge 2 commits into
google:mainfrom
Fruiterer333:fix/live-eval-invocation-duration
Open

Fruiterer333 wants to merge 2 commits into
google:mainfrom
Fruiterer333:fix/live-eval-invocation-duration

Conversation

@Fruiterer333

Copy link
Copy Markdown
Contributor

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

Problem:
In Live mode (_generate_inferences_from_root_agent_live), eval never times its turns and calls convert_events_to_eval_invocations without durations. Every Live Invocation therefore has duration=None, and invocation_duration_v1 reports n/a per invocation and overall, while the same agent gets a duration for every turn on the regular path. The converter's docstring notes that durations can only be measured while the agent runs, so nothing downstream can recover them.

Solution:
Time each Live turn and pass the durations to the converter, as the regular path does.

Design

  • What a turn's duration covers: from sending the user turn until the model reports turn completion (time.monotonic(), rounded to milliseconds as on the regular path). The user simulator's turnaround stays outside the measurement, as on the regular path.
  • Model/tool split left as None: in Live mode the model streams over one connection held open for the whole session, and the events are consumed by a background task started once per session (_LiveSession._consume_events). A per-turn collect_busy_intervals() cannot reach that task, and there is no per-turn model call to time, so reporting a split would mean inventing numbers. _InvocationDurationV1Evaluator already handles model_duration/tool_duration being None.
  • A turn cut off by the Live session ending is left untimed: it never completed, so its elapsed time is not a turn duration.

Out of scope: a time-to-first-response metric for voice agents, mentioned as possible follow-up in #8471.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

New test in tests/unittests/evaluation/test_evaluation_generator.py (modelled on test_records_a_duration_for_each_invocation): test_records_a_duration_for_each_live_invocation. It fails on main (all durations None) and passes with the change. tests/unittests/evaluation passes locally.

Manual End-to-End (E2E) Tests:

Ran the offline repro from #8471 (fake Live connection that answers each turn after 0.2 s, no API key):

main:        live path durations [None, None]    invocation_duration_v1 overall_score=None
this branch: live path durations [0.203, 0.201]  invocation_duration_v1 overall_score=0.202

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.

Additional context

I used Grok Bot to help find the issue and draft the change; I reviewed the change, the repro output and the test results myself.

@suirindo

suirindo commented Dec 2, 2026

Copy link
Copy Markdown

I checked this with the HEAD live-evaluation loop and single-turn helper in an offline harness. A final turn_complete followed by clean EOF kept the completed reply but recorded no duration. A completed turn without EOF recorded 0.250 s, and mid-turn EOF correctly recorded none. The foreground loop checks live_finished after draining the turn but before storing its duration. Could we distinguish actual turn completion from the shutdown wake-up and add both EOF cases to the regression?

AI-assisted review; verification scope is described above.

The foreground loop used `live_finished` to decide whether to record a
turn's duration, but that event is also set when the session closes cleanly
right after a final `turn_complete`, so a completed turn lost its duration.

Record whether `turn_complete` was actually received for the current turn
and use that to decide; a stream that ends mid-turn is still left untimed.
Add regression tests for both EOF cases.
@Fruiterer333

Fruiterer333 commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for running this so carefully, and for the exact three-way breakdown (completed turn / completed + clean EOF / mid-turn EOF) — that made the problem easy to see. You're right: live_finished is also set when the session closes cleanly right after a final turn_complete, so the check dropped the duration of a turn that had actually completed.

I pushed a follow-up commit, fede1a2, instead of amending. _LiveSession now records whether the agent's turn_complete was actually received for the current turn (separate from the event that also wakes the foreground loop at shutdown). The loop stores the duration only when that flag is set, and still breaks afterwards if the session has finished, so a stream that ends mid-turn stays untimed.

There are two new regression cases (parametrized): turn_complete followed by clean EOF keeps the reply and records a duration, and EOF without turn_complete records none. The first one fails on the previous commit and passes now.

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.

Live eval never times its turns, so invocation_duration_v1 is n/a for every invocation of a Live (run_live) agent

2 participants