Fix crash in STT/TTS latency calc on TurnMetricsData entries#72
Merged
Conversation
Pipecat's smart-turn detector writes TurnMetricsData entries to pipecat_metrics.jsonl whose `value` field is a dict, not a number. The latency calculators ran the numeric range check `0 < value_sec < N` before filtering by metric type, so the dict comparison raised TypeError and aborted the whole file — returning no latencies at all. Reorder the checks so type/processor/stage filtering runs first, then validate `value` is numeric via isinstance. Also wrap per-line parsing in try/except so one malformed entry no longer discards the rest, and log the offending entry (line number, value type, raw JSON) for future diagnosis. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
katstankiewicz
approved these changes
Apr 23, 2026
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
ConversationWorkercrashed the entire pass (returningNonefor STT/TTS latency) wheneverpipecat_metrics.jsonlcontained aTurnMetricsDataentry, because Pipecat's smart-turn detector writes a dict-shapedvalue({is_complete, probability, e2e_processing_time_ms}) and the numeric range check0 < value_sec < Nran before the type filter._calculate_stt_latencyand_calculate_tts_latencyto filter bytype/processor/stagefirst, then validatevalueis numeric viaisinstancebefore multiplying.valueand its Python type, themetric.type, and the truncated raw JSON — so future shape surprises surface as warnings instead of silently losing all latency data.logger.exceptionfor a traceback if something unexpected does slip through.Symptom that triggered this
Raw offending entry:
{"type": "TurnMetricsData", "processor": "BaseSmartTurn", "value": {"is_complete": false, "probability": 0.028, "e2e_processing_time_ms": 51.2}}Test plan
pipecat_metrics.jsonlcontainsTurnMetricsDataentries and confirmlatency.stt/latency.ttsare populated in the result instead ofnull.ProcessingMetricsData/TTFBMetricsData/LatencyMetricentries — latency numbers should match prior runs.valuetype, and raw JSON and processing continues.🤖 Generated with Claude Code