Skip to content

The agent that grows with you

desktop: distinguish backend connection from messaging-gateway health

Cursor Agent2801f72c2569
diff --git a/apps/desktop/src/app/shell/hooks/use-statusbar-items.tsx b/apps/desktop/src/app/shell/hooks/use-statusbar-items.tsx
index 79073ca375b..b31ae0c9686 100644
--- a/apps/desktop/src/app/shell/hooks/use-statusbar-items.tsx
+++ b/apps/desktop/src/app/shell/hooks/use-statusbar-items.tsx
@@ -30,6 +30,7 @@ import {
Terminal,
Zap
} from '@/lib/icons'
+import { statusBarGatewayHealth } from '@/lib/gateway-health-pill'
import { runtimeReadinessDisplay, type RuntimeReadinessResult } from '@/lib/runtime-readiness'
import { resolveSessionTimerSince } from '@/lib/session-timer-since'
import { cacheHitLabel, contextBarLabel, LiveDuration, tokensPerSecondLabel, usageContextLabel } from '@/lib/statusbar'
@@ -365,20 +366,28 @@ export function useStatusbarItems({
const gatewayOpen = gatewayState === 'open'
const gatewayConnecting = gatewayState === 'connecting'
- const inferenceReady = gatewayOpen && inferenceStatus?.ready === true
- const gatewayDegraded = gatewayOpen || gatewayConnecting
- const readinessDisplay = runtimeReadinessDisplay(inferenceStatus)
-
- const gatewayDetail = gatewayOpen
- ? {
- checking: copy.gatewayChecking,
- needs_setup: copy.gatewayNeedsSetup,
- ready: copy.gatewayReady,
- unavailable: copy.gatewayUnavailable
- }[readinessDisplay]
- : gatewayConnecting
- ? copy.gatewayConnecting
- : copy.gatewayOffline
+ const gatewayHealth = statusBarGatewayHealth({
+ connectionState: gatewayState,
+ copy: {
+ backend: copy.backend,
+ checking: copy.gatewayChecking,
+ connecting: copy.gatewayConnecting,
+ messagingDegraded: copy.messagingDegraded,
+ messagingStopped: copy.messagingStopped,
+ needsSetup: copy.gatewayNeedsSetup,
+ offline: copy.gatewayOffline,
+ ready: copy.gatewayReady,
+ restarting: copy.gatewayRestarting,
+ unavailable: copy.gatewayUnavailable
+ },
+ inferenceStatus,
+ messagingRunning: statusSnapshot?.gateway_running,
+ messagingState: statusSnapshot?.gateway_state,
+ platforms: statusSnapshot?.gateway_platforms,
+ restarting: gatewayRestarting
+ })
+ const inferenceReady = gatewayOpen && inferenceStatus?.ready === true && !gatewayHealth.degraded
+ const gatewayDegraded = gatewayOpen || gatewayConnecting || gatewayHealth.degraded
const gatewayClassName = inferenceReady
? undefined
@@ -502,7 +511,7 @@ export function useStatusbarItems({
},
{
className: gatewayRestarting ? undefined : gatewayClassName,
- detail: gatewayRestarting ? copy.gatewayRestarting : gatewayDetail,
+ detail: gatewayHealth.detail,
hidden: botsShowing,
icon: gatewayRestarting ? (
<GlyphSpinner ariaLabel={copy.gatewayRestarting} className="size-3" />
@@ -512,12 +521,12 @@ export function useStatusbarItems({
<AlertCircle className="size-3" />
),
id: 'gateway-health',
- label: copy.gateway,
+ label: gatewayHealth.label,
menuClassName: 'w-72',
menuContent: gatewayMenuContent,
- // Tip only when there's a real status reason — not "gateway status" restating the label.
- title: inferenceStatus?.reason || undefined,
- toggleLabel: copy.gateway,
+ // Tip only when there's a real status reason — not a restatement of the label.
+ title: gatewayHealth.title || inferenceStatus?.reason || undefined,
+ toggleLabel: copy.backend,
variant: 'menu'
},
{
@@ -650,7 +659,7 @@ export function useStatusbarItems({
guideOwnsSignIn,
gatewayMenuContent,
gatewayClassName,
- gatewayDetail,
+ gatewayHealth,
gatewayRestarting,
inferenceReady,
inferenceStatus?.reason,
diff --git a/apps/desktop/src/i18n/ar_chrome.ts b/apps/desktop/src/i18n/ar_chrome.ts
index 760bd9a4365..c321d53f13d 100644
--- a/apps/desktop/src/i18n/ar_chrome.ts
+++ b/apps/desktop/src/i18n/ar_chrome.ts
@@ -431,7 +431,10 @@ export const arChrome = {
showTerminal: 'إظهار الطرفية',
hideTerminal: 'إخفاء الطرفية',
gateway: 'البوابة',
- gatewayReady: 'البوابة جاهزة',
+ backend: 'الخلفية',
+ messagingStopped: 'الرسائل متوقفة',
+ messagingDegraded: name => `${name} متوقف`,
+ gatewayReady: 'جاهز',
gatewayNeedsSetup: 'البوابة تحتاج إعدادا',
gatewayUnavailable: 'الاستدلال غير متاح',
gatewayChecking: 'جار فحص البوابة',
diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.ts
index bed9a6c3e6d..64ed294e2a9 100644
--- a/apps/desktop/src/i18n/en.ts
+++ b/apps/desktop/src/i18n/en.ts
@@ -4684,6 +4684,9 @@ export const en: Translations = {
showTerminal: 'Show terminal',
hideTerminal: 'Hide terminal',
gateway: 'Gateway',
+ backend: 'Backend',
+ messagingStopped: 'messaging stopped',
+ messagingDegraded: name => `${name} down`,
gatewayReady: 'ready',
gatewayNeedsSetup: 'needs setup',
gatewayUnavailable: 'inference unavailable',
diff --git a/apps/desktop/src/i18n/ja.ts b/apps/desktop/src/i18n/ja.ts
index 2008ff86fc2..4b695eabe94 100644
--- a/apps/desktop/src/i18n/ja.ts
+++ b/apps/desktop/src/i18n/ja.ts
@@ -3410,6 +3410,9 @@ export const ja = defineLocale({
showTerminal: 'ターミナルを表示',
hideTerminal: 'ターミナルを非表示',
gateway: 'ゲートウェイ',
+ backend: 'バックエンド',
+ messagingStopped: 'メッセージング停止',
+ messagingDegraded: name => `${name} 停止`,
gatewayReady: '準備完了',
gatewayNeedsSetup: '設定が必要',
gatewayUnavailable: '推論を利用できません',
diff --git a/apps/desktop/src/i18n/ru.ts b/apps/desktop/src/i18n/ru.ts
index 1d4c7eed8b6..9b4fc3c793a 100644
--- a/apps/desktop/src/i18n/ru.ts
+++ b/apps/desktop/src/i18n/ru.ts
@@ -3588,6 +3588,9 @@ export const ru = defineLocale({
showTerminal: 'Показать терминал',
hideTerminal: 'Скрыть терминал',
gateway: 'Шлюз',
+ backend: 'Бэкенд',
+ messagingStopped: 'шлюз сообщений остановлен',
+ messagingDegraded: name => `${name} недоступен`,
gatewayReady: 'готов',
gatewayNeedsSetup: 'нужна настройка',
gatewayChecking: 'проверка',
diff --git a/apps/desktop/src/i18n/types.ts b/apps/desktop/src/i18n/types.ts
index 3b82ae6c84d..d2c84b1f204 100644
--- a/apps/desktop/src/i18n/types.ts
+++ b/apps/desktop/src/i18n/types.ts
@@ -3930,6 +3930,9 @@ export interface Translations {
showTerminal: string
hideTerminal: string
gateway: string
+ backend: string
+ messagingStopped: string
+ messagingDegraded: (name: string) => string
gatewayReady: string
gatewayNeedsSetup: string
gatewayUnavailable: string
diff --git a/apps/desktop/src/i18n/zh-hant_chrome.ts b/apps/desktop/src/i18n/zh-hant_chrome.ts
index 0fba77eaa90..4e5b21b83e7 100644
--- a/apps/desktop/src/i18n/zh-hant_chrome.ts
+++ b/apps/desktop/src/i18n/zh-hant_chrome.ts
@@ -348,6 +348,9 @@ export const zhHantChrome = {
showTerminal: '顯示終端機',
hideTerminal: '隱藏終端機',
gateway: '閘道',
+ backend: '後端',
+ messagingStopped: '訊息閘道已停止',
+ messagingDegraded: name => `${name} 異常`,
gatewayReady: '就緒',
gatewayNeedsSetup: '需要設定',
gatewayUnavailable: '推論不可用',
diff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.ts
index af539a1e981..8ae23133cd8 100644
--- a/apps/desktop/src/i18n/zh.ts
+++ b/apps/desktop/src/i18n/zh.ts
@@ -4378,6 +4378,9 @@ export const zh = defineLocale({
showTerminal: '显示终端',
hideTerminal: '隐藏终端',
gateway: '网关',
+ backend: '后端',
+ messagingStopped: '消息网关已停止',
+ messagingDegraded: name => `${name} 异常`,
gatewayReady: '就绪',
gatewayNeedsSetup: '需要设置',
gatewayUnavailable: '推理不可用',
diff --git a/apps/desktop/src/lib/gateway-health-pill.test.ts b/apps/desktop/src/lib/gateway-health-pill.test.ts
new file mode 100644
index 00000000000..a21bd494f8c
--- /dev/null
+++ b/apps/desktop/src/lib/gateway-health-pill.test.ts
@@ -0,0 +1,69 @@
+import { describe, expect, it } from 'vitest'
+
+import { en } from '@/i18n/en'
+
+import { statusBarGatewayHealth } from './gateway-health-pill'
+
+const copy = {
+ backend: en.shell.statusbar.backend,
+ checking: en.shell.statusbar.gatewayChecking,
+ connecting: en.shell.statusbar.gatewayConnecting,
+ messagingDegraded: en.shell.statusbar.messagingDegraded,
+ messagingStopped: en.shell.statusbar.messagingStopped,
+ needsSetup: en.shell.statusbar.gatewayNeedsSetup,
+ offline: en.shell.statusbar.gatewayOffline,
+ ready: en.shell.statusbar.gatewayReady,
+ restarting: en.shell.statusbar.gatewayRestarting,
+ unavailable: en.shell.statusbar.gatewayUnavailable
+}
+
+const inferenceReady = {
+ checksDisagree: false,
+ ready: true,
+ reason: null,
+ source: 'runtime_check' as const
+}
+
+const openReady = {
+ connectionState: 'open',
+ copy,
+ inferenceStatus: inferenceReady
+}
+
+describe('statusBarGatewayHealth', () => {
+ it('does not paint Gateway ready when the serve socket is up and messaging is down', () => {
+ const pill = statusBarGatewayHealth({
+ ...openReady,
+ messagingRunning: false,
+ messagingState: 'stopped',
+ platforms: {}
+ })
+
+ expect(`${pill.label} ${pill.detail}`).not.toBe('Gateway ready')
+ expect(pill.label).toBe(copy.backend)
+ expect(pill.detail).toBe(copy.messagingStopped)
+ expect(pill.degraded).toBe(true)
+ })
+
+ it('stays backend-ready when messaging was never configured, and names a down platform while the process is up', () => {
+ const quiet = statusBarGatewayHealth({
+ ...openReady,
+ messagingRunning: false,
+ messagingState: null,
+ platforms: {}
+ })
+
+ expect(`${quiet.label} ${quiet.detail}`).toBe(`${copy.backend} ${copy.ready}`)
+ expect(quiet.degraded).toBe(false)
+
+ const discordDown = statusBarGatewayHealth({
+ ...openReady,
+ messagingRunning: true,
+ messagingState: 'running',
+ platforms: { discord: { state: 'fatal' } }
+ })
+
+ expect(discordDown.detail).toBe(copy.messagingDegraded('discord'))
+ expect(discordDown.degraded).toBe(true)
+ })
+})
diff --git a/apps/desktop/src/lib/gateway-health-pill.ts b/apps/desktop/src/lib/gateway-health-pill.ts
new file mode 100644
index 00000000000..c753fce1fe5
--- /dev/null
+++ b/apps/desktop/src/lib/gateway-health-pill.ts
@@ -0,0 +1,117 @@
+/**
+ * Status-bar "backend health" pill. The serve/chat socket and the messaging
+ * gateway are different processes; this derivation is the one place that
+ * names them so the painted label cannot be read as "Discord is up".
+ */
+
+import { runtimeReadinessDisplay, type RuntimeReadinessResult } from '@/lib/runtime-readiness'
+
+export interface GatewayHealthPillCopy {
+ backend: string
+ checking: string
+ connecting: string
+ messagingDegraded: (name: string) => string
+ messagingStopped: string
+ needsSetup: string
+ offline: string
+ ready: string
+ restarting: string
+ unavailable: string
+}
+
+export interface GatewayHealthPlatform {
+ state: string
+}
+
+export interface GatewayHealthPillInput {
+ connectionState: string
+ copy: GatewayHealthPillCopy
+ inferenceStatus: RuntimeReadinessResult | null
+ messagingRunning?: boolean
+ messagingState?: null | string
+ platforms?: null | Record<string, GatewayHealthPlatform>
+ restarting?: boolean
+}
+
+export interface GatewayHealthPill {
+ degraded: boolean
+ detail: string
+ label: string
+ title?: string
+}
+
+const HEALTHY_PLATFORM_STATES = new Set(['connected'])
+const IGNORED_PLATFORM_STATES = new Set(['disabled', 'not_configured', 'not configured'])
+
+function platformLeaf(id: string): string {
+ const sep = id.lastIndexOf(':')
+
+ return sep >= 0 ? id.slice(sep + 1) : id
+}
+
+function unhealthyPlatformNames(platforms: GatewayHealthPillInput['platforms']): string[] {
+ return Object.entries(platforms || {})
+ .filter(([, platform]) => {
+ const state = (platform?.state || '').trim().toLowerCase()
+
+ return Boolean(state) && !HEALTHY_PLATFORM_STATES.has(state) && !IGNORED_PLATFORM_STATES.has(state)
+ })
+ .map(([id]) => platformLeaf(id))
+}
+
+function messagingWasConfigured(
+ messagingState: GatewayHealthPillInput['messagingState'],
+ platforms: GatewayHealthPillInput['platforms']
+): boolean {
+ const state = (messagingState || '').trim().toLowerCase()
+
+ if (state === 'stopped' || state === 'startup_failed') {
+ return true
+ }
+
+ return Object.keys(platforms || {}).length > 0
+}
+
+function messagingDetail(copy: GatewayHealthPillCopy, names: string[]): string {
+ return names.length > 0 ? copy.messagingDegraded(names[0]!) : copy.messagingStopped
+}
+
+function inferenceDetail(copy: GatewayHealthPillCopy, inferenceStatus: RuntimeReadinessResult | null): string {
+ return {
+ checking: copy.checking,
+ needs_setup: copy.needsSetup,
+ ready: copy.ready,
+ unavailable: copy.unavailable
+ }[runtimeReadinessDisplay(inferenceStatus)]
+}
+
+export function statusBarGatewayHealth({
+ connectionState,
+ copy,
+ inferenceStatus,
+ messagingRunning,
+ messagingState,
+ platforms,
+ restarting = false
+}: GatewayHealthPillInput): GatewayHealthPill {
+ const connectionOpen = connectionState === 'open'
+ const connectionConnecting = connectionState === 'connecting'
+ const downNames = unhealthyPlatformNames(platforms)
+ const messagingDown =
+ messagingWasConfigured(messagingState, platforms) && (messagingRunning === false || downNames.length > 0)
+
+ const connectionDetail = connectionOpen
+ ? inferenceDetail(copy, inferenceStatus)
+ : connectionConnecting
+ ? copy.connecting
+ : copy.offline
+
+ const detail = restarting ? copy.restarting : messagingDown && connectionOpen ? messagingDetail(copy, downNames) : connectionDetail
+
+ return {
+ degraded: Boolean(messagingDown && connectionOpen),
+ detail,
+ label: copy.backend,
+ title: messagingDown && connectionOpen ? messagingDetail(copy, downNames) : undefined
+ }
+}