Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(ok): restore the failed-install deferral on same-MMP bumps (PRD-7639) (#3822)

Andrew Mikofalvy54e22fd7cda5
diff --git a/.changeset/restore-install-deferral-same-mmp.md b/.changeset/restore-install-deferral-same-mmp.md
new file mode 100644
index 000000000..75aadc62f
--- /dev/null
+++ b/.changeset/restore-install-deferral-same-mmp.md
@@ -0,0 +1,5 @@
+---
+"@inkeep/open-knowledge": patch
+---
+
+Fixed a false "your update didn't install" notice that could appear while the update was in fact still installing. A beta-to-beta bump within the same version number, committed by a quit that no live process observed, lost the only timestamp the app had for when the install began, so the next launch judged a healthy install as failed. The app now keeps that timestamp across its own boot-time bookkeeping and holds the verdict until the install has really had its chance.
diff --git a/packages/desktop/src/main/auto-updater.ts b/packages/desktop/src/main/auto-updater.ts
index a71df6d2b..142e2d665 100644
--- a/packages/desktop/src/main/auto-updater.ts
+++ b/packages/desktop/src/main/auto-updater.ts
@@ -791,6 +791,20 @@ function installHandoffAgeMs(handoffAt: number | null, nowMs: number): number |
return elapsed < 0 ? null : elapsed;
}
+/**
+ * The moment the in-flight window is measured from: the handoff a live process
+ * recorded, or the staging moment when none did.
+ *
+ * One function rather than the `??` written at each site, because the verdict
+ * and the log line that reports its inputs have to agree about which moment
+ * they mean. They once did not: the predicate read a field the reconciliation
+ * had already nulled while the log kept printing the pre-clear value, so a
+ * report of the resulting false failure notice read as impossible.
+ */
+function resolveInstallHandoffMoment(state: AppState, stagedAt: number | null): number | null {
+ return state.attemptedInstallHandoffAt ?? stagedAt;
+}
+
/**
* Whether an install this app committed to may still have been running at
* `nowMs` — and, when it may, which version and from what moment.
@@ -815,15 +829,28 @@ function installHandoffAgeMs(handoffAt: number | null, nowMs: number): number |
*
* 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.
+ *
+ * `stagedAt` is a required parameter rather than a read of
+ * `state.versionPendingInstallStagedAt`, and the difference is load-bearing.
+ * The boot reconciliation runs the stale-pending clear BEFORE it reaches this
+ * question, and that clear nulls the staging stamp — so by the time the verdict
+ * is due, the field on `state` no longer holds the moment the artifact was
+ * actually staged. On the shape where nothing else recorded the commit (an
+ * unobserved quit, so no `attemptedInstallHandoffAt`) that field is the only
+ * lower bound left, and reading the cleared one silently condemns an install
+ * that is still running. Passing it in forces each caller to say which snapshot
+ * it means: the reconciliation passes the value it captured before its own
+ * mutation, and a caller reading fresh from disk passes the field as-is.
*/
export function installMayStillBeRunning(
state: AppState,
nowMs: number,
+ stagedAt: number | null,
): { 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 handoffAt = resolveInstallHandoffMoment(state, stagedAt);
const handoffAgeMs = installHandoffAgeMs(handoffAt, nowMs);
if (
handoffAt === null ||
@@ -2338,13 +2365,14 @@ export function startAutoUpdater(opts: StartAutoUpdaterOpts): StartAutoUpdaterHa
// 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 handoffAt = resolveInstallHandoffMoment(state, attemptStagedAt);
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) {
+ // reached from rather than the verdict alone. Both resolve the moment
+ // through the same helper, so they cannot come to disagree about it.
+ if (installMayStillBeRunning(state, reconciledAtMs, attemptStagedAt) !== 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.ts b/packages/desktop/src/main/crash-detection.ts
index 62321ece4..8b0347c23 100644
--- a/packages/desktop/src/main/crash-detection.ts
+++ b/packages/desktop/src/main/crash-detection.ts
@@ -811,9 +811,11 @@ export function createCrashDetection(deps: CrashDetectionDeps): CrashDetection {
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".
+ // Null when no install was in flight, whatever the reason — a reboot
+ // that happened to land inside an install window carries a version
+ // here too. 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
diff --git a/packages/desktop/src/main/index.ts b/packages/desktop/src/main/index.ts
index 64eee77b9..ed3223bcb 100644
--- a/packages/desktop/src/main/index.ts
+++ b/packages/desktop/src/main/index.ts
@@ -7658,6 +7658,23 @@ function bootPrimaryInstance(): void {
'desktop main process starting',
);
+ // Read once, here, before anything in this function can touch the state file.
+ //
+ // Crash detection needs to know whether an install this app committed to may
+ // still have been running when the previous session ended, and the updater's
+ // boot reconciliation later in this function CLEARS that record the moment
+ // the running version catches up. Taking the snapshot at the top makes the
+ // answer independent of where either consumer ends up sitting: the two are
+ // ~1000 lines apart today, and a reordering that put the updater first would
+ // otherwise silently disable install-kill suppression while every test stayed
+ // green, because nothing here composes the two boot steps.
+ //
+ // Off disk rather than the module-level `appState`, which is still
+ // `emptyState()` this early: nothing has hydrated it yet at this point in
+ // boot, so reading it here would answer "no install was in flight" for every
+ // session regardless of the truth.
+ const bootStateSnapshot = loadAppState();
+
// Stand up the renderer-ready mount-ack sink before anything can open a
// window: the preload invokes `ok:mcp-wiring:renderer-ready` /
// `ok:onboarding:renderer-ready` on every renderer mount, and the sink's
@@ -7714,19 +7731,21 @@ function bootPrimaryInstance(): void {
// 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.
+ // Answered from `bootStateSnapshot`, taken at the top of this function
+ // before anything here can mutate the state file, so the verdict does not
+ // depend on this call sitting ahead of the updater's boot reconciliation.
+ // The staging stamp is passed as-is: the snapshot predates the stale-pending
+ // clear, so the field still holds the moment the artifact was staged.
//
- // 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()),
+ // Asked of the updater's own predicate rather than re-derived, so the bound
+ // cannot drift from the one deciding whether to tell the user an install
+ // failed.
+ installInFlight: () =>
+ installMayStillBeRunning(
+ bootStateSnapshot,
+ Date.now(),
+ bootStateSnapshot.versionPendingInstallStagedAt,
+ ),
logger: getLogger('crash-detection'),
});
crashDetection.detectBootCrash();
diff --git a/packages/desktop/tests/integration/auto-updater.test.ts b/packages/desktop/tests/integration/auto-updater.test.ts
index 73bc955d2..e4da2f9e3 100644
--- a/packages/desktop/tests/integration/auto-updater.test.ts
+++ b/packages/desktop/tests/integration/auto-updater.test.ts
@@ -2344,6 +2344,59 @@ describe('boot-time failed-install detection — install still in flight', () =>
expect(rig.state.attemptedInstall).toBe(ATTEMPTED_BETA);
});
+ test('an unobserved commit on a same-MMP beta bump still defers', async () => {
+ // The intersection the two fixtures above each leave open, and the only
+ // state where the pre-clear staging snapshot is load-bearing. The
+ // stale-pending reconciliation nulls `versionPendingInstallStagedAt` on an
+ // MMP-only compare, and an unobserved quit means nothing ever stamped
+ // `attemptedInstallHandoffAt` — so the moment the artifact was staged
+ // survives ONLY in the snapshot taken before that clear. A verdict that
+ // reads the field off the reconciled state instead has no bound left at all
+ // and condemns an install that is still running.
+ //
+ // Neither sibling fixture reaches here: the staging-fallback one uses the
+ // default version pair, so the clear never fires; the same-MMP one commits
+ // by a plain quit, so the handoff is stamped and the fallback is never
+ // consulted.
+ const RUNNING_BETA = '0.54.0-beta.0';
+ const ATTEMPTED_BETA = '0.54.0-beta.1';
+ const rig = reopenAt(
+ await stageAndCommit('unobserved-quit', {
+ running: RUNNING_BETA,
+ attempted: ATTEMPTED_BETA,
+ }),
+ new Date(STAGED_AT.getTime() + 45 * SECOND),
+ RUNNING_BETA,
+ );
+
+ // Both premises, asserted so the test cannot drift off the hazard and start
+ // passing for the wrong reason.
+ expect(rig.dispatches).toContain('stale-pending-cleared' as DispatchKind);
+ expect(rig.state.attemptedInstallHandoffAt).toBeNull();
+
+ expect(failureCards(rig)).toHaveLength(0);
+ expect(rig.dispatches).toContain('install-in-flight-deferred' as DispatchKind);
+ expect(rig.dispatches).not.toContain('install-failed-on-boot' as DispatchKind);
+ expect(rig.state.attemptedInstallSurfacedCount).toBe(0);
+ // WHICH moment the hold leaned on, not merely that it held. Without this the
+ // fixture would pass on a verdict that deferred off some other bound, which
+ // is exactly the failure it exists to catch.
+ expect(rig.logger.info).toHaveBeenCalledWith(
+ expect.stringContaining('defer'),
+ expect.objectContaining({ recordedHandoff: false, handoffAt: STAGED_AT.getTime() }),
+ );
+ });
+
+ // The unobserved-quit counterpart of the second-reopen fixture below. Boot 1's
+ // stale-pending clear nulls the staging stamp on disk, and an unobserved quit
+ // stamps no handoff, so boot 2 reads both witnesses as null and condemns an
+ // install that may still be running. Left as a todo rather than a skip: the
+ // fixture cannot be written honestly until the staging instant lives in a
+ // field no reconciliation clears, which needs a parseAppState schema addition.
+ test.todo(
+ 'an unobserved commit on a same-MMP beta bump survives a SECOND reopen (needs PRD-8291)',
+ );
+
test('a same-MMP beta bump survives a SECOND reopen inside the window', async () => {
// The same-MMP shape reaches the verdict having just lost a field: the
// stale-pending reconciliation fires on an MMP-only compare and persists the
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.ts
index c7ce82d4d..bd3f4fd2c 100644
--- a/packages/desktop/tests/unit/auto-updater-install-in-flight.test.ts
+++ b/packages/desktop/tests/unit/auto-updater-install-in-flight.test.ts
@@ -1,5 +1,6 @@
import { describe, expect, test } from 'vitest';
import { installMayStillBeRunning } from '../../src/main/auto-updater.ts';
+import type { AppState } from '../../src/main/state-store.ts';
import { emptyState } from '../../src/main/state-store.ts';
/**
@@ -23,15 +24,23 @@ 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>> = {}) {
+function state(overrides: Partial<AppState> = {}): AppState {
return { ...emptyState(), ...overrides };
}
+/**
+ * The ordinary call shape: a caller reading state that nothing has mutated
+ * passes the staging stamp straight through. The reconciliation's shape, where
+ * the two diverge, is pinned separately below.
+ */
+function check(s: AppState, nowMs: number = NOW) {
+ return installMayStillBeRunning(s, nowMs, s.versionPendingInstallStagedAt);
+}
+
describe('installMayStillBeRunning', () => {
test('an install handed off moments ago is in flight', () => {
- const inFlight = installMayStillBeRunning(
+ const inFlight = check(
state({ attemptedInstall: '0.61.3', attemptedInstallHandoffAt: HANDOFF }),
- NOW,
);
expect(inFlight).toEqual({
@@ -42,35 +51,55 @@ describe('installMayStillBeRunning', () => {
});
test('nothing attempted means nothing in flight', () => {
- expect(installMayStillBeRunning(state({ attemptedInstallHandoffAt: HANDOFF }), NOW)).toBeNull();
+ expect(check(state({ attemptedInstallHandoffAt: HANDOFF }))).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();
+ expect(check(state({ attemptedInstall: '0.61.3' }))).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(
+ const inFlight = check(
state({ attemptedInstall: '0.61.3', versionPendingInstallStagedAt: NOW - 60_000 }),
- NOW,
);
expect(inFlight?.attemptedVersion).toBe('0.61.3');
expect(inFlight?.recordedHandoff).toBe(false);
});
+ test("the staging moment is the caller's to supply, not read off the state", () => {
+ // The regression this parameter exists to prevent. The boot reconciliation
+ // runs its stale-pending clear first, which nulls the staging stamp on
+ // `state`; the moment the artifact was really staged survives only in the
+ // snapshot the caller took beforehand. Reading the cleared field instead
+ // condemns an install that is still running.
+ const afterStalePendingClear = state({
+ attemptedInstall: '0.54.0-beta.1',
+ // Unobserved quit: nothing stamped a handoff, so the staging moment is
+ // the only lower bound there is.
+ attemptedInstallHandoffAt: null,
+ versionPendingInstallStagedAt: null,
+ });
+ const snapshotTakenBeforeTheClear = NOW - 60_000;
+
+ expect(
+ installMayStillBeRunning(afterStalePendingClear, NOW, snapshotTakenBeforeTheClear),
+ ).not.toBeNull();
+ // Same state, read the way the bug read it.
+ expect(installMayStillBeRunning(afterStalePendingClear, NOW, null)).toBeNull();
+ });
+
test('a recorded handoff wins over the staging fallback', () => {
- const inFlight = installMayStillBeRunning(
+ const inFlight = check(
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,
@@ -84,23 +113,20 @@ describe('installMayStillBeRunning', () => {
attemptedInstall: '0.61.3',
attemptedInstallHandoffAt: NOW - GRACE_MS,
});
- expect(installMayStillBeRunning(atEdge, NOW)).not.toBeNull();
+ expect(check(atEdge)).not.toBeNull();
const pastEdge = state({
attemptedInstall: '0.61.3',
attemptedInstallHandoffAt: NOW - GRACE_MS - 1,
});
- expect(installMayStillBeRunning(pastEdge, NOW)).toBeNull();
+ expect(check(pastEdge)).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,
- ),
+ check(state({ attemptedInstall: '0.61.3', attemptedInstallHandoffAt: NOW + 60_000 })),
).toBeNull();
});
@@ -110,7 +136,7 @@ describe('installMayStillBeRunning', () => {
attemptedInstallHandoffAt: HANDOFF,
attemptedInstallDeferredBoots: MAX_BOOTS - 1,
});
- expect(installMayStillBeRunning(lastBoot, NOW)).not.toBeNull();
+ expect(check(lastBoot)).not.toBeNull();
// Without this bound, an install that never lands keeps looking newly
// handed off — electron-updater re-arms `update-downloaded` from its cache
@@ -120,6 +146,6 @@ describe('installMayStillBeRunning', () => {
attemptedInstallHandoffAt: HANDOFF,
attemptedInstallDeferredBoots: MAX_BOOTS,
});
- expect(installMayStillBeRunning(spent, NOW)).toBeNull();
+ expect(check(spent)).toBeNull();
});
});