hermes-agent/apps/desktop/electron/remote-oauth-ticket.ts
Brooklyn Nicholson 02e4118110 fix(desktop): distinguish transport failure classes in WS-ticket mint copy
The original 401-misclassification from #98647 (a rejected WS-ticket
mint reported as "Could not reach the remote Hermes gateway") was fixed
on main by #95701: the shared httpStatusError attaches err.statusCode
and gatewayTicketFailure routes 401/403 to the sign-in copy with
needsOauthLogin/isReauthRequired.

What remained live was the transport leg: resolveRemoteOauthTicket
wrapped EVERY non-auth mint failure - timeout, ERR_CONNECTION_REFUSED,
DNS failure, a reverse-proxy 502 - in one undifferentiated sentence
(remote-oauth-ticket.ts:38 passed a static transportMessage), so fleet
logs hid three different upstream causes behind identical copy
(~1,100 lines across 47 hours in the reporter's fleet, zero of which
named the actual failure).

- connection-config.ts: new exported gatewayTicketTransportMessage(error)
  names the failure class: timeout/unreachable/DNS -> "timed out or the
  host could not be resolved... check your network/VPN path";
  ECONNREFUSED -> "connection was refused... the gateway process is
  likely down"; anything else keeps the legacy one-liner.
- remote-oauth-ticket.ts: resolveRemoteOauthTicket derives its
  transportMessage from the cause instead of a static string. Auth
  classification is unchanged.

Refs #98647
2026-09-29 19:52:44 -05:00

43 lines
1.7 KiB
TypeScript

import { makeNousCloudBackendDownError } from './backend-health'
import { gatewayTicketFailure, gatewayTicketTransportMessage } from './connection-config'
import { oauthTicketFailureAuthMessage } from './native-auth-decisions'
interface RemoteOauthTicketDeps {
hasNativeSession: (baseUrl: string) => boolean
mintGatewayWsTicket: (baseUrl: string, headers: Record<string, string>) => Promise<string>
}
// Roster dials use this same mint path before readiness; the ordinary 10s
// deadline can discard a healthy OAuth source while its cold session warms.
export function rosterSourceEnumerationTimeoutMs(connection: { kind?: string; authMode?: string }): number {
return (connection.kind === 'remote' || connection.kind === 'cloud') && connection.authMode === 'oauth'
? 30_000
: 10_000
}
export async function resolveRemoteOauthTicket(
baseUrl: string,
headers: Record<string, string>,
deps: RemoteOauthTicketDeps
): Promise<string> {
// The mint is authoritative: a cold cookie partition may not yet report a
// session. Snapshot native state only for copy; a rejected mint can erase it.
const hadNativeSession = deps.hasNativeSession(baseUrl)
try {
return await deps.mintGatewayWsTicket(baseUrl, headers)
} catch (error) {
// Transport faults keep one headline ("could not reach") but the copy now
// names the actual failure class — timeout/DNS vs connection refused vs
// an HTTP fault — so fleet logs stop hiding three different upstream
// causes behind one sentence (#98647).
throw (
makeNousCloudBackendDownError(baseUrl, error) ??
gatewayTicketFailure(
error,
oauthTicketFailureAuthMessage(hadNativeSession),
gatewayTicketTransportMessage(error)
)
)
}
}