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

address review (codex): detect Apple Silicon hardware under Rosetta

[._.]/ Adam Eivy5fdc79fd5383
diff --git a/server/lib/platform.js b/server/lib/platform.js
index 3a1cd52deb..880e46ffb2 100644
--- a/server/lib/platform.js
+++ b/server/lib/platform.js
@@ -1,19 +1,41 @@
-import { exec } from 'child_process';
+import { exec, execSync } from 'child_process';
import { promisify } from 'util';
const execAsync = promisify(exec);
const platform = process.platform;
+// Probe the real CPU for arm64, cached. Needed because a Node launched under
+// Rosetta on an M-series Mac reports `process.arch === 'x64'` even though the
+// hardware (and a native LM Studio) is Apple Silicon — `hw.optional.arm64` is the
+// hardware truth regardless of the process's translation. try/catch is the
+// sanctioned child-process boundary (the sysctl key is absent on Intel → throws).
+let arm64HardwareCache;
+function probeArm64Hardware() {
+ if (arm64HardwareCache === undefined) {
+ try {
+ arm64HardwareCache = execSync('sysctl -n hw.optional.arm64', { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() === '1';
+ } catch {
+ arm64HardwareCache = false;
+ }
+ }
+ return arm64HardwareCache;
+}
+
/**
- * Is this an Apple-Silicon Mac (arm64 darwin)? Gates MLX model features: MLX is
- * Apple's native ML framework, so MLX formats only run on Apple Silicon. (Node
- * under Rosetta reports `process.arch === 'x64'`, which correctly reads false.)
- * Detect at the route boundary and pass into pure services, like `os.totalmem()`.
+ * Is this an Apple-Silicon Mac? Gates MLX model features (MLX is Apple's native
+ * framework, so MLX formats only run on Apple Silicon). Detect at the route
+ * boundary and pass into pure services, like `os.totalmem()`.
+ *
+ * `process.arch === 'arm64'` is the fast native answer; an x64 darwin process may
+ * still be arm64 hardware under Rosetta, so that case probes `hw.optional.arm64`.
+ * The `platform`/`arch`/`probe` overrides exist for deterministic tests.
* @returns {boolean}
*/
-export function isAppleSilicon() {
- return process.platform === 'darwin' && process.arch === 'arm64';
+export function isAppleSilicon({ platform: plat = process.platform, arch = process.arch, probe = probeArm64Hardware } = {}) {
+ if (plat !== 'darwin') return false;
+ if (arch === 'arm64') return true;
+ return probe();
}
/**
diff --git a/server/lib/platform.test.js b/server/lib/platform.test.js
index f1fe526be9..ea34491452 100644
--- a/server/lib/platform.test.js
+++ b/server/lib/platform.test.js
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest'
-import { platform, getListeningPorts, isPortInUse, findAvailablePorts } from './platform.js'
+import { platform, getListeningPorts, isPortInUse, findAvailablePorts, isAppleSilicon } from './platform.js'
describe('platform module', () => {
describe('platform constant', () => {
@@ -62,4 +62,26 @@ describe('platform module', () => {
expect(ports).toEqual([])
})
})
+
+ describe('isAppleSilicon', () => {
+ it('is false on non-darwin platforms', () => {
+ expect(isAppleSilicon({ platform: 'linux', arch: 'x64' })).toBe(false)
+ expect(isAppleSilicon({ platform: 'win32', arch: 'arm64' })).toBe(false)
+ })
+
+ it('is true on native arm64 darwin without probing hardware', () => {
+ let probed = false
+ const result = isAppleSilicon({ platform: 'darwin', arch: 'arm64', probe: () => { probed = true; return false } })
+ expect(result).toBe(true)
+ expect(probed).toBe(false) // native arch short-circuits the sysctl probe
+ })
+
+ it('detects Apple Silicon under Rosetta (x64 darwin but arm64 hardware)', () => {
+ expect(isAppleSilicon({ platform: 'darwin', arch: 'x64', probe: () => true })).toBe(true)
+ })
+
+ it('is false on a genuine Intel Mac (x64 darwin, no arm64 hardware)', () => {
+ expect(isAppleSilicon({ platform: 'darwin', arch: 'x64', probe: () => false })).toBe(false)
+ })
+ })
})