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
fix: reset AuK worker and kill failed process on spawn and stream errors (#10101)
Adam Eivyaa567d8fec05
diff --git a/server/services/voice/aukRuntime.js b/server/services/voice/aukRuntime.jsindex fb9407f531..c6907665ec 100644--- a/server/services/voice/aukRuntime.js+++ b/server/services/voice/aukRuntime.js@@ -92,8 +92,15 @@ function ensureWorker() {worker = child;// Drain diagnostics without copying prompts, paths, or model data into shared logs.child.stderr.on('data', () => {});- child.stdin.on('error', () => { if (pending?.child === child) pending.reject(new ServerError('AuK input stream closed.', { status: 502 })); });const lines = createInterface({ input: child.stdout });+ // A broken stdin or failed spawn leaves a dead handle; tear it down so the next call re-spawns.+ const teardown = (message, status) => {+ lines.close();+ if (worker === child) worker = null;+ if (pending?.child === child) pending.reject(new ServerError(message, { status }));+ child.kill('SIGKILL');+ };+ child.stdin.on('error', () => teardown('AuK input stream closed.', 502));lines.on('line', line => {if (!pending || pending.child !== child) return;let response;@@ -101,7 +108,7 @@ function ensureWorker() {if (response.ok) pending.resolve(response);else pending.reject(new ServerError(`AuK inference failed (${response.error || 'runtime error'}).`, { status: 502 }));});- child.on('error', () => pending?.child === child && pending.reject(new ServerError('AuK could not start. Run setup again.', { status: 503 })));+ child.on('error', () => teardown('AuK could not start. Run setup again.', 503));child.on('close', () => {lines.close();if (worker === child) worker = null;@@ -140,7 +147,10 @@ export async function synthesizeAuk(text, opts = {}, signal) {child.stdin.write(`${JSON.stringify({ segments, instructions: opts.instructions || 'Natural, clear speaking voice',referenceAudio: opts.referenceAudio || null, seed: opts.seed ?? 42,pitchSemitones: opts.pitchSemitones || 0, output })}\n`, error => {- if (error) reject(new ServerError('AuK request could not be sent.', { status: 502 }));+ if (!error) return;+ if (worker === child) worker = null;+ reject(new ServerError('AuK request could not be sent.', { status: 502 }));+ child.kill('SIGKILL');});});return result.then(async meta => ({ ...meta, wav: await readFile(output), engine: 'auk',diff --git a/server/services/voice/aukRuntime.test.js b/server/services/voice/aukRuntime.test.jsindex 1ec4977d83..3027858917 100644--- a/server/services/voice/aukRuntime.test.js+++ b/server/services/voice/aukRuntime.test.js@@ -4,12 +4,14 @@ import { PassThrough } from 'node:stream';import { pinPlatform, pinArch } from '../../lib/testHelper.js';const children = [];const access = vi.fn();+let failWrite = false;vi.mock('node:fs/promises', () => ({ access: (...args) => access(...args), mkdir: vi.fn(),readFile: vi.fn().mockResolvedValue(Buffer.from('test wav')), rm: vi.fn().mockResolvedValue() }));vi.mock('../../lib/childProcess.js', () => ({ execFile: vi.fn(), spawn: vi.fn(() => {const child = new EventEmitter();child.stdin = new PassThrough(); child.stdout = new PassThrough(); child.stderr = new PassThrough();child.kill = vi.fn(() => { child.emit('close', null); return true; });+ if (failWrite) child.stdin.write = (_data, cb) => cb(new Error('EPIPE'));children.push(child); return child;}) }));vi.mock('../../lib/processEnv.js', () => ({ safeChildProcessOptions: value => value, whichFirst: vi.fn() }));@@ -21,7 +23,7 @@ let restoreArch;beforeEach(() => {restorePlatform = pinPlatform('darwin');restoreArch = pinArch('arm64');- access.mockReset().mockResolvedValue(); children.length = 0;+ access.mockReset().mockResolvedValue(); children.length = 0; failWrite = false;});afterEach(() => {unloadAuk();@@ -65,6 +67,31 @@ describe('AuK resident inference lifecycle', () => {expect(children[0].kill).toHaveBeenCalledWith('SIGKILL');expect(await getAukStatus()).toMatchObject({ busy: false, loaded: false });});+ it.each([+ ['spawn error', child => child.emit('error', new Error('ENOENT')), 503],+ ['stdin stream error', child => child.stdin.emit('error', new Error('EPIPE')), 502],+ ])('discards the worker after a %s so the next request re-spawns', async (_name, fail, status) => {+ const failed = synthesizeAuk('Hello.', {});+ const check = expect(failed).rejects.toMatchObject({ status });+ await vi.waitFor(() => expect(children).toHaveLength(1));+ fail(children[0]);+ await check;+ expect(children[0].kill).toHaveBeenCalledWith('SIGKILL');+ expect(await getAukStatus()).toMatchObject({ busy: false, loaded: false });+ const retry = synthesizeAuk('Again.', {});+ await vi.waitFor(() => expect(children).toHaveLength(2));+ response(children[1]);+ await retry;+ });+ it('kills the worker and clears it when the request write fails', async () => {+ failWrite = true;+ const failed = synthesizeAuk('Hello.', {});+ const check = expect(failed).rejects.toThrow('could not be sent');+ await vi.waitFor(() => expect(children).toHaveLength(1));+ await check;+ expect(children[0].kill).toHaveBeenCalledWith('SIGKILL');+ expect((await getAukStatus()).loaded).toBe(false);+ });it('never starts a process or reports readiness for missing model artifacts', async () => {access.mockRejectedValue(new Error('missing'));expect(await getAukStatus()).toMatchObject({ ready: false, loaded: false });