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
Keep forgotten hosts forgotten; reset reachability on host removal
raullopez-sandboxa723253848d0
diff --git a/console/apps/switch-console-desktop/src/main/core/remote-hosts/controller.ts b/console/apps/switch-console-desktop/src/main/core/remote-hosts/controller.tsindex eb91ce6e9..f36c79cba 100644--- a/console/apps/switch-console-desktop/src/main/core/remote-hosts/controller.ts+++ b/console/apps/switch-console-desktop/src/main/core/remote-hosts/controller.ts@@ -93,6 +93,7 @@ export const remoteHostsController = createRPCController({await hostControllerService.forgetHost(sshHost);await removeRemoteHost(sshHost);await discardSetupPlan(sshHost);+ await hostReachabilityService.reset(sshHost);await releaseHostIfUnused(sshHost);evictRemoteDependencyManager(sshHost);} catch (error) {diff --git a/console/apps/switch-console-desktop/src/main/core/remote-hosts/host-reachability-service.test.ts b/console/apps/switch-console-desktop/src/main/core/remote-hosts/host-reachability-service.test.tsindex b3dc96991..ec0f4e8c1 100644--- a/console/apps/switch-console-desktop/src/main/core/remote-hosts/host-reachability-service.test.ts+++ b/console/apps/switch-console-desktop/src/main/core/remote-hosts/host-reachability-service.test.ts@@ -240,4 +240,54 @@ describe('HostReachabilityService', () => {expect(timers).toHaveLength(0);expect(svc.getAll()).toEqual([]);});++ it('lets a save already in flight land before forget deletes the row', async () => {+ const order: string[] = [];+ let land!: () => void;+ vi.mocked(savePersistedReachability).mockImplementationOnce(+ () => new Promise<void>((resolve) => (land = () => (order.push('save'), resolve())))+ );+ vi.mocked(deletePersistedReachability).mockImplementationOnce(async () => {+ order.push('delete');+ });+ const { service: svc } = makeService(async () => {});++ svc.reportFailure('example-gone', new Error('Connection lost before handshake'));+ const forgetting = svc.forget('example-gone');+ await settle();+ land();+ await forgetting;++ expect(order).toEqual(['save', 'delete']);+ });++ it('does not resurrect a forgotten host on a later failure or read', async () => {+ const { service: svc, timers } = makeService(async () => {});++ await svc.forget('example-gone');+ expect(svc.isBlocked('example-gone')).toBe(false);+ svc.reportFailure('example-gone', new Error('Connection lost before handshake'));+ await settle();++ expect(savePersistedReachability).not.toHaveBeenCalled();+ expect(timers).toHaveLength(0);+ expect(svc.getAll()).toEqual([]);++ await svc.checkNow('example-gone');+ expect(svc.getAll().map((r) => r.sshHost)).toEqual(['example-gone']);+ });++ it('resets a suspended host to unknown and deletes its saved record', async () => {+ const { service: svc, published } = makeService(async () => {+ throw new AuthError('All configured authentication methods failed');+ });+ await svc.checkNow('example-host');+ expect(svc.get('example-host').status).toBe('suspended');++ await svc.reset('example-host');++ expect(deletePersistedReachability).toHaveBeenCalledWith('example-host');+ expect(svc.get('example-host').status).toBe('unknown');+ expect(published.at(-1)?.status).toBe('unknown');+ });});diff --git a/console/apps/switch-console-desktop/src/main/core/remote-hosts/host-reachability-service.ts b/console/apps/switch-console-desktop/src/main/core/remote-hosts/host-reachability-service.tsindex 7aff8bab0..db3819905 100644--- a/console/apps/switch-console-desktop/src/main/core/remote-hosts/host-reachability-service.ts+++ b/console/apps/switch-console-desktop/src/main/core/remote-hosts/host-reachability-service.ts@@ -60,6 +60,8 @@ type HostEntry = {timer?: NodeJS.Timeout;/** In-flight probe, so concurrent callers coalesce onto one round trip. */inFlight?: Promise<HostReachability>;+ /** Saves run one after another, so the last state written is the last one set. */+ saving?: Promise<void>;};export type HostReachabilityChange = {@@ -78,6 +80,8 @@ export type HostReachabilityChange = {export class HostReachabilityService extends EventEmitter {private readonly deps: Required<HostReachabilityServiceDeps>;private readonly hosts = new Map<string, HostEntry>();+ /** Hosts released as unused: failures reported for them are not tracked until a probe or success adopts them again. */+ private readonly forgotten = new Set<string>();private loaded = false;constructor(deps: HostReachabilityServiceDeps) {@@ -151,10 +155,11 @@ export class HostReachabilityService extends EventEmitter {* never probed redundantly.*/reportSuccess(sshHost: string): void {+ this.forgotten.delete(sshHost);const entry = this.entry(sshHost);if (entry.reachability.status === 'reachable') return;this.cancelProbe(entry);- void this.transition(sshHost, {+ void this.transition(entry, sshHost, {status: 'reachable',lastError: null,consecutiveFailures: 0,@@ -172,7 +177,7 @@ export class HostReachabilityService extends EventEmitter {const status: HostReachabilityStatus = this.deps.isAuthError(error)? 'suspended': 'unreachable';- void this.transition(sshHost, {+ void this.transition(entry, sshHost, {status,lastError: message,consecutiveFailures: entry.reachability.consecutiveFailures + 1,@@ -189,6 +194,7 @@ export class HostReachabilityService extends EventEmitter {* validation and background recovery share one code path.*/async checkNow(sshHost: string): Promise<HostReachability> {+ this.forgotten.delete(sshHost);const entry = this.entry(sshHost);if (entry.inFlight) return entry.inFlight;this.cancelProbe(entry);@@ -198,7 +204,7 @@ export class HostReachabilityService extends EventEmitter {try {await this.deps.probe(sshHost);if (this.hosts.get(sshHost) !== entry) return entry.reachability;- return await this.transition(sshHost, {+ return await this.transition(entry, sshHost, {status: 'reachable',lastError: null,consecutiveFailures: 0,@@ -209,7 +215,7 @@ export class HostReachabilityService extends EventEmitter {const status: HostReachabilityStatus = this.deps.isAuthError(error)? 'suspended': 'unreachable';- const next = await this.transition(sshHost, {+ const next = await this.transition(entry, sshHost, {status,lastError: message,consecutiveFailures: entry.reachability.consecutiveFailures + 1,@@ -239,10 +245,11 @@ export class HostReachabilityService extends EventEmitter {return;}if (event.type === 'reconnect-failed') {- void this.transition(sshHost, {+ const entry = this.entry(sshHost);+ void this.transition(entry, sshHost, {status: 'suspended',- lastError: this.get(sshHost).lastError ?? 'SSH authentication failed',- consecutiveFailures: this.get(sshHost).consecutiveFailures + 1,+ lastError: entry.reachability.lastError ?? 'SSH authentication failed',+ consecutiveFailures: entry.reachability.consecutiveFailures + 1,});return;}@@ -259,14 +266,28 @@ export class HostReachabilityService extends EventEmitter {}/**- * Stop tracking a host nothing uses any more: cancel its probe and delete its- * persisted record. A probe already in flight settles without saving it back.+ * Drop a host's state back to unknown: cancel its probe and delete its+ * persisted record once any save already in flight has landed. A probe still+ * in flight settles without saving it back.*/- async forget(sshHost: string): Promise<void> {+ async reset(sshHost: string): Promise<void> {const entry = this.hosts.get(sshHost);- if (entry) this.cancelProbe(entry);this.hosts.delete(sshHost);+ if (entry) {+ this.cancelProbe(entry);+ await entry.saving;+ }await deletePersistedReachability(sshHost);+ this.deps.publish(unknownHostReachability(sshHost));+ }++ /**+ * Stop tracking a host nothing uses any more. Until a probe or a success+ * adopts it again, failures reported for it neither save nor schedule probes.+ */+ async forget(sshHost: string): Promise<void> {+ this.forgotten.add(sshHost);+ await this.reset(sshHost);}/** Stop all timers (app shutdown / tests). */@@ -278,7 +299,7 @@ export class HostReachabilityService extends EventEmitter {let entry = this.hosts.get(sshHost);if (!entry) {entry = { reachability: unknownHostReachability(sshHost) };- this.hosts.set(sshHost, entry);+ if (!this.forgotten.has(sshHost)) this.hosts.set(sshHost, entry);}return entry;}@@ -291,10 +312,10 @@ export class HostReachabilityService extends EventEmitter {}private async transition(+ entry: HostEntry,sshHost: string,patch: Pick<HostReachability, 'status' | 'lastError' | 'consecutiveFailures'>): Promise<HostReachability> {- const entry = this.entry(sshHost);const previous = entry.reachability.status;const checkedAt = new Date(this.deps.now()).toISOString();@@ -308,6 +329,7 @@ export class HostReachabilityService extends EventEmitter {nextProbeAt: patch.status === 'reachable' ? null : entry.reachability.nextProbeAt,};entry.reachability = next;+ if (this.hosts.get(sshHost) !== entry) return next;// Log only on a status change: an unreachable host must be loud once, not// once per retry — the log spam was half of what CHOO-1682 reports.@@ -325,7 +347,9 @@ export class HostReachabilityService extends EventEmitter {this.emit('change', { previous, current: next } satisfies HostReachabilityChange);}- await this.persist(next);+ const saving = (entry.saving ?? Promise.resolve()).then(() => this.persist(next));+ entry.saving = saving;+ await saving;return next;}