fix(diag): compute busFlowing from per-poll counter deltas

Cumulative pushed/consumed never regress, so '> 0' stayed true forever
after the first frame — a stalled renderer bus (one of the states this
diagnostic exists to expose) would still report flowing. First sample
after enable reports false (no baseline yet).

Addresses CodeRabbit review on #95.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
OmikronApex
2026-07-11 00:18:10 +02:00
co-authored by Claude Fable 5
parent ee7abe3dc9
commit d069414300
+17 -3
View File
@@ -341,12 +341,27 @@ export function initAudioBridge(): void {
if (audio && isDebugEnabled()) {
let lastSnapshot = '';
let lastLogged = 0;
// busFlowing must reflect the CURRENT poll interval: cumulative
// pushed/consumed counters never regress, so "> 0" would stay true
// forever after the first frame — masking a stalled bus, which is
// one of the states this diagnostic exists to expose.
let prevBusCounts: { pushed: number; consumed: number } | null = null;
setInterval(() => {
try {
if (!audio) return;
const running = !!audio.isAudioRunning?.();
const dev = running ? audio.getCurrentDevice?.() : null;
const bus = audio.getRendererBusMetrics?.() ?? null;
let busFlowing = false;
if (bus) {
if (prevBusCounts) {
busFlowing = bus.pushedFrames > prevBusCounts.pushed
&& bus.consumedFrames > prevBusCounts.consumed;
}
prevBusCounts = { pushed: bus.pushedFrames, consumed: bus.consumedFrames };
} else {
prevBusCounts = null;
}
const snapshot = JSON.stringify({
running,
inputType: dev?.inputType ?? '',
@@ -357,9 +372,8 @@ export function initAudioBridge(): void {
backingPlaying: !!audio.isBackingPlaying?.(),
streamOutputActive: !!audio.isStreamOutputActive?.(),
busEnabled: bus?.enabled ?? null,
// pushed/consumed prove frames are flowing; deltas matter,
// absolute counts churn — bucket to "moving or not".
busFlowing: !!bus && bus.pushedFrames > 0 && bus.consumedFrames > 0,
// per-poll delta ("moved this interval"), not cumulative.
busFlowing,
busUnderflows: bus?.underflowCount ?? null,
busOverflows: bus?.overflowCount ?? null,
});