Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

feat(desktop): auto-restart a leftover server after an app upgrade; drop dev reclaim notice (PRD-7386/7387) (#2713)

mike-inkeepeb7a31d4e9e4
diff --git a/.changeset/auto-restart-server-on-upgrade.md b/.changeset/auto-restart-server-on-upgrade.md
new file mode 100644
index 000000000..6e90ecbbe
--- /dev/null
+++ b/.changeset/auto-restart-server-on-upgrade.md
@@ -0,0 +1,9 @@
+---
+"@inkeep/open-knowledge": patch
+---
+
+Auto-restart a leftover server after an app update, and drop the dev "started a fresh server" notice
+
+When OpenKnowledge Desktop auto-updated, a server for a project could survive the pre-install teardown (a CLI-spawned one, or one whose shutdown timed out). The relaunched app then attached to that stale build and asked you to click "Restart with this app's version" before it worked. Now, on the first launch after an update, the app detects the version-mismatched leftover and restarts it to match automatically — no prompt. This only happens on the launch right after an update: a running server that merely differs in version (for example a newer CLI you started yourself) is never auto-restarted. No extra notice appears — the existing "Updated to Version X" banner already tells you the app updated.
+
+The dev-only "Started a fresh OpenKnowledge server…" toast that popped up whenever a dev session reclaimed a leftover server is removed — the reclaim still happens, just silently.
diff --git a/packages/app/src/lib/desktop-bridge-types.ts b/packages/app/src/lib/desktop-bridge-types.ts
index 24d0c2619..0a52ec11c 100644
--- a/packages/app/src/lib/desktop-bridge-types.ts
+++ b/packages/app/src/lib/desktop-bridge-types.ts
@@ -882,8 +882,6 @@ export interface OkDesktopBridge {
onServerVersionDrift(cb: (info: OkServerVersionDriftInfo) => void): OkUnsubscribe;
/** Subscribe to `ok:server-restarted`. Canonical JSDoc in `bridge-contract.ts`. */
onServerRestarted(cb: (info: { readonly appRuntime: string }) => void): OkUnsubscribe;
- /** Subscribe to `ok:server-reclaimed`. Canonical JSDoc in `bridge-contract.ts`. */
- onServerReclaimed(cb: (info: { readonly appRuntime: string }) => void): OkUnsubscribe;
/** Restart the project's server to match this app's version. Canonical JSDoc in `bridge-contract.ts`. */
restartServer(projectPath: string): Promise<OkServerRestartOutcome>;
/**
diff --git a/packages/app/src/lib/install-server-drift-listener.test.ts b/packages/app/src/lib/install-server-drift-listener.test.ts
index 57c94f2bb..1c14cdc39 100644
--- a/packages/app/src/lib/install-server-drift-listener.test.ts
+++ b/packages/app/src/lib/install-server-drift-listener.test.ts
@@ -34,7 +34,6 @@ mock.module('sonner', () => ({
type DriftModule = typeof import('@/lib/install-server-drift-listener');
let driftToastBody: DriftModule['driftToastBody'];
let installServerDriftListener: DriftModule['installServerDriftListener'];
-let reclaimNoticeMessage: DriftModule['reclaimNoticeMessage'];
let restartDisruptionWarning: DriftModule['restartDisruptionWarning'];
let restartFailureMessage: DriftModule['restartFailureMessage'];
let restartSuccessMessage: DriftModule['restartSuccessMessage'];
@@ -42,7 +41,6 @@ beforeAll(async () => {
({
driftToastBody,
installServerDriftListener,
- reclaimNoticeMessage,
restartDisruptionWarning,
restartFailureMessage,
restartSuccessMessage,
@@ -61,18 +59,14 @@ function makeBridge(opts?: { restartOutcome?: OkServerRestartOutcome; restartRej
bridge: OkDesktopBridge;
fireDrift: (info: OkServerVersionDriftInfo) => void;
fireRestarted: (appRuntime: string) => void;
- fireReclaimed: (appRuntime: string) => void;
restartServer: ReturnType<typeof mock>;
unsubDrift: ReturnType<typeof mock>;
unsubRestarted: ReturnType<typeof mock>;
- unsubReclaimed: ReturnType<typeof mock>;
} {
let driftCb: ((info: OkServerVersionDriftInfo) => void) | null = null;
let restartedCb: ((info: { appRuntime: string }) => void) | null = null;
- let reclaimedCb: ((info: { appRuntime: string }) => void) | null = null;
const unsubDrift = mock(() => {});
const unsubRestarted = mock(() => {});
- const unsubReclaimed = mock(() => {});
const restartServer = mock(async () => {
if (opts?.restartReject) throw new Error('channel closed');
return opts?.restartOutcome ?? { ok: true };
@@ -87,21 +81,15 @@ function makeBridge(opts?: { restartOutcome?: OkServerRestartOutcome; restartRej
restartedCb = cb;
return unsubRestarted;
},
- onServerReclaimed: (cb: (info: { appRuntime: string }) => void) => {
- reclaimedCb = cb;
- return unsubReclaimed;
- },
restartServer,
} as unknown as OkDesktopBridge;
return {
bridge,
fireDrift: (info) => driftCb?.(info),
fireRestarted: (appRuntime) => restartedCb?.({ appRuntime }),
- fireReclaimed: (appRuntime) => reclaimedCb?.({ appRuntime }),
restartServer,
unsubDrift,
unsubRestarted,
- unsubReclaimed,
};
}
@@ -142,16 +130,6 @@ describe('drift copy', () => {
expect(restartSuccessMessage('0.8.2')).toContain('0.8.2');
});
- test('reclaim notice names the dev session, the version, MCP, and the agent remedy', () => {
- const msg = reclaimNoticeMessage('0.8.2');
- expect(msg.toLowerCase()).toContain('dev session');
- expect(msg).toContain('0.8.2');
- expect(msg).toContain('terminated');
- expect(msg).toContain('MCP');
- expect(msg.toLowerCase()).toContain('restart the agent');
- expect(msg).toContain('Claude Code');
- });
-
test('eperm failure points at a different account + reboot, never `ok stop all`', () => {
const msg = restartFailureMessage('eperm');
expect(msg.toLowerCase()).toContain('different account');
@@ -169,14 +147,13 @@ describe('installServerDriftListener', () => {
expect(installServerDriftListener({ bridge: undefined })).toBeUndefined();
});
- test('subscribes to all three events and unsubscribes on teardown', () => {
+ test('subscribes to both events and unsubscribes on teardown', () => {
const h = makeBridge();
const cleanup = installServerDriftListener({ bridge: h.bridge });
expect(cleanup).toBeDefined();
cleanup?.();
expect(h.unsubDrift).toHaveBeenCalledTimes(1);
expect(h.unsubRestarted).toHaveBeenCalledTimes(1);
- expect(h.unsubReclaimed).toHaveBeenCalledTimes(1);
});
// The drift toast renders a custom component via `toast.custom`; inspect the
@@ -258,18 +235,4 @@ describe('installServerDriftListener', () => {
expect(toastSuccess).toHaveBeenCalledTimes(1);
expect(toastSuccess.mock.calls[0]?.[0]).toBe(restartSuccessMessage('0.8.2'));
});
-
- test('reclaimed event shows a transient warning (not a success) naming the side effect', () => {
- toastWarning.mockClear();
- toastSuccess.mockClear();
- const h = makeBridge();
- installServerDriftListener({ bridge: h.bridge });
- h.fireReclaimed('0.8.2');
- expect(toastWarning).toHaveBeenCalledTimes(1);
- expect(toastWarning.mock.calls[0]?.[0]).toBe(reclaimNoticeMessage('0.8.2'));
- // Finite duration so it doesn't pile up on repeat dev launches, but long
- // enough to read the multi-sentence side-effect copy.
- expect(toastWarning.mock.calls[0]?.[1]).toMatchObject({ duration: 15_000 });
- expect(toastSuccess).not.toHaveBeenCalled();
- });
});
diff --git a/packages/app/src/lib/install-server-drift-listener.ts b/packages/app/src/lib/install-server-drift-listener.ts
index 4adf1130f..2b8aa293e 100644
--- a/packages/app/src/lib/install-server-drift-listener.ts
+++ b/packages/app/src/lib/install-server-drift-listener.ts
@@ -9,10 +9,10 @@
* confirmation arrives on the NEW window via `ok:server-restarted` and only a
* failure resolves back here (showing the branched remedy).
*
- * On `ok:server-reclaimed` (a dev-only session auto-terminated a foreign server
- * on this project's contentDir and spawned its own — see the window-manager
- * reclaim branch), surface a transient warning naming the dropped-MCP side
- * effect. No user action initiated it, so it informs rather than confirms.
+ * The packaged upgrade reconcile (main auto-restarts a pre-upgrade survivor
+ * server on the first launch after an update) is intentionally silent here —
+ * the existing "Updated to Version X" whats-new notice already tells the user
+ * the app updated, so no extra toast fires.
*
* Registered imperatively during `main.tsx` module init (not in a React
* effect) so the listeners are in place before main fires the events on
@@ -62,23 +62,11 @@ export function driftToastBody(info: OkServerVersionDriftInfo): string {
: t`This project's server (v${info.serverRuntime}) is newer than this app (v${info.appRuntime}).`;
}
-/** Success confirmation shown on the recreated window. Pure — exported for tests. */
+/** Success confirmation shown on the recreated window after a manual restart. Pure — exported for tests. */
export function restartSuccessMessage(appRuntime: string): string {
return t`Restarted — now running v${appRuntime}.`;
}
-/**
- * Disruption notice shown on the freshly-spawned window after a dev session
- * auto-reclaimed a foreign server (act-then-inform — no user action initiated
- * it, so this informs rather than confirms). Names the dropped-MCP side effect
- * with the same remedy as {@link restartDisruptionWarning} so a dev who sees
- * their agents disconnect understands they caused it by launching this build.
- * Pure — exported for tests.
- */
-export function reclaimNoticeMessage(appRuntime: string): string {
- return t`Started a fresh OpenKnowledge server (v${appRuntime}) for this dev session — the server already running for this project was terminated. Connected agents (Claude Code, Codex, Cursor) just lost their OpenKnowledge MCP connection; restart the agent, or toggle its OpenKnowledge MCP server off and on, to reconnect.`;
-}
-
/**
* Branched failure copy. EPERM means a different user owns the server, so the
* user's own `ok stop all` would hit the same wall — the only remedy is a
@@ -150,18 +138,8 @@ export function installServerDriftListener(opts: {
toast.success(restartSuccessMessage(info.appRuntime));
});
- // Dev-only: main auto-reclaimed a foreign server and spawned its own. Inform
- // (don't confirm) — `warning`, and a generous-but-finite duration so the
- // multi-sentence side-effect copy is readable without piling up on repeat
- // dev launches. Fires only when a reclaim actually happened (a leftover
- // server was present), not on every launch.
- const unsubscribeReclaimed = bridge.onServerReclaimed((info) => {
- toast.warning(reclaimNoticeMessage(info.appRuntime), { duration: 15_000 });
- });
-
return () => {
unsubscribeDrift();
unsubscribeRestarted();
- unsubscribeReclaimed();
};
}
diff --git a/packages/app/src/locales/en/messages.json b/packages/app/src/locales/en/messages.json
index f0b34f96e..3c32d3e1a 100644
--- a/packages/app/src/locales/en/messages.json
+++ b/packages/app/src/locales/en/messages.json
@@ -267,11 +267,6 @@
"5AzM72": ["This setting is per-machine and isn't shared with collaborators."],
"5ClEAu": ["Inline hashtag for cross-doc grouping."],
"5D3Ior": ["Hide folder"],
- "5DFPDh": [
- "Started a fresh OpenKnowledge server (v",
- ["appRuntime"],
- ") for this dev session — the server already running for this project was terminated. Connected agents (Claude Code, Codex, Cursor) just lost their OpenKnowledge MCP connection; restart the agent, or toggle its OpenKnowledge MCP server off and on, to reconnect."
- ],
"5F5HYj": [["ahead"], " ahead, ", ["behind"], " behind"],
"5GKMSz": ["Indent or outdent the current list item."],
"5GRxoA": ["Search files, folders, and commands for the current workspace."],
diff --git a/packages/app/src/locales/en/messages.po b/packages/app/src/locales/en/messages.po
index da5356a3d..1d798a7d2 100644
--- a/packages/app/src/locales/en/messages.po
+++ b/packages/app/src/locales/en/messages.po
@@ -7495,10 +7495,6 @@ msgstr "Start source completion"
msgid "Start writing to create this page"
msgstr "Start writing to create this page"
-#: src/lib/install-server-drift-listener.ts
-msgid "Started a fresh OpenKnowledge server (v{appRuntime}) for this dev session — the server already running for this project was terminated. Connected agents (Claude Code, Codex, Cursor) just lost their OpenKnowledge MCP connection; restart the agent, or toggle its OpenKnowledge MCP server off and on, to reconnect."
-msgstr "Started a fresh OpenKnowledge server (v{appRuntime}) for this dev session — the server already running for this project was terminated. Connected agents (Claude Code, Codex, Cursor) just lost their OpenKnowledge MCP connection; restart the agent, or toggle its OpenKnowledge MCP server off and on, to reconnect."
-
#: src/components/TemplateBody.tsx
msgid "Starter content"
msgstr "Starter content"
diff --git a/packages/app/src/locales/pseudo/messages.json b/packages/app/src/locales/pseudo/messages.json
index bf3d9846b..acb0f34e2 100644
--- a/packages/app/src/locales/pseudo/messages.json
+++ b/packages/app/src/locales/pseudo/messages.json
@@ -267,11 +267,6 @@
"5AzM72": ["Ţĥĩś śēţţĩńĝ ĩś ƥēŕ-ḿàćĥĩńē àńď ĩśń'ţ śĥàŕēď ŵĩţĥ ćōĺĺàƀōŕàţōŕś."],
"5ClEAu": ["Ĩńĺĩńē ĥàśĥţàĝ ƒōŕ ćŕōśś-ďōć ĝŕōũƥĩńĝ."],
"5D3Ior": ["Ĥĩďē ƒōĺďēŕ"],
- "5DFPDh": [
- "Śţàŕţēď à ƒŕēśĥ ŌƥēńĶńōŵĺēďĝē śēŕvēŕ (v",
- ["appRuntime"],
- ") ƒōŕ ţĥĩś ďēv śēśśĩōń — ţĥē śēŕvēŕ àĺŕēàďŷ ŕũńńĩńĝ ƒōŕ ţĥĩś ƥŕōĴēćţ ŵàś ţēŕḿĩńàţēď. Ćōńńēćţēď àĝēńţś (Ćĺàũďē Ćōďē, Ćōďēx, Ćũŕśōŕ) Ĵũśţ ĺōśţ ţĥēĩŕ ŌƥēńĶńōŵĺēďĝē ḾĆƤ ćōńńēćţĩōń; ŕēśţàŕţ ţĥē àĝēńţ, ōŕ ţōĝĝĺē ĩţś ŌƥēńĶńōŵĺēďĝē ḾĆƤ śēŕvēŕ ōƒƒ àńď ōń, ţō ŕēćōńńēćţ."
- ],
"5F5HYj": [["ahead"], " àĥēàď, ", ["behind"], " ƀēĥĩńď"],
"5GKMSz": ["Ĩńďēńţ ōŕ ōũţďēńţ ţĥē ćũŕŕēńţ ĺĩśţ ĩţēḿ."],
"5GRxoA": ["Śēàŕćĥ ƒĩĺēś, ƒōĺďēŕś, àńď ćōḿḿàńďś ƒōŕ ţĥē ćũŕŕēńţ ŵōŕķśƥàćē."],
diff --git a/packages/app/src/locales/pseudo/messages.po b/packages/app/src/locales/pseudo/messages.po
index 80dbe84f9..9942df5f6 100644
--- a/packages/app/src/locales/pseudo/messages.po
+++ b/packages/app/src/locales/pseudo/messages.po
@@ -7491,10 +7491,6 @@ msgstr ""
msgid "Start writing to create this page"
msgstr ""
-#: src/lib/install-server-drift-listener.ts
-msgid "Started a fresh OpenKnowledge server (v{appRuntime}) for this dev session — the server already running for this project was terminated. Connected agents (Claude Code, Codex, Cursor) just lost their OpenKnowledge MCP connection; restart the agent, or toggle its OpenKnowledge MCP server off and on, to reconnect."
-msgstr ""
-
#: src/components/TemplateBody.tsx
msgid "Starter content"
msgstr ""
diff --git a/packages/app/tests/stress/file-tree-create.e2e.ts b/packages/app/tests/stress/file-tree-create.e2e.ts
index d1010521d..48a76af42 100644
--- a/packages/app/tests/stress/file-tree-create.e2e.ts
+++ b/packages/app/tests/stress/file-tree-create.e2e.ts
@@ -234,7 +234,6 @@ async function installDelayedDesktopSessionBridge(
onShareReceived: () => unsubscribe,
onServerVersionDrift: () => unsubscribe,
onServerRestarted: () => unsubscribe,
- onServerReclaimed: () => unsubscribe,
restartServer: async () => ({ ok: true }),
dialog: {
openFolder: async () => null,
diff --git a/packages/app/tests/stress/fixtures/handoff-mocks.ts b/packages/app/tests/stress/fixtures/handoff-mocks.ts
index 62c1741c7..eadf4457c 100644
--- a/packages/app/tests/stress/fixtures/handoff-mocks.ts
+++ b/packages/app/tests/stress/fixtures/handoff-mocks.ts
@@ -375,7 +375,6 @@ export async function installHandoffMocks(page: Page, cfg: HandoffMockConfig): P
onShareReceived: () => () => {},
onServerVersionDrift: () => () => {},
onServerRestarted: () => () => {},
- onServerReclaimed: () => () => {},
restartServer: async () => ({ ok: true as const }),
// Theme bridge is invoked on first ConfigProvider render via
// useThemeBridge — must not throw or the ConfigProvider subtree
diff --git a/packages/core/src/desktop-bridge.ts b/packages/core/src/desktop-bridge.ts
index 46612a496..75f1784ba 100644
--- a/packages/core/src/desktop-bridge.ts
+++ b/packages/core/src/desktop-bridge.ts
@@ -855,16 +855,6 @@ export interface OkServerRestartedInfo {
readonly appRuntime: string;
}
-/**
- * Payload for `onServerReclaimed` — fired on the freshly-spawned window after a
- * dev session auto-terminated a foreign server it found on the project's
- * contentDir and started its own in its place. `appRuntime` is the app version
- * the fresh server runs.
- */
-export interface OkServerReclaimedInfo {
- readonly appRuntime: string;
-}
-
/**
* Result of `restartServer`. Only the failure case reaches the originating
* renderer — on success the window is recreated, so its invoke promise never
@@ -1032,16 +1022,6 @@ export interface OkDesktopBridge {
* server now matches the app.
*/
onServerRestarted(cb: (info: OkServerRestartedInfo) => void): OkUnsubscribe;
- /**
- * Subscribe to `ok:server-reclaimed` — fired on a freshly-spawned window when
- * this (dev-only) session auto-terminated a foreign server already running on
- * the project's contentDir and started its own in its place. The renderer
- * surfaces an informational notice naming the side effect: connected agents'
- * OpenKnowledge MCP connections were dropped. Unlike `onServerRestarted` no
- * user action initiated this (act-then-inform), so it is a disruption notice,
- * not a success confirmation.
- */
- onServerReclaimed(cb: (info: OkServerReclaimedInfo) => void): OkUnsubscribe;
/**
* Restart the project's server to match this app's version: terminate the
* attached (not-owned) server and recreate the window against a fresh
diff --git a/packages/desktop/src/main/index.ts b/packages/desktop/src/main/index.ts
index 2fc277246..066eb00ec 100644
--- a/packages/desktop/src/main/index.ts
+++ b/packages/desktop/src/main/index.ts
@@ -369,6 +369,7 @@ import {
} from './url-scheme.ts';
import { migrateLegacyUserDataDir } from './userdata-migration.ts';
import { buildUtilityForkEnv } from './utility-fork-env.ts';
+import { computeFirstLaunchAfterUpgrade } from './version-drift.ts';
import {
buildViewMenuStateDeps,
createDefaultEditorViewMenuState,
@@ -704,6 +705,17 @@ let pendingSchemaIncompatibility: SchemaIncompatibilityDiagnostic | null = null;
export function getPendingSchemaIncompatibility(): SchemaIncompatibilityDiagnostic | null {
return pendingSchemaIncompatibility;
}
+/**
+ * True iff THIS launch is the first run after the app version changed — an
+ * auto-update installed a new build. A per-session snapshot captured at
+ * bootstrap from `appState.lastSeenVersion` BEFORE the auto-updater advances
+ * that marker (boot step 6, after the first project window opens at step 4), so
+ * it stays true for every project opened this run. The window-manager reads it
+ * (via the `isFirstLaunchAfterUpgrade` dep) to auto-restart a pre-upgrade
+ * survivor server instead of prompting. `lastSeenVersion === null` is a fresh
+ * install, not an upgrade → false.
+ */
+let firstLaunchAfterUpgrade = false;
/**
* Drop the pending diagnostic so subsequent `ok:state:query` calls return
* `null` for `schemaIncompatibility`. Called from the refuse-downgrade UX's
@@ -1393,6 +1405,11 @@ function ensureWindowManager() {
// rather than silently attaching to the stale one. Off in packaged builds,
// where attaching to a live server is the intended shared-server behavior.
reclaimForeignServerInDev: !app.isPackaged,
+ // Packaged upgrade reconcile: on the first launch after an app update,
+ // auto-restart a pre-upgrade survivor server the attach path would
+ // otherwise attach to (+ prompt). Reads the bootstrap snapshot, not live
+ // state, so it holds for the whole session. See `firstLaunchAfterUpgrade`.
+ isFirstLaunchAfterUpgrade: () => firstLaunchAfterUpgrade,
setTimeout: (cb, ms) => setTimeout(cb, ms),
killProbe: (pid, signal) => {
process.kill(pid, signal as NodeJS.Signals | 0);
@@ -1416,6 +1433,13 @@ function ensureWindowManager() {
onUtilityExit: (utility) => {
ensureDebugIpc().cancelPendingForUtility(utility);
},
+ // The window-manager's `log` dep is optional; an unwired `this.deps.log`
+ // makes every `log?.info/warn` in window-manager.ts a silent no-op. Wire it
+ // to the 'window-manager' subsystem logger (same pattern keepalive /
+ // server-exit use) so its diagnostics — server spawn/attach, dev reclaim,
+ // the `desktop-upgrade-reconcile` upgrade signal, restart — reach
+ // `~/.ok/logs/`.
+ log: getLogger('window-manager'),
recordServerExit: (info) => getServerExitRecorder().recordExit(info),
// Presence-invisible keepalive WS — registers the desktop as an active
// `/collab*` upgrade for as long as a project window is open, so a brief
@@ -5362,6 +5386,15 @@ function bootPrimaryInstance(): void {
});
appState = result.appState;
pendingSchemaIncompatibility = result.pendingSchemaIncompatibility;
+ // Snapshot the post-upgrade signal BEFORE step 6 (`bootAutoUpdater`)
+ // advances `lastSeenVersion` — this bootstrap runs at step 2, the first
+ // project window opens at step 4, and the updater consumes the marker at
+ // step 6. Captured once so it stays true for every project opened this
+ // run (a live re-read would flip false after the updater advances).
+ firstLaunchAfterUpgrade = computeFirstLaunchAfterUpgrade(
+ appState.lastSeenVersion,
+ app.getVersion(),
+ );
// Startup instrumentation: bootstrap (IPC handlers, menu, dock, state)
// is complete; the next launch phase is the project-window open + spawn.
startupWaterfall.mark('bootstrapDone');
diff --git a/packages/desktop/src/main/version-drift.test.ts b/packages/desktop/src/main/version-drift.test.ts
index 4aab23b3c..7aa3d6a1a 100644
--- a/packages/desktop/src/main/version-drift.test.ts
+++ b/packages/desktop/src/main/version-drift.test.ts
@@ -1,6 +1,10 @@
import { describe, expect, test } from 'bun:test';
import { CLIENT_RUNTIME_VERSION_FALLBACK } from '@inkeep/open-knowledge-core';
-import { classifyServerVersion, type DesktopVersion } from './version-drift.ts';
+import {
+ classifyServerVersion,
+ computeFirstLaunchAfterUpgrade,
+ type DesktopVersion,
+} from './version-drift.ts';
const SELF: DesktopVersion = { protocolVersion: 1, runtimeVersion: '0.8.2' };
@@ -107,3 +111,23 @@ describe('classifyServerVersion', () => {
).toEqual({ relation: 'older', dimension: 'protocol' });
});
});
+
+describe('computeFirstLaunchAfterUpgrade', () => {
+ test('fresh install (lastSeenVersion === null) → false, not an upgrade', () => {
+ expect(computeFirstLaunchAfterUpgrade(null, '0.8.2')).toBe(false);
+ });
+
+ test('same version as last launch → false', () => {
+ expect(computeFirstLaunchAfterUpgrade('0.8.2', '0.8.2')).toBe(false);
+ });
+
+ test('version changed since last launch → true (upgrade)', () => {
+ expect(computeFirstLaunchAfterUpgrade('0.8.1', '0.8.2')).toBe(true);
+ });
+
+ test('version changed downward (rollback) also counts → true', () => {
+ // The signal is "the version differs from last launch", not a direction —
+ // a rollback is still a first launch on a different build.
+ expect(computeFirstLaunchAfterUpgrade('0.9.0', '0.8.2')).toBe(true);
+ });
+});
diff --git a/packages/desktop/src/main/version-drift.ts b/packages/desktop/src/main/version-drift.ts
index b5869794e..a140ae71d 100644
--- a/packages/desktop/src/main/version-drift.ts
+++ b/packages/desktop/src/main/version-drift.ts
@@ -84,3 +84,23 @@ export function classifyServerVersion(
if (cmp > 0) return { relation: 'newer', dimension: 'runtime' };
return { relation: 'same', dimension: null };
}
+
+/**
+ * Decide whether THIS launch is the first run after the app version changed —
+ * the signal the packaged upgrade reconcile gates on. `lastSeenVersion` is the
+ * version persisted on the previous launch (`null` on a fresh install). A fresh
+ * install is NOT an upgrade — there is no prior version to have drifted from —
+ * so it returns false; only a real version transition (either direction)
+ * returns true.
+ *
+ * Pure — no Electron, no fs — so the three cases (null / same / changed) are
+ * exhaustively unit-testable. `index.ts` captures the result once at bootstrap,
+ * BEFORE the auto-updater advances `lastSeenVersion`, and holds it for the
+ * session (a live re-read would flip false once the updater advances).
+ */
+export function computeFirstLaunchAfterUpgrade(
+ lastSeenVersion: string | null,
+ currentVersion: string,
+): boolean {
+ return lastSeenVersion !== null && lastSeenVersion !== currentVersion;
+}
diff --git a/packages/desktop/src/main/window-manager.ts b/packages/desktop/src/main/window-manager.ts
index 1be5fd34f..ced07a666 100644
--- a/packages/desktop/src/main/window-manager.ts
+++ b/packages/desktop/src/main/window-manager.ts
@@ -567,8 +567,8 @@ export interface WindowManagerDeps {
* `electron-vite dev` against a project that still has a server from a prior
* packaged-app run (or a CLI / another instance) actually exercises their
* working-tree server + core code instead of silently attaching to the stale
- * build. Act-then-inform: the freshly-spawned window fires `ok:server-
- * reclaimed` so the renderer can surface the dropped-MCP side effect.
+ * build. The reclaim terminates + respawns silently — the routine per-rebuild
+ * restart is not worth a notice.
*
* Wired from `!app.isPackaged` in `index.ts`; never set in packaged builds
* (a packaged user attaching to a live server is the intended shared-server
@@ -576,6 +576,26 @@ export interface WindowManagerDeps {
* exactly as before.
*/
reclaimForeignServerInDev?: boolean;
+ /**
+ * Packaged-path upgrade reconcile: `true` iff THIS launch is the first run
+ * after the app's version changed (an auto-update installed a new build).
+ * When set, the attach path treats a version-mismatched server it would
+ * otherwise attach to as a pre-upgrade survivor — the pre-install teardown
+ * (`stopAllOwnedServers`) only reaps servers this desktop spawned, so a
+ * CLI-spawned or teardown-timed-out server outlives the swap — and
+ * terminates it, spawning the app's own version in its place rather than
+ * attaching to the stale build and prompting the user to restart. Any drift
+ * direction qualifies: the trigger is "we just upgraded", not the version
+ * ordering.
+ *
+ * A stable per-session snapshot, NOT a live read: `index.ts` captures it at
+ * bootstrap from `appState.lastSeenVersion` BEFORE the auto-updater advances
+ * that marker, so it stays true for every project opened this run. A live
+ * read would flip false once the updater advances mid-session and miss a
+ * second project opened later. Omitted (test harnesses, dev) → the attach
+ * path never auto-terminates on version mismatch.
+ */
+ isFirstLaunchAfterUpgrade?(): boolean;
/** Schedule a one-shot timer (test injection for the post-exit liveness probe). */
setTimeout(cb: () => void, ms: number): unknown;
/** `process.kill(pid, signal)` — used in the post-exit liveness probe. */
@@ -1419,15 +1439,26 @@ export class WindowManager {
const candidate = this.tryAttachExistingServer(lockDir);
const attached =
candidate !== null && (await this.probeAttachableLock(candidate)) ? candidate : null;
- // Dev-only reclaim: when the attachable server is foreign (not one this
- // session spawned), terminate it and fall through to a fresh own-build
- // spawn instead of attaching. `spawnedDetachedPids` is empty under the dev
- // utility-fork path, so the pid guard reads as "always foreign" there — but
- // it stays load-bearing if a future build wires detached spawn in dev (then
- // a same-session reopen would re-attach to our OWN server, which we must
- // NOT kill). On termination failure we fall back to attaching, never
- // leaving the project window-less.
- let pendingServerReclaimedToast = false;
+ // Two reasons to terminate an attachable foreign server and spawn our own
+ // instead of attaching. Both are SILENT (no toast) and both fall through to
+ // the `runClean` + fresh-spawn sequence below; on termination failure both
+ // fall back to attaching, so a project is never left window-less.
+ //
+ // 1. Dev-only reclaim (`reclaimForeignServerInDev`): a dev session runs
+ // its working-tree build against a project even when a prior packaged
+ // run / CLI / another instance left a server behind. The routine
+ // restart of a rebuild is not worth a notice.
+ // 2. Packaged upgrade reconcile (`isFirstLaunchAfterUpgrade`): the first
+ // launch after an app update, where a version-mismatched server that
+ // survived the pre-install teardown is a stale build. We restart it to
+ // the app's version rather than attaching to the stale build and
+ // prompting. No toast — the "Updated to Version X" whats-new notice
+ // already tells the user the app updated.
+ //
+ // `spawnedDetachedPids` is empty under the dev utility-fork path, so the
+ // foreign guard reads as "always foreign" there — but it stays load-bearing
+ // for the packaged path (a same-session reopen re-attaches to OUR OWN
+ // server, which must NOT be reclaimed).
if (attached) {
const isForeign = this.spawnedDetachedPids.get(canonicalKey) !== attached.pid;
let reclaimed = false;
@@ -1457,6 +1488,48 @@ export class WindowManager {
);
}
}
+ // Packaged upgrade reconcile — only if the dev path didn't already handle
+ // it, and only when the survivor is a genuinely different build. Gating on
+ // a real drift (any direction) means a same-version server we'd share is
+ // left untouched, so we never needlessly bounce a project on upgrade.
+ if (!reclaimed && this.deps.isFirstLaunchAfterUpgrade?.() === true && isForeign) {
+ const selfProtocol = this.deps.selfProtocolVersion;
+ const selfRuntime = this.deps.selfRuntimeVersion;
+ if (selfProtocol !== undefined && selfRuntime !== undefined) {
+ const drift = classifyServerVersion(
+ { protocolVersion: attached.protocolVersion, runtimeVersion: attached.runtimeVersion },
+ { protocolVersion: selfProtocol, runtimeVersion: selfRuntime },
+ );
+ if (drift.relation === 'older' || drift.relation === 'newer') {
+ const term = await this.terminateServerByPid(lockDir, attached.pid);
+ if (term.ok) {
+ this.deps.log?.info(
+ {
+ event: 'desktop-upgrade-reconcile',
+ outcome: 'terminated',
+ escalated: term.escalated,
+ relation: drift.relation,
+ pid: attached.pid,
+ projectPath,
+ },
+ '[window-manager] first launch after upgrade — auto-terminated pre-upgrade server; spawning fresh own-version server',
+ );
+ reclaimed = true;
+ } else {
+ this.deps.log?.warn(
+ {
+ event: 'desktop-upgrade-reconcile',
+ outcome: term.reason,
+ relation: drift.relation,
+ pid: attached.pid,
+ projectPath,
+ },
+ '[window-manager] upgrade auto-terminate failed; attaching to the pre-upgrade server (the manual version-drift prompt still offers a restart)',
+ );
+ }
+ }
+ }
+ }
if (!reclaimed) {
return this.attachToExistingServer({
projectPath,
@@ -1475,7 +1548,6 @@ export class WindowManager {
// Reclaimed: the terminated server's (possibly stale) lock is cleared by
// the `runClean` step below before the fresh spawn — same sequence the
// user-initiated `restartAttachedServer` path relies on.
- pendingServerReclaimedToast = true;
}
if (this.deps.runClean) {
@@ -1793,20 +1865,10 @@ export class WindowManager {
});
}
- // Dev-reclaim notice. This is the SOLE delivery site: reclaim is gated to
- // `!app.isPackaged`, where the spawn always takes this utility-fork branch
- // (detached spawn is wired only in packaged builds), so the flag can only
- // ever be truthy here. Fire on `did-finish-load` so the sonner subscriber
- // is mounted, same as the restarted/onboarding toasts. `appVersion` is
- // always present, so the inform fires unconditionally.
- if (pendingServerReclaimedToast) {
- registerPendingDelivery(
- window.webContents,
- 'ok:server-reclaimed',
- { appRuntime: this.deps.appVersion },
- { event: 'did-finish-load' },
- );
- }
+ // (The dev reclaim path used to deliver a "started a fresh server" notice
+ // here; both it and the packaged upgrade reconcile now terminate + respawn
+ // silently, so no server-lifecycle toast is delivered on this dev/test-only
+ // utility-fork branch.)
// Defer OS-level window display until both first-paint AND chrome-theme
// signals arrive — `show: false` in DEFAULT_WIN_OPTS hides the native
diff --git a/packages/desktop/src/preload/index.ts b/packages/desktop/src/preload/index.ts
index 25b958f59..a796aeadf 100644
--- a/packages/desktop/src/preload/index.ts
+++ b/packages/desktop/src/preload/index.ts
@@ -45,7 +45,6 @@ import type {
OkOnboardingShowPayload,
OkPtyData,
OkPtyExit,
- OkServerReclaimedInfo,
OkServerRestartedInfo,
OkServerVersionDriftInfo,
OkShareReceivedPayload,
@@ -366,13 +365,6 @@ const bridge: OkDesktopBridge = {
return () => ipcRenderer.removeListener('ok:server-restarted', listener);
},
- onServerReclaimed(cb: (info: OkServerReclaimedInfo) => void) {
- const listener = (_event: IpcRendererEvent, info: OkServerReclaimedInfo) => cb(info);
- // biome-ignore lint/plugin/no-loosely-typed-webcontents-ipc: preload-side subscription wrapper (precedent #14)
- ipcRenderer.on('ok:server-reclaimed', listener);
- return () => ipcRenderer.removeListener('ok:server-reclaimed', listener);
- },
-
restartServer: (projectPath: string) => invoke('ok:project:restart-server', projectPath),
setThemeSource: (source: OkThemeSource) => invoke('ok:theme:set-source', { source }),
diff --git a/packages/desktop/src/shared/bridge-contract.ts b/packages/desktop/src/shared/bridge-contract.ts
index 0a6971048..e3cdfc49a 100644
--- a/packages/desktop/src/shared/bridge-contract.ts
+++ b/packages/desktop/src/shared/bridge-contract.ts
@@ -849,16 +849,6 @@ export interface OkServerRestartedInfo {
readonly appRuntime: string;
}
-/**
- * Payload for `onServerReclaimed` — fired on the freshly-spawned window after a
- * dev session auto-terminated a foreign server it found on the project's
- * contentDir and started its own in its place. `appRuntime` is the app version
- * the fresh server runs (always present — sourced from `app.getVersion()`).
- */
-export interface OkServerReclaimedInfo {
- readonly appRuntime: string;
-}
-
/**
* Result of `restartServer`. Only the failure case reaches the originating
* renderer — on success the window is recreated, so its invoke promise never
@@ -1066,16 +1056,6 @@ export interface OkDesktopBridge {
* server now matches the app.
*/
onServerRestarted(cb: (info: OkServerRestartedInfo) => void): OkUnsubscribe;
- /**
- * Subscribe to `ok:server-reclaimed` — fired on a freshly-spawned window when
- * this (dev-only) session auto-terminated a foreign server already running on
- * the project's contentDir and started its own in its place. The renderer
- * surfaces an informational notice naming the side effect: connected agents'
- * OpenKnowledge MCP connections were dropped. No user action initiated this
- * (act-then-inform), so unlike `onServerRestarted` it is not a success
- * confirmation but a disruption notice.
- */
- onServerReclaimed(cb: (info: OkServerReclaimedInfo) => void): OkUnsubscribe;
/**
* Restart the project's server to match this app's version: terminate the
* attached (not-owned) server and recreate the window against a fresh
diff --git a/packages/desktop/src/shared/ipc-events.ts b/packages/desktop/src/shared/ipc-events.ts
index fa35abb15..8f81b0d2a 100644
--- a/packages/desktop/src/shared/ipc-events.ts
+++ b/packages/desktop/src/shared/ipc-events.ts
@@ -22,7 +22,6 @@ import type {
OkMenuAction,
OkPtyData,
OkPtyExit,
- OkServerReclaimedInfo,
OkServerRestartedInfo,
OkServerVersionDriftInfo,
OkShareReceivedPayload,
@@ -259,14 +258,6 @@ export interface EventChannels {
* app. Delivered via the same `did-finish-load` path as `ok:onboarding:toast`.
*/
'ok:server-restarted': { payload: OkServerRestartedInfo };
- /**
- * Main → renderer on a freshly-spawned window after a dev session auto-
- * terminated a foreign server on the project's contentDir and started its
- * own (act-then-inform). Renderer surfaces a disruption notice naming the
- * dropped-MCP side effect. Delivered via the same `did-finish-load` path as
- * `ok:server-restarted`.
- */
- 'ok:server-reclaimed': { payload: OkServerReclaimedInfo };
/**
* Main → renderer coalesced PTY output. Main batches the utilityProcess's
diff --git a/packages/desktop/tests/main/window-manager.test.ts b/packages/desktop/tests/main/window-manager.test.ts
index 2137314fe..5be7575e6 100644
--- a/packages/desktop/tests/main/window-manager.test.ts
+++ b/packages/desktop/tests/main/window-manager.test.ts
@@ -945,7 +945,7 @@ describe('WindowManager', () => {
expect(env.windows.length).toBe(1);
});
- test('reclaimForeignServerInDev terminates a foreign server and spawns fresh via utility-fork, firing ok:server-reclaimed on did-finish-load', async () => {
+ test('reclaimForeignServerInDev terminates a foreign server and spawns fresh via utility-fork, SILENTLY (no notice)', async () => {
env.deps.reclaimForeignServerInDev = true;
let killed = false;
const killProbe = mock((_pid: number, signal: string) => {
@@ -977,23 +977,18 @@ describe('WindowManager', () => {
const w = env.windows[0];
if (!w) throw new Error('no window created');
- const reclaimSends = () =>
- (w.webContents.send as ReturnType<typeof mock>).mock.calls.filter(
- (c: unknown[]) => c[0] === 'ok:server-reclaimed',
- );
- // Must arrive on did-finish-load (sonner mounted), NOT dom-ready — a
- // regression dropping `{ event: 'did-finish-load' }` would deliver before
- // the toast subscriber mounts and silently lose the notice. Mirror the
- // drift-test ordering: dom-ready → still 0, did-finish-load → 1.
- expect(reclaimSends().length).toBe(0);
+ // The dev reclaim is a routine per-rebuild event — it must NOT pop a
+ // toast. Fire both lifecycle edges and assert no restart confirmation
+ // reaches the renderer (the "started a fresh server" notice is gone).
w.fireDomReady();
- expect(reclaimSends().length).toBe(0);
w.fireDidFinishLoad();
- expect(reclaimSends().length).toBe(1);
- expect((reclaimSends()[0] as unknown[])[1]).toEqual({ appRuntime: '9.9.9-test' });
+ const lifecycleSends = (w.webContents.send as ReturnType<typeof mock>).mock.calls.filter(
+ (c: unknown[]) => c[0] === 'ok:server-restarted',
+ );
+ expect(lifecycleSends.length).toBe(0);
});
- test('without reclaimForeignServerInDev (production default), a foreign server is attached — no termination, no reclaim notice', async () => {
+ test('without reclaimForeignServerInDev (production default), a foreign server is attached — no termination, no notice', async () => {
const killProbe = mock(() => {});
env.deps.killProbe = killProbe;
enableAttachProbe();
@@ -1006,10 +1001,183 @@ describe('WindowManager', () => {
const w = env.windows[0];
if (!w) throw new Error('no window created');
w.fireDidFinishLoad();
- const reclaimSends = (w.webContents.send as ReturnType<typeof mock>).mock.calls.filter(
- (c: unknown[]) => c[0] === 'ok:server-reclaimed',
+ const lifecycleSends = (w.webContents.send as ReturnType<typeof mock>).mock.calls.filter(
+ (c: unknown[]) => c[0] === 'ok:server-restarted',
+ );
+ expect(lifecycleSends.length).toBe(0);
+ });
+
+ test('first launch after upgrade auto-terminates a drifted survivor and respawns SILENTLY (no toast, no prompt)', async () => {
+ // Packaged path: detached spawn → attach. The attach path finds a lock
+ // from a build that outlived the update teardown; because this is the
+ // first launch after the version changed, terminate it and spawn our
+ // own version instead of attaching + prompting. No toast — the whats-new
+ // "Updated to Version X" notice already covers the upgrade.
+ env.deps.selfProtocolVersion = 1;
+ env.deps.selfRuntimeVersion = '0.8.2';
+ env.deps.isFirstLaunchAfterUpgrade = () => true;
+ let killed = false;
+ let spawned = false;
+ const survivorLock = { ...liveLock, pid: 5555, protocolVersion: 1, runtimeVersion: '0.8.0' };
+ const freshLock = {
+ ...liveLock,
+ pid: 6666,
+ port: 60000,
+ protocolVersion: 1,
+ runtimeVersion: '0.8.2',
+ };
+ const killProbe = mock((_pid: number, signal: string) => {
+ if (signal === 'SIGTERM') killed = true;
+ });
+ enableAttachProbe({
+ readServerLock: () => (spawned ? freshLock : killed ? null : survivorLock),
+ isProcessAlive: (pid) => (pid === 5555 ? !killed : true),
+ });
+ env.deps.killProbe = killProbe;
+ env.deps.spawnDetachedServer = async () => {
+ spawned = true;
+ return { pid: 6666 };
+ };
+
+ const wm = new WindowManager(env.deps);
+ const ctx = await wm.createProjectWindow({ projectPath: '/tmp/dragon' });
+
+ // Terminated the survivor and respawned our own version — not an attach.
+ expect(killProbe).toHaveBeenCalledWith(5555, 'SIGTERM');
+ expect(ctx.port).toBe(60000);
+ expect(env.windows.length).toBe(1);
+
+ const w = env.windows[0];
+ if (!w) throw new Error('no window created');
+ // Reconciled → neither the manual version-drift prompt nor a restart
+ // toast fires (the reconcile is silent).
+ w.fireDomReady();
+ expect(driftSends(w).length).toBe(0);
+ w.fireDidFinishLoad();
+ const restartedSends = (w.webContents.send as ReturnType<typeof mock>).mock.calls.filter(
+ (c: unknown[]) => c[0] === 'ok:server-restarted',
+ );
+ expect(restartedSends.length).toBe(0);
+ });
+
+ test('upgrade reconcile also fires for a NEWER survivor (any drift direction qualifies)', async () => {
+ // Trigger is "we just upgraded", not the version ordering — a survivor
+ // newer than the app (e.g. a rollback scenario) is reconciled too.
+ env.deps.selfProtocolVersion = 1;
+ env.deps.selfRuntimeVersion = '0.8.2';
+ env.deps.isFirstLaunchAfterUpgrade = () => true;
+ let killed = false;
+ let spawned = false;
+ const survivorLock = { ...liveLock, pid: 5555, protocolVersion: 1, runtimeVersion: '0.9.0' };
+ const freshLock = {
+ ...liveLock,
+ pid: 6666,
+ port: 60000,
+ protocolVersion: 1,
+ runtimeVersion: '0.8.2',
+ };
+ const killProbe = mock((_pid: number, signal: string) => {
+ if (signal === 'SIGTERM') killed = true;
+ });
+ enableAttachProbe({
+ readServerLock: () => (spawned ? freshLock : killed ? null : survivorLock),
+ isProcessAlive: (pid) => (pid === 5555 ? !killed : true),
+ });
+ env.deps.killProbe = killProbe;
+ env.deps.spawnDetachedServer = async () => {
+ spawned = true;
+ return { pid: 6666 };
+ };
+ const wm = new WindowManager(env.deps);
+ const ctx = await wm.createProjectWindow({ projectPath: '/tmp/dragon' });
+ expect(killProbe).toHaveBeenCalledWith(5555, 'SIGTERM');
+ expect(ctx.port).toBe(60000);
+ });
+
+ test('upgrade reconcile leaves a SAME-version server untouched (never needlessly bounced)', async () => {
+ // A same-version server we would share is left attached even on the first
+ // launch after an upgrade — the reconcile only fires on a real drift.
+ env.deps.selfProtocolVersion = 1;
+ env.deps.selfRuntimeVersion = '0.8.2';
+ env.deps.isFirstLaunchAfterUpgrade = () => true;
+ const killProbe = mock(() => {});
+ env.deps.killProbe = killProbe;
+ enableAttachProbe({
+ readServerLock: () => ({ ...liveLock, protocolVersion: 1, runtimeVersion: '0.8.2' }),
+ });
+ const wm = new WindowManager(env.deps);
+ const ctx = await wm.createProjectWindow({ projectPath: '/tmp/dragon' });
+ expect(ctx.ownsServer).toBe(false); // attached, not respawned
+ expect(ctx.port).toBe(59534);
+ expect(killProbe).not.toHaveBeenCalled();
+ expect(env.utilities.length).toBe(0);
+ const w = env.windows[0];
+ if (!w) throw new Error('no window created');
+ w.fireDomReady();
+ // Same version → no drift prompt either.
+ expect(driftSends(w).length).toBe(0);
+ });
+
+ test('a drifted server is left attached (manual prompt) when NOT the first launch after upgrade', async () => {
+ // Same drift as the reconcile test, but no upgrade this launch → attach +
+ // fire the manual version-drift prompt, never auto-terminate.
+ env.deps.selfProtocolVersion = 1;
+ env.deps.selfRuntimeVersion = '0.8.2';
+ // isFirstLaunchAfterUpgrade left unset (undefined).
+ const killProbe = mock(() => {});
+ env.deps.killProbe = killProbe;
+ enableAttachProbe({
+ readServerLock: () => ({ ...liveLock, protocolVersion: 1, runtimeVersion: '0.8.0' }),
+ });
+ const wm = new WindowManager(env.deps);
+ const ctx = await wm.createProjectWindow({ projectPath: '/tmp/dragon' });
+ expect(ctx.ownsServer).toBe(false);
+ expect(env.utilities.length).toBe(0);
+ expect(killProbe).not.toHaveBeenCalled();
+ const w = env.windows[0];
+ if (!w) throw new Error('no window created');
+ w.fireDomReady();
+ // The manual version-drift prompt fires; no auto-restart confirmation.
+ expect(driftSends(w).length).toBe(1);
+ w.fireDidFinishLoad();
+ const restartedSends = (w.webContents.send as ReturnType<typeof mock>).mock.calls.filter(
+ (c: unknown[]) => c[0] === 'ok:server-restarted',
+ );
+ expect(restartedSends.length).toBe(0);
+ });
+
+ test('upgrade reconcile falls back to attaching (with the manual prompt) when terminating the survivor fails', async () => {
+ // First launch after upgrade, but the survivor can't be killed (EPERM —
+ // another account owns it). Rather than leave the project window-less, we
+ // attach to the stale build; the manual version-drift prompt still offers
+ // a restart, exactly as before this feature.
+ env.deps.selfProtocolVersion = 1;
+ env.deps.selfRuntimeVersion = '0.8.2';
+ env.deps.isFirstLaunchAfterUpgrade = () => true;
+ env.deps.killProbe = mock(() => {
+ const err = new Error('operation not permitted') as NodeJS.ErrnoException;
+ err.code = 'EPERM';
+ throw err;
+ });
+ enableAttachProbe({
+ readServerLock: () => ({ ...liveLock, protocolVersion: 1, runtimeVersion: '0.8.0' }),
+ });
+ const wm = new WindowManager(env.deps);
+ const ctx = await wm.createProjectWindow({ projectPath: '/tmp/dragon' });
+ // Fell back to attaching the survivor, not a fresh spawn.
+ expect(ctx.ownsServer).toBe(false);
+ expect(ctx.port).toBe(59534);
+ expect(env.utilities.length).toBe(0);
+ const w = env.windows[0];
+ if (!w) throw new Error('no window created');
+ w.fireDomReady();
+ // The manual version-drift prompt is the fallback remedy.
+ expect(driftSends(w).length).toBe(1);
+ w.fireDidFinishLoad();
+ const restartedSends = (w.webContents.send as ReturnType<typeof mock>).mock.calls.filter(
+ (c: unknown[]) => c[0] === 'ok:server-restarted',
);
- expect(reclaimSends.length).toBe(0);
+ expect(restartedSends.length).toBe(0);
});
test('reclaim does NOT terminate a server THIS session spawned (own-pid guard)', async () => {
@@ -1061,10 +1229,10 @@ describe('WindowManager', () => {
const w = env.windows[0];
if (!w) throw new Error('no window created');
w.fireDidFinishLoad();
- const reclaimSends = (w.webContents.send as ReturnType<typeof mock>).mock.calls.filter(
- (c: unknown[]) => c[0] === 'ok:server-reclaimed',
+ const restartedSends = (w.webContents.send as ReturnType<typeof mock>).mock.calls.filter(
+ (c: unknown[]) => c[0] === 'ok:server-restarted',
);
- expect(reclaimSends.length).toBe(0);
+ expect(restartedSends.length).toBe(0);
});
test('stale lock (pid dead) falls through to spawn mode', async () => {