Skip to content

fix(metrics): re-arm turn guard in anchorUserSpeechStart — pipeline turns emit no metrics/transcript#125

Merged
nicolotognoni merged 1 commit into
mainfrom
worktree-fix-pipeline-turn-metrics-rearm
May 30, 2026
Merged

fix(metrics): re-arm turn guard in anchorUserSpeechStart — pipeline turns emit no metrics/transcript#125
nicolotognoni merged 1 commit into
mainfrom
worktree-fix-pipeline-turn-metrics-rearm

Conversation

@nicolotognoni
Copy link
Copy Markdown
Collaborator

Summary

One-line bug in both SDKs. In pipeline mode, every user→agent turn after the firstMessage emitted no per-turn metrics and no live dashboard transcript. Root cause: anchorUserSpeechStart() re-opens a turn (sets _turnStart) but did not clear the _turnAlreadyClosed guard left set by the previous turn's recordTurnComplete. Since startTurnIfIdle() no-ops once _turnStart is non-null, the guard never re-armed, so every subsequent recordTurnComplete() short-circuited to null.

emitTurnMetrics(null) then bails before MetricsStore.recordTurn(), which is what broadcasts the SSE turn_complete event the dashboard transcript subscribes to — so both the metrics and the live transcript share that dropped path (one root cause, not two bugs).

Symptoms (real Twilio + Deepgram + Cerebras + Inworld pipeline call)

  • Dashboard LATENCY panel all / 0 ms; COST panel empty per turn.
  • Transcript only appears after the call ends, not live.
  • Only one [event] metrics fired (turn 0 = firstMessage); the real user turns emitted transcript but no metrics.
  • call_end metrics.turns had a single element despite 8 transcript entries.

Fix

Clear the guard in anchorUserSpeechStart(), mirroring what startTurn() already does:

  • libraries/typescript/src/metrics.tsthis._turnAlreadyClosed = false;
  • libraries/python/getpatter/services/metrics.pyself._turn_already_closed = False

Safe: anchorUserSpeechStart() no-ops once the turn is committed (_turnCommittedMono/_turn_committed_mono guard), so the flag is only re-armed at the start of a fresh, uncommitted turn — never the post-commit barge-in path the guard protects.

Breaking change?

No. Internal metrics-accumulator fix, no public API change.

Versioning

No version bump — lands under ## Unreleased### Fixed. Release rolls it into the next version later (not blocking). (package-lock.json version synced 0.6.2 → 0.6.3 to match package.json on main — stale lockfile, not a bump.)

Test plan

  • New metrics-turn-rearm tests (TS + Python) — fail before the fix (recordTurnComplete returns null), pass after.
  • Python: pytest tests/ -m "not soak"1940 passed.
  • TypeScript: npm test1555 passed; npm run lint + npm run build clean.
  • Parity: identical one-line fix + symmetric tests in both SDKs.

…rns)

Pipeline-mode user→agent turns after the firstMessage emitted no per-turn
metrics and no live dashboard transcript. anchorUserSpeechStart() re-opens
a turn (sets _turnStart) but did not clear the _turnAlreadyClosed guard
left set by the previous turn's recordTurnComplete. startTurnIfIdle() is a
no-op once _turnStart is non-null, so the guard never re-armed, and every
subsequent recordTurnComplete() short-circuited to null — dropping per-turn
latency/cost AND the live SSE turn_complete that feeds the dashboard
transcript (it only showed up after call end).

Fix: clear _turnAlreadyClosed in anchorUserSpeechStart(), mirroring
startTurn(). The method already no-ops after commit, so this only re-arms
at the start of a fresh uncommitted turn — the post-commit barge-in guard
is untouched. Parity: identical one-line fix in both SDKs.

No version bump (lands under ## Unreleased; release later). package-lock
version synced 0.6.2 -> 0.6.3 to match package.json on main (stale lockfile).

Tests: new metrics-turn-rearm tests (RED before, GREEN after) in both SDKs.
Python 1940 pass, TypeScript 1555 pass, lint + build clean.
@nicolotognoni nicolotognoni force-pushed the worktree-fix-pipeline-turn-metrics-rearm branch from 90de711 to 2ab4de6 Compare May 29, 2026 16:05
@nicolotognoni nicolotognoni merged commit 8f14e62 into main May 30, 2026
13 checks passed
@github-actions github-actions Bot deleted the worktree-fix-pipeline-turn-metrics-rearm branch May 31, 2026 07:46
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.

1 participant