Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.
Python agent-orchestrationaiai-agentschatopsdiscordlangchainmcpmicrosoft-teamsmulti-agentopen-sourceopenaiself-hostedslack
fix(console): stop a sign-in-options hiccup from overriding a good status check
Wojciech Wojtyniakd7815f9fdfbd
diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/switch-servers-store.test.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/switch-servers-store.test.tsindex d3a5926b2..4eaa39cab 100644--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/switch-servers-store.test.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/switch-servers-store.test.ts@@ -62,13 +62,22 @@ function newStore(servers: SwitchServer[]) {return store;}-/** A promise the test resolves by hand, to hold a fetch in flight. */+/** A promise the test settles by hand, to hold a fetch in flight and control+ * exactly when — and in what order relative to another fetch — it lands. */function deferred<T>() {let resolve!: (value: T) => void;- const promise = new Promise<T>((r) => {- resolve = r;+ let reject!: (reason: unknown) => void;+ const promise = new Promise<T>((res, rej) => {+ resolve = res;+ reject = rej;});- return { promise, resolve };+ return { promise, resolve, reject };+}++/** Flushes pending timers and microtasks so an in-flight fetch's `.then`+ * chain (including its `runInAction` writes) has fully landed. */+async function flush(): Promise<void> {+ await new Promise((resolve) => setTimeout(resolve, 0));}beforeEach(() => {@@ -255,15 +264,44 @@ describe('the manual refresh button', () => {expect(store.authConfigFor('srv-a')).toEqual(updatedConfig);});+});- it('does not make the mount path re-fetch a cached config', async () => {+describe("the unreachable card's automatic retry", () => {+ it('does not re-fetch sign-in options once they are already known', async () => {+ // Before the manual-refresh fix, the auto-retry's call to refreshServer+ // would have started re-fetching sign-in options on every tick forever.+ // The retry loop exists to re-probe connectivity, not to hammer an+ // endpoint whose answer rarely changes.const store = newStore([server('srv-a')]);await store.ensureAuthConfig('srv-a');getAuthConfig.mockClear();- await store.ensureAuthConfig('srv-a');+ await store.retryConnection('srv-a');expect(getAuthConfig).not.toHaveBeenCalled();+ expect(getConnectionStatus).toHaveBeenCalledWith('srv-a');+ });+});++describe('the reachability flag under concurrent checks', () => {+ it('does not evict a reachable server over a later-landing sign-in-options failure', async () => {+ // refreshServer runs the connection check and the sign-in-options check+ // concurrently. If the connection check lands first and succeeds, a+ // sign-in-options fetch that fails afterward must not overwrite that with+ // "unreachable" — that would throw a perfectly signed-in user onto the+ // cannot-reach screen over an unrelated endpoint's hiccup.+ const store = newStore([server('srv-a')]);+ const authPending = deferred<typeof authConfig>();+ getAuthConfig.mockReturnValueOnce(authPending.promise);++ const refreshing = store.refreshServer('srv-a');+ await flush();+ expect(store.isUnreachable('srv-a')).toBe(false);++ authPending.reject(new Error('fetch failed'));+ await refreshing;++ expect(store.isUnreachable('srv-a')).toBe(false);});});diff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/switch-servers-store.ts b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/switch-servers-store.tsindex 4789fad3f..d160b5083 100644--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/switch-servers-store.ts+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/switch-servers-store.ts@@ -33,10 +33,17 @@ export class SwitchServersStore {/** Server ids with an auth-config fetch in flight, so several recovery* signals arriving at once collapse into a single request. */private readonly authConfigInFlight = new Set<string>();- /** Server ids whose last gateway read failed. The page shows a single- * "cannot reach" state for these: with the gateway down there is nothing to- * sign into, so a sign-in form would be a dead end dressed up as a choice. */- readonly unreachable = new Set<string>();+ /** Server ids whose last connection-status read failed. Authoritative for+ * page-level reachability whenever a status read has ever run for that+ * server: {@link isUnreachable} defers to this over+ * {@link authConfigUnreachable} so a hiccup on the sign-in-options endpoint+ * cannot evict a server whose status just came back fine. */+ readonly statusUnreachable = new Set<string>();+ /** Server ids whose last auth-config read failed. Only decisive before any+ * status read has ever run for that server — the mount-time window where+ * status is still unknown but a totally unreachable gateway has already+ * failed the auth-config call. */+ readonly authConfigUnreachable = new Set<string>();loadingServers = false;/** Whether the list has been read at least once. Until it has, an empty@@ -85,9 +92,16 @@ export class SwitchServersStore {return this.statuses.get(serverId)?.connected ?? false;}- /** Whether the last read of this server's gateway failed to reach it. */+ /**+ * Whether this server counts as unreachable for the page. Once a status+ * read has ever run for it, status is the sole authority — a signed-in+ * server whose sign-in-options endpoint hiccups must not lose its signed-in+ * view over that. Before status has ever answered, an auth-config failure+ * is the only signal available, so it decides instead.+ */isUnreachable(serverId: string): boolean {- return this.unreachable.has(serverId);+ if (this.statuses.has(serverId)) return this.statusUnreachable.has(serverId);+ return this.authConfigUnreachable.has(serverId);}async init(): Promise<void> {@@ -168,6 +182,17 @@ export class SwitchServersStore {await Promise.all([this.refreshStatus(serverId), this.refreshAuthConfig(serverId)]);}+ /**+ * The unreachable card's probe, on its 10-second timer and its own Retry+ * button alike. Only connectivity is worth re-checking on a fixed interval;+ * sign-in options keep the once-cached behavior of {@link ensureAuthConfig}+ * so a genuine outage does not turn into two doomed round trips forever —+ * only one, until either succeeds.+ */+ async retryConnection(serverId: string): Promise<void> {+ await Promise.all([this.refreshStatus(serverId), this.ensureAuthConfig(serverId)]);+ }+async refreshStatus(serverId: string): Promise<void> {runInAction(() => {this.refreshing.add(serverId);@@ -176,7 +201,7 @@ export class SwitchServersStore {const status = await rpc.switchServers.getConnectionStatus(serverId);runInAction(() => {this.statuses.set(serverId, status);- this.unreachable.delete(serverId);+ this.statusUnreachable.delete(serverId);});} catch (cause) {// An unreachable server is a real, displayable state — record it as@@ -187,7 +212,7 @@ export class SwitchServersStore {console.warn(`[switch-servers] could not read status for ${serverId}`, cause);runInAction(() => {this.statuses.set(serverId, { serverId, connected: false, user: null });- this.unreachable.add(serverId);+ this.statusUnreachable.add(serverId);});} finally {runInAction(() => {@@ -217,9 +242,9 @@ export class SwitchServersStore {* the manual refresh path, where the cached answer is exactly what might be* wrong (an operator turning on OIDC after Console cached password-only). A* failed refresh leaves the stale config in place rather than clearing it:- * `unreachable` is the disclosed signal that the answer might be out of- * date, so dropping the cache would only trade one indefinite state for- * another.+ * a server that is otherwise reachable keeps working on what it already+ * knew, and {@link isUnreachable} does not let this failure alone evict a+ * server whose connection status is fine (see {@link authConfigUnreachable}).*/async refreshAuthConfig(serverId: string): Promise<void> {runInAction(() => {@@ -242,7 +267,7 @@ export class SwitchServersStore {const config = await rpc.switchServers.getAuthConfig(serverId);runInAction(() => {this.authConfigs.set(serverId, config);- this.unreachable.delete(serverId);+ this.authConfigUnreachable.delete(serverId);});} catch (cause) {// Not the error banner: the raw text is our own IPC method name wrapped@@ -251,7 +276,7 @@ export class SwitchServersStore {// reached, and the detail stays in the console for us.console.warn(`[switch-servers] could not read auth config for ${serverId}`, cause);runInAction(() => {- this.unreachable.add(serverId);+ this.authConfigUnreachable.add(serverId);});} finally {runInAction(() => {@@ -359,7 +384,8 @@ export class SwitchServersStore {this.statuses.delete(serverId);this.authConfigs.delete(serverId);this.authConfigWanted.delete(serverId);- this.unreachable.delete(serverId);+ this.statusUnreachable.delete(serverId);+ this.authConfigUnreachable.delete(serverId);});// The removed id also sits in the server view's saved params, where it// outlives the record and would be read back — as a page for a serverdiff --git a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/view.tsx b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/view.tsxindex bd5715109..b50a5240d 100644--- a/console/apps/switch-console-desktop/src/renderer/features/switch-servers/view.tsx+++ b/console/apps/switch-console-desktop/src/renderer/features/switch-servers/view.tsx@@ -414,10 +414,13 @@ const ServerUnreachableCard = observer(function ServerUnreachableCard({const retrying = store.refreshing.has(serverId);// Keep probing while this is on screen. Waiting for the user to press- // something would leave a server that recovered looking down.+ // something would leave a server that recovered looking down. This only+ // re-checks connectivity, not sign-in options: those keep their once-cached+ // behavior so a real outage does not turn into two doomed round trips on+ // every tick, forever.useEffect(() => {const timer = setInterval(() => {- if (!document.hidden) void store.refreshServer(serverId);+ if (!document.hidden) void store.retryConnection(serverId);}, UNREACHABLE_RETRY_MS);return () => clearInterval(timer);}, [serverId, store]);@@ -435,7 +438,7 @@ const ServerUnreachableCard = observer(function ServerUnreachableCard({variant="outline"size="sm"disabled={retrying}- onClick={() => void store.refreshServer(serverId)}+ onClick={() => void store.retryConnection(serverId)}><RefreshCw className={retrying ? 'size-4 animate-spin' : 'size-4'} />Retry