Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review (claude): release a stale primary on a disabled-voice claim
[._.]/ Adam Eivy5001f3d721ce
diff --git a/server/services/voice/voiceOutput.js b/server/services/voice/voiceOutput.jsindex dc9ecb658e..7d3a1f5bc3 100644--- a/server/services/voice/voiceOutput.js+++ b/server/services/voice/voiceOutput.js@@ -72,23 +72,33 @@ export const registerVoiceOutputCandidate = (socket) => {candidates.add(socket);};-// Make `socket` the sole proactive-output recipient. The user's active tab-// calls this (via the `voice:output:claim` socket event) on focus / visibility-// / explicit request. The previous primary is told it lost the binding so its-// UI can reflect the change; the new primary is told it now owns output.// Stamp claim recency so a later election or promotion picks the-// most-recently-focused tab (not merely the newest connection), without making-// it primary. Used directly while voice is disabled so focus history survives-// until voice is enabled.-export const noteVoiceOutputFocus = (socket) => {- if (!socket) return;+// most-recently-focused tab, not merely the newest connection.+const stampFocus = (socket) => {candidates.add(socket);claimSeq.set(socket, ++claimCounter);};+// Record a focus claim while voice is disabled: stamp recency without electing a+// primary (and without logging). A primary held by another tab is cleared so the+// first election after voice is re-enabled follows focus instead of keeping a+// tab the user has since left.+export const noteVoiceOutputFocus = (socket) => {+ if (!socket) return;+ stampFocus(socket);+ if (!primary || primary === socket) return;+ const prev = primary;+ primary = null;+ if (isLive(prev)) prev.emit('voice:output:detached', { reason: 'claimed-elsewhere' });+};++// Make `socket` the sole proactive-output recipient. The user's active tab+// calls this (via the `voice:output:claim` socket event) on focus / visibility+// / explicit request. The previous primary is told it lost the binding so its+// UI can reflect the change; the new primary is told it now owns output.export const claimVoiceOutput = (socket) => {if (!socket) return null;- noteVoiceOutputFocus(socket);+ stampFocus(socket);if (primary === socket) return socket;const prev = primary;primary = socket;diff --git a/server/sockets/voice.test.js b/server/sockets/voice.test.jsindex 40a0885a08..bf206f7e23 100644--- a/server/sockets/voice.test.js+++ b/server/sockets/voice.test.js@@ -353,6 +353,26 @@ describe('voice:output single-recipient wiring', () => {expect(getVoiceOutputSocket()).toBe(focused);});+ it('a claim while voice is disabled releases a stale primary held by another tab', async () => {+ const a = makeFakeSocket();+ const b = makeFakeSocket();+ registerVoiceHandlers(a);+ registerVoiceHandlers(b);+ a.fire('voice:output:available');+ b.fire('voice:output:available');+ a.fire('voice:output:claim');+ await flush();+ expect(getVoiceOutputSocket()).toBe(a);++ // Voice disabled, user moves to b, then re-enables voice without refocusing.+ getVoiceConfig.mockResolvedValue({ enabled: false });+ b.fire('voice:output:claim');+ await flush();+ expect(a.emitted.some((e) => e.event === 'voice:output:detached')).toBe(true);+ getVoiceConfig.mockResolvedValue({ enabled: true });+ expect(getVoiceOutputSocket()).toBe(b);+ });+it('drops a claim from a tab that disconnected while the config was read', async () => {const a = makeFakeSocket();registerVoiceHandlers(a);