Skip to content

an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions

fix(memory): NaN embeddings on Apple Silicon — pin mempalace device to cpu on macOS

Gastón Péchieu70092b6aef22
diff --git a/package.json b/package.json
index 97bb375a..597deb34 100644
--- a/package.json
+++ b/package.json
@@ -19,7 +19,7 @@
"typecheck:node": "tsc --noEmit -p tsconfig.node.json",
"typecheck:web": "tsc --noEmit -p tsconfig.web.json",
"typecheck": "npm run typecheck:node && npm run typecheck:web",
- "test:focused": "node --test test/codex-remote.test.cjs test/control.test.cjs test/provider-automation.test.cjs test/provider-config.test.cjs test/queue-delivery.test.cjs test/terminal-automation.test.cjs test/terminal-recovery.test.cjs test/terminal-selection.test.cjs test/roster.test.cjs test/proc-kill.test.cjs test/expand-tilde.test.cjs test/hive-cwd.test.cjs test/hive-task-mutation.test.cjs test/hive-hook-node.test.cjs test/hive-roster-injection.test.cjs test/hive-runtime-path.test.cjs test/cli-install-ladder.test.cjs test/node-install.test.cjs test/office-gl-recovery.test.cjs test/update-state.test.cjs test/release-notes.test.cjs test/transcript-project-dir.test.cjs test/commit-graph.test.cjs test/ide-image.test.cjs test/win-cmd-shim.test.cjs test/hive-windows-prompt.test.cjs test/release-drop.test.cjs test/skills.test.cjs test/skills-install.test.cjs test/hero-payload.test.cjs",
+ "test:focused": "node --test test/codex-remote.test.cjs test/control.test.cjs test/provider-automation.test.cjs test/provider-config.test.cjs test/queue-delivery.test.cjs test/terminal-automation.test.cjs test/terminal-recovery.test.cjs test/terminal-selection.test.cjs test/roster.test.cjs test/proc-kill.test.cjs test/expand-tilde.test.cjs test/hive-cwd.test.cjs test/hive-task-mutation.test.cjs test/hive-hook-node.test.cjs test/hive-roster-injection.test.cjs test/hive-runtime-path.test.cjs test/cli-install-ladder.test.cjs test/node-install.test.cjs test/office-gl-recovery.test.cjs test/update-state.test.cjs test/release-notes.test.cjs test/transcript-project-dir.test.cjs test/commit-graph.test.cjs test/ide-image.test.cjs test/win-cmd-shim.test.cjs test/hive-windows-prompt.test.cjs test/release-drop.test.cjs test/skills.test.cjs test/skills-install.test.cjs test/hero-payload.test.cjs test/mempalace-device.test.cjs",
"check:links": "node tools/check-release-links.cjs",
"dist": "npm run build && electron-builder",
"dist:mac": "npm run build && electron-builder --mac",
diff --git a/src/main/memory.ts b/src/main/memory.ts
index 008e680b..f84befa4 100644
--- a/src/main/memory.ts
+++ b/src/main/memory.ts
@@ -56,6 +56,37 @@ export interface MemoryStatus {
const MINE_INTERVAL_MS = 180_000; // re-mine changed memories every 3 min
const MINE_TIMEOUT_MS = 10 * 60_000; // hard cap per mine (first run downloads the embedding model)
+/** mempalace's device "auto" picks the CoreML execution provider on Apple
+ * Silicon, and CoreML runs the quantized embeddinggemma ONNX graph partially
+ * (330/1647 nodes) with fp16 partitions that overflow → EVERY vector comes
+ * back NaN and chroma rejects every upsert ("Embeddings must not contain NaN
+ * or Infinity values"), so no memory ever gets indexed. Reproduced + verified
+ * 2026-08-16: same input is NaN under CoreMLExecutionProvider and clean under
+ * CPU. Pin cpu for BOTH the mine loop and the agents' own `mempalace search`
+ * (a query embedded to NaN breaks recall the same way).
+ *
+ * Scope, deliberately macOS-WIDE rather than per-model: the pin costs the
+ * other model nothing. minilm rides chromadb's ONNXMiniLM_L6_V2, whose model
+ * build UNCONDITIONALLY removes CoreMLExecutionProvider ("not as well
+ * optimized as CPU" — chromadb's words), so minilm never runs on CoreML with
+ * or without this pin; embeddinggemma (mempalace's own ONNX class, no such
+ * pruning) is the only path that would reach CoreML, and that path is the NaN
+ * bug. Other platforms keep mempalace's own default ("auto").
+ *
+ * A user's OWN device choice wins: if MEMPALACE_EMBEDDING_DEVICE is already
+ * exported we emit nothing, so the inherited value flows through untouched —
+ * which also leaves a one-command way to reproduce the NaN behaviour
+ * (`MEMPALACE_EMBEDDING_DEVICE=coreml`). Exported as a function of
+ * (platform, envOverride) so every branch is reachable from a test on any
+ * platform — same trick as `buildMissingCliScript`. */
+export function mempalaceDevice(
+ platform: NodeJS.Platform,
+ envOverride: string | undefined
+): string | undefined {
+ if (envOverride) return undefined; // explicit user choice — never override
+ return platform === 'darwin' ? 'cpu' : undefined;
+}
+const MEMPALACE_DEVICE = mempalaceDevice(process.platform, process.env.MEMPALACE_EMBEDDING_DEVICE);
export class MemoryManager {
private binCache: string | null | undefined;
@@ -139,14 +170,19 @@ export class MemoryManager {
env(): Record<string, string> {
const palace = this.palacePath();
if (!this.active() || !palace) return {};
- return { MEMPALACE_PALACE_PATH: palace, MEMPALACE_EMBEDDING_MODEL: this.model() };
+ return {
+ MEMPALACE_PALACE_PATH: palace,
+ MEMPALACE_EMBEDDING_MODEL: this.model(),
+ ...(MEMPALACE_DEVICE ? { MEMPALACE_EMBEDDING_DEVICE: MEMPALACE_DEVICE } : {})
+ };
}
private childEnv(): NodeJS.ProcessEnv {
return {
...process.env,
MEMPALACE_PALACE_PATH: this.palacePath() ?? '',
- MEMPALACE_EMBEDDING_MODEL: this.model()
+ MEMPALACE_EMBEDDING_MODEL: this.model(),
+ ...(MEMPALACE_DEVICE ? { MEMPALACE_EMBEDDING_DEVICE: MEMPALACE_DEVICE } : {})
};
}
diff --git a/test/mempalace-device.test.cjs b/test/mempalace-device.test.cjs
new file mode 100644
index 00000000..9d768968
--- /dev/null
+++ b/test/mempalace-device.test.cjs
@@ -0,0 +1,36 @@
+'use strict';
+
+/**
+ * mempalace's `auto` device resolves to CoreML on Apple Silicon, and CoreML
+ * embeds EVERYTHING to NaN with the quantized embeddinggemma graph — chroma
+ * then rejects every upsert and no memory is ever indexed, while queries
+ * embedded through the same path break recall. The app pins cpu on macOS.
+ * These tests pin the pin: darwin only, and never over a user's own choice.
+ */
+
+const test = require('node:test');
+const assert = require('node:assert/strict');
+const loadTs = require('./load-ts.cjs');
+
+const { mempalaceDevice } = loadTs('src/main/memory.ts');
+
+test('darwin pins cpu — CoreML is the only accelerator auto can pick there, and it NaNs', () => {
+ assert.equal(mempalaceDevice('darwin', undefined), 'cpu');
+});
+
+test('other platforms keep mempalace\'s own default (no var emitted)', () => {
+ assert.equal(mempalaceDevice('linux', undefined), undefined);
+ assert.equal(mempalaceDevice('win32', undefined), undefined);
+});
+
+test('an explicit MEMPALACE_EMBEDDING_DEVICE always wins — the pin emits nothing', () => {
+ // The escape hatch: the exported value flows through the inherited env
+ // untouched, including the one-command NaN repro (=coreml).
+ assert.equal(mempalaceDevice('darwin', 'coreml'), undefined);
+ assert.equal(mempalaceDevice('darwin', 'cpu'), undefined);
+ assert.equal(mempalaceDevice('linux', 'cuda'), undefined);
+});
+
+test('an empty exported value is not a choice — the darwin default still applies', () => {
+ assert.equal(mempalaceDevice('darwin', ''), 'cpu');
+});