Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
thin client: render a status-only host's serve_status_only envelope
garrytan860713b526dd
diff --git a/src/cli.ts b/src/cli.tsindex de42f789e1..bb96ca7a8b 100755--- a/src/cli.ts+++ b/src/cli.ts@@ -806,7 +806,7 @@ async function runThinClientRouted(// D1: a server tool error renders its own code/fix; --json gets the one v1// envelope on stdout while transport failures keep their human text on stderr.const scopeDenied = isScopeErrorCode(e.detail?.code, e.detail?.canonical_code, e.detail?.reason);- if (e.reason === 'tool_error' && !scopeDenied) { process.off('SIGINT', onSigint); exitCliError(e, op.cliHints?.name ?? op.name); }+ if ((e.reason === 'tool_error' && !scopeDenied) || e.detail?.code === 'serve_status_only') { process.off('SIGINT', onSigint); exitCliError(e, op.cliHints?.name ?? op.name); }const failExit = params.json === true ? writeCliError(e, op.cliHints?.name ?? op.name, { stderr: false }) : 1;const url = cfg.remote_mcp!.mcp_url;switch (e.reason) {diff --git a/src/core/doctor-remote.ts b/src/core/doctor-remote.tsindex 2ec69acf6a..273b12bdbe 100644--- a/src/core/doctor-remote.ts+++ b/src/core/doctor-remote.ts@@ -20,6 +20,11 @@ import { safeCompare, driftLevel, loadPromptState } from './thin-client-upgrade-import { VERSION } from '../version.ts';import { writeJsonDocument } from './cli-force-exit.ts';+/** A status-only host's envelope on a failed check: the code, its fix and the words to relay. */+function statusOnlyDetail(env: Record<string, unknown> | undefined): Record<string, unknown> {+ return env ? { code: 'serve_status_only', fix: env.fix, user_message: env.user_message, retry_after_s: env.retry_after_s } : {};+}+export interface RemoteCheck {name: string;status: 'ok' | 'warn' | 'fail';@@ -158,7 +163,7 @@ export async function collectRemoteDoctorReport(name: 'oauth_discovery',status: 'fail',message: disco.message,- detail: { reason: disco.reason, ...(disco.status ? { status: disco.status } : {}) },+ detail: { reason: disco.reason, ...(disco.status ? { status: disco.status } : {}), ...statusOnlyDetail(disco.status_only) },});return finalize(remote, checks);}@@ -177,7 +182,7 @@ export async function collectRemoteDoctorReport(message: tokenRes.message,detail: {reason: tokenRes.reason, ...(tokenRes.status ? { status: tokenRes.status } : {}),- ...(tokenRes.retry_after_s !== undefined ? { retry_after_s: tokenRes.retry_after_s } : {}),+ ...(tokenRes.retry_after_s !== undefined ? { retry_after_s: tokenRes.retry_after_s } : {}), ...statusOnlyDetail(tokenRes.status_only),},});return finalize(remote, checks);diff --git a/src/core/mcp-client.ts b/src/core/mcp-client.tsindex 0e01bd8f8f..5cb16cee51 100644--- a/src/core/mcp-client.ts+++ b/src/core/mcp-client.ts@@ -306,7 +306,8 @@ async function getAccessToken(config: GBrainConfig, force = false, signal?: Aborthrow new RemoteMcpError(disco.reason === 'http' || disco.reason === 'parse' ? 'discovery' : 'network',`OAuth discovery failed: ${disco.message}`,- { ...(disco.status ? { status: disco.status } : {}), ...(disco.kind ? { kind: disco.kind } : {}), mcp_url: remote.mcp_url },+ { ...(disco.status ? { status: disco.status } : {}), ...(disco.kind ? { kind: disco.kind } : {}), mcp_url: remote.mcp_url,+ ...(disco.status_only ? { ...extractToolErrorDetail(JSON.stringify(disco.status_only)), retry_after_s: disco.retry_after_s } : {}) },);}@@ -321,6 +322,7 @@ async function getAccessToken(config: GBrainConfig, force = false, signal?: Abor...(tokenRes.status ? { status: tokenRes.status } : {}), ...(tokenRes.kind ? { kind: tokenRes.kind } : {}),...(tokenRes.retry_after_s !== undefined ? { retry_after_s: tokenRes.retry_after_s } : {}), mcp_url: remote.mcp_url,...(tokenRes.reason === 'rate_limited' ? rateLimitedMintDetail(tokenRes.retry_after_s) : {}),+ ...(tokenRes.status_only ? extractToolErrorDetail(JSON.stringify(tokenRes.status_only)) : {}),},);}diff --git a/src/core/remote-mcp-probe.ts b/src/core/remote-mcp-probe.tsindex f873e9cf97..fbcae6c00e 100644--- a/src/core/remote-mcp-probe.ts+++ b/src/core/remote-mcp-probe.ts@@ -24,9 +24,29 @@ type ProbeFailure<Reason extends string> = {kind?: 'timeout' | 'aborted';/** Seconds the server asked the caller to wait (Retry-After), when it said. */retry_after_s?: number;+ /** A status-only `gbrain serve --http` answered 503: its `serve_status_only` envelope. */+ status_only?: Record<string, unknown>;message: string;};+/**+ * A 503 from a status-only `gbrain serve --http` carries a `serve_status_only`+ * envelope (why, fix, user_message); any other body is not one. Consumes the+ * body only for a 503.+ */+async function statusOnlyFailure(res: Response, label: string): Promise<ProbeFailure<'http'> | null> {+ if (res.status !== 503) return null;+ let body: unknown;+ try { body = await res.json(); } catch { return null; }+ if (!body || typeof body !== 'object' || (body as { code?: unknown }).code !== 'serve_status_only') return null;+ const env = body as Record<string, unknown>;+ const retryAfter = parseRetryAfterSeconds(res.headers.get('retry-after'));+ return {+ ok: false, reason: 'http', status: 503, status_only: env, ...(retryAfter !== undefined ? { retry_after_s: retryAfter } : {}),+ message: `${label} answered 503: the gbrain server is in status-only mode. ${typeof env.why === 'string' ? env.why : ''}`.trim(),+ };+}+/** Longest Retry-After honoured; a larger value is clamped to it. */const MAX_RETRY_AFTER_S = 24 * 60 * 60;@@ -85,6 +105,8 @@ export async function discoverOAuth(try {const res = await fetch(url, { signal });if (!res.ok) {+ const statusOnly = await statusOnlyFailure(res, 'OAuth discovery');+ if (statusOnly) return statusOnly;await res.body?.cancel().catch(() => {});return { ok: false, reason: 'http', status: res.status, message: `OAuth discovery returned ${res.status} for ${url}` };}@@ -160,6 +182,8 @@ export async function mintClientCredentialsToken(};}if (!res.ok) {+ const statusOnly = await statusOnlyFailure(res, 'OAuth /token');+ if (statusOnly) return statusOnly;await res.body?.cancel().catch(() => {});return { ok: false, reason: 'http', status: res.status, message: `OAuth /token returned ${res.status}` };}