Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

fix(desktop): stop a broken macOS update installer from restarting forever

leepokaid31fd5f174c3
diff --git a/apps/desktop/src/main/updates.ts b/apps/desktop/src/main/updates.ts
index 2b0e80e0..770a46c7 100644
--- a/apps/desktop/src/main/updates.ts
+++ b/apps/desktop/src/main/updates.ts
@@ -1,10 +1,14 @@
+import { execFile } from 'node:child_process'
import { EventEmitter } from 'node:events'
+import { existsSync } from 'node:fs'
+import { homedir } from 'node:os'
import { join } from 'node:path'
import { app, BrowserWindow, ipcMain, powerMonitor, shell } from 'electron'
import electronUpdater, { type UpdateInfo } from 'electron-updater'
import { isBelow, parseVersion } from '../shared/compat'
import type { UpdateState } from '../shared/ipc'
import { isMainEnvironment } from './account'
+import { identity } from './environment'
import { prefs, type HostController } from './host-controller'
const { autoUpdater } = electronUpdater
@@ -52,6 +56,7 @@ export class Updates extends EventEmitter {
this.on('change', () => {
for (const w of windows()) w.webContents.send('updates:change', this.state)
})
+ removeStuckShipIt()
if (!enabled) return
// macOS relaunches the updated app from the background, behind the app in front, and ignores
// `app.focus` there (cooperative activation); opening its own bundle brings it forward.
@@ -84,7 +89,10 @@ export class Updates extends EventEmitter {
})
setTimeout(() => this.scheduled(), 30_000)
- setInterval(() => this.scheduled(), 3600_000)
+ setInterval(() => {
+ removeStuckShipIt()
+ this.scheduled()
+ }, 3600_000)
}
setAutoCheck(on: boolean) {
@@ -230,6 +238,22 @@ export class Updates extends EventEmitter {
}
}
+/**
+ * macOS's installer job (Squirrel's ShipIt) restarts every 2 s until it exits cleanly, so once its
+ * update request is gone (a cleaned Caches folder) it fails forever and its log grows without
+ * bound. An idle job without a request can't install anything: remove it.
+ */
+function removeStuckShipIt() {
+ if (process.platform !== 'darwin') return
+ const label = `${identity.appId}.ShipIt`
+ if (existsSync(join(homedir(), 'Library/Caches', label, 'ShipItState.plist'))) return
+ execFile('/bin/launchctl', ['list', label], (error, stdout) => {
+ // Not submitted, or running right now (the next check finds it idle).
+ if (error || stdout.includes('"PID" =')) return
+ execFile('/bin/launchctl', ['remove', label], () => {})
+ })
+}
+
/** The iPhone app's version live in the App Store (iTunes lookup); null when unknown. */
async function appStoreVersion(): Promise<string | null> {
try {
diff --git a/apps/desktop/src/shared/test-support/updater.ts b/apps/desktop/src/shared/test-support/updater.ts
index e4ef59d9..1808db71 100644
--- a/apps/desktop/src/shared/test-support/updater.ts
+++ b/apps/desktop/src/shared/test-support/updater.ts
@@ -12,8 +12,20 @@ interface UpdatesInstance extends EventEmitter {
setAutoDownload(on: boolean): void
}
-export function updaterFixture(options: { packaged?: boolean; main?: boolean; prefs?: Record<string, unknown> } = {}) {
+type ShipIt = { request: boolean; job: 'none' | 'idle' | 'running' }
+
+export function updaterFixture(options: { packaged?: boolean; main?: boolean; prefs?: Record<string, unknown>; shipIt?: ShipIt } = {}) {
const calls = { check: 0, download: 0, install: 0, prepare: 0, resume: 0, quit: 0, fetch: 0 }
+ // macOS's installer job: whether its update request exists, and its launchd state.
+ const shipIt = { ...(options.shipIt ?? { request: true, job: 'idle' }), removed: 0 }
+ const launchctl = (_bin: string, args: string[], done: (error: Error | null, stdout: string) => void) => {
+ if (args[0] === 'remove') {
+ shipIt.removed++
+ return done(null, '')
+ }
+ if (shipIt.job === 'none') return done(new Error('Could not find service'), '')
+ done(null, shipIt.job === 'running' ? '{\n\t"PID" = 42;\n};' : '{\n\t"LastExitStatus" = 256;\n};')
+ }
const opened: string[] = []
const preferences = new Map(Object.entries(options.prefs ?? {}))
const timers = new Map<number, { callback: () => unknown; ms: number }>()
@@ -63,12 +75,16 @@ export function updaterFixture(options: { packaged?: boolean; main?: boolean; pr
return id
}
const { Updates } = loadMainModule<{ Updates: new (host: unknown) => UpdatesInstance }>('updates', {
+ 'node:child_process': { execFile: launchctl },
'node:events': { EventEmitter },
+ 'node:fs': { existsSync: (file: string) => shipIt.request && file === '/Users/me/Library/Caches/com.pokai.Codync.ShipIt/ShipItState.plist' },
+ 'node:os': { homedir: () => '/Users/me' },
'node:path': path,
electron: { app, ipcMain: ipc, shell: { openPath: async (target: string) => { opened.push(target); return '' } }, BrowserWindow: { getFocusedWindow: () => behavior.focused }, powerMonitor: { getSystemIdleTime: () => behavior.idleSeconds } },
'electron-updater': { autoUpdater: updater },
'../shared/compat': compat,
'./account': { isMainEnvironment: () => options.main ?? true },
+ './environment': { identity: { appId: 'com.pokai.Codync' } },
'./host-controller': { prefs: { get: (key: string) => preferences.get(key), set: (key: string, value: unknown) => preferences.set(key, value) } },
}, {
Date: class extends Date { static override now() { return now } },
@@ -90,5 +106,5 @@ export function updaterFixture(options: { packaged?: boolean; main?: boolean; pr
}
await settle()
}
- return { updates, app, ipc, handlers, updater, calls, opened, behavior, preferences, sent, timers, emit, tick, advance: (ms: number) => { now += ms } }
+ return { updates, app, ipc, handlers, updater, calls, opened, behavior, preferences, sent, timers, shipIt, emit, tick, advance: (ms: number) => { now += ms } }
}
diff --git a/apps/desktop/src/shared/updates.test.ts b/apps/desktop/src/shared/updates.test.ts
index 498b239b..a0f98e0d 100644
--- a/apps/desktop/src/shared/updates.test.ts
+++ b/apps/desktop/src/shared/updates.test.ts
@@ -19,6 +19,17 @@ for (const options of [{ packaged: false }, { main: false }]) {
})
}
+test('an idle macOS installer job whose update request is gone is removed, at launch and hourly', async () => {
+ assert.equal(updaterFixture({ shipIt: { request: false, job: 'idle' } }).shipIt.removed, 1)
+ for (const shipIt of [{ request: true, job: 'idle' }, { request: false, job: 'running' }, { request: false, job: 'none' }] as const) {
+ assert.equal(updaterFixture({ shipIt }).shipIt.removed, 0, JSON.stringify(shipIt))
+ }
+ const f = updaterFixture()
+ f.shipIt.request = false
+ await f.tick(3600_000)
+ assert.equal(f.shipIt.removed, 1)
+})
+
test('manual check downloads with progress, then waits for Restart to update', async () => {
const f = updaterFixture()
const stopped = deferred()
diff --git a/docs/architecture/desktop-app.md b/docs/architecture/desktop-app.md
index 3537f25b..f7b72ce6 100644
--- a/docs/architecture/desktop-app.md
+++ b/docs/architecture/desktop-app.md
@@ -92,6 +92,8 @@ The TUI connects to one host at a time, so it keeps its single roster.
iPhone gate as before). Installs of the SwiftUI app get the first desktop release through one
more Sparkle appcast, generated for the zip by the release workflow (deprecated, removed after
2026-11-06: [updates guide](../guides/updates.md#deprecated-the-sparkle-migration-appcast-remove-after-2026-11-06)).
+ On macOS the app removes an idle installer job (`<appId>.ShipIt`) whose update request is gone:
+ launchd would otherwise restart it every 2 seconds, forever.
## Development