Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix(ui): restart MCP servers when the update install fails

thinhlpgc38ffc7c84f4
diff --git a/web-app/src/services/updater/__tests__/tauri.test.ts b/web-app/src/services/updater/__tests__/tauri.test.ts
index 5299b344d..f55af1641 100644
--- a/web-app/src/services/updater/__tests__/tauri.test.ts
+++ b/web-app/src/services/updater/__tests__/tauri.test.ts
@@ -272,6 +272,42 @@ describe('TauriUpdaterService', () => {
errorSpy.mockRestore()
})
+ it('restarts the MCP servers when the installer fails after the shutdown', async () => {
+ const err = new Error('install failed')
+ vi.mocked(invoke).mockResolvedValue(undefined)
+ vi.mocked(check).mockResolvedValueOnce({
+ version: '2.0.0',
+ download: vi.fn().mockResolvedValue(undefined),
+ install: vi.fn().mockRejectedValue(err),
+ } as unknown as Update)
+ const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
+
+ await expect(svc.downloadAndInstallWithProgress(vi.fn())).rejects.toBe(err)
+ expect(vi.mocked(invoke).mock.calls.map(([command]) => command)).toEqual([
+ 'shutdown_for_update',
+ 'restart_mcp_servers',
+ ])
+ errorSpy.mockRestore()
+ })
+
+ it('reports the install error when restarting the MCP servers fails too', async () => {
+ const err = new Error('install failed')
+ vi.mocked(invoke).mockImplementation(async (command: string) => {
+ if (command === 'restart_mcp_servers') throw new Error('restart failed')
+ })
+ vi.mocked(check).mockResolvedValueOnce({
+ version: '2.0.0',
+ download: vi.fn().mockResolvedValue(undefined),
+ install: vi.fn().mockRejectedValue(err),
+ } as unknown as Update)
+ const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
+ const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})
+
+ await expect(svc.downloadAndInstallWithProgress(vi.fn())).rejects.toBe(err)
+ errorSpy.mockRestore()
+ warnSpy.mockRestore()
+ })
+
it('handles errors in progress callback gracefully', async () => {
const download = vi.fn().mockImplementation(async (cb) => {
cb({ event: 'Started' })
diff --git a/web-app/src/services/updater/tauri.ts b/web-app/src/services/updater/tauri.ts
index a6be11acb..7c94ac712 100644
--- a/web-app/src/services/updater/tauri.ts
+++ b/web-app/src/services/updater/tauri.ts
@@ -162,7 +162,17 @@ export class TauriUpdaterService extends DefaultUpdaterService {
}
})
await invoke('shutdown_for_update')
- await update.install()
+ try {
+ await update.install()
+ } catch (installError) {
+ // The app is still running, so bring back what `shutdown_for_update`
+ // stopped. The engine restarts on the next model load, MCP servers do
+ // not, and a failed restart must not hide the install error.
+ await invoke('restart_mcp_servers').catch((restartError) => {
+ console.warn('Could not restart MCP servers after a failed install:', restartError)
+ })
+ throw installError
+ }
} catch (error) {
console.error('Error downloading update with progress in Tauri:', error)
throw error