Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix(meeting): require transcript match before dropping held-back mic segments (#1093)

Gabriel Stein4d6f2d2e8b46
diff --git a/src/helpers/ipcHandlers.js b/src/helpers/ipcHandlers.js
index d52be59b7..c99772c1f 100644
--- a/src/helpers/ipcHandlers.js
+++ b/src/helpers/ipcHandlers.js
@@ -21,6 +21,7 @@ const AudioStorageManager = require("./audioStorage");
const TINFOIL_REALTIME_MODEL = "voxtral-mini-4b-realtime";
const liveSpeakerIdentifier = require("./liveSpeakerIdentifier");
const MeetingEchoLeakDetector = require("./meetingEchoLeakDetector");
+const { partitionPendingMicFinals, isWithinRetractWindow } = require("./meetingMicHoldback");
const { applySmartSpacing } = require("./smartSpacing");
const {
transcriptsOverlap,
@@ -3963,7 +3964,11 @@ class IPCHandlers {
const DUPLICATE_TRANSCRIPT_WINDOW_MS = 6000;
const DUPLICATE_TRANSCRIPT_MERGE_LIMIT = 3;
const STREAMING_RISKY_MIC_SEGMENT_HOLDBACK_MS = 3000;
- const LOCAL_RISKY_MIC_SEGMENT_HOLDBACK_MS = 4500;
+ const LOCAL_MEETING_CHUNK_INTERVAL_MS = 5000;
+ // Must outlast one local transcription cycle so a straddling remote
+ // utterance's next-cycle system transcript can confirm buffered echo.
+ const LOCAL_RISKY_MIC_SEGMENT_HOLDBACK_MS = LOCAL_MEETING_CHUNK_INTERVAL_MS + 1000;
+ const RACING_MIC_RETRACT_WINDOW_MS = 4000;
const buildNearbyTranscriptCandidates = (
targetSource,
@@ -4035,9 +4040,15 @@ class IPCHandlers {
for (let i = meetingDiarizationSegments.length - 1; i >= 0; i -= 1) {
const candidate = meetingDiarizationSegments[i];
if (candidate.source !== "mic" || candidate.timestamp == null) continue;
- if (systemTimestamp != null && Math.abs(candidate.timestamp - systemTimestamp) > 4000) {
- if (candidate.timestamp < systemTimestamp) break;
- continue;
+ if (systemTimestamp != null) {
+ const windowMs =
+ candidate.hasBleedEvidence || candidate.likelyRenderBleed
+ ? DUPLICATE_TRANSCRIPT_WINDOW_MS
+ : RACING_MIC_RETRACT_WINDOW_MS;
+ if (!isWithinRetractWindow({ candidate, systemTimestamp, windowMs })) {
+ if (candidate.timestamp < systemTimestamp - DUPLICATE_TRANSCRIPT_WINDOW_MS) break;
+ continue;
+ }
}
const hasMicDuplicateRisk =
candidate.likelyRenderBleed ||
@@ -4068,11 +4079,22 @@ class IPCHandlers {
meetingLocalTranscript += `${meetingLocalTranscript ? " " : ""}${text}`;
};
+ // Held-back mic segments are appended at release time, so insertion order
+ // is not spoken order.
+ const buildOrderedTranscriptText = (segments) =>
+ segments
+ .slice()
+ .sort((left, right) => (left.timestamp ?? 0) - (right.timestamp ?? 0))
+ .map((segment) => segment.text)
+ .join(" ")
+ .trim();
+
const storeMeetingDiarizationSegment = (text, source, timestamp, micSuppression = null) => {
meetingDiarizationSegments.push({
text,
source,
timestamp,
+ committedAt: Date.now(),
suppressionReason: source === "mic" ? micSuppression?.reason || null : null,
hasBleedEvidence: source === "mic" ? !!micSuppression?.hasBleedEvidence : false,
likelyRenderBleed: source === "mic" ? !!micSuppression?.likelyRenderBleed : false,
@@ -4112,52 +4134,41 @@ class IPCHandlers {
return;
}
- const ready = [];
- const deferred = [];
- const now = Date.now();
-
- for (const pending of meetingPendingMicFinals) {
- if (!force && pending.releaseAt > now) {
- deferred.push(pending);
- continue;
- }
-
- if (
- shouldSkipDuplicateMicSegment(pending.text, pending.timestamp, pending.micSuppression)
- ) {
- debugLogger.debug(
- "Dropping buffered mic segment after system context confirmed duplicate",
- {
- text: pending.text.slice(0, 80),
- averageCorrelation: pending.micSuppression?.averageCorrelation?.toFixed(3),
- averageResidual: pending.micSuppression?.averageResidual?.toFixed(3),
- }
- );
- continue;
- }
-
- ready.push(pending);
- }
+ const { deferred, duplicates, releases } = partitionPendingMicFinals({
+ pending: meetingPendingMicFinals,
+ now: Date.now(),
+ force,
+ isDuplicate: (entry) =>
+ shouldSkipDuplicateMicSegment(entry.text, entry.timestamp, entry.micSuppression),
+ });
meetingPendingMicFinals = deferred;
schedulePendingMicFinalFlush();
- for (const pending of ready) {
- if (pending.micSuppression?.hasBleedEvidence) {
- debugLogger.debug("Dropping flagged-bleed mic segment after holdback", {
+ for (const pending of duplicates) {
+ debugLogger.debug(
+ "Dropping buffered mic segment after system context confirmed duplicate",
+ {
+ text: pending.text.slice(0, 80),
+ averageCorrelation: pending.micSuppression?.averageCorrelation?.toFixed(3),
+ averageResidual: pending.micSuppression?.averageResidual?.toFixed(3),
+ }
+ );
+ }
+
+ for (const pending of releases) {
+ debugLogger.debug(
+ pending.micSuppression?.hasBleedEvidence
+ ? "Releasing bleed-flagged mic segment after holdback (no transcript match)"
+ : "Releasing buffered mic segment after duplicate holdback",
+ {
text: pending.text.slice(0, 80),
holdbackMs: pending.holdbackMs,
+ reason: pending.micSuppression?.reason,
averageCorrelation: pending.micSuppression?.averageCorrelation?.toFixed(3),
averageResidual: pending.micSuppression?.averageResidual?.toFixed(3),
- });
- continue;
- }
- debugLogger.debug("Releasing buffered mic segment after duplicate holdback", {
- text: pending.text.slice(0, 80),
- holdbackMs: pending.holdbackMs,
- averageCorrelation: pending.micSuppression?.averageCorrelation?.toFixed(3),
- averageResidual: pending.micSuppression?.averageResidual?.toFixed(3),
- });
+ }
+ );
pending.emit();
}
}
@@ -4986,7 +4997,7 @@ class IPCHandlers {
source === "mic" &&
rms < MEETING_MIC_BLEED_RMS_CEILING &&
peak < MEETING_MIC_BLEED_PEAK_CEILING &&
- meetingEchoLeakDetector.isSystemSpeaking(Date.now() - 5000)
+ meetingEchoLeakDetector.isSystemSpeaking(Date.now() - LOCAL_MEETING_CHUNK_INTERVAL_MS)
) {
debugLogger.debug("Skipping system-dominant mic chunk", {
source,
@@ -5537,7 +5548,7 @@ class IPCHandlers {
meetingLocalTimer = setInterval(() => {
transcribeAllLocalBuffers();
- }, 5000);
+ }, LOCAL_MEETING_CHUNK_INTERVAL_MS);
({ systemAudioMode, systemAudioStrategy } = await startMeetingSystemAudio(
event,
@@ -5784,10 +5795,7 @@ class IPCHandlers {
const { diarizationPcmPath, diarizationSegments, diarizationStartedAt } =
await captureMeetingDiarizationState();
const transcript =
- diarizationSegments
- .map((segment) => segment.text)
- .join(" ")
- .trim() || meetingLocalTranscript;
+ buildOrderedTranscriptText(diarizationSegments) || meetingLocalTranscript;
const sessionSpeakerConfigSnapshot = this.activeMeetingSpeakerConfig;
const noteIdSnapshot = meetingNoteId;
this.activeMeetingSpeakerConfig = null;
@@ -5812,10 +5820,8 @@ class IPCHandlers {
const { diarizationPcmPath, diarizationSegments, diarizationStartedAt } =
await captureMeetingDiarizationState();
const transcript =
- diarizationSegments
- .map((segment) => segment.text)
- .join(" ")
- .trim() || [results[0]?.text, results[1]?.text].filter(Boolean).join(" ");
+ buildOrderedTranscriptText(diarizationSegments) ||
+ [results[0]?.text, results[1]?.text].filter(Boolean).join(" ");
const sessionSpeakerConfigSnapshot = this.activeMeetingSpeakerConfig;
const noteIdSnapshot = meetingNoteId;
diff --git a/src/helpers/meetingMicHoldback.js b/src/helpers/meetingMicHoldback.js
new file mode 100644
index 000000000..e035e51af
--- /dev/null
+++ b/src/helpers/meetingMicHoldback.js
@@ -0,0 +1,57 @@
+/**
+ * Partitions buffered ("risky") meeting mic finals into entries still inside
+ * their holdback window, confirmed system-audio duplicates, and entries to
+ * release.
+ *
+ * Policy: a text match (`isDuplicate`) is the only condition that may drop a
+ * held-back segment. Audio-only echo evidence delays a segment, never
+ * discards it — field logs showed genuine local speech scoring correlations
+ * of 0.73–0.81 during double-talk, above every audio gate. Released segments
+ * with bleed flags can still be retracted when a matching system transcript
+ * arrives late (see removeRacingMicEntriesFor in ipcHandlers.js).
+ */
+const partitionPendingMicFinals = ({ pending, now, force = false, isDuplicate }) => {
+ const deferred = [];
+ const duplicates = [];
+ const releases = [];
+
+ for (const entry of pending) {
+ if (!force && entry.releaseAt > now) {
+ deferred.push(entry);
+ continue;
+ }
+
+ if (isDuplicate(entry)) {
+ duplicates.push(entry);
+ continue;
+ }
+
+ releases.push(entry);
+ }
+
+ return { deferred, duplicates, releases };
+};
+
+/**
+ * A committed mic segment may be retracted by an arriving system transcript
+ * when the two plausibly describe the same audio. Capture timestamps race
+ * directly for segments committed on arrival; held-back segments commit only
+ * after their holdback window, so their confirming transcript — delayed by up
+ * to a transcription cycle — races their commit time instead. Without the
+ * commit-time comparison, a segment released at capture + holdback could
+ * never be retracted: the confirming transcript always arrives more than
+ * `holdback` away from the capture timestamp.
+ */
+const isWithinRetractWindow = ({ candidate, systemTimestamp, windowMs }) => {
+ if (Math.abs(candidate.timestamp - systemTimestamp) <= windowMs) {
+ return true;
+ }
+
+ return (
+ candidate.committedAt != null &&
+ systemTimestamp >= candidate.timestamp &&
+ Math.abs(candidate.committedAt - systemTimestamp) <= windowMs
+ );
+};
+
+module.exports = { partitionPendingMicFinals, isWithinRetractWindow };
diff --git a/test/helpers/meetingMicHoldback.test.js b/test/helpers/meetingMicHoldback.test.js
new file mode 100644
index 000000000..8bdc45e01
--- /dev/null
+++ b/test/helpers/meetingMicHoldback.test.js
@@ -0,0 +1,228 @@
+const test = require("node:test");
+const assert = require("node:assert/strict");
+
+const {
+ partitionPendingMicFinals,
+ isWithinRetractWindow,
+} = require("../../src/helpers/meetingMicHoldback");
+
+const NOW = 1_000_000;
+
+const entry = (overrides = {}) => ({
+ text: "hello there",
+ timestamp: NOW - 5000,
+ releaseAt: NOW - 1,
+ micSuppression: null,
+ ...overrides,
+});
+
+test("defers entries whose holdback has not elapsed without evaluating them", () => {
+ const waiting = entry({ releaseAt: NOW + 2000 });
+ const due = entry({ releaseAt: NOW - 500 });
+ const evaluated = [];
+
+ const { deferred, duplicates, releases } = partitionPendingMicFinals({
+ pending: [waiting, due],
+ now: NOW,
+ isDuplicate: (candidate) => {
+ evaluated.push(candidate);
+ return false;
+ },
+ });
+
+ assert.deepEqual(deferred, [waiting]);
+ assert.deepEqual(duplicates, []);
+ assert.deepEqual(releases, [due]);
+ // The dedupe verdict must be taken at release time, when the system channel
+ // has had the full holdback window to produce a matching transcript.
+ assert.deepEqual(evaluated, [due]);
+});
+
+test("entries due exactly at now are evaluated, not re-deferred", () => {
+ // The flush timer fires at exactly releaseAt, so now === releaseAt is the
+ // common case; re-deferring would cause a needless 0ms reschedule loop.
+ const due = entry({ releaseAt: NOW });
+
+ const { deferred, releases } = partitionPendingMicFinals({
+ pending: [due],
+ now: NOW,
+ isDuplicate: () => false,
+ });
+
+ assert.deepEqual(deferred, []);
+ assert.deepEqual(releases, [due]);
+});
+
+test("force flush evaluates entries still inside the holdback window", () => {
+ const waiting = entry({ releaseAt: NOW + 2000 });
+
+ const { deferred, releases } = partitionPendingMicFinals({
+ pending: [waiting],
+ now: NOW,
+ force: true,
+ isDuplicate: () => false,
+ });
+
+ assert.deepEqual(deferred, []);
+ assert.deepEqual(releases, [waiting]);
+});
+
+test("force flush still drops confirmed duplicates (meeting-stop path)", () => {
+ // flushPendingMicFinals(true) runs at meeting stop; entries inside their
+ // holdback window get their one and only dedupe check there.
+ const echoed = entry({ releaseAt: NOW + 2000, text: "so that is eight dollars a month" });
+ const genuine = entry({ releaseAt: NOW + 2000, text: "thanks for taking the time" });
+
+ const { deferred, duplicates, releases } = partitionPendingMicFinals({
+ pending: [echoed, genuine],
+ now: NOW,
+ force: true,
+ isDuplicate: (candidate) => candidate === echoed,
+ });
+
+ assert.deepEqual(deferred, []);
+ assert.deepEqual(duplicates, [echoed]);
+ assert.deepEqual(releases, [genuine]);
+});
+
+test("drops entries only when the transcript matcher confirms a duplicate", () => {
+ const echoed = entry({ text: "we have our own cloud server" });
+ const genuine = entry({ text: "how do you make money off of this" });
+
+ const { duplicates, releases } = partitionPendingMicFinals({
+ pending: [echoed, genuine],
+ now: NOW,
+ isDuplicate: (candidate) => candidate === echoed,
+ });
+
+ assert.deepEqual(duplicates, [echoed]);
+ assert.deepEqual(releases, [genuine]);
+});
+
+test("regression: bleed-flagged speech without a transcript match is released, not dropped", () => {
+ // Field logs (2026-07-02, Windows): genuine local speech during double-talk
+ // scored correlations of 0.73–0.81 and was silently discarded after holdback
+ // even though no system transcript ever matched it.
+ const flagged = entry({
+ text: "how do you make money off of this one",
+ micSuppression: {
+ reason: "double_talk",
+ hasBleedEvidence: true,
+ likelyRenderBleed: false,
+ averageCorrelation: 0.742,
+ averageResidual: 0.45,
+ },
+ });
+
+ const { deferred, duplicates, releases } = partitionPendingMicFinals({
+ pending: [flagged],
+ now: NOW,
+ isDuplicate: () => false,
+ });
+
+ assert.deepEqual(deferred, []);
+ assert.deepEqual(duplicates, []);
+ assert.deepEqual(releases, [flagged]);
+});
+
+test("bleed-flagged speech that matches a system transcript is still dropped", () => {
+ const echoed = entry({
+ text: "we are very early and so i am still trying to figure out the best",
+ micSuppression: { hasBleedEvidence: true, averageCorrelation: 0.81 },
+ });
+
+ const { duplicates, releases } = partitionPendingMicFinals({
+ pending: [echoed],
+ now: NOW,
+ isDuplicate: () => true,
+ });
+
+ assert.deepEqual(duplicates, [echoed]);
+ assert.deepEqual(releases, []);
+});
+
+test("preserves queue order within each partition", () => {
+ const first = entry({ text: "first", releaseAt: NOW - 30 });
+ const second = entry({ text: "second", releaseAt: NOW - 20 });
+ const third = entry({ text: "third", releaseAt: NOW - 10 });
+
+ const { releases } = partitionPendingMicFinals({
+ pending: [first, second, third],
+ now: NOW,
+ isDuplicate: () => false,
+ });
+
+ assert.deepEqual(
+ releases.map((candidate) => candidate.text),
+ ["first", "second", "third"]
+ );
+});
+
+test("handles an empty queue", () => {
+ const { deferred, duplicates, releases } = partitionPendingMicFinals({
+ pending: [],
+ now: NOW,
+ isDuplicate: () => false,
+ });
+
+ assert.deepEqual(deferred, []);
+ assert.deepEqual(duplicates, []);
+ assert.deepEqual(releases, []);
+});
+
+test("retract window matches on capture timestamps for segments committed on arrival", () => {
+ const candidate = { timestamp: NOW, committedAt: NOW };
+
+ assert.equal(
+ isWithinRetractWindow({ candidate, systemTimestamp: NOW + 3000, windowMs: 6000 }),
+ true
+ );
+ assert.equal(
+ isWithinRetractWindow({ candidate, systemTimestamp: NOW + 6001, windowMs: 6000 }),
+ false
+ );
+});
+
+test("regression: late confirmation races commit time for held-back segments", () => {
+ // Local mode stamps segments at transcription completion and releases them
+ // holdback ms later, so a confirming next-cycle system transcript is always
+ // more than `holdback` past the capture timestamp. On capture timestamps
+ // alone this candidate could categorically never be retracted.
+ const holdback = 6000;
+ const released = { timestamp: NOW, committedAt: NOW + holdback };
+
+ assert.equal(
+ isWithinRetractWindow({ candidate: released, systemTimestamp: NOW + 6500, windowMs: 6000 }),
+ true
+ );
+ assert.equal(
+ isWithinRetractWindow({
+ candidate: released,
+ systemTimestamp: NOW + holdback + 6001,
+ windowMs: 6000,
+ }),
+ false
+ );
+});
+
+test("commit-time race never matches system transcripts from before the segment was spoken", () => {
+ const released = { timestamp: NOW, committedAt: NOW + 6000 };
+
+ assert.equal(
+ isWithinRetractWindow({ candidate: released, systemTimestamp: NOW - 6500, windowMs: 6000 }),
+ false
+ );
+});
+
+test("segments without a commit time fall back to the capture window only", () => {
+ const legacy = { timestamp: NOW, committedAt: null };
+
+ assert.equal(
+ isWithinRetractWindow({ candidate: legacy, systemTimestamp: NOW + 6500, windowMs: 6000 }),
+ false
+ );
+ assert.equal(
+ isWithinRetractWindow({ candidate: legacy, systemTimestamp: NOW + 5000, windowMs: 6000 }),
+ true
+ );
+});