Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

fix(desktop): stop an installed release before Windows setup replaces it

claude-opus-5-5-mediumd58bcd324ebd
diff --git a/apps/desktop/AGENTS.md b/apps/desktop/AGENTS.md
index 63122781..3b8393e2 100644
--- a/apps/desktop/AGENTS.md
+++ b/apps/desktop/AGENTS.md
@@ -232,6 +232,17 @@ Gateway and runs Agents. The daemon exits with the app.
left alone and it gives up after about two minutes. It keeps
`%APPDATA%\Linger` and the Linger home with all their data and asks nothing;
a later install starts the services again (resume, or setup's Install).
+ Setup over an installed release stops it the same way before it replaces
+ the files, since the services run on `Linger.exe` and hold it open. Each
+ install writes `resources\stops-services`; a release without it would start
+ on `--quit` and has no `--stop`, so setup skips `--quit` (CloseLinger asks
+ the person to quit a running app) and runs its own `installer.js`, copied to
+ the plugins folder, on the old `Linger.exe`. Retry in that prompt runs the
+ stop again. Nothing running: the stop finds nothing and setup goes on. The
+ localmodels tool's foundations controller (`foundations run`, which
+ `foundations ensure` starts detached on Windows) keeps running: the tool has
+ no command to stop it, and Linger does not end the tool's processes itself.
+ The tool refuses the chat stack on Windows, so no engine runs there.
- `src/main/legacy-migration.ts`: on start, stops a bridge an older version
left running and moves its credential and the Desktop 0.16 daemon identity
into the daemon layout, so the computer keeps its id.
diff --git a/apps/desktop/packaging/win/installer.nsi b/apps/desktop/packaging/win/installer.nsi
index 58e07288..1e17e72b 100644
--- a/apps/desktop/packaging/win/installer.nsi
+++ b/apps/desktop/packaging/win/installer.nsi
@@ -36,7 +36,8 @@ VIAddVersionKey "LegalCopyright" "Linger"
!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "SimpChinese"
-; A running Linger holds its files open.
+; A running Linger holds its files open. Its services, run on Linger.exe, are
+; stopped again on Retry, in case it started them before it quit.
!macro CLOSE_LINGER UN
Function ${UN}CloseLinger
retry:
@@ -44,8 +45,11 @@ Function ${UN}CloseLinger
IfFileExists "$INSTDIR\Linger.exe" 0 done
Delete "$INSTDIR\Linger.exe"
IfErrors 0 done
- MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "Linger is running. Quit it from its icon in the notification area, then select Retry." IDRETRY retry
+ MessageBox MB_RETRYCANCEL|MB_ICONEXCLAMATION "Linger is running. Quit it from its icon in the notification area, then select Retry." IDRETRY again
Abort
+ again:
+ Call ${UN}StopLinger
+ Goto retry
done:
FunctionEnd
!macroend
@@ -73,47 +77,38 @@ Function RemoveLegacyInstall
done:
FunctionEnd
-Section "Linger"
- SetOutPath "$INSTDIR"
- Call CloseLinger
- Call RemoveLegacyInstall
- ; An update replaces the whole app folder.
- RMDir /r "$INSTDIR\resources"
- File /r "${STAGE}\*"
- WriteUninstaller "$INSTDIR\Uninstall Linger.exe"
- ; The app writes its notification id into this shortcut (index.ts).
- CreateShortcut "$SMPROGRAMS\Linger.lnk" "$INSTDIR\Linger.exe"
- WriteRegStr HKCU "${UNINSTALL_KEY}" "DisplayName" "Linger"
- WriteRegStr HKCU "${UNINSTALL_KEY}" "DisplayVersion" "${VERSION}"
- WriteRegStr HKCU "${UNINSTALL_KEY}" "Publisher" "Linger"
- WriteRegStr HKCU "${UNINSTALL_KEY}" "DisplayIcon" "$INSTDIR\Linger.exe"
- WriteRegStr HKCU "${UNINSTALL_KEY}" "InstallLocation" "$INSTDIR"
- WriteRegStr HKCU "${UNINSTALL_KEY}" "UninstallString" '"$INSTDIR\Uninstall Linger.exe"'
- WriteRegDWORD HKCU "${UNINSTALL_KEY}" "NoModify" 1
- WriteRegDWORD HKCU "${UNINSTALL_KEY}" "NoRepair" 1
-SectionEnd
-
-; Uninstalling stops what Linger runs, so nothing keeps running or holds a
-; file: a running Linger quits (index.ts), then the bundled installer, run by
-; the app's own Node, stops the installation manager and the services of the
-; local installation (TeamHub, web, node-services, LiveKit, PostgreSQL). The
-; installer ends on its own after a time limit; the uninstall goes on whatever
-; it reports. Data stays and a new install starts the services again.
+; Uninstalling, and installing over an earlier release, stops what Linger
+; runs, so nothing keeps running or holds a file (the services run on
+; Linger.exe as their Node): a running Linger quits (index.ts), then an
+; installer script, run by the app's own Node, stops the installation manager
+; and the services of the local installation (TeamHub, web, node-services,
+; LiveKit, PostgreSQL). The script ends on its own after a time limit; setup
+; goes on whatever it reports. Data stays and Linger starts the services again.
!define INSTALLER_SCRIPT "$INSTDIR\resources\app\dist\installer\installer.js"
-Function un.StopLinger
+; Written by every install since --quit and --stop: an earlier Linger.exe
+; starts on --quit instead of quitting, and its script has no --stop.
+!define STOP_MARKER "$INSTDIR\resources\stops-services"
+; $R0 is the installer script that stops the services.
+!macro STOP_LINGER UN
+Function ${UN}StopLinger
IfFileExists "$INSTDIR\Linger.exe" 0 done
+ IfFileExists "${STOP_MARKER}" 0 stop
; Without a running Linger this exits at once.
ExecWait '"$INSTDIR\Linger.exe" --quit'
- IfFileExists "${INSTALLER_SCRIPT}" 0 closing
+ stop:
+ IfFileExists "$R0" 0 stopped
DetailPrint "Stopping Linger on this computer..."
System::Call 'Kernel32::SetEnvironmentVariable(t "ELECTRON_RUN_AS_NODE", t "1")'
- nsExec::ExecToLog '"$INSTDIR\Linger.exe" "${INSTALLER_SCRIPT}" --instance desktop --stop'
+ nsExec::ExecToLog '"$INSTDIR\Linger.exe" "$R0" --instance desktop --stop'
Pop $0
System::Call 'Kernel32::SetEnvironmentVariable(t "ELECTRON_RUN_AS_NODE", n)'
- StrCmp $0 "0" closing
+ StrCmp $0 "0" stopped
DetailPrint "Some of Linger's services may still be running."
- closing:
- ; The app takes a moment to quit; un.CloseLinger asks after that.
+ stopped:
+ ; Only a release that was asked to quit is waited for; a running earlier
+ ; one never exits on its own and CloseLinger asks at once.
+ IfFileExists "${STOP_MARKER}" 0 done
+ ; The app takes a moment to quit; CloseLinger asks after that.
StrCpy $1 0
wait:
ClearErrors
@@ -125,10 +120,52 @@ Function un.StopLinger
Goto wait
done:
FunctionEnd
+!macroend
+!insertmacro STOP_LINGER ""
+!insertmacro STOP_LINGER "un."
+
+; An earlier release that cannot stop its services is stopped by this
+; release's script, run by that release's Linger.exe. A running app of such a
+; release is left to CloseLinger.
+Function StopEarlierLinger
+ IfFileExists "$INSTDIR\Linger.exe" 0 done
+ StrCpy $R0 "${INSTALLER_SCRIPT}"
+ IfFileExists "${STOP_MARKER}" stop
+ InitPluginsDir
+ File "/oname=$PLUGINSDIR\stop.mjs" "${STAGE}\resources\app\dist\installer\installer.js"
+ StrCpy $R0 "$PLUGINSDIR\stop.mjs"
+ stop:
+ Call StopLinger
+ done:
+FunctionEnd
+
+Section "Linger"
+ SetOutPath "$INSTDIR"
+ Call StopEarlierLinger
+ Call CloseLinger
+ Call RemoveLegacyInstall
+ ; An update replaces the whole app folder.
+ RMDir /r "$INSTDIR\resources"
+ File /r "${STAGE}\*"
+ FileOpen $0 "${STOP_MARKER}" w
+ FileClose $0
+ WriteUninstaller "$INSTDIR\Uninstall Linger.exe"
+ ; The app writes its notification id into this shortcut (index.ts).
+ CreateShortcut "$SMPROGRAMS\Linger.lnk" "$INSTDIR\Linger.exe"
+ WriteRegStr HKCU "${UNINSTALL_KEY}" "DisplayName" "Linger"
+ WriteRegStr HKCU "${UNINSTALL_KEY}" "DisplayVersion" "${VERSION}"
+ WriteRegStr HKCU "${UNINSTALL_KEY}" "Publisher" "Linger"
+ WriteRegStr HKCU "${UNINSTALL_KEY}" "DisplayIcon" "$INSTDIR\Linger.exe"
+ WriteRegStr HKCU "${UNINSTALL_KEY}" "InstallLocation" "$INSTDIR"
+ WriteRegStr HKCU "${UNINSTALL_KEY}" "UninstallString" '"$INSTDIR\Uninstall Linger.exe"'
+ WriteRegDWORD HKCU "${UNINSTALL_KEY}" "NoModify" 1
+ WriteRegDWORD HKCU "${UNINSTALL_KEY}" "NoRepair" 1
+SectionEnd
Section "Uninstall"
; Settings, sign-in and logs stay in %APPDATA%\Linger, and the local
; installation (%USERPROFILE%\.simplexai) with its data.
+ StrCpy $R0 "${INSTALLER_SCRIPT}"
Call un.StopLinger
Call un.CloseLinger
Delete "$SMPROGRAMS\Linger.lnk"
diff --git a/apps/desktop/src/main/windows-installer.test.ts b/apps/desktop/src/main/windows-installer.test.ts
new file mode 100644
index 00000000..f259b7e1
--- /dev/null
+++ b/apps/desktop/src/main/windows-installer.test.ts
@@ -0,0 +1,94 @@
+import { readFileSync } from "node:fs";
+import path from "node:path";
+import { fileURLToPath } from "node:url";
+
+import { expect, it } from "vitest";
+
+// makensis runs only in the Windows packaging; these check how its script
+// stops Linger before files are replaced or removed.
+const script = readFileSync(
+ path.join(
+ path.dirname(fileURLToPath(import.meta.url)),
+ "../../packaging/win/installer.nsi",
+ ),
+ "utf8",
+);
+const block = (start: string, end: string) => {
+ const from = script.indexOf(start);
+ expect(from).toBeGreaterThanOrEqual(0);
+ return script.slice(from, script.indexOf(end, from));
+};
+const order = (text: string, ...steps: string[]) => {
+ const at = steps.map((step) => text.indexOf(step));
+ expect(at.every((index) => index >= 0)).toBe(true);
+ expect(at).toEqual([...at].sort((a, b) => a - b));
+};
+
+it("stops an earlier release before an install replaces its files", () => {
+ order(
+ block('Section "Linger"', "SectionEnd"),
+ "Call StopEarlierLinger",
+ "Call CloseLinger",
+ 'RMDir /r "$INSTDIR\\resources"',
+ 'File /r "${STAGE}\\*"',
+ 'FileOpen $0 "${STOP_MARKER}" w',
+ );
+});
+
+it("stops Linger before the uninstall removes it", () => {
+ order(
+ block('Section "Uninstall"', "SectionEnd"),
+ 'StrCpy $R0 "${INSTALLER_SCRIPT}"',
+ "Call un.StopLinger",
+ "Call un.CloseLinger",
+ 'RMDir /r "$INSTDIR"',
+ );
+});
+
+it("asks only a release that knows --quit to quit, then runs the stop", () => {
+ const stop = block("Function ${UN}StopLinger", "FunctionEnd");
+ order(
+ stop,
+ 'IfFileExists "${STOP_MARKER}" 0 stop',
+ "--quit",
+ "stop:",
+ "--instance desktop --stop",
+ );
+});
+
+it("waits for the app to exit only when it was asked to quit", () => {
+ const stop = block("Function ${UN}StopLinger", "FunctionEnd");
+ order(
+ stop,
+ "--instance desktop --stop",
+ "stopped:",
+ 'IfFileExists "${STOP_MARKER}" 0 done',
+ "Sleep 500",
+ "done:",
+ );
+});
+
+it("stops a release without --stop with this release's script", () => {
+ const earlier = block("Function StopEarlierLinger", "FunctionEnd");
+ order(
+ earlier,
+ 'IfFileExists "$INSTDIR\\Linger.exe" 0 done',
+ 'IfFileExists "${STOP_MARKER}" stop',
+ "${STAGE}\\resources\\app\\dist\\installer\\installer.js",
+ 'StrCpy $R0 "$PLUGINSDIR\\stop.mjs"',
+ "Call StopLinger",
+ );
+ expect(script).toContain(
+ '!define INSTALLER_SCRIPT "$INSTDIR\\resources\\app\\dist\\installer\\installer.js"',
+ );
+});
+
+it("stops the services again when Retry follows a running Linger", () => {
+ order(
+ block("Function ${UN}CloseLinger", "FunctionEnd"),
+ "IDRETRY again",
+ "again:",
+ "Call ${UN}StopLinger",
+ "Goto retry",
+ );
+});
diff --git a/apps/linger-installer/AGENTS.md b/apps/linger-installer/AGENTS.md
index 7437e723..a1a1900a 100644
--- a/apps/linger-installer/AGENTS.md
+++ b/apps/linger-installer/AGENTS.md
@@ -21,10 +21,11 @@ after a reboot and reads the outcome from the single JSON line on stdout. It
also restarts running services when the instance's `user.env` no longer
matches the configuration they started with.
-`--stop` (with `--instance`) is the desktop uninstall's: it stops the
+`--stop` (with `--instance`) is the desktop uninstall's and Windows setup's: it stops the
manager the desktop started for that instance (its `/api/stop` cancels a
running job) and the instance's services, deletes nothing, and prints one
-JSON line with what failed.
+JSON line with what failed. It needs nothing beside `installer.js`, so
+setup can run it from a copy on an earlier release's `Linger.exe`.
Every other mode first converts an install from before the rename to Linger
(`migrateLegacyInstallation`); `--migrate` does only that and exits, for the