-
+
{props.entry.name}
- {server().http.url}
+ {ServerConnection.http(server())?.url}
diff --git a/packages/app/src/settings/servers/switcher.tsx b/packages/app/src/settings/servers/switcher.tsx
index 336d691882c..34ce29b9b79 100644
--- a/packages/app/src/settings/servers/switcher.tsx
+++ b/packages/app/src/settings/servers/switcher.tsx
@@ -4,7 +4,7 @@ import { Menu } from "@opencode/ui/menu"
import { For, Show } from "solid-js"
import { useLanguage } from "@/runtime/i18n/language"
import { useGlobal } from "@/runtime/server/runtime"
-import type { ServerHealth } from "@/runtime/server/health"
+import type { ServerHealth } from "@/runtime/server/health-machine"
import { ServerHealthIndicator } from "@/servers/registry/row"
import { ServerLabel } from "@/servers/registry/label"
import { useSettingsSurface } from "@/settings/surface"
@@ -72,11 +72,11 @@ export function SettingsServerSwitcher() {
}
function ServerDot(props: { health: ServerHealth | undefined; unreachable: boolean }) {
- const health = () => props.health ?? (props.unreachable ? { healthy: false } : undefined)
+ const health = (): ServerHealth | undefined => props.health ?? (props.unreachable ? { type: "unreachable" } : undefined)
return (
-
+
)
}
diff --git a/packages/app/src/shell/commands/session-search.tsx b/packages/app/src/shell/commands/session-search.tsx
index 2b503fc9eb3..11f4ee15281 100644
--- a/packages/app/src/shell/commands/session-search.tsx
+++ b/packages/app/src/shell/commands/session-search.tsx
@@ -3,6 +3,7 @@ import { startTransition } from "solid-js"
import { useGlobal } from "@/runtime/server/runtime"
import { useLanguage } from "@/runtime/i18n/language"
import { ServerConnection, useServers } from "@/runtime/server/registry"
+import { isServerFailed } from "@/runtime/server/health-machine"
import { useTabs } from "@/shell/tabs/tabs"
import { createKnownServerSessions, createServerSessionEntries, type CommandPaletteEntry } from "./palette"
import { CommandPaletteView } from "./dialog"
@@ -18,9 +19,7 @@ export function DialogSessionSearch(props: { archived?: boolean }) {
const tabs = useTabs()
const registry = useServers()
- const servers = registry.visible.filter(
- (conn) => global.servers.health[ServerConnection.key(conn)]?.healthy !== false,
- )
+ const servers = registry.visible.filter((conn) => !isServerFailed(global.servers.health[ServerConnection.key(conn)]))
const loaders = servers.flatMap((conn) => {
const ctx = global.serverCtx(ServerConnection.key(conn))
diff --git a/packages/app/src/shell/routes/routes.tsx b/packages/app/src/shell/routes/routes.tsx
index ea097305e59..7303f5d26e5 100644
--- a/packages/app/src/shell/routes/routes.tsx
+++ b/packages/app/src/shell/routes/routes.tsx
@@ -4,6 +4,7 @@ import { Home } from "@/home/route"
import { ServerProvider } from "@/runtime/server/current"
import { useGlobal } from "@/runtime/server/runtime"
import { ServerConnection, useServers } from "@/runtime/server/registry"
+import { isServerUnauthorized } from "@/runtime/server/health-machine"
import { SessionPanelFrame, SessionRouteFrame } from "@/session/session-frame"
import { ServerSignedOutPanel } from "@/session/server-unavailable-panel"
import { LayoutProvider } from "@/shell/state/layout"
@@ -115,7 +116,7 @@ function AppLayout(props: ParentProps) {
if (only?.type !== "http") return
- return global.servers.health[ServerConnection.key(only)]?.unauthorized ? only : undefined
+ return isServerUnauthorized(global.servers.health[ServerConnection.key(only)]) ? only : undefined
}
return (
diff --git a/packages/app/src/shell/titlebar/inbox-model.ts b/packages/app/src/shell/titlebar/inbox-model.ts
index 257c360fdd0..151a836644d 100644
--- a/packages/app/src/shell/titlebar/inbox-model.ts
+++ b/packages/app/src/shell/titlebar/inbox-model.ts
@@ -4,6 +4,7 @@ import { createStore } from "solid-js/store"
import { createEffect, createMemo, onCleanup, startTransition } from "solid-js"
import { useGlobal, type ServerCtx } from "@/runtime/server/runtime"
import { ServerConnection, useServers } from "@/runtime/server/registry"
+import { canUseServer } from "@/runtime/server/health-machine"
import { useLanguage } from "@/runtime/i18n/language"
import { projectSettingsKey, useSettings } from "@/settings/model"
import { useLayout } from "@/shell/state/layout"
@@ -239,9 +240,7 @@ export function createSessionInbox(options: { archived?: boolean } = {}) {
previous ||
(servers.hydrated() &&
connections().every((item, index) => {
- const health = global.servers.health[ServerConnection.key(item.conn)]
-
- if (health && !health.checking && !health.healthy) return true
+ if (!canUseServer(global.servers.health[ServerConnection.key(item.conn)])) return true
return !!queries[index]?.isSuccess || !!queries[index]?.isError
}) &&
diff --git a/packages/app/src/workspaces/selection/picker.test.ts b/packages/app/src/workspaces/selection/picker.test.ts
index 547d3d92924..e46b5c91cf0 100644
--- a/packages/app/src/workspaces/selection/picker.test.ts
+++ b/packages/app/src/workspaces/selection/picker.test.ts
@@ -11,9 +11,8 @@ const remote = {
type: "plugin",
key: "ssh:example",
plugin: "ssh",
- state: "ready",
- connecting: false,
- authenticationRequired: false,
+ status: { type: "ready", http: { url: "http://localhost:4096" } },
+ authenticate: () => false,
managed: true,
http: { url: "http://localhost:4096" },
} as const
diff --git a/packages/app/test-browser/plugin-server-stream.test.ts b/packages/app/test-browser/plugin-server-stream.test.ts
index 5cfb5dae8af..1526646412b 100644
--- a/packages/app/test-browser/plugin-server-stream.test.ts
+++ b/packages/app/test-browser/plugin-server-stream.test.ts
@@ -47,9 +47,10 @@ test("a plugin server's event stream follows the endpoint the plugin reports", a
type: "plugin",
key: "remote:box",
plugin: "remote",
- state: "ready",
- connecting: false,
- authenticationRequired: false,
+ get status() {
+ return { type: "ready" as const, http: http() }
+ },
+ authenticate: () => false,
managed: false,
get http() {
return http()
diff --git a/packages/app/test-browser/ssh-health.test.ts b/packages/app/test-browser/ssh-health.test.ts
index 6684c4cf509..b4c66df745c 100644
--- a/packages/app/test-browser/ssh-health.test.ts
+++ b/packages/app/test-browser/ssh-health.test.ts
@@ -1,148 +1,143 @@
import { expect, test } from "bun:test"
-import { createRoot } from "solid-js"
-import { createStore } from "solid-js/store"
-import { createServerHealth, type ServerHealth } from "../src/runtime/server/health"
+import { createRoot, createSignal } from "solid-js"
+import { createServerHealth } from "../src/runtime/server/health"
+import type { ServerProbeResult } from "../src/runtime/server/health-machine"
+import type { PluginServerStatus } from "../src/runtime/server/plugin-machine"
import { ServerConnection } from "../src/runtime/server/registry"
-test("SSH health is checked only with an active tunnel, and cancellation clears stale failures", async () => {
- const requests: ReturnType
>[] = []
+const flush = () => new Promise((resolve) => setTimeout(resolve, 0))
+
+function plugin(status: () => PluginServerStatus): ServerConnection.Plugin {
+ return {
+ type: "plugin",
+ key: "ssh:fixture",
+ plugin: "ssh",
+ managed: true,
+ http: { url: "http://127.0.0.1:0" },
+ authenticate: () => false,
+ get status() {
+ return status()
+ },
+ }
+}
+
+function probes() {
+ const requests: ReturnType>[] = []
+
+ return {
+ requests,
+ check: () => {
+ const request = Promise.withResolvers()
+ requests.push(request)
+
+ return request.promise
+ },
+ }
+}
+
+test("SSH health follows the plugin's stage and checks only an active tunnel", async () => {
+ const fake = probes()
+ const tunnel = { type: "ready", http: { url: "http://127.0.0.1:12345" } } as const
const app = createRoot((dispose) => {
- const [state, setState] = createStore<{ state: ServerConnection.Plugin["state"] }>({ state: "stopped" })
+ const [status, setStatus] = createSignal({ type: "stopped" })
+ const connection = plugin(status)
+ const health = createServerHealth(() => [connection], fake.check)
- const connection: ServerConnection.Plugin = {
- type: "plugin",
- key: "ssh:fixture",
- plugin: "ssh",
- connecting: false,
- authenticationRequired: false,
- managed: true,
- http: { url: "http://127.0.0.1:12345" },
- get state() {
- return state.state
- },
- }
-
- const health = createServerHealth(
- () => [connection],
- () => true,
- () => {
- const request = Promise.withResolvers()
- requests.push(request)
-
- return request.promise
- },
- )
-
- return { dispose, setState, health: () => health.status[ServerConnection.key(connection)] }
+ return { dispose, setStatus, health: () => health.status[ServerConnection.key(connection)] }
})
try {
- expect(app.health()).toBeUndefined()
- app.setState("state", "starting")
- app.setState("state", "auth")
- app.setState("state", "stopped")
- expect(requests).toHaveLength(0)
- expect(app.health()).toBeUndefined()
- app.setState("state", "ready")
- expect(requests).toHaveLength(1)
- expect(app.health()?.checking).toBe(true)
- app.setState("state", "auth")
- requests[0]?.resolve({ healthy: false })
- await Promise.resolve()
- expect(app.health()).toBeUndefined()
- app.setState("state", "failed")
- expect(app.health()?.healthy).toBe(false)
- app.setState("state", "auth")
- expect(app.health()).toBeUndefined()
- app.setState("state", "ready")
- requests[1]?.resolve({ healthy: false })
- await Promise.resolve()
- expect(app.health()).toEqual({ healthy: false })
+ expect(app.health()).toEqual({ type: "stopped" })
+ app.setStatus({ type: "starting" })
+ expect(app.health()).toEqual({ type: "starting" })
+ app.setStatus({ type: "auth" })
+ expect(app.health()).toEqual({ type: "auth" })
+ expect(fake.requests).toHaveLength(0)
+
+ app.setStatus(tunnel)
+ expect(fake.requests).toHaveLength(1)
+ expect(app.health()).toEqual({ type: "checking", managed: true })
+
+ // The tunnel asks for sign-in again before its probe answers: the late answer is stale.
+ app.setStatus({ type: "auth" })
+ fake.requests[0]?.resolve({ type: "unreachable" })
+ await flush()
+ expect(app.health()).toEqual({ type: "auth" })
+
+ app.setStatus({ type: "failed" })
+ expect(app.health()).toEqual({ type: "unreachable" })
+
+ app.setStatus(tunnel)
+ fake.requests[1]?.resolve({ type: "healthy", version: "2.0.0" })
+ await flush()
+ expect(app.health()).toEqual({ type: "healthy", version: "2.0.0" })
} finally {
app.dispose()
}
})
test("a late failure from the old endpoint cannot overwrite the new endpoint check", async () => {
- const requests: ReturnType>[] = []
+ const fake = probes()
const app = createRoot((dispose) => {
- const [state, setState] = createStore({ url: "http://127.0.0.1:0" })
+ const [url, setUrl] = createSignal("http://127.0.0.1:12344")
+ const connection = plugin(() => ({ type: "ready", http: { url: url() } }))
+ const health = createServerHealth(() => [connection], fake.check)
- const connection: ServerConnection.Plugin = {
- type: "plugin",
- key: "ssh:fixture",
- plugin: "ssh",
- state: "ready",
- connecting: false,
- authenticationRequired: false,
- managed: true,
- get http() {
- return { url: state.url }
- },
- }
-
- const health = createServerHealth(
- () => [connection],
- () => true,
- () => {
- const request = Promise.withResolvers()
- requests.push(request)
-
- return request.promise
- },
- )
-
- return { dispose, setState, health: () => health.status[ServerConnection.key(connection)] }
+ return { dispose, setUrl, health: () => health.status[ServerConnection.key(connection)] }
})
try {
- app.setState({ url: "http://127.0.0.1:12345" })
- requests[0]?.resolve({ healthy: false })
- await Promise.resolve()
- expect(app.health()).toEqual({ healthy: false, checking: true })
- requests[1]?.resolve({ healthy: true })
- await Promise.resolve()
- expect(app.health()).toEqual({ healthy: true })
+ app.setUrl("http://127.0.0.1:12345")
+ fake.requests[0]?.resolve({ type: "unreachable" })
+ await flush()
+ expect(app.health()).toEqual({ type: "checking", managed: true })
+ fake.requests[1]?.resolve({ type: "healthy" })
+ await flush()
+ expect(app.health()).toEqual({ type: "healthy" })
} finally {
app.dispose()
}
})
-test("retry probes again before the next poll and resolves once that round answers", async () => {
- const requests: ReturnType>[] = []
+test("retry probes again before the next poll and resolves once that probe answers", async () => {
+ const fake = probes()
const connection: ServerConnection.Http = { type: "http", http: { url: "http://127.0.0.1:12346" } }
const app = createRoot((dispose) => {
- const health = createServerHealth(
- () => [connection],
- () => true,
- () => {
- const request = Promise.withResolvers()
- requests.push(request)
-
- return request.promise
- },
- )
+ const health = createServerHealth(() => [connection], fake.check)
return { dispose, retry: health.retry, health: () => health.status[ServerConnection.key(connection)] }
})
try {
- requests[0]?.resolve({ healthy: false })
- await Promise.resolve()
- expect(app.health()?.healthy).toBe(false)
+ fake.requests[0]?.resolve({ type: "unreachable" })
+ await flush()
+ expect(app.health()).toEqual({ type: "unreachable" })
const state = { done: false }
const retried = app.retry().then(() => (state.done = true))
- expect(requests).toHaveLength(2)
- await Promise.resolve()
+ expect(fake.requests).toHaveLength(2)
+ await flush()
expect(state.done).toBe(false)
- requests[1]?.resolve({ healthy: true })
+ fake.requests[1]?.resolve({ type: "healthy" })
await retried
- expect(app.health()?.healthy).toBe(true)
+ expect(app.health()).toEqual({ type: "healthy" })
} finally {
app.dispose()
}
})
+
+test("disposal releases a retry whose probe never answers", async () => {
+ const fake = probes()
+ const connection: ServerConnection.Http = { type: "http", http: { url: "http://127.0.0.1:12347" } }
+
+ const app = createRoot((dispose) => ({ dispose, health: createServerHealth(() => [connection], fake.check) }))
+
+ const retried = app.health.retry()
+ app.dispose()
+
+ await retried
+ expect(fake.requests).toHaveLength(2)
+})
diff --git a/packages/gui-plugins/src/ssh/dialog.stories.tsx b/packages/gui-plugins/src/ssh/dialog.stories.tsx
index 27a48d83db4..abff7f3f3e9 100644
--- a/packages/gui-plugins/src/ssh/dialog.stories.tsx
+++ b/packages/gui-plugins/src/ssh/dialog.stories.tsx
@@ -245,7 +245,7 @@ function AuthenticationHome() {
recentlyClosed={[]}
selection={{ server: ServerConnection.key(server) }}
homedir="/home/user"
- serverHealth={() => ({ healthy: ssh.servers[0]?.stage === "ready" })}
+ serverHealth={() => (ssh.servers[0]?.stage === "ready" ? { type: "healthy" } : { type: "unreachable" })}
serverLabel={(server) => server.displayName ?? server.http.url}
projectsForServer={() => projects}
collapsed={() => false}