Skip to content

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

[CHOO-3798] Notice Docker starting on the server page, and show a local Mattermost once it is up (#1021)

Christian McDermott05bb7a2979e4
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 88e3f38e3..5b4c52ebb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -140,6 +140,10 @@ version of their own to them without also giving them a release of their own.
an agent writing a template did not know they existed or what shape they
take. It now gives each one's fields, a sentence on what it does, and a
short example.
+- **switch-buddy no longer says the Mattermost switch waits for a server
+ restart.** Turning it on starts Mattermost straight away on a running local
+ server, but switch-buddy's instructions still said it took effect at the next
+ start, which sent people to restart the server for nothing (#1021).
- **The Teams command menu fits Teams' limit again.** Switch's own Teams app
listed thirteen commands, one more than Teams allows, once `/remove-agent`
joined it. Both Teams apps now offer the same twelve: `/remove-agent` is in,
@@ -1954,6 +1958,18 @@ version of their own to them without also giving them a release of their own.
starting Docker meanwhile left the setup skipping Mattermost until you went
back. It now checks again every few seconds, and when Console regains focus,
while Docker isn't answering.
+- **Starting Docker with the server page open now enables the Mattermost
+ switch.** The server page checked for Docker only when it opened, so Docker
+ Desktop started afterwards left the switch greyed out until you left the
+ page and came back. It now checks again the way the setup step does. A
+ running server whose Mattermost was left out or failed to start, because
+ Docker was off, shows the switch off, so turning it on brings Mattermost up
+ without a restart (#1021).
+- **A local Mattermost shows up as soon as it is ready.** When the Mattermost
+ beside a local server finished setting up, pages already open kept showing no
+ Mattermost and asked you to link an account until the server was restarted.
+ They now refresh the messaging apps and linked accounts the moment it is up
+ (#1021).
- **Agents say who can answer their questions and approvals.** The Switch
skill said a request card needed the owner's linked identity and room
membership. Its addressing policy decides, and agents now read theirs with
diff --git a/console/apps/switch-console-desktop/src/main/core/managed-switch-server/docker-detect.test.ts b/console/apps/switch-console-desktop/src/main/core/managed-switch-server/docker-detect.test.ts
new file mode 100644
index 000000000..605d7369e
--- /dev/null
+++ b/console/apps/switch-console-desktop/src/main/core/managed-switch-server/docker-detect.test.ts
@@ -0,0 +1,51 @@
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+/**
+ * Switch Console's server page asks for Docker every few seconds while it is
+ * down, so a log line per failed check would fill the log file with the same
+ * sentence for as long as the page stays open.
+ */
+
+type Callback = (error: Error | null, result?: { stdout: string; stderr: string }) => void;
+const execFile = vi.hoisted(() => vi.fn());
+const info = vi.hoisted(() => vi.fn());
+vi.mock('node:child_process', () => ({ execFile }));
+vi.mock('@main/lib/logger', () => ({ log: { info, warn: vi.fn(), error: vi.fn() } }));
+
+const { detectDocker } = await import('./docker');
+
+function daemon(state: 'down' | 'up'): void {
+ execFile.mockImplementation((_bin: string, _args: string[], _opts: unknown, done: Callback) => {
+ if (state === 'down')
+ done(new Error('Cannot connect to the Docker daemon. Is the docker daemon running?'));
+ else done(null, { stdout: '28.0.0\n', stderr: '' });
+ });
+}
+
+beforeEach(() => {
+ vi.clearAllMocks();
+});
+
+describe('detectDocker', () => {
+ it('logs Docker being down once, not on every check', async () => {
+ daemon('down');
+ for (let i = 0; i < 5; i += 1) {
+ expect(await detectDocker()).toMatchObject({ available: false, reason: 'daemon-down' });
+ }
+ expect(info).toHaveBeenCalledTimes(1);
+ });
+
+ it('logs it again when Docker goes down after it was up', async () => {
+ daemon('up');
+ expect(await detectDocker()).toEqual({ available: true, version: '28.0.0' });
+ daemon('down');
+ await detectDocker();
+ await detectDocker();
+ daemon('up');
+ await detectDocker();
+ daemon('down');
+ await detectDocker();
+
+ expect(info).toHaveBeenCalledTimes(2);
+ });
+});
diff --git a/console/apps/switch-console-desktop/src/main/core/managed-switch-server/docker.ts b/console/apps/switch-console-desktop/src/main/core/managed-switch-server/docker.ts
index 8ff9bf516..a4e4989b2 100644
--- a/console/apps/switch-console-desktop/src/main/core/managed-switch-server/docker.ts
+++ b/console/apps/switch-console-desktop/src/main/core/managed-switch-server/docker.ts
@@ -92,6 +92,19 @@ export function classifyDockerError(error: unknown): {
return { reason: 'daemon-down', detail: message };
}
+/**
+ * The last line logged about Docker being unusable. A page waiting on Docker
+ * asks every few seconds while it is down, and a line each time a failure
+ * changes says as much as a line on every check.
+ */
+let lastUnavailableLog: string | null = null;
+
+function logUnavailable(message: string, context?: Record<string, unknown>): void {
+ if (message === lastUnavailableLog) return;
+ lastUnavailableLog = message;
+ log.info(message, context);
+}
+
/**
* Detect whether Docker is usable: the CLI resolves AND the daemon answers.
* `docker version --format {{.Server.Version}}` fails (non-zero exit) when the
@@ -115,10 +128,11 @@ export async function detectDocker(): Promise<DockerAvailability> {
}
const compose = await detectCompose();
if (compose !== null) return compose;
+ lastUnavailableLog = null;
return { available: true, version };
} catch (error) {
const { reason, detail } = classifyDockerError(error);
- log.info(`local-switch-server: docker unavailable (${reason})`);
+ logUnavailable(`local-switch-server: docker unavailable (${reason})`);
return { available: false, reason, detail };
}
}
@@ -137,7 +151,7 @@ async function detectCompose(): Promise<DockerAvailability | null> {
await execFileAsync(dockerExecutable(), ['compose', 'version'], { timeout: 15_000 });
return null;
} catch (error) {
- log.info('local-switch-server: docker compose unavailable', { error: String(error) });
+ logUnavailable('local-switch-server: docker compose unavailable', { error: String(error) });
return {
available: false,
reason: 'not-installed',
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 128040bf1..2f925ca7f 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
@@ -559,7 +559,39 @@ it('turns Mattermost on for a running server without restarting it', async () =>
await service.setMattermost(false);
expect(mattermost.stop).toHaveBeenCalledWith(expect.anything(), false);
- expect(service.getStatus()).toMatchObject({ phase: 'running', mattermostState: null });
+ expect(service.getStatus()).toMatchObject({ phase: 'running', mattermostState: 'off' });
+});
+
+it('brings up a Mattermost that failed at start when it is turned on again', async () => {
+ runtime.read.mockResolvedValue('native');
+ native.start.mockResolvedValue({
+ result: started,
+ bringUpMattermost: () =>
+ Promise.reject(new Error('Mattermost needs Docker, which is not available.')),
+ });
+ const bringUp = vi.fn(async () => {});
+ native.launcher.mockResolvedValue(bringUp);
+ const service = new LocalServerService();
+ await boot(service);
+ await service.start();
+ await vi.waitFor(() => expect(service.getStatus().mattermostState).toBe('failed'));
+
+ await service.setMattermost(true);
+
+ await vi.waitFor(() => expect(service.getStatus().mattermostState).toBe('running'));
+ expect(bringUp).toHaveBeenCalledOnce();
+ expect(service.getStatus()).toMatchObject({ phase: 'running', notice: null });
+});
+
+it('says Mattermost is off when a native server starts without it', async () => {
+ runtime.read.mockResolvedValue('native');
+ native.start.mockResolvedValue({ result: started, bringUpMattermost: null });
+ const service = new LocalServerService();
+ await boot(service);
+
+ await service.start();
+
+ expect(service.getStatus()).toMatchObject({ phase: 'running', mattermostState: 'off' });
});
const exported = { dir: '/data/backups/moved', dumps: [], deployedVersion: '0.11.0' };
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 72eefcd4d..c26eecc7b 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
@@ -177,9 +177,8 @@ export class LocalServerService {
}
/**
- * Turn Mattermost on or off for a native server. Takes effect at the next
- * start; a running Mattermost is left alone until then, like any setting a
- * running server read when it started.
+ * Turn Mattermost on or off for a native server: brought up or stopped now
+ * when the server is running, and at its next start when it is not.
*/
async setMattermost(enabled: boolean): Promise<void> {
if ((await this.runtime()) !== 'native') {
@@ -195,7 +194,7 @@ export class LocalServerService {
const layout = nativeLayout(localServerDir());
this.mattermostRun++;
if (!enabled) {
- this.setStatus({ mattermostState: null, notice: null });
+ this.setStatus({ mattermostState: 'off', notice: null });
await stopMattermost(layout, false);
return;
}
@@ -538,7 +537,7 @@ export class LocalServerService {
? `Could not move this server off Docker, so it is still running on Docker: ` +
`${moveFailure} Its data is safe; Switch Console tries again at the next start.`
: result.warning,
- mattermostState: bringUpMattermost ? 'starting' : null,
+ mattermostState: bringUpMattermost ? 'starting' : ranNative ? 'off' : null,
});
if (bringUpMattermost) void this.runMattermost(bringUpMattermost);
if (updatedTo !== null) await recordLocalActivity('updated', updatedTo);
diff --git a/console/apps/switch-console-desktop/src/renderer/App.tsx b/console/apps/switch-console-desktop/src/renderer/App.tsx
index dc38bbdc5..447132eb6 100644
--- a/console/apps/switch-console-desktop/src/renderer/App.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/App.tsx
@@ -7,6 +7,7 @@ import { Workspace } from './app/workspace';
import { ConsoleLinkListener } from './features/deeplinks/console-link-listener';
import { SessionDeeplinkListener } from './features/switch-rooms/session-deeplink-listener';
import { BridgePlatformsLoader } from './features/switch-servers/bridge-platforms-loader';
+import { LocalMattermostListener } from './features/switch-servers/local-mattermost-listener';
import { TelemetryConsentGate } from './features/telemetry/TelemetryConsentGate';
import { WorkspaceLayoutContextProvider } from './lib/layout/layout-provider';
import { WorkspaceViewProvider } from './lib/layout/provider';
@@ -27,6 +28,7 @@ function AppContent() {
<SessionDeeplinkListener />
<ConsoleLinkListener />
<BridgePlatformsLoader />
+ <LocalMattermostListener />
<RightSidebarProvider>
<ThemeProvider>
<ModalRenderer />
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/AddServerModal.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/AddServerModal.tsx
index 73989ffea..eadda86c5 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/AddServerModal.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/AddServerModal.tsx
@@ -32,7 +32,7 @@ import {
urlOrigin,
} from '@shared/core/switch-servers/switch-servers';
import { ConnectionsStep } from './connections-step';
-import { recheckDocker } from './docker-recheck';
+import { DOCKER_RECHECK_MS, recheckDocker } from './docker-recheck';
import { LinkAccountsStep } from './link-accounts-step';
import { localServerStore } from './local-server-store';
import { LogTail } from './log-tail';
@@ -153,9 +153,6 @@ const CHOICE_FOR_STEP: Record<Step, AddServerChoiceName | null> = {
linkAccounts: null,
};
-/** How often the local setup step asks again for a Docker that wasn't answering. */
-const DOCKER_RECHECK_MS = 3000;
-
export const AddServerModal = observer(function AddServerModal(props: Props) {
const isEdit = props.serverId != null;
const openedAt: Step = isEdit ? 'external' : (props.mode ?? 'choose');
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/docker-recheck.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/docker-recheck.ts
index 99bea9e25..2056bc989 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/docker-recheck.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/docker-recheck.ts
@@ -1,5 +1,8 @@
type FocusTarget = Pick<EventTarget, 'addEventListener' | 'removeEventListener'>;
+/** How often a page waiting on Docker asks again for one that wasn't answering. */
+export const DOCKER_RECHECK_MS = 3000;
+
/**
* Asks for Docker again until stopped: `everyMs` after each check finishes, and
* at once when the window regains focus. A check can take seconds while Docker
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/local-mattermost-listener.test.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/local-mattermost-listener.test.ts
new file mode 100644
index 000000000..6a209f205
--- /dev/null
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/local-mattermost-listener.test.ts
@@ -0,0 +1,89 @@
+import type { QueryClient } from '@tanstack/react-query';
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+import type { LocalServerStatus } from '@shared/core/managed-switch-server/managed-switch-server';
+
+/**
+ * The Mattermost beside a native local server registers its bridge and links
+ * the admin's account after the server is already in use. Pages that were open
+ * kept showing no Mattermost, and asking to link an account, until the server
+ * was restarted.
+ */
+
+const listeners = vi.hoisted(() => [] as ((status: LocalServerStatus) => void)[]);
+const refreshRoomState = vi.hoisted(() => vi.fn(() => Promise.resolve()));
+vi.mock('@renderer/lib/ipc', () => ({
+ events: {
+ on: (_channel: unknown, listener: (status: LocalServerStatus) => void) => {
+ listeners.push(listener);
+ return () => listeners.splice(listeners.indexOf(listener), 1);
+ },
+ },
+}));
+vi.mock('@renderer/features/workspaces/workspaces-store', () => ({
+ workspacesStore: { idOnServerInScope: (serverId: string | null) => `ws-on-${serverId}` },
+}));
+vi.mock('./switch-rooms-store', () => ({ switchRoomsStore: { refreshRoomState } }));
+
+const { refreshWhenLocalMattermostIsUp } = await import('./local-mattermost-listener');
+
+const invalidateQueries = vi.fn(() => Promise.resolve());
+const queryClient = { invalidateQueries } as unknown as QueryClient;
+
+function push(mattermostState: LocalServerStatus['mattermostState']): void {
+ const status = { serverId: 'local', mattermostState } as LocalServerStatus;
+ for (const listener of listeners) listener(status);
+}
+
+beforeEach(() => {
+ vi.clearAllMocks();
+ listeners.length = 0;
+});
+
+describe('when the local Mattermost comes up', () => {
+ it("re-reads the server's messaging apps, the linked accounts and the rooms", () => {
+ const stop = refreshWhenLocalMattermostIsUp(queryClient);
+ push('starting');
+ expect(invalidateQueries).not.toHaveBeenCalled();
+
+ push('running');
+
+ expect(invalidateQueries.mock.calls).toEqual([
+ [{ queryKey: ['remote-bridges', 'ws-on-local'] }],
+ [{ queryKey: ['my-switch-identities', 'ws-on-local'] }],
+ [{ queryKey: ['owns-owner-addressed-agent', 'ws-on-local'] }],
+ ]);
+ expect(refreshRoomState).toHaveBeenCalledTimes(1);
+ stop();
+ });
+
+ it('re-reads once, not on every status pushed while it stays up', () => {
+ const stop = refreshWhenLocalMattermostIsUp(queryClient);
+ push('running');
+ push('running');
+ push('running');
+
+ expect(refreshRoomState).toHaveBeenCalledTimes(1);
+ stop();
+ });
+
+ it('re-reads again when it is turned off and back on', () => {
+ const stop = refreshWhenLocalMattermostIsUp(queryClient);
+ push('running');
+ push(null);
+ push('starting');
+ push('running');
+
+ expect(refreshRoomState).toHaveBeenCalledTimes(2);
+ stop();
+ });
+
+ it('leaves everything alone when it fails to come up', () => {
+ const stop = refreshWhenLocalMattermostIsUp(queryClient);
+ push('starting');
+ push('failed');
+
+ expect(invalidateQueries).not.toHaveBeenCalled();
+ expect(refreshRoomState).not.toHaveBeenCalled();
+ stop();
+ });
+});
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/local-mattermost-listener.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/local-mattermost-listener.tsx
new file mode 100644
index 000000000..93813e857
--- /dev/null
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/local-mattermost-listener.tsx
@@ -0,0 +1,39 @@
+import { type QueryClient, useQueryClient } from '@tanstack/react-query';
+import { useEffect } from 'react';
+import { workspacesStore } from '@renderer/features/workspaces/workspaces-store';
+import { events } from '@renderer/lib/ipc';
+import type { LocalServerStatus } from '@shared/core/managed-switch-server/managed-switch-server';
+import { localServerStatusChannel } from '@shared/events/localSwitchServerEvents';
+import { switchRoomsStore } from './switch-rooms-store';
+import { myIdentitiesQueryKey } from './use-my-identities';
+
+/**
+ * Re-read what the Mattermost beside a native local server changed, once it
+ * has come up.
+ *
+ * It comes up after the server does, then registers its bridge and links the
+ * admin's account to it by itself, on no signal Switch Console receives. A page
+ * already open would go on showing no Mattermost and asking to link an account
+ * until something remounted it, which in practice meant restarting the server.
+ * The status says when the bring-up has finished, so that is when they re-read.
+ * Exported for its test; {@link LocalMattermostListener} is its only other user.
+ */
+export function refreshWhenLocalMattermostIsUp(queryClient: QueryClient): () => void {
+ let previous: LocalServerStatus['mattermostState'] = null;
+ return events.on(localServerStatusChannel, (status) => {
+ const cameUp = status.mattermostState === 'running' && previous !== 'running';
+ previous = status.mattermostState;
+ if (!cameUp) return;
+ const workspaceId = workspacesStore.idOnServerInScope(status.serverId);
+ void queryClient.invalidateQueries({ queryKey: ['remote-bridges', workspaceId] });
+ void queryClient.invalidateQueries({ queryKey: myIdentitiesQueryKey(workspaceId) });
+ void queryClient.invalidateQueries({ queryKey: ['owns-owner-addressed-agent', workspaceId] });
+ void switchRoomsStore.refreshRoomState();
+ });
+}
+
+export function LocalMattermostListener() {
+ const queryClient = useQueryClient();
+ useEffect(() => refreshWhenLocalMattermostIsUp(queryClient), [queryClient]);
+ return null;
+}
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/local-server-mattermost-switch.test.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/local-server-mattermost-switch.test.ts
new file mode 100644
index 000000000..899f8bc14
--- /dev/null
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/local-server-mattermost-switch.test.ts
@@ -0,0 +1,86 @@
+import { describe, expect, it, vi } from 'vitest';
+import type {
+ DockerAvailability,
+ LocalServerStatus,
+} from '@shared/core/managed-switch-server/managed-switch-server';
+
+/**
+ * The server page notices Docker coming up while it is open. A running server
+ * that went without Mattermost (Docker down at start, so left out or failed to
+ * come up) has to show the switch off and free to turn on then, not on with
+ * nothing running, where the only click turns it off and getting Mattermost up
+ * takes a toggle off and on or a restart.
+ */
+
+const detectDocker = vi.hoisted(() => vi.fn<() => Promise<DockerAvailability>>());
+vi.mock('@renderer/lib/ipc', () => ({
+ rpc: { localSwitchServer: { detectDocker } },
+ events: { on: () => () => {} },
+}));
+vi.mock('@renderer/features/locations/stores/agents-store', () => ({ agentsStore: {} }));
+vi.mock('./switch-servers-store', () => ({
+ switchServersStore: { init: () => Promise.resolve() },
+}));
+
+const { LocalServerStore } = await import('./local-server-store');
+
+const DOWN: DockerAvailability = {
+ available: false,
+ reason: 'daemon-down',
+ detail: 'Docker is installed but the daemon is not running.',
+};
+const UP: DockerAvailability = { available: true, version: '28.0.0' };
+
+function status(
+ phase: LocalServerStatus['phase'],
+ mattermost: boolean | null,
+ mattermostState: LocalServerStatus['mattermostState']
+): LocalServerStatus {
+ return { phase, mattermost, mattermostState } as LocalServerStatus;
+}
+
+async function storeWith(given: LocalServerStatus, docker: DockerAvailability) {
+ const store = new LocalServerStore();
+ store.status = given;
+ detectDocker.mockResolvedValue(docker);
+ await store.checkDocker();
+ return store;
+}
+
+describe('the Mattermost switch on a running server', () => {
+ it('stays off when Docker comes up after a start that left Mattermost out', async () => {
+ const store = await storeWith(status('running', null, 'off'), DOWN);
+ expect(store.mattermost).toBe(false);
+
+ detectDocker.mockResolvedValue(UP);
+ await store.checkDocker();
+
+ expect(store.docker?.available).toBe(true);
+ expect(store.mattermost).toBe(false);
+ });
+
+ it('reads off when Mattermost was turned on but failed to come up, so a click retries', async () => {
+ const store = await storeWith(status('running', true, 'failed'), UP);
+ expect(store.mattermost).toBe(false);
+ });
+
+ it('reads on while Mattermost is up or coming up, whatever Docker last said', async () => {
+ expect((await storeWith(status('running', null, 'running'), DOWN)).mattermost).toBe(true);
+ expect((await storeWith(status('running', null, 'starting'), DOWN)).mattermost).toBe(true);
+ });
+
+ it('falls back to the setting where Console has not seen the start', async () => {
+ // Console relaunched beside a server that kept running: nothing seen yet.
+ expect((await storeWith(status('running', null, null), UP)).mattermost).toBe(true);
+ expect((await storeWith(status('running', false, null), UP)).mattermost).toBe(false);
+ });
+});
+
+describe('the Mattermost switch on a stopped server', () => {
+ it('says whether the next start runs it', async () => {
+ expect((await storeWith(status('stopped', true, null), DOWN)).mattermost).toBe(true);
+ expect((await storeWith(status('stopped', false, null), UP)).mattermost).toBe(false);
+ expect((await storeWith(status('stopped', null, null), UP)).mattermost).toBe(true);
+ expect((await storeWith(status('stopped', null, null), DOWN)).mattermost).toBe(false);
+ });
+});
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/local-server-store.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/local-server-store.ts
index 6024d7577..fd8cde0a9 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/local-server-store.ts
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/local-server-store.ts
@@ -114,8 +114,19 @@ export class LocalServerStore {
return this.runtime === 'native';
}
- /** Whether Mattermost is turned on for a native server. */
+ /**
+ * Whether Mattermost is on for a native server: for a running one, whether
+ * it is up or coming up, where that is known; otherwise whether the next
+ * start runs it. A running server going without it (left out at start, or
+ * failed to come up) reads off, so turning the switch on brings it up rather
+ * than a click on a switch already on turning it off.
+ */
get mattermost(): boolean {
+ if (this.isRunning) {
+ const state = this.mattermostState;
+ if (state === 'off' || state === 'failed') return false;
+ if (state === 'starting' || state === 'running') return true;
+ }
// Never chosen means on wherever Docker can run it.
return this.status?.mattermost ?? this.docker?.available ?? false;
}
@@ -205,7 +216,7 @@ export class LocalServerStore {
}
}
- /** Turn Mattermost on or off for a native server; applies at the next start. */
+ /** Turn Mattermost on or off for a native server; a running one applies it now. */
async setMattermost(enabled: boolean): Promise<void> {
try {
await rpc.localSwitchServer.setMattermost(enabled);
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/managed-server-view.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/managed-server-view.tsx
index 25cc7c4bc..41a304704 100644
--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/managed-server-view.tsx
+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/managed-server-view.tsx
@@ -20,6 +20,7 @@ import {
} from '@shared/core/managed-switch-server/managed-switch-server';
import { explainStartFailure } from '@shared/core/managed-switch-server/start-failure';
import type { SwitchServer } from '@shared/core/switch-servers/switch-servers';
+import { DOCKER_RECHECK_MS, recheckDocker } from './docker-recheck';
import { localServerStore } from './local-server-store';
import { LogTail } from './log-tail';
import {
@@ -159,6 +160,14 @@ const ManagedServerPage = observer(function ManagedServerPage({
}
}, [sshHost]);
+ // The Mattermost switch waits on Docker, which people often start only after
+ // opening this page to find the switch greyed out.
+ const localDockerDown = sshHost === null && localServerStore.docker?.available === false;
+ useEffect(() => {
+ if (!localDockerDown) return;
+ return recheckDocker(() => localServerStore.checkDocker(), window, DOCKER_RECHECK_MS);
+ }, [localDockerDown]);
+
const state = managedServerState(server) ?? null;
const status = sshHost ? remoteServerStore.statusFor(sshHost) : localServerStore.status;
const reason = state?.reason ?? 'stopped';
diff --git a/console/apps/switch-console-desktop/src/shared/core/managed-switch-server/managed-switch-server.ts b/console/apps/switch-console-desktop/src/shared/core/managed-switch-server/managed-switch-server.ts
index 53bc5c2e6..d37b481e9 100644
--- a/console/apps/switch-console-desktop/src/shared/core/managed-switch-server/managed-switch-server.ts
+++ b/console/apps/switch-console-desktop/src/shared/core/managed-switch-server/managed-switch-server.ts
@@ -191,9 +191,11 @@ export type LocalServerStatus = {
* available. A Docker server always runs it, so this is null there. */
mattermost: boolean | null;
/** How the Mattermost beside a native server is doing since the last start:
- * it comes up after the server does. Null when it is off, or when nothing has
- * been seen of it since Console launched. */
- mattermostState: 'starting' | 'running' | 'failed' | null;
+ * it comes up after the server does. `off` when the running server is going
+ * without it: turned off, or left out at start because Docker was not there.
+ * Null when the server is not running, or when nothing has been seen of it
+ * since Console launched. */
+ mattermostState: 'off' | 'starting' | 'running' | 'failed' | null;
/** Something the last start could not do that did not stop it (Mattermost
* skipped or failed, say), for the server page to say; else null. */
notice: string | null;
diff --git a/core/switch_core/official_templates/switch-buddy/AGENT.md b/core/switch_core/official_templates/switch-buddy/AGENT.md
index a705222bb..fbfdf1db1 100644
--- a/core/switch_core/official_templates/switch-buddy/AGENT.md
+++ b/core/switch_core/official_templates/switch-buddy/AGENT.md
@@ -243,7 +243,8 @@ you, and link them to the page that does it.
Switch Console runs (`get_my_context` says which kind it is); anyone else's
server is run by whoever set it up, so send them to that person instead. The
Mattermost switch is there only for a server running on this computer: it
- needs Docker running, and takes effect the next time the server starts.
+ needs Docker running, and starts Mattermost right away when the server is
+ running, so there is no need to restart the server for it.
- Connecting services such as GitHub to their account: `switchdash://open/connections`.
- Deleting an agent: its page, `switchdash://open/agent/<agent-id>?tab=settings`.