feat(ui-flow): voice trace bytes/sec window and reset on leave-voice

Track rolling bytesPerSec in voice-capture trace logs and reset capture
counters when the user leaves voice.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Raven Scott
2026-05-23 05:22:13 -04:00
co-authored by Cursor
parent c01d59a381
commit 82fb4a090c
+32 -11
View File
@@ -9,6 +9,16 @@ const flowLog = createLogger('ui-flow')
let voiceCaptureChunkCount = 0
let voiceCaptureBytes = 0
let displayCaptureFrameCount = 0
let voiceCaptureTraceWindowStart = 0
let voiceCaptureTraceWindowBytes = 0
function resetVoiceCaptureTrace () {
voiceCaptureChunkCount = 0
voiceCaptureBytes = 0
displayCaptureFrameCount = 0
voiceCaptureTraceWindowStart = Date.now()
voiceCaptureTraceWindowBytes = 0
}
function fromBase64 (str) {
if (typeof Buffer !== 'undefined') return Buffer.from(str || '', 'base64')
@@ -426,19 +436,29 @@ async function dispatchUiMessage (platform, msg, hooks = {}) {
if (t === 'voice-capture-chunk') {
voiceCaptureChunkCount++
const chunk = msg.data
let nbytes = 0
if (chunk) {
if (typeof chunk === 'string') voiceCaptureBytes += chunk.length
else if (chunk.byteLength != null) voiceCaptureBytes += chunk.byteLength
else if (chunk.length != null) voiceCaptureBytes += chunk.length
if (typeof chunk === 'string') nbytes = chunk.length
else if (chunk.byteLength != null) nbytes = chunk.byteLength
else if (chunk.length != null) nbytes = chunk.length
voiceCaptureBytes += nbytes
}
if (
process.env.PEARCORD_LOG_VOICE_CAPTURE_TRACE === '1' &&
voiceCaptureChunkCount % 200 === 0
) {
log.trace('voice-capture chunks', {
count: voiceCaptureChunkCount,
bytes: voiceCaptureBytes
})
if (process.env.PEARCORD_LOG_VOICE_CAPTURE_TRACE === '1') {
if (!voiceCaptureTraceWindowStart) voiceCaptureTraceWindowStart = Date.now()
voiceCaptureTraceWindowBytes += nbytes
if (voiceCaptureChunkCount % 200 === 0) {
const elapsedSec = Math.max(
0.001,
(Date.now() - voiceCaptureTraceWindowStart) / 1000
)
log.trace('voice-capture chunks', {
count: voiceCaptureChunkCount,
bytes: voiceCaptureBytes,
bytesPerSec: Math.round(voiceCaptureTraceWindowBytes / elapsedSec)
})
voiceCaptureTraceWindowStart = Date.now()
voiceCaptureTraceWindowBytes = 0
}
}
platform.ingestVoiceCapture(msg.data)
return true
@@ -553,6 +573,7 @@ async function dispatchUiMessage (platform, msg, hooks = {}) {
}
if (t === 'leave-voice') {
await platform.leaveVoiceChannel()
resetVoiceCaptureTrace()
pushState()
return true
}