Latency Metrics (end-to-end) — re-implemented on new architecture#124
Open
angrave wants to merge 3 commits into
Open
Latency Metrics (end-to-end) — re-implemented on new architecture#124angrave wants to merge 3 commits into
angrave wants to merge 3 commits into
Conversation
added 2 commits
July 15, 2026 22:28
Re-implements PR #67 (latency-metrics) onto the current staging architecture, which had replaced the codebase the original PR targeted. Protocol - New @scribear/audio-frame-protocol lib: versioned, self-describing binary audio-frame envelope (SAFP v1) with magic, TLV metadata fields, and a trailing CRC-32. Mirrored Python codec produces byte-identical frames. Replaces PR #67's hard-coded byte offsets so kiosk/node/python can evolve independently. - ClockSync (Cristian's algorithm) helper for source-vs-server clock offset. Node server - Orchestrator decodes source frames, keeps a bounded per-session chunkId -> {recvMono, sentAt} map, forwards audio upstream, and on each transcript emits two latencies: skew-free monotonic pipelineMs and, once synced, e2eMs. New LatencyChannel -> latencyUpdate server message. - Controller answers timeSyncPing with timeSyncPong. - Schemas: chunk_ids on the upstream transcript message; latencyUpdate + timeSync messages on the node-server schema. Kiosk / client - Kiosk frames audio (chunkId + clock-corrected sentAt) and runs periodic clock-sync probes. - Shared transcription-content-store gains rolling latency averages; the client webapp renders a latency badge. Python - chunkId threaded through controller/service/session/providers; whisper job keeps a chunk->sample ledger and echoes final/in_progress chunk_ids. Tests: SAFP codec + ClockSync unit tests, cross-language frame parity, orchestrator latency correlation, service latencyUpdate, whisper-job ledger, and container integration (SAFP round-trip, non-zero audio, timeSync). See TOBEREVIEWED.md for deferred items and production concerns.
2dce2cb to
0b5122b
Compare
3 tasks
Node Server - Unit Tests Coverage Report
|
Node Server - Integration Tests Coverage Report
|
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.
Supersedes #67. The original
latency-metricsPR was built against the pre-refactor architecture and could not be conflict-merged —staginghad rewritten the node-server, deleted thetranscription-service-clientlib, splitwebappintoclient-webapp/kiosk-webapp, and refactored the Python worker pool, and the new pipeline carried no chunk-id/timestamp to hang latency off of. This PR rebuilds the feature on the current architecture.What it does
@scribear/audio-frame-protocol, "SAFP" v1: magic + version + TLV metadata + CRC-32) carrying achunkIdand a clock-correctedsentAt.chunkId → {recvMono, sentAt}map, forwards audio upstream, and on each transcript correlates the echoedchunk_idsto emit two latencies:pipelineMs— measured on the node's monotonic clock (skew-free);e2eMs— capture→display, using a clock-syncedsentAt;nulluntil synced.timeSyncPing/timeSyncPong(Cristian's algorithm, min-RTT sample).chunkIdthrough the provider/job and echoesfinal/in_progresschunk_idson the transcript message.Design notes
pipelineMsis the trustworthy metric for alerting;e2eMsis indicative (depends on clock-offset estimation).Verification
audio-frame-protocol19 tests (codec + CRC known-answer + ClockSync).Processed 0.0000 secondson its tick regardless) — it now sends a real SAFP frame and asserts a non-zero processed duration.Follow-ups
See
TOBEREVIEWED.mdfor deliberately-deferred items (VAD-config exposure, Python stage-timing diagnostics) and production concerns (clock-skew reliability, decode-drop observability, unauthenticated/unthrottledtimeSyncPing,pendingChunkscap, CRC cost).🤖 Generated with Claude Code