Skip to content

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

fix: address review (claude): phone-call barge-in never cancelled the in-flight reply

[._.]/ Adam Eivy552d3d8f01a1
diff --git a/server/sockets/voice.js b/server/sockets/voice.js
index 65832696b5..c07404aaff 100644
--- a/server/sockets/voice.js
+++ b/server/sockets/voice.js
@@ -397,7 +397,7 @@ export const registerVoiceHandlers = (socket) => {
// `runTurn` utterances the microphone produces, and the destination of the
// reply, which is played into the call rather than out of the speakers.
// ---------------------------------------------------------------------------
- const call = { endpointer: null, busy: false };
+ const call = { endpointer: null, busy: false, ctrl: null };
// Speak the line the caller was rung to hear, once, as soon as the far end
// picks up. Without this a mind-placed call connects to silence and the user
@@ -434,6 +434,9 @@ export const registerVoiceHandlers = (socket) => {
const runCallUtterance = async (utterance) => {
call.busy = true;
markSpeaking();
+ call.ctrl?.abort();
+ call.ctrl = new AbortController();
+ const { signal } = call.ctrl;
let spoken = '';
try {
await runTurn({
@@ -441,12 +444,14 @@ export const registerVoiceHandlers = (socket) => {
mimeType: 'audio/wav',
history: state.history,
state,
+ signal,
// A mind-placed call carries the mind's own briefing, so the voice on
// the phone continues that conversation instead of answering cold.
systemContext: getCallContext(),
// The pipeline speaks the widget's event vocabulary; only the audio is
// re-addressed, so persona, tools, and the confirm gate are unchanged.
emit: (event, data) => {
+ if (signal.aborted) return;
if (event === 'voice:tts:audio') {
spoken = data?.sentence || spoken;
socket.emit('voice:call:tts', data);
@@ -456,8 +461,10 @@ export const registerVoiceHandlers = (socket) => {
socket.emit(event, data);
},
});
+ if (signal.aborted) return;
if (spoken) recordTurn('assistant', spoken);
} catch (err) {
+ if (signal.aborted) return;
console.error(`📞 call turn failed: ${err.message}`);
socket.emit('voice:error', { stage: 'call', message: err.message });
} finally {
@@ -510,7 +517,7 @@ export const registerVoiceHandlers = (socket) => {
// Barge-in: the caller talking over a reply cancels it, exactly as
// pressing the widget's interrupt does.
if (call.endpointer.speaking && call.busy) {
- state.ctrl?.abort();
+ call.ctrl?.abort();
state.pendingDestructive = null;
socket.emit('voice:interrupt', { reason: 'barge-in' });
}
@@ -634,6 +641,7 @@ export const registerVoiceHandlers = (socket) => {
// keeps exactly one home.
releaseVoiceOutput(socket);
state.ctrl?.abort();
+ call.ctrl?.abort();
// Abort any pending UI refresh waiters so their turns don't hang.
const waiters = state.uiWaiters;
state.uiWaiters = [];
diff --git a/server/sockets/voice.test.js b/server/sockets/voice.test.js
index dc3b7357f2..aa6d6fbdc9 100644
--- a/server/sockets/voice.test.js
+++ b/server/sockets/voice.test.js
@@ -20,6 +20,10 @@ vi.mock('../services/voice/tts.js', () => ({
// Meeting capture transcribes over the network (whisper.cpp's HTTP server);
// stub it so the capture-routing tests below run offline and deterministically.
vi.mock('../services/voice/stt.js', () => ({ transcribe: vi.fn() }));
+// The call-host audio path (runCallUtterance) drives the full LLM/tools
+// pipeline; stub it so the barge-in test below can observe exactly what
+// signal a call turn was given without a real STT/LLM/TTS round trip.
+vi.mock('../services/voice/pipeline.js', () => ({ runTurn: vi.fn(async () => ({})) }));
const { truncateOnWordBoundary, registerVoiceHandlers } = await import('./voice.js');
const {
@@ -28,6 +32,7 @@ const {
__resetVoiceOutput,
} = await import('../services/voice/voiceOutput.js');
const { transcribe } = await import('../services/voice/stt.js');
+const { runTurn } = await import('../services/voice/pipeline.js');
const {
attachHost: attachCallHost,
__resetCallSession,
@@ -482,4 +487,42 @@ describe('voice:capture socket handlers (meeting capture)', () => {
expect(() => socket.fire('voice:call:audio', { pcm: loudFrame() })).not.toThrow();
expect(transcribe).not.toHaveBeenCalled();
});
+
+ it('barge-in aborts the in-flight call turn\'s own signal, not just the widget state.ctrl', async () => {
+ // Regression: runCallUtterance previously ran the phone-call pipeline
+ // with no AbortController at all (state.ctrl belongs to the
+ // browser-widget voice:turn/voice:text path), so the barge-in handler's
+ // `state.ctrl?.abort()` was a no-op for calls — the caller talking over
+ // a reply never actually cancelled it.
+ const socket = makeFakeSocket();
+ registerVoiceHandlers(socket);
+ await socket.fire('voice:call:attach');
+
+ let capturedSignal;
+ let releaseFirstTurn;
+ runTurn.mockImplementationOnce(({ signal }) => {
+ capturedSignal = signal;
+ return new Promise((resolve) => { releaseFirstTurn = resolve; });
+ });
+
+ // First utterance: loud frames start a turn, then silence endpoints it —
+ // runCallUtterance fires and stays pending (call.busy === true).
+ for (let i = 0; i < 14; i += 1) socket.fire('voice:call:audio', { pcm: loudFrame() });
+ for (let i = 0; i < 36; i += 1) socket.fire('voice:call:audio', { pcm: silentFrame() });
+ await flushMicrotasks();
+ expect(runTurn).toHaveBeenCalledTimes(1);
+ expect(capturedSignal).toBeInstanceOf(AbortSignal);
+ expect(capturedSignal.aborted).toBe(false);
+
+ // Caller talks over the still-in-flight reply — the endpointer reports
+ // speaking again while call.busy is true.
+ socket.fire('voice:call:audio', { pcm: loudFrame() });
+ await flushMicrotasks();
+
+ expect(capturedSignal.aborted).toBe(true);
+ expect(socket.emitted.some((e) => e.event === 'voice:interrupt' && e.payload.reason === 'barge-in')).toBe(true);
+
+ releaseFirstTurn({});
+ await flushMicrotasks();
+ });
});