Skip to content

Private AI meeting notes that stay on your computer. No meeting bot. Free and open source for Mac, Windows and Linux. An alternative to Granola, Otter and Fireflies.

Notes engine: start fresh after a lost graphics card, and try the card again after a crash without it (#32, #36); Windows call audio Manage opens Sound settings (#35); no id -F off a Mac

christianmat0f378ef3163d
diff --git a/app/src/main/engine.ts b/app/src/main/engine.ts
index 7abbbfbf..d4254792 100644
--- a/app/src/main/engine.ts
+++ b/app/src/main/engine.ts
@@ -13,6 +13,9 @@ export class GraphicsGaveUpError extends Error { name = 'GraphicsGaveUpError' }
export const WATCH = { probeMs: 90_000, loadMs: 5 * 60_000, firstTokenMs: 5 * 60_000, cpuLoadMs: 15 * 60_000, cpuFirstTokenMs: 30 * 60_000 }
type Limits = typeof WATCH
+/** Vulkan's "the graphics card was reset" (a driver hang): the process that saw it can never use the card again */
+export const deviceLost = (message: string): boolean => /ErrorDeviceLost|VK_ERROR_DEVICE_LOST/i.test(message)
+
export type ChatRequest = { messages: EngineMessage[]; maxTokens?: number; thoughtBudget?: number; /** instead of the family's sampling temperature */ temperature?: number }
export interface Engine {
@@ -51,7 +54,11 @@ export class UtilityEngine implements Engine {
private limits: Limits
- constructor(private workerPath: string, private opts: { gpuFallback?: boolean } & Partial<Limits> = {}) {
+ /**
+ * cpuCrashes (Linux): the engine dies on the processor alone (code 132: Electron's allocator refuses llama.cpp's
+ * single > 2 GiB weight buffer), so a lost graphics card starts the engine again on the card, not without it.
+ */
+ constructor(private workerPath: string, private opts: { gpuFallback?: boolean; cpuCrashes?: boolean } & Partial<Limits> = {}) {
this.limits = { ...WATCH, ...opts }
}
@@ -97,15 +104,26 @@ export class UtilityEngine implements Engine {
clearTimeout(p.timer)
if (e.type === 'result' && p.model) this.loaded = true
if (e.type === 'result') p.resolve(e.data)
- else p.reject(e.code === 'OOM' ? new InsufficientMemoryError(e.message) : new Error(e.message))
+ else if (this.opts.gpuFallback && deviceLost(e.message)) {
+ // the card was reset under it: a fresh engine (on the processor, where that works) is the only way on
+ if (!this.opts.cpuCrashes) this.cpuOnly = true
+ console.warn(`notes engine: the graphics card was lost (${e.message}); starting it again${this.cpuOnly ? ' without the graphics card' : ''}`)
+ this.pending.set(e.id, p)
+ this.drop(() => new GraphicsGaveUpError(`The graphics card was lost: ${e.message}`))
+ } else p.reject(e.code === 'OOM' ? new InsufficientMemoryError(e.message) : new Error(e.message))
})
proc.on('exit', (code: number) => {
// stopped as stuck (drop): already dealt with
if (this.proc !== proc) return
this.proc = undefined
- const starting = !!this.opts.gpuFallback && !this.cpuOnly && !this.loaded && [...this.pending.values()].some((p) => p.load)
+ const loading = !!this.opts.gpuFallback && !this.loaded && [...this.pending.values()].some((p) => p.load)
+ const starting = loading && !this.cpuOnly
+ // it died starting without the card too (Linux, code 132): staying off the card would only crash again, so the
+ // next try uses the card, with a fresh look at it (the first look sometimes finds no card at all)
+ const backToCard = loading && this.cpuOnly
if (starting) this.cpuOnly = true
- if (!this.disposed) console.error(`notes engine stopped (code ${code})${starting ? '; starting it again without the graphics card' : ''}`)
+ if (backToCard) this.cpuOnly = false
+ if (!this.disposed) console.error(`notes engine stopped (code ${code})${starting ? '; starting it again without the graphics card' : backToCard ? ' without the graphics card too; the next try uses the card again' : ''}`)
for (const p of this.pending.values()) { clearTimeout(p.timer); p.reject(starting ? new GraphicsGaveUpError('The notes engine stopped while starting on the graphics card') : new Error('The notes engine stopped unexpectedly')) }
this.pending.clear()
if (!this.disposed) for (const cb of this.exitListeners) cb()
diff --git a/app/src/main/index.ts b/app/src/main/index.ts
index 7c0b0a64..2b091302 100644
--- a/app/src/main/index.ts
+++ b/app/src/main/index.ts
@@ -550,7 +550,7 @@ app.whenReady().then(() => {
// 32 GB and up: the notes model reads each meeting in as it happens (notes/readAhead.ts)
const readsAhead = !isFake() && readAheadAllowed(os.totalmem())
// the notes model: one job at a time, recording first; loaded when needed, the best one downloaded
- const engine = isFake() ? new FakeEngine() : new UtilityEngine(join(__dirname, 'engine.js'), { gpuFallback: process.platform !== 'darwin' })
+ const engine = isFake() ? new FakeEngine() : new UtilityEngine(join(__dirname, 'engine.js'), { gpuFallback: process.platform !== 'darwin', cpuCrashes: process.platform === 'linux' })
if (engine instanceof UtilityEngine) probeGpu = () => engine.probe().then((g) => {
console.info('NOTES', `graphics: ${g.gpuType || 'none'}${g.gpuNames.length ? ` (${g.gpuNames.join(', ')})` : ''}, ${g.vramTotalGB.toFixed(1)} GB`)
return g
diff --git a/app/src/main/permissions.ts b/app/src/main/permissions.ts
index 1c5b102f..a4021c25 100644
--- a/app/src/main/permissions.ts
+++ b/app/src/main/permissions.ts
@@ -35,7 +35,7 @@ export function parseStatus(raw: unknown, o: { axAsked?: boolean } = {}): Omit<P
}
/** Windows' own pages for these (Linux has none): a mic blocked under Privacy & security is turned on there */
-const WINDOWS_SETTINGS: Partial<Record<PermissionKind, string>> = { mic: 'ms-settings:privacy-microphone', notifications: 'ms-settings:notifications' }
+const WINDOWS_SETTINGS: Partial<Record<PermissionKind, string>> = { mic: 'ms-settings:privacy-microphone', systemAudio: 'ms-settings:sound', notifications: 'ms-settings:notifications' }
const ASK: Record<Exclude<PermissionKind, 'notifications'>, string> = { mic: 'mic-auth', systemAudio: 'audio-auth', calendar: 'calendar-auth', accessibility: 'ax-auth' }
diff --git a/app/src/main/user.ts b/app/src/main/user.ts
index f3aa38f3..549502ab 100644
--- a/app/src/main/user.ts
+++ b/app/src/main/user.ts
@@ -2,9 +2,10 @@ import { execFileSync } from 'node:child_process'
import { userInfo } from 'node:os'
let cached: string | undefined
-/** The full name of the person using this Mac (Daniel Brooks), not the short one (daniel); cached */
-export function macFullName(): string {
- if (cached !== undefined) return cached
- try { cached = execFileSync('id', ['-F'], { encoding: 'utf8', timeout: 2000 }).trim() } catch { cached = '' }
+/** The full name of the person using this Mac (Daniel Brooks), not the short one (daniel); cached. Elsewhere the login name. */
+export function macFullName(platform: string = process.platform): string {
+ if (cached) return cached
+ // id -F is the Mac's own: elsewhere it only prints an error
+ if (platform === 'darwin') try { cached = execFileSync('id', ['-F'], { encoding: 'utf8', timeout: 2000, stdio: ['ignore', 'pipe', 'ignore'] }).trim() } catch { cached = '' }
return (cached ||= userInfo().username)
}
diff --git a/app/test/engineWatchdog.test.ts b/app/test/engineWatchdog.test.ts
index f9431fc2..f9a8f65a 100644
--- a/app/test/engineWatchdog.test.ts
+++ b/app/test/engineWatchdog.test.ts
@@ -99,3 +99,61 @@ describe('the notes engine on a Mac', () => {
expect(procs[0].killed).toBe(false)
})
})
+
+describe('the notes engine off a Mac: a graphics card that is lost, and a processor that crashes (#32, #36)', () => {
+ const fail = (p: Proc, type: string, message: string) => { const m = p.sent.find((x) => x.type === type); p.emit('message', { id: m.id, type: 'error', message }) }
+ const loaded = async (e: InstanceType<typeof UtilityEngine>, p = 0) => { const l = e.load('m.gguf', 32768, 8192); procs[p].answer('load', { contextSize: 32768 }); await l }
+
+ it('a lost graphics device stops the engine (that process can never use the card again) and the next try starts fresh', async () => {
+ const e = new UtilityEngine('engine.js', { gpuFallback: true, ...limits })
+ await loaded(e)
+ const exits: number[] = []
+ e.onExit(() => exits.push(1))
+ const c = e.chat(chat, () => {}).catch((x) => x)
+ fail(procs[0], 'chat', 'vk::Queue::submit: ErrorDeviceLost')
+ expect(await c).toBeInstanceOf(GraphicsGaveUpError)
+ expect(procs[0].killed).toBe(true)
+ expect(exits).toEqual([1])
+ void e.load('m.gguf', 32768, 8192).catch(() => {})
+ expect(procs).toHaveLength(2)
+ })
+
+ it('on Windows the next try runs on the processor; on Linux, where the processor crashes, on the card again', async () => {
+ const win = new UtilityEngine('engine.js', { gpuFallback: true, ...limits })
+ await loaded(win)
+ const c = win.chat(chat, () => {}).catch((x) => x)
+ fail(procs[0], 'chat', 'vk::Queue::submit: ErrorDeviceLost'); await c
+ void win.load('m.gguf', 32768, 8192).catch(() => {})
+ expect(procs[1].env?.YOGURT_ENGINE_GPU).toBe('off')
+
+ procs.length = 0
+ const linux = new UtilityEngine('engine.js', { gpuFallback: true, cpuCrashes: true, ...limits })
+ await loaded(linux)
+ const d = linux.chat(chat, () => {}).catch((x) => x)
+ fail(procs[0], 'chat', 'VK_ERROR_DEVICE_LOST'); await d
+ void linux.load('m.gguf', 32768, 8192).catch(() => {})
+ expect(procs[1].env?.YOGURT_ENGINE_GPU).toBeUndefined()
+ })
+
+ it('an ordinary error leaves the engine running', async () => {
+ const e = new UtilityEngine('engine.js', { gpuFallback: true, ...limits })
+ await loaded(e)
+ const c = e.chat(chat, () => {}).catch((x) => x)
+ fail(procs[0], 'chat', 'Last message must be from the user')
+ expect(await c).not.toBeInstanceOf(GraphicsGaveUpError)
+ expect(procs[0].killed).toBe(false)
+ })
+
+ it('the engine crashing as it loads without the card turns the card back on for the next try, not CPU for the whole session', async () => {
+ const e = new UtilityEngine('engine.js', { gpuFallback: true, ...limits })
+ const first = e.load('m.gguf', 32768, 8192).catch((x) => x)
+ procs[0].emit('exit', 132)
+ expect(await first).toBeInstanceOf(GraphicsGaveUpError)
+ const second = e.load('m.gguf', 32768, 8192).catch((x) => x)
+ expect(procs[1].env?.YOGURT_ENGINE_GPU).toBe('off')
+ procs[1].emit('exit', 132)
+ expect(await second).not.toBeInstanceOf(GraphicsGaveUpError)
+ void e.load('m.gguf', 32768, 8192).catch(() => {})
+ expect(procs[2].env?.YOGURT_ENGINE_GPU).toBeUndefined()
+ })
+})
diff --git a/app/test/permissions.test.ts b/app/test/permissions.test.ts
index a8da567c..a2cbe14e 100644
--- a/app/test/permissions.test.ts
+++ b/app/test/permissions.test.ts
@@ -111,6 +111,11 @@ describe('permissions on Windows and Linux', () => {
blocked = false
expect((await p.status()).mic).toBe('granted')
})
+ it("Windows: Manage for call audio opens Windows' Sound page (it did nothing), where the device a call plays on shows", async () => {
+ const { p, opened } = offMac('win32')
+ await p.openSettings('systemAudio')
+ expect(opened).toEqual(['ms-settings:sound'])
+ })
it('Linux has no settings page to open', async () => {
const { p, opened } = offMac('linux')
await p.openSettings('mic')
diff --git a/app/test/user.test.ts b/app/test/user.test.ts
new file mode 100644
index 00000000..2f70a033
--- /dev/null
+++ b/app/test/user.test.ts
@@ -0,0 +1,16 @@
+import { beforeEach, expect, it, vi } from 'vitest'
+
+const run = vi.fn(() => 'Daniel Brooks\n')
+vi.mock('node:child_process', () => ({ execFileSync: run }))
+const fresh = async () => { vi.resetModules(); return (await import('../src/main/user')).macFullName }
+beforeEach(() => run.mockClear())
+
+it('never runs the Mac-only id -F off a Mac (Linux printed an error): the login name instead', async () => {
+ expect((await fresh())('linux')).not.toBe('')
+ expect(run).not.toHaveBeenCalled()
+})
+
+it('asks the Mac for the full name', async () => {
+ expect((await fresh())('darwin')).toBe('Daniel Brooks')
+ expect(run).toHaveBeenCalledWith('id', ['-F'], expect.anything())
+})