Skip to content

tests: trace-shape schema and checker - #7148

Open
davidzhao wants to merge 2 commits into
dz/telemetry-agent-turnfrom
dz/telemetry-trace-schema
Open

tests: trace-shape schema and checker#7148
davidzhao wants to merge 2 commits into
dz/telemetry-agent-turnfrom
dz/telemetry-trace-schema

Conversation

@davidzhao

@davidzhao davidzhao commented Sep 6, 2026

Copy link
Copy Markdown
Member

What

The nesting of spans is an emergent property of many call sites. A refactor can move a span under the wrong parent while every existing test passes, because each test only asserts the one edge it was written for. This layer writes the rules down once and checks every span in every full-session test against them, and applies the same rules to a real run's export.

How

tests/trace_schema.py (test support, not shipped):

  • SPAN_PARENTS: for every span name the framework emits, the parents it may have (ROOT for none, ANY for spans that follow their caller: rpc_call, event_loop_blocked). An unknown name is a violation, so a new span must be registered.
  • MAY_OUTLIVE_PARENT: the four child/parent edges where the child is allowed to end after its parent, each with the reason (the three startup spans session.start() does not wait for, on_enter, and stalls whose end is one heartbeat late). Everything else must sit inside its parent, with 2 ms of slack.
  • check_trace(): one trace id, every parent present, parent allowed by the schema, bounds, and the per-turn invariants: one agent_turn per lk.speech_id, lk.generation_count equal to the number of generation events, every eou_wait with an outcome. Returns the violations as one line each.
  • Two span sources, same rules: from_readable_spans for an in-memory exporter, from_otlp_json for an export downloaded from LiveKit Cloud. As a CLI, uv run python -m tests.trace_schema traces.json prints the span summary and the violations, so a downloaded trace is validated in seconds (a partial export, keyed to one span, is checked with orphans tolerated).

assert_trace_well_formed(exporter.get_finished_spans()) now ends the full-session tests: the tool call and plain reply in test_agent_turn_span, the barge-in and handoff in test_coverage_spans, the hook and redaction sessions in test_eou_wait_span, the lifecycle and SIP sessions in test_startup_spans. Each scenario guards the whole tree.

Tests

tests/test_trace_schema.py: the schema is self-consistent; a sound trace passes; a misparented llm_request (the keyterm-detection mistake), an eou_detection outside its wait, an unknown span, a missing parent, a child outside its parent, a duplicated speech turn, a generation-count mismatch and a second trace id are each reported; the deliberate overruns pass; the OTLP and in-memory sources agree; a full fake session is well-formed.

Not covered here: the job-level spans (job_entrypoint, room_connect, job_shutdown) have no fake-session path and stay on their unit tests, and only a real room exercises the task contexts that leaked earlier, so the CLI on a downloaded export remains part of the workflow.

Stacked on #7143.

🤖 Generated with Claude Code

@davidzhao davidzhao changed the title tests: a trace-shape schema and checker for every full-session test and for exports tests: trace-shape schema and checker Sep 6, 2026
@davidzhao
davidzhao force-pushed the dz/telemetry-trace-schema branch 2 times, most recently from cec2b33 to ff6cbdf Compare September 6, 2026 23:40
@davidzhao
davidzhao force-pushed the dz/telemetry-trace-schema branch from 419b712 to fe20391 Compare September 7, 2026 00:10
@davidzhao
davidzhao force-pushed the dz/telemetry-trace-schema branch from fe20391 to baf98f2 Compare September 7, 2026 03:54
@davidzhao
davidzhao force-pushed the dz/telemetry-trace-schema branch 2 times, most recently from 1a6bb39 to 6464a56 Compare September 7, 2026 04:14
@davidzhao
davidzhao marked this pull request as ready for review September 7, 2026 05:05
@davidzhao
davidzhao requested a review from a team as a code owner September 7, 2026 05:05
@davidzhao
davidzhao force-pushed the dz/telemetry-trace-schema branch from 6464a56 to aab813c Compare September 7, 2026 05:05

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Devin Review: 1 flag

Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

@davidzhao
davidzhao force-pushed the dz/telemetry-trace-schema branch from aab813c to f524ea1 Compare September 7, 2026 05:48
@davidzhao
davidzhao force-pushed the dz/telemetry-trace-schema branch from f524ea1 to 5d8b16f Compare September 7, 2026 06:26
@davidzhao
davidzhao force-pushed the dz/telemetry-trace-schema branch from 5d8b16f to 1037b94 Compare September 7, 2026 06:50
Comment thread tests/trace_schema.py
"keyterm_detection",
"judge_evaluation",
"amd",
},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A fallback can also trigger:

llm_fallback_adapter
└── llm_request_run
    └── llm_request
        └── llm_request_run
  • llm_fallback_adapter → llm_request_run → llm_request
  • tts_fallback_adapter → tts_request_run → tts_request
  • tts_node → tts_stream_adapter → tts_request_run → tts_request

@davidzhao
davidzhao force-pushed the dz/telemetry-trace-schema branch from 1037b94 to f876f07 Compare September 8, 2026 04:23
@davidzhao
davidzhao force-pushed the dz/telemetry-trace-schema branch from f876f07 to 06e9590 Compare September 8, 2026 04:26
@davidzhao
davidzhao force-pushed the dz/telemetry-trace-schema branch from 06e9590 to 359f6fb Compare September 8, 2026 04:32
@davidzhao
davidzhao force-pushed the dz/telemetry-trace-schema branch 2 times, most recently from 150aaef to ce939a1 Compare September 8, 2026 05:06
@davidzhao
davidzhao force-pushed the dz/telemetry-trace-schema branch from ce939a1 to f0c99d5 Compare September 8, 2026 05:21
@davidzhao
davidzhao force-pushed the dz/telemetry-trace-schema branch 2 times, most recently from 0a22c73 to b95bbce Compare September 8, 2026 05:48
@davidzhao
davidzhao force-pushed the dz/telemetry-trace-schema branch from b95bbce to e7260a5 Compare September 8, 2026 05:58
@davidzhao
davidzhao force-pushed the dz/telemetry-trace-schema branch from e7260a5 to 189771f Compare September 8, 2026 06:10
davidzhao and others added 2 commits September 8, 2026 00:27
…nd for exports

SPAN_PARENTS lists, for every span the framework emits, the parents it may
have; MAY_OUTLIVE_PARENT the four deliberate overruns. check_trace applies
them plus the per-turn invariants (one agent_turn per speech, generation
events matching lk.generation_count, an outcome on every eou_wait) to spans
from an in-memory exporter or an OTLP JSON export, and doubles as a CLI for
downloaded traces. The full-session tests now end with the checker, so each
scenario guards the whole tree rather than the one edge it names.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… outlast it

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@davidzhao
davidzhao force-pushed the dz/telemetry-trace-schema branch from 189771f to 2632d51 Compare September 8, 2026 07:30
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.

2 participants