Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

feat(updater): report refused self-updates and check-only feed failures

reviewe3439b0064b7
diff --git a/src/main/update-install-marker.test.ts b/src/main/update-install-marker.test.ts
new file mode 100644
index 000000000..8c736e0d8
--- /dev/null
+++ b/src/main/update-install-marker.test.ts
@@ -0,0 +1,69 @@
+import { describe, expect, it } from 'vitest'
+import {
+ consumeUpdateFailedMarker,
+ describeUpdateInstallFailure,
+ updateFailedMarkerPath
+} from './update-install-marker'
+
+const LAD = 'C:\\Users\\me\\AppData\\Local'
+const FILE = 'C:\\Users\\me\\AppData\\Local\\nodeterm\\update-failed.json'
+
+function fakeFs(content: string | null) {
+ const removed: string[] = []
+ const reads: string[] = []
+ return {
+ removed,
+ reads,
+ readFile: (f: string) => {
+ reads.push(f)
+ if (content === null) throw Object.assign(new Error('ENOENT'), { code: 'ENOENT' })
+ return content
+ },
+ removeFile: (f: string) => {
+ removed.push(f)
+ }
+ }
+}
+
+describe('update-failed marker (U6)', () => {
+ it('lives where the installer writes it', () => {
+ expect(updateFailedMarkerPath(LAD)).toBe(FILE)
+ })
+
+ it('reads the installer note once and deletes it', () => {
+ const f = fakeFs('{"reason":"preflight","code":10,"version":"0.4.5"}')
+ expect(consumeUpdateFailedMarker({ platform: 'win32', localAppData: LAD, ...f })).toEqual({
+ reason: 'preflight',
+ code: 10,
+ version: '0.4.5'
+ })
+ expect(f.reads).toEqual([FILE])
+ expect(f.removed).toEqual([FILE])
+ })
+
+ it('no marker, or not Windows, is nothing', () => {
+ expect(consumeUpdateFailedMarker({ platform: 'win32', localAppData: LAD, ...fakeFs(null) })).toBeNull()
+ const f = fakeFs('{"code":10}')
+ expect(consumeUpdateFailedMarker({ platform: 'darwin', localAppData: LAD, ...f })).toBeNull()
+ expect(consumeUpdateFailedMarker({ platform: 'linux', localAppData: LAD, ...f })).toBeNull()
+ expect(f.reads).toEqual([])
+ expect(consumeUpdateFailedMarker({ platform: 'win32', localAppData: undefined, ...f })).toBeNull()
+ })
+
+ it('a malformed note still reports a failure and is still removed', () => {
+ const f = fakeFs('not json')
+ expect(consumeUpdateFailedMarker({ platform: 'win32', localAppData: LAD, ...f })).toEqual({
+ reason: 'unknown',
+ code: null,
+ version: null
+ })
+ expect(f.removed).toEqual([FILE])
+ })
+
+ it('says why in one line', () => {
+ expect(describeUpdateInstallFailure({ reason: 'preflight', code: 10, version: '0.4.5' })).toMatch(
+ /update to 0\.4\.5 did not install: nodeterm was still running/
+ )
+ expect(describeUpdateInstallFailure({ reason: 'preflight', code: 20, version: null })).toMatch(/could not verify/)
+ })
+})
diff --git a/src/main/update-install-marker.ts b/src/main/update-install-marker.ts
new file mode 100644
index 000000000..b4b3f277d
--- /dev/null
+++ b/src/main/update-install-marker.ts
@@ -0,0 +1,73 @@
+// The NSIS preflight's failure note (build/installer.nsh, U6). When an update the app handed itself
+// over to (`--updated`) cannot start because nodeterm is still running after the bounded wait, the
+// installer writes `%LOCALAPPDATA%\nodeterm\update-failed.json`, relaunches the installed build and
+// quits. This reads that note once on the next start and deletes it, so the failure is reported
+// instead of the update silently not happening. Windows only; pure apart from the injected fs.
+
+import fs from 'fs'
+import path from 'path'
+
+export interface UpdateInstallFailure {
+ reason: string
+ /** The preflight's exit code: 10 = still running, 20 = could not verify. */
+ code: number | null
+ /** The version the installer would have installed. */
+ version: string | null
+}
+
+export interface MarkerDeps {
+ platform: NodeJS.Platform | string
+ localAppData: string | null | undefined
+ readFile?: (file: string) => string
+ removeFile?: (file: string) => void
+}
+
+export function updateFailedMarkerPath(localAppData: string): string {
+ return path.win32.join(localAppData, 'nodeterm', 'update-failed.json')
+}
+
+/**
+ * Read and delete the marker. `null` when there is none (or not Windows). The file is read ONCE
+ * and then removed — no exists-then-read — and a malformed note still counts as a failure (its
+ * existence is the fact), reported with what could be parsed. Never throws.
+ */
+export function consumeUpdateFailedMarker(deps: MarkerDeps): UpdateInstallFailure | null {
+ if (deps.platform !== 'win32' || !deps.localAppData) return null
+ const file = updateFailedMarkerPath(deps.localAppData)
+ const readFile = deps.readFile ?? ((f: string) => fs.readFileSync(f, 'utf8'))
+ const removeFile = deps.removeFile ?? ((f: string) => fs.rmSync(f, { force: true }))
+ let raw: string
+ try {
+ raw = readFile(file)
+ } catch {
+ return null
+ }
+ try {
+ removeFile(file)
+ } catch {
+ /* reported anyway; a later start reports it again rather than never */
+ }
+ let parsed: Record<string, unknown> = {}
+ try {
+ const value: unknown = JSON.parse(raw)
+ if (value && typeof value === 'object' && !Array.isArray(value)) parsed = value as Record<string, unknown>
+ } catch {
+ /* existence is the fact */
+ }
+ return {
+ reason: typeof parsed.reason === 'string' ? parsed.reason : 'unknown',
+ code: Number.isInteger(parsed.code) ? (parsed.code as number) : null,
+ version: typeof parsed.version === 'string' ? parsed.version : null
+ }
+}
+
+/** One log line for the debug ring. */
+export function describeUpdateInstallFailure(f: UpdateInstallFailure): string {
+ const why =
+ f.code === 10
+ ? 'nodeterm was still running when the installer checked'
+ : f.code === 20
+ ? 'the installer could not verify that nodeterm had exited'
+ : `reason ${f.reason}`
+ return `the last update${f.version ? ` to ${f.version}` : ''} did not install: ${why}. The previous version was restarted.`
+}
diff --git a/src/main/updater.no-channel.test.ts b/src/main/updater.no-channel.test.ts
index de5b715c1..f4aac7ecb 100644
--- a/src/main/updater.no-channel.test.ts
+++ b/src/main/updater.no-channel.test.ts
@@ -61,7 +61,7 @@ vi.mock('./main-window', () => ({
}))
vi.mock('./notifications', () => ({ retainUntilDismissed: () => {} }))
-import { initUpdater } from './updater'
+import { describeCheckFailure, initUpdater, lastUpdateCheck } from './updater'
const realReadFileSync = fs.readFileSync
@@ -260,6 +260,16 @@ describe('the unsigned Windows beta (manual marker)', () => {
expect(channels()).toContain(IPC.appUpdateError)
})
+ it('a silent check failure is recorded and logged as an actionable warning, not dropped', () => {
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
+ updaterEvents['error']?.(new Error('HttpError: 404 "method: GET url: https://nodeterm.dev/updates/latest.yml"'))
+ expect(channels()).not.toContain(IPC.appUpdateError)
+ expect(lastUpdateCheck()).toMatchObject({ ok: false, message: expect.stringContaining('404') })
+ expect(warn).toHaveBeenCalledWith('[updater]', expect.stringMatching(/update feed is missing/))
+ updaterEvents['update-not-available']?.()
+ expect(lastUpdateCheck()).toMatchObject({ ok: true })
+ })
+
it('refuses restart-to-update in main: quitAndInstall never runs', () => {
restart()
expect(autoUpdater.quitAndInstall).not.toHaveBeenCalled()
@@ -303,3 +313,16 @@ describe('restart-to-update elsewhere', () => {
expect(autoUpdater.quitAndInstall).not.toHaveBeenCalled()
})
})
+
+describe('describeCheckFailure', () => {
+ it('names a 404 on a latest*.yml as a missing feed file', () => {
+ expect(describeCheckFailure('HttpError: 404 Not Found ... latest.yml')).toMatch(/feed is missing/)
+ expect(describeCheckFailure('Cannot find latest-linux.yml (404)')).toMatch(/feed is missing/)
+ })
+ it('anything else is a plain check failure', () => {
+ expect(describeCheckFailure('net::ERR_INTERNET_DISCONNECTED')).toBe(
+ 'update check failed: net::ERR_INTERNET_DISCONNECTED'
+ )
+ expect(describeCheckFailure('HttpError: 500 latest.yml')).toMatch(/^update check failed/)
+ })
+})
diff --git a/src/main/updater.ts b/src/main/updater.ts
index 264a958b9..64a800a52 100644
--- a/src/main/updater.ts
+++ b/src/main/updater.ts
@@ -19,9 +19,35 @@ import {
} from '../shared/update-platform'
import { getMainWindow, sendToMain } from './main-window'
import { retainUntilDismissed } from './notifications'
+import { consumeUpdateFailedMarker, describeUpdateInstallFailure } from './update-install-marker'
const SIX_HOURS = 6 * 60 * 60 * 1000
+/** The outcome of the most recent feed check (any trigger). Recorded so a check-only build's
+ * silent automatic failures are still observable — see the 'error' handler. */
+export interface UpdateCheckRecord {
+ at: number
+ ok: boolean
+ message?: string
+}
+let lastCheck: UpdateCheckRecord | null = null
+export function lastUpdateCheck(): UpdateCheckRecord | null {
+ return lastCheck
+}
+
+/**
+ * One actionable log line for a failed check in a check-only build. A 404 on a `latest*.yml` is
+ * the feed itself missing — the nodeterm.dev/updates mirror not serving that platform's file —
+ * which is an ops fix, not a network blip, and reads like one in a device report. Pure; exported
+ * for tests.
+ */
+export function describeCheckFailure(message: string): string {
+ const feedMissing = /\b404\b/.test(message) && /latest[\w.-]*\.yml/i.test(message)
+ return feedMissing
+ ? `update feed is missing this platform's latest*.yml (${message}); the passive update notice cannot fire until the update mirror serves it`
+ : `update check failed: ${message}`
+}
+
/**
* The `nodeTermUpdates` marker a LOCAL package carries in its packaged package.json, injected by
* the `dist*` scripts via electron-builder's `extraMetadata`. `release` does not set it, so a
@@ -70,6 +96,14 @@ function packagedUpdateMode(): unknown {
export function initUpdater(onBeforeRestart?: () => void): void {
const send = (channel: string, payload?: unknown) => sendToMain(channel, payload)
+ // A self-update the installer refused on the way in (build/installer.nsh writes this note and
+ // restarts the previous version). Read once and deleted; Windows only, a no-op elsewhere.
+ const failedInstall = consumeUpdateFailedMarker({
+ platform: process.platform,
+ localAppData: process.env.LOCALAPPDATA
+ })
+ if (failedInstall) console.warn('[updater]', describeUpdateInstallFailure(failedInstall))
+
const updateMode = packagedUpdateMode()
const delivery = updateDelivery({
isPackaged: app.isPackaged,
@@ -118,7 +152,12 @@ export function initUpdater(onBeforeRestart?: () => void): void {
autoUpdater.autoDownload = !manualUpdates
autoUpdater.autoInstallOnAppQuit = !manualUpdates
+ const recordCheck = (ok: boolean, message?: string): void => {
+ lastCheck = { at: Date.now(), ok, ...(message === undefined ? {} : { message }) }
+ }
+
autoUpdater.on('update-available', (info) => {
+ recordCheck(true)
send(IPC.appUpdateAvailable, toUpdateAvailablePayload(info, manualUpdates))
})
@@ -155,20 +194,30 @@ export function initUpdater(onBeforeRestart?: () => void): void {
}
})
- autoUpdater.on('update-not-available', () => send(IPC.appUpdateNotAvailable))
+ autoUpdater.on('update-not-available', () => {
+ recordCheck(true)
+ send(IPC.appUpdateNotAvailable)
+ })
// A check-only build (`nodeTermUpdates=manual`, the unsigned Windows beta) downloads nothing, so
// every 'error' event it can emit is a CHECK failure — and electron-updater emits one for the
// silent launch/6h checks too. The beta previously showed nothing at all; an error card on every
// launch (offline, or a feed mirror that does not serve latest.yml yet) would be a regression
- // for exactly the users this notice exists for. So there the event is logged only; a
- // user-initiated check still surfaces its failure through the catch below. Every other build
- // keeps its historical behaviour.
+ // for exactly the users this notice exists for. So there the event is not shown — but it is NOT
+ // silent either: it is recorded (`lastUpdateCheck`) and logged as one actionable warning, so a
+ // feed that 404s (the mirror not serving latest.yml) is visible in the debug log instead of
+ // looking like "no update yet". A user-initiated check still surfaces its failure through the
+ // catch below. Every other build keeps its historical behaviour.
const checkOnly = delivery === 'manual-install' && updateMode === MANUAL_UPDATE_MODE
autoUpdater.on('error', (err) => {
const message = err?.message ?? String(err)
+ recordCheck(false, message)
+ if (checkOnly) {
+ console.warn('[updater]', describeCheckFailure(message))
+ return
+ }
console.error('[updater]', message)
- if (!checkOnly) send(IPC.appUpdateError, message)
+ send(IPC.appUpdateError, message)
})
// Manual check from Settings; surfaces failures to the card.