voice gateway: instrument end-to-end latency

Add trace boundaries and timings so the last-word -> first-audio latency can
be split by section:

- voice_transport: emit `voice_speech_end` (the last VAD-speech frame, i.e. the
  true "last word"), `voice_speak_start`, `voice_tts_synth` (Piper duration +
  audio length), and `voice_playback_start` (the instant the first reply
  samples reach the device).
- trace: `TraceLog.append` accepts an explicit `ts` so an event records when it
  happened, not when it was written.
- gateway/voice: trace `gateway_reply_dequeued` at the outbound pump.
- gateway/service: trace `humanize` (duration) and `gateway_reply_queued`; a
  best-effort `_trace` helper tolerates test doubles with no trace log.
- log: persist the engine's per-decision `input_tokens`/`forward_seconds`/
  `total_seconds` (already computed by the backend, previously discarded) into
  the decision row's `extra.timing`.

scripts/voice-latency.py reads data/runs.jsonl and prints a per-interaction
breakdown (endpointing, STT, each SemIf guard, act/assess, humanize, TTS,
playback) plus aggregates.
This commit is contained in:
gabby committed 2026-10-06 22:01:32 +00:00
1 parent e426998cf7
commit 5bb0e9d21d
6 files changed
+284 -4

No files matched your search

+8
View File
@@ -42,6 +42,14 @@ class DecisionLog:
}
if extra:
row["extra"] = extra
result_extra = getattr(result, "extra", None) or {}
timing = {
key: result_extra[key]
for key in ("input_tokens", "forward_seconds", "total_seconds")
if key in result_extra
}
if timing:
row.setdefault("extra", {})["timing"] = timing
self.path.parent.mkdir(parents=True, exist_ok=True)
with self.path.open("a") as handle:
handle.write(json.dumps(row) + "\n")