Beautiful, AI-native markdown IDE and LLM wiki
TypeScript 2nd-brainagent-skillsclaudecodexcompany-braindocsknowledge-knowledge-baseknowledge-managementllmllm-wikillm-wiki-karpathymarkdownmarkdown-editormdmdxnotespkmsecond-brainskills
fix(ok): stop the crash prompt after an auto-update install (PRD-7639) (#3814)
Andrew Mikofalvy3be954129a73
diff --git a/.changeset/no-crash-prompt-after-auto-update.md b/.changeset/no-crash-prompt-after-auto-update.mdnew file mode 100644index 000000000..f59a7d3b3--- /dev/null+++ b/.changeset/no-crash-prompt-after-auto-update.md@@ -0,0 +1,5 @@+---+"@inkeep/open-knowledge": patch+---++The desktop app no longer tells you the previous session crashed after a successful auto-update. Installing an update means terminating the running app so its files can be replaced, and that shutdown is not the orderly one, so the next launch found the marker an unclean exit leaves behind and offered to report a crash that never happened. It now recognises its own installer as the cause and stays quiet. A genuine crash during an update still prompts, because a real crash report on disk always takes precedence, and a session that ended uncleanly with no update in flight is reported exactly as before.diff --git a/packages/desktop/src/main/auto-updater.ts b/packages/desktop/src/main/auto-updater.tsindex 644f2ec16..a71df6d2b 100644--- a/packages/desktop/src/main/auto-updater.ts+++ b/packages/desktop/src/main/auto-updater.ts@@ -791,6 +791,55 @@ function installHandoffAgeMs(handoffAt: number | null, nowMs: number): number |return elapsed < 0 ? null : elapsed;}+/**+ * Whether an install this app committed to may still have been running at+ * `nowMs` — and, when it may, which version and from what moment.+ *+ * Two callers ask the same question for different reasons, which is why it is+ * a function rather than an inline condition. The boot reconciliation below+ * asks it to decide whether to condemn an install as failed. Crash detection+ * asks it to decide whether a session that ended without a clean quit was+ * killed by the installer rather than by a fault — the installer terminates the+ * running process to replace its files, which bypasses the quit sequence and+ * leaves the dirty-shutdown sentinel behind. Both need the claim+ * bounded the same way; two copies of the bound would drift, and the pair that+ * drifted would tell the user an install failed while telling them nothing+ * about the crash it caused, or the reverse.+ *+ * The bound is the interesting part, and neither half of it is optional. The+ * grace window keeps a stale record from claiming an install is in flight+ * forever; the boot count is what survives electron-updater re-arming+ * `update-downloaded` from its on-disk cache and clearing the handoff stamp,+ * which would otherwise make an install that never lands look perpetually+ * fresh. See both constants' own docs for the calibration.+ *+ * Returned as a value rather than a boolean so a caller can name the version in+ * a log line without re-reading state that the next moment may have cleared.+ */+export function installMayStillBeRunning(+ state: AppState,+ nowMs: number,+): { attemptedVersion: string; handoffAt: number; recordedHandoff: boolean } | null {+ const attempted = state.attemptedInstall;+ // Nothing was committed to, so nothing can be in flight.+ if (attempted === null) return null;+ const handoffAt = state.attemptedInstallHandoffAt ?? state.versionPendingInstallStagedAt;+ const handoffAgeMs = installHandoffAgeMs(handoffAt, nowMs);+ if (+ handoffAt === null ||+ handoffAgeMs === null ||+ handoffAgeMs > INSTALL_IN_FLIGHT_GRACE_MS ||+ state.attemptedInstallDeferredBoots >= INSTALL_DEFER_MAX_BOOTS+ ) {+ return null;+ }+ return {+ attemptedVersion: attempted,+ handoffAt,+ recordedHandoff: state.attemptedInstallHandoffAt !== null,+ };+}+// ————————————————————————————————————————————————————————// Main entry// ————————————————————————————————————————————————————————@@ -2288,13 +2337,14 @@ export function startAutoUpdater(opts: StartAutoUpdaterOpts): StartAutoUpdaterHa// staging moment. The install cannot have begun before the artifact// existed, so staging is a sound lower bound on the handoff, just not a// tight one, and it degrades further once the reconciliation clears it.+ const reconciledAtMs = now().getTime();const handoffAt = state.attemptedInstallHandoffAt ?? attemptStagedAt;- const handoffAgeMs = installHandoffAgeMs(handoffAt, now().getTime());- if (- handoffAgeMs !== null &&- handoffAgeMs <= INSTALL_IN_FLIGHT_GRACE_MS &&- state.attemptedInstallDeferredBoots < INSTALL_DEFER_MAX_BOOTS- ) {+ const handoffAgeMs = installHandoffAgeMs(handoffAt, reconciledAtMs);+ // The predicate itself lives in `installMayStillBeRunning` so crash+ // detection can ask the same question with the same bound; the locals+ // above stay for the log lines, which report the inputs the verdict was+ // reached from rather than the verdict alone.+ if (installMayStillBeRunning(state, reconciledAtMs) !== null) {// Inside the install window, and the hold has boots left: decide// nothing about the attempt. `attemptedInstall` stays armed so a later// boot still reconciles it as success or as failure,diff --git a/packages/desktop/src/main/crash-detection.test.ts b/packages/desktop/src/main/crash-detection.test.tsindex d2c6ddc7f..6a747b712 100644--- a/packages/desktop/src/main/crash-detection.test.ts+++ b/packages/desktop/src/main/crash-detection.test.ts@@ -22,6 +22,7 @@ import { afterEach, describe, expect, test } from 'vitest';import {type CrashDetectionDeps,createCrashDetection,+ type InstallInFlight,startLocalCrashReporter,} from './crash-detection.ts';import { buildMinidump } from './minidump.test-helper.ts';@@ -76,6 +77,11 @@ interface Rig {setRendererAvailable(available: boolean): void;/** Swap the kernel boot-session identity, simulating a reboot between sessions. */setBootSessionUuid(uuid: string | null): void;+ /**+ * Arm (or clear) the updater's "an install may still be running" verdict,+ * simulating a session the installer killed to swap the binary.+ */+ setInstallInFlight(inFlight: InstallInFlight | null): void;/** Swap the running app version, simulating an auto-update between sessions. */setAppVersion(version: string): void;/** Advance and return the fake clock (10s per tick). */@@ -92,6 +98,7 @@ function makeRig(): Rig {const warnings: Record<string, unknown>[] = [];let rendererAvailable = true;let bootSessionUuid: string | null = 'boot-epoch-a';+ let installInFlight: InstallInFlight | null = null;let clockMs = Date.parse('2026-07-10T00:00:00.000Z');const appBundleRoot = join(dir, 'Applications', 'OpenKnowledge.app');// A helper process rather than the main binary: renderer/GPU/utility crashes@@ -133,6 +140,9 @@ function makeRig(): Rig {setBootSessionUuid(uuid: string | null) {bootSessionUuid = uuid;},+ setInstallInFlight(inFlight: InstallInFlight | null) {+ installInFlight = inFlight;+ },setAppVersion(version: string) {rig.deps.appVersion = version;},@@ -163,6 +173,7 @@ function makeRig(): Rig {return new Date(clockMs);},currentBootSessionUuid: () => bootSessionUuid,+ installInFlight: () => installInFlight,logger: {info: () => {},warn: (payload) => {@@ -1914,3 +1925,124 @@ describe('non-crash minidumps', () => {expect(logged?.unreadableDumpsSkipped).toBe(0);});});++describe('auto-update install kill suppression', () => {+ /** What the updater reports while an install it committed to may still be running. */+ const IN_FLIGHT: InstallInFlight = {+ attemptedVersion: '0.61.3',+ handoffAt: Date.parse('2026-08-23T23:10:28.727Z'),+ recordedHandoff: true,+ };++ test('a session the installer killed never prompts', () => {+ const rig = makeRig();+ createCrashDetection(rig.deps).detectBootCrash();+ // Session A is killed by the installer swapping the binary underneath it:+ // no quit sequence runs, so the sentinel survives dirty. Same kernel+ // session, no OS-shutdown marker, no suspend marker, no dump — every+ // existing suppression class correctly declines, which is why this one+ // has to exist.+ rig.setInstallInFlight(IN_FLIGHT);++ const sessionB = createCrashDetection(rig.deps);+ expect(sessionB.detectBootCrash()).toBeNull();+ sessionB.notifyRendererReady();+ expect(rig.emitted).toHaveLength(0);+ });++ test('suppression logs a breadcrumb naming the attempted version', () => {+ const rig = makeRig();+ const infoLines: Array<Record<string, unknown>> = [];+ rig.deps.logger = {+ info: (payload: Record<string, unknown>) => {+ infoLines.push(payload);+ },+ warn: () => {},+ };+ createCrashDetection(rig.deps).detectBootCrash();++ rig.setInstallInFlight(IN_FLIGHT);+ createCrashDetection(rig.deps).detectBootCrash();++ const breadcrumb = infoLines.find(+ (line) => line.event === 'crash-detection.machine-level-death',+ );+ expect(breadcrumb?.reason).toBe('update-install');+ // Naming the version is the whole point: without it a suppressed boot is+ // indistinguishable in the logs from one where detection never ran.+ expect(breadcrumb?.attemptedInstall).toBe('0.61.3');+ expect(breadcrumb?.recordedHandoff).toBe(true);+ });++ test('a fresh minidump still prompts through an install kill', () => {+ const rig = makeRig();+ createCrashDetection(rig.deps).detectBootCrash();+ seedMinidump(rig, 'pending/native-crash.dmp', rig.tick());+ // The app native-crashed while an install happened to be in flight. A dump+ // is proof the app itself faulted, and proof outranks every suppression+ // class — the same rule the reboot path follows.+ rig.setInstallInFlight(IN_FLIGHT);++ const armed = createCrashDetection(rig.deps).detectBootCrash();+ expect(armed?.kind).toBe('boot');+ if (armed?.kind === 'boot') {+ expect(armed.context.newMinidumps).toBe(1);+ }+ });++ test('a dirty shutdown with no install in flight prompts exactly as before', () => {+ const rig = makeRig();+ createCrashDetection(rig.deps).detectBootCrash();+ // The no-regression case the reboot class pinned: kill -9 with nothing+ // staged, same kernel epoch. Nothing about this class may quieten it.+ rig.setInstallInFlight(null);++ const armed = createCrashDetection(rig.deps).detectBootCrash();+ expect(armed?.kind).toBe('boot');+ if (armed?.kind === 'boot') {+ expect(armed.context.dirtyShutdown).toBe(true);+ }+ });++ test('the win32 installer-swap shape is suppressed', () => {+ const rig = makeRig();+ rig.deps.platform = 'win32';+ rig.setAppVersion('0.58.8');+ // A session boots on the old binary while the NSIS installer runs, and is+ // killed mid-swap. The next boot is the newly installed version, so the+ // versions differ here — but a version delta cannot itself be the+ // classifier: when an install FAILS the relaunched app is the same version+ // as the one killed, and the delta is zero on exactly that subset.+ createCrashDetection(rig.deps).detectBootCrash();++ rig.setInstallInFlight(IN_FLIGHT);+ rig.setAppVersion('0.61.3');+ const sessionB = createCrashDetection(rig.deps);+ expect(sessionB.detectBootCrash()).toBeNull();+ sessionB.notifyRendererReady();+ expect(rig.emitted).toHaveLength(0);+ });++ test('a staging-fallback handoff suppresses too', () => {+ const rig = makeRig();+ createCrashDetection(rig.deps).detectBootCrash();+ // No live process saw the commit (a force-quit, a power loss), so the+ // updater fell back to the staging moment. The macOS instances this ticket+ // was opened from take this path — a session killed mid-flight never+ // quits, so it never stamps a handoff of its own.+ rig.setInstallInFlight({ ...IN_FLIGHT, recordedHandoff: false });++ expect(createCrashDetection(rig.deps).detectBootCrash()).toBeNull();+ });++ test('an absent reader leaves every existing verdict unchanged', () => {+ const rig = makeRig();+ // Any caller that wires no updater state must behave exactly as before:+ // fail-open toward prompting.+ rig.deps.installInFlight = undefined;+ createCrashDetection(rig.deps).detectBootCrash();++ const armed = createCrashDetection(rig.deps).detectBootCrash();+ expect(armed?.kind).toBe('boot');+ });+});diff --git a/packages/desktop/src/main/crash-detection.ts b/packages/desktop/src/main/crash-detection.tsindex bf3caf5af..62321ece4 100644--- a/packages/desktop/src/main/crash-detection.ts+++ b/packages/desktop/src/main/crash-detection.ts@@ -234,9 +234,43 @@ export interface CrashDetectionDeps {* toward prompting, i.e. the pre-classification behavior).*/currentBootSessionUuid(): string | null;+ /**+ * The updater's verdict that an install it committed to may still have been+ * running when the previous session ended — the fourth thing that can end a+ * session without the app having crashed.+ *+ * Asked of the updater rather than decided here: the grace window and the+ * boot bound that make "may still be running" a bounded claim are the+ * updater's calibration, and a second copy of that judgment would drift from+ * the one that decides whether to tell the user an install failed.+ *+ * Optional, and null when nothing is in flight. An absent reader skips the+ * classification entirely — fail-open toward prompting, the same posture+ * `currentBootSessionUuid` takes when the probe is unavailable.+ */+ installInFlight?(): InstallInFlight | null;logger: CrashLogger;}+/**+ * What the updater knows about an install that had been committed to but had+ * not yet been observed to land. Carries the version so the suppression+ * breadcrumb can name it, and the moment so a reader can tell a held verdict+ * from a stale one.+ */+export interface InstallInFlight {+ /** The version the installer was launched to install. */+ attemptedVersion: string;+ /**+ * Epoch ms at which the install was handed off, or — when no live process+ * saw the commit — the moment the artifact was staged, which is a sound+ * lower bound on the handoff.+ */+ handoffAt: number;+ /** False when `handoffAt` is the staging fallback rather than a real stamp. */+ recordedHandoff: boolean;+}+export interface CrashDetection {/*** Boot-time scan: reads the previous session's sentinel and the minidump@@ -749,16 +783,43 @@ export function createCrashDetection(deps: CrashDetectionDeps): CrashDetection {sentinelPresent &&(rebootedBetweenSessions || prevPendingOsShutdownAt !== null || prevSuspendedAt !== null);+ // The fourth way a session ends without the app having crashed, and the+ // only one the machine did not cause: this app committed to an update,+ // and the installer terminated the running process to replace its files.+ // That kill bypasses the quit sequence on both platforms — SIGKILL from+ // ShipIt, an outright process termination from NSIS — so `will-quit`+ // never runs, `markCleanQuit()` never clears the sentinel, and without+ // this class the next boot reports a death the app arranged on purpose.+ //+ // Deliberately asked of the updater rather than inferred here. A version+ // delta between the crashed and detecting sessions is the tempting cheap+ // test and it is unsound: when the install FAILS, the relaunched app is+ // the same version as the one that was killed, so the delta is zero on+ // exactly the subset this class was first reported from.+ const installInFlight = deps.installInFlight?.() ?? null;+ const updateInstallDeath = sentinelPresent && installInFlight !== null;+let armed: OkBugReportCrashDetectedEvent | null = null;- if (machineLevelDeath && newDumps.length === 0) {+ if ((machineLevelDeath || updateInstallDeath) && newDumps.length === 0) {const reason = rebootedBetweenSessions? 'system-reboot': prevPendingOsShutdownAt !== null? 'os-shutdown'- : 'suspended';+ : prevSuspendedAt !== null+ ? 'suspended'+ : 'update-install';const breadcrumb = {event: 'crash-detection.machine-level-death',reason,+ // Null for the three machine-level reasons. Carried on every line+ // rather than only the update one so a reader can tell "no install+ // was in flight" from "this build predates the class".+ attemptedInstall: installInFlight?.attemptedVersion ?? null,+ // False when the moment above is the staging fallback rather than a+ // handoff a live process recorded — the same distinction the+ // updater's own boot logs draw, and the one that says how tight the+ // window bounding this suppression actually was.+ recordedHandoff: installInFlight?.recordedHandoff ?? null,detectedAt: detectedAt.toISOString(),prevBootId,prevBootSessionUuid,@@ -785,7 +846,9 @@ export function createCrashDetection(deps: CrashDetectionDeps): CrashDetection {breadcrumb,reason === 'system-reboot'? 'previous session was killed by a system reboot — suppressing the report prompt'- : 'previous session died asleep without resuming — suppressing the report prompt',+ : reason === 'suspended'+ ? 'previous session died asleep without resuming — suppressing the report prompt'+ : 'previous session was killed by an update install — suppressing the report prompt',);}} else if (sentinelPresent || newDumps.length > 0) {@@ -796,8 +859,10 @@ export function createCrashDetection(deps: CrashDetectionDeps): CrashDetection {//// A machine-level death with fresh dumps still prompts, but as the// dump-driven variant: the reboot ended the session, the dump is the- // crash — framing it as an app dirty-shutdown would misattribute.- const dumpDriven = !sentinelPresent || machineLevelDeath;+ // crash — framing it as an app dirty-shutdown would misattribute. An+ // install kill reads the same way: the installer ended the session,+ // and a dump that survived it is still the app faulting on its own.+ const dumpDriven = !sentinelPresent || machineLevelDeath || updateInstallDeath;const eventId = dumpDriven? `boot:dump:${Math.max(...newDumps)}`: `boot:${prevBootId ?? `unreadable:${detectedAt.getTime()}`}`;diff --git a/packages/desktop/src/main/index.ts b/packages/desktop/src/main/index.tsindex 01adcb342..58034708c 100644--- a/packages/desktop/src/main/index.ts+++ b/packages/desktop/src/main/index.ts@@ -184,6 +184,7 @@ import { resolveEffectiveInstanceName } from './auto-instance.ts';import {bootAutoUpdater,channelFromVersion,+ installMayStillBeRunning,type StartAutoUpdaterHandle,} from './auto-updater.ts';import { applyBackgroundThrottle } from './background-throttle.ts';@@ -7671,6 +7672,23 @@ function bootPrimaryInstance(): void {},now: () => new Date(),currentBootSessionUuid: readBootSessionUuid,+ // Was an install this app committed to still possibly running when the+ // previous session ended? If so the installer killed it to replace its+ // files, and the dirty sentinel it left behind is not a crash.+ //+ // Read from disk rather than from the in-memory `appState`, which is not+ // hydrated this early in boot, and asked of the updater's own predicate so+ // the bound cannot drift from the one deciding whether to tell the user an+ // install failed.+ //+ // ORDERING: this must run before the updater's boot reconciliation, which+ // clears `attemptedInstall` the moment the running version catches up — a+ // field report put that clear 249ms after detection, so the margin is real+ // but thin. Both calls are in `bootPrimaryInstance` in that order today;+ // moving updater init ahead of `detectBootCrash()` would silently disable+ // this class, so the suppression tests in `crash-detection.test.ts` are+ // the tripwire.+ installInFlight: () => installMayStillBeRunning(loadAppState(), Date.now()),logger: getLogger('crash-detection'),});crashDetection.detectBootCrash();diff --git a/packages/desktop/tests/unit/auto-updater-install-in-flight.test.ts b/packages/desktop/tests/unit/auto-updater-install-in-flight.test.tsnew file mode 100644index 000000000..c7ce82d4d--- /dev/null+++ b/packages/desktop/tests/unit/auto-updater-install-in-flight.test.ts@@ -0,0 +1,125 @@+import { describe, expect, test } from 'vitest';+import { installMayStillBeRunning } from '../../src/main/auto-updater.ts';+import { emptyState } from '../../src/main/state-store.ts';++/**+ * Pure-helper coverage for the "an install may still be running" predicate.+ *+ * Two callers depend on this bound and they fail in opposite directions, which+ * is why the boundaries below are pinned rather than left to the integration+ * rig. Too loose and crash detection suppresses a genuine crash forever behind+ * a stale record, which is the risk of keying on `attemptedInstall` alone. Too+ * tight and a session the installer really did kill gets reported to the user+ * as a crash, which is the bug this predicate exists to prevent.+ *+ * The boot-reconciliation side of this predicate is exercised end to end by the+ * FakeUpdater rig in `tests/integration/auto-updater.test.ts`; this file owns+ * the boundary arithmetic.+ */++const GRACE_MS = 30 * 60 * 1000;+const MAX_BOOTS = 3;+const NOW = Date.parse('2026-08-23T23:12:51.339Z');+/** A handoff from a real field report, recorded 142.6s before detection ran. */+const HANDOFF = Date.parse('2026-08-23T23:10:28.727Z');++function state(overrides: Partial<ReturnType<typeof emptyState>> = {}) {+ return { ...emptyState(), ...overrides };+}++describe('installMayStillBeRunning', () => {+ test('an install handed off moments ago is in flight', () => {+ const inFlight = installMayStillBeRunning(+ state({ attemptedInstall: '0.61.3', attemptedInstallHandoffAt: HANDOFF }),+ NOW,+ );++ expect(inFlight).toEqual({+ attemptedVersion: '0.61.3',+ handoffAt: HANDOFF,+ recordedHandoff: true,+ });+ });++ test('nothing attempted means nothing in flight', () => {+ expect(installMayStillBeRunning(state({ attemptedInstallHandoffAt: HANDOFF }), NOW)).toBeNull();+ });++ test('an attempt with no handoff and no staging moment cannot be reasoned from', () => {+ // Neither witness survived. Claiming an install is in flight on no evidence+ // would suppress every dirty shutdown for as long as the record stands.+ expect(installMayStillBeRunning(state({ attemptedInstall: '0.61.3' }), NOW)).toBeNull();+ });++ test('the staging moment stands in when no live process recorded the handoff', () => {+ // A session killed mid-flight never quits, so it never stamps a handoff —+ // the path the macOS instances this class was first reported from take.+ const inFlight = installMayStillBeRunning(+ state({ attemptedInstall: '0.61.3', versionPendingInstallStagedAt: NOW - 60_000 }),+ NOW,+ );++ expect(inFlight?.attemptedVersion).toBe('0.61.3');+ expect(inFlight?.recordedHandoff).toBe(false);+ });++ test('a recorded handoff wins over the staging fallback', () => {+ const inFlight = installMayStillBeRunning(+ state({+ attemptedInstall: '0.61.3',+ attemptedInstallHandoffAt: HANDOFF,+ versionPendingInstallStagedAt: NOW - GRACE_MS * 2,+ }),+ NOW,+ );++ // The staging moment is far outside the window; the real handoff is not,+ // and it is the tighter and truer of the two.+ expect(inFlight?.handoffAt).toBe(HANDOFF);+ expect(inFlight?.recordedHandoff).toBe(true);+ });++ test('the grace window is inclusive at its edge and closed past it', () => {+ const atEdge = state({+ attemptedInstall: '0.61.3',+ attemptedInstallHandoffAt: NOW - GRACE_MS,+ });+ expect(installMayStillBeRunning(atEdge, NOW)).not.toBeNull();++ const pastEdge = state({+ attemptedInstall: '0.61.3',+ attemptedInstallHandoffAt: NOW - GRACE_MS - 1,+ });+ expect(installMayStillBeRunning(pastEdge, NOW)).toBeNull();+ });++ test('a handoff in the future is not treated as freshly handed off', () => {+ // `Date.now()` is wall-clock and this record crosses a process quit, so an+ // NTP correction or a VM resume can leave the stamp ahead of now.+ expect(+ installMayStillBeRunning(+ state({ attemptedInstall: '0.61.3', attemptedInstallHandoffAt: NOW + 60_000 }),+ NOW,+ ),+ ).toBeNull();+ });++ test('the hold terminates once the boot budget is spent', () => {+ const lastBoot = state({+ attemptedInstall: '0.61.3',+ attemptedInstallHandoffAt: HANDOFF,+ attemptedInstallDeferredBoots: MAX_BOOTS - 1,+ });+ expect(installMayStillBeRunning(lastBoot, NOW)).not.toBeNull();++ // Without this bound, an install that never lands keeps looking newly+ // handed off — electron-updater re-arms `update-downloaded` from its cache+ // and the next quit stamps a fresh moment.+ const spent = state({+ attemptedInstall: '0.61.3',+ attemptedInstallHandoffAt: HANDOFF,+ attemptedInstallDeferredBoots: MAX_BOOTS,+ });+ expect(installMayStillBeRunning(spent, NOW)).toBeNull();+ });+});