Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

fix(console): watch a local server set up after launch

Simon Flack67ba13c2e725
diff --git a/console/apps/switch-console-desktop/src/main/core/managed-switch-server/local-server-service.test.ts b/console/apps/switch-console-desktop/src/main/core/managed-switch-server/local-server-service.test.ts
index 0a2ca56a9..6440af876 100644
--- a/console/apps/switch-console-desktop/src/main/core/managed-switch-server/local-server-service.test.ts
+++ b/console/apps/switch-console-desktop/src/main/core/managed-switch-server/local-server-service.test.ts
@@ -856,3 +856,26 @@ it('ignores what it saw when a stop began while it looked', async () => {
expect(service.getStatus().phase).toBe('stopped');
expect(m.record).not.toHaveBeenCalledWith('crashed', expect.anything());
});
+
+it('watches a server set up after launch, on a first install', async () => {
+ vi.useFakeTimers();
+ try {
+ runtime.read.mockResolvedValue('native');
+ m.managed.mockResolvedValueOnce(null);
+ const service = new LocalServerService();
+ await boot(service);
+ expect(await service.start()).toEqual(started);
+ native.running.mockResolvedValue(true);
+
+ await vi.advanceTimersByTimeAsync(5_000);
+ expect(service.getStatus().phase).toBe('running');
+
+ native.running.mockResolvedValue(false);
+ await vi.advanceTimersByTimeAsync(5_000);
+ await vi.waitFor(() => expect(service.getStatus().phase).toBe('error'));
+ expect(service.getStatus().failedTo).toBe('run');
+ service.dispose();
+ } finally {
+ vi.useRealTimers();
+ }
+});
diff --git a/console/apps/switch-console-desktop/src/main/core/managed-switch-server/local-server-service.ts b/console/apps/switch-console-desktop/src/main/core/managed-switch-server/local-server-service.ts
index 888fffbc6..b00b8b931 100644
--- a/console/apps/switch-console-desktop/src/main/core/managed-switch-server/local-server-service.ts
+++ b/console/apps/switch-console-desktop/src/main/core/managed-switch-server/local-server-service.ts
@@ -317,7 +317,9 @@ export class LocalServerService {
* Memoised: {@link ensureReady} awaits the same reconcile, then the upgrade
* it started. */
initialize(): Promise<void> {
- this.initialization ??= this.reconcile();
+ // Watching starts whatever the boot check found: a first install has no
+ // server to find, and the one it is about to start needs watching too.
+ this.initialization ??= this.reconcile().finally(() => this.startWatching());
return this.initialization;
}
@@ -382,7 +384,6 @@ export class LocalServerService {
this.setStatus({ checked: true });
host.dispose();
}
- this.startWatching();
// Not awaited: the boot check is done once the upgrade is under way, and a
// Start click or a session joins the upgrade through `starting`.
if (upgradeNow || moveNow) void this.beginStart(false);