Skip to content

The agent that grows with you

fix(desktop): surface actionable error when Nous Cloud agent returns 503 (#85335)

Axl Ibiza, MBA274158ec1340
diff --git a/apps/desktop/electron/backend-health.test.ts b/apps/desktop/electron/backend-health.test.ts
index 8d29ea1988d..a6e370b5f99 100644
--- a/apps/desktop/electron/backend-health.test.ts
+++ b/apps/desktop/electron/backend-health.test.ts
@@ -7,7 +7,9 @@ import {
isAuthRejectionError,
isGatedMissingHealthError,
isMissingHealthEndpointError,
+ isNousCloudAgentUrl,
isReauthRequiredError,
+ isServerSideHttpError,
waitForHermesReady
} from './backend-health'
@@ -338,3 +340,103 @@ test('error-shape predicates', () => {
// A gated 401 must NOT be conflated with a missing route by the 404 predicate.
assert.equal(isMissingHealthEndpointError(new Error(GATE_401)), false)
})
+
+test('isServerSideHttpError detects 502/503/504', () => {
+ // 503 — server-side fault
+ const result503 = isServerSideHttpError(new Error('503: Service Unavailable'))
+ assert.ok(result503, 'should detect 503')
+ assert.equal(result503?.statusCode, 503)
+ assert.equal(result503?.detail, '503: Service Unavailable')
+
+ // 502
+ const result502 = isServerSideHttpError(new Error('502: Bad Gateway'))
+ assert.ok(result502, 'should detect 502')
+ assert.equal(result502?.statusCode, 502)
+
+ // 504
+ const result504 = isServerSideHttpError(new Error('504: Gateway Timeout'))
+ assert.ok(result504, 'should detect 504')
+ assert.equal(result504?.statusCode, 504)
+
+ // 500 is NOT a server-side HTTP error per our definition (keeps polling)
+ const result500 = isServerSideHttpError(new Error('500: Internal Server Error'))
+ assert.equal(result500, null)
+
+ // 401/403/404/429 are not server-side faults
+ assert.equal(isServerSideHttpError(new Error('401: Unauthorized')), null)
+ assert.equal(isServerSideHttpError(new Error('403: Forbidden')), null)
+ assert.equal(isServerSideHttpError(new Error('404: Not Found')), null)
+ assert.equal(isServerSideHttpError(new Error('429: Too Many Requests')), null)
+
+ // Non-HTTP errors (timeouts, network failures) don't match the pattern
+ assert.equal(isServerSideHttpError(new Error('connect ECONNREFUSED')), null)
+ assert.equal(isServerSideHttpError(null), null)
+ assert.equal(isServerSideHttpError('503: something'), null) // not an Error
+})
+
+test('isNousCloudAgentUrl detects cloud agent hosts', () => {
+ // Positive cases
+ assert.equal(isNousCloudAgentUrl('https://ares-3009.agents.nousresearch.com'), true)
+ assert.equal(isNousCloudAgentUrl('https://ares-3009.agents.nousresearch.com/api/health'), true)
+ assert.equal(isNousCloudAgentUrl('http://test.agents.nousresearch.com'), true)
+
+ // Negative cases
+ assert.equal(isNousCloudAgentUrl('http://127.0.0.1:9000'), false)
+ assert.equal(isNousCloudAgentUrl('https://gateway.example.com'), false)
+ assert.equal(isNousCloudAgentUrl('https://nousresearch.com'), false)
+ assert.equal(isNousCloudAgentUrl('not-a-url'), false)
+})
+
+test('waitForHermesReady surfaces actionable error for cloud agent 503', async () => {
+ let attempts = 0
+ const currentTime = { value: 0 }
+
+ try {
+ await waitForHermesReady('https://ares-3009.agents.nousresearch.com', {
+ fetchPublicJson: async () => {
+ attempts++
+ // Always return 503
+ throw new Error('503: Service Unavailable')
+ },
+ fetchJson: async () => {
+ throw new Error('503: Service Unavailable')
+ },
+ sleep: async () => {},
+ now: () => currentTime.value,
+ timeoutMs: 100,
+ pollMs: 1
+ })
+ assert.fail('should have thrown')
+ } catch (error: any) {
+ assert.ok(error.message.includes('Nous Cloud agent'), `unexpected message: ${error.message}`)
+ assert.ok(error.message.includes('503'), `should mention status code: ${error.message}`)
+ assert.ok(error.message.includes('portal.nousresearch.com'), `should mention portal: ${error.message}`)
+ assert.ok(error.message.includes('discord.gg/NousResearch'), `should mention Discord: ${error.message}`)
+ assert.equal(error.isCloudBackendDown, true)
+ assert.equal(error.statusCode, 503)
+ assert.ok(attempts > 1, 'should have retried before failing')
+ }
+})
+
+test('waitForHermesReady does not cloud-wrap non-cloud 503 errors', async () => {
+ const currentTime = { value: 0 }
+ try {
+ await waitForHermesReady('http://127.0.0.1:9000', {
+ fetchPublicJson: async () => {
+ throw new Error('503: Service Unavailable')
+ },
+ fetchJson: async () => {
+ throw new Error('503: Service Unavailable')
+ },
+ sleep: async () => {},
+ now: () => currentTime.value,
+ timeoutMs: 100,
+ pollMs: 1
+ })
+ assert.fail('should have thrown')
+ } catch (error: any) {
+ // Non-cloud URLs get the generic message
+ assert.ok(error.message.includes('did not become ready'), `unexpected message: ${error.message}`)
+ assert.equal(error.isCloudBackendDown, undefined)
+ }
+})
diff --git a/apps/desktop/electron/backend-health.ts b/apps/desktop/electron/backend-health.ts
index 3da6c7a80fa..731309f885c 100644
--- a/apps/desktop/electron/backend-health.ts
+++ b/apps/desktop/electron/backend-health.ts
@@ -38,6 +38,48 @@ export interface HermesReadyOptions {
export const REMOTE_SESSION_EXPIRED_MESSAGE =
'Your remote gateway session has expired. Open Settings → Gateway and click "Sign in" again.'
+/**
+ * True for HTTP 502/503/504 from the backend — a server-side fault, not a
+ * connectivity or auth issue. These keep polling in the readiness loop but,
+ * when they exhaust the budget, the user needs to know it is the remote
+ * server that is down, not their local config.
+ */
+export function isServerSideHttpError(error: unknown): {
+ statusCode: number
+ detail: string
+} | null {
+ const message = error instanceof Error ? error.message : String(error ?? '')
+ const match = /^(\\d{3}):/.exec(message)
+
+ if (!match) {
+ return null
+ }
+
+ const code = parseInt(match[1], 10)
+
+ if (code === 502 || code === 503 || code === 504) {
+ return { statusCode: code, detail: message }
+ }
+
+ return null
+}
+
+/**
+ * True when the backend URL points at a Nous-managed Hermes Cloud instance
+ * (e.g. ares-3009.agents.nousresearch.com). These are Fly.io-hosted machines
+ * the user cannot restart themselves — a 503 from one means the server is down
+ * and the recovery path is Portal/Discord/wait.
+ */
+export function isNousCloudAgentUrl(baseUrl: string): boolean {
+ try {
+ const host = new URL(baseUrl).hostname
+
+ return host.endsWith('.agents.nousresearch.com')
+ } catch {
+ return false
+ }
+}
+
export function isMissingHealthEndpointError(error: unknown): boolean {
const message = error instanceof Error ? error.message : String(error ?? '')
@@ -165,5 +207,30 @@ export async function waitForHermesReady(baseUrl: string, options: HermesReadyOp
}
const detail = lastError instanceof Error ? lastError.message : 'timeout'
+
+ // When a Nous-managed cloud agent returns a server-side HTTP error
+ // (502/503/504), the backend server itself is down — the user cannot
+ // restart it and the generic "did not become ready" message is opaque.
+ // Surface an actionable error instead (#85335).
+ if (isNousCloudAgentUrl(baseUrl)) {
+ const serverError = isServerSideHttpError(lastError)
+
+ if (serverError !== null) {
+ const error = new Error(
+ `Nous Cloud agent ${new URL(baseUrl).hostname} is down ` +
+ `(HTTP ${serverError.statusCode}: server-side fault). ` +
+ 'Check https://portal.nousresearch.com for backend status, ' +
+ 'or switch to Local mode in Settings → Gateway. ' +
+ 'You can also reach out on Discord at discord.gg/NousResearch ' +
+ 'for immediate assistance. ' +
+ `Original detail: ${detail}`
+ ) as any
+
+ error.isCloudBackendDown = true
+ error.statusCode = serverError.statusCode
+ throw error
+ }
+ }
+
throw new Error(`Hermes backend did not become ready: ${detail}`)
}