Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

readiness, doctor, mcp expose: report a status-only serve --http

garrytandd33c88adae5
diff --git a/src/commands/doctor/checks/harness-wiring.ts b/src/commands/doctor/checks/harness-wiring.ts
index df9bf903a3..42e3660136 100644
--- a/src/commands/doctor/checks/harness-wiring.ts
+++ b/src/commands/doctor/checks/harness-wiring.ts
@@ -9,14 +9,19 @@
* otherwise spawn the registered argv (15 s bound) and run initialize +
* tools/list + `recall {query:"gbrain install check", limit:1}` (an empty
* result passes). A `gbrain_status` reply (status-only serve) is reported with
- * its reason and fix. Doctor writes nothing and seeds nothing.
+ * its reason and fix. A live status-only `serve --http` (its marker under
+ * GBRAIN_HOME, answering `/health` 503 as that instance within 500 ms) is
+ * reported first as `serve_status_only` (transport http) with the status
+ * reason's fix. Doctor seeds nothing; the only file it removes is a status
+ * marker whose process is gone.
*/
import { existsSync, readFileSync } from 'node:fs';
import { homedir } from 'node:os';
import { isAbsolute, join } from 'node:path';
import { gbrainPath, loadConfig } from '../../../core/config.ts';
import { peekLock } from '../../../core/pglite-lock.ts';
-import { harnessWiringEntry, type ReadinessHarness } from '../../../core/readiness.ts';
+import { harnessWiringEntry, httpStatusServerEntry, type ReadinessHarness } from '../../../core/readiness.ts';
+import { verifiedStatusMarkers } from '../../../core/serve-http-status-marker.ts';
import { agentProcessMarker } from '../../../core/interaction.ts';
import { resolveGbrainBin } from '../../../core/gbrain-bin.ts';
import type { Action } from '../../../core/agent-output.ts';
@@ -231,6 +236,13 @@ async function smoke(r: HarnessRegistration): Promise<Check> {
/** Registration read (full run) or registration read + smoke (`--only harness_wiring`). */
export async function harnessWiringCheck(opts: { smoke: boolean }): Promise<Check> {
+ // A shared HTTP server that answers in status-only mode outranks every registration verdict.
+ const statusServer = (await verifiedStatusMarkers())[0];
+ if (statusServer) {
+ const entry = httpStatusServerEntry(statusServer);
+ return { name: NAME, status: 'warn', message: entry.why, ...(entry.fix ? { fix: entry.fix } : { fix_unavailable_reason: 'no_safe_automatic_fix' as const }),
+ details: { reason: entry.reason, transport: 'http', port: statusServer.port, pid: statusServer.pid, status_reason: statusServer.reason } };
+ }
const regs = readHarnessRegistrations();
if (regs.length === 0) {
const harnesses = detectedHarnesses();
diff --git a/src/commands/mcp-expose-probe.ts b/src/commands/mcp-expose-probe.ts
index 40ab111fa9..338983c484 100644
--- a/src/commands/mcp-expose-probe.ts
+++ b/src/commands/mcp-expose-probe.ts
@@ -21,6 +21,7 @@
import { lookup } from 'node:dns/promises';
import { createConnection, isIP } from 'node:net';
import { TAILSCALE_ACCEPT_DNS_COMMAND } from '../core/tailscale.ts';
+import { liveStatusMarkerFor } from '../core/serve-http-status-marker.ts';
export type ProbeFetch = (url: string, init?: { signal?: AbortSignal; redirect?: 'manual' | 'error' | 'follow' }) => Promise<{ ok: boolean; status: number }>;
/** Bounded TCP connect to `host:port` (true on connect, false on refusal / timeout). */
@@ -168,3 +169,13 @@ export async function pollHealth(d: ProbeDeps, url: string, budgetMs: number): P
export function unresolvedDetail(dnsName: string): string {
return `this host cannot resolve ${dnsName} (MagicDNS may be off here: \`${TAILSCALE_ACCEPT_DNS_COMMAND}\`); devices that do resolve it may already reach the server`;
}
+
+/**
+ * `verify.local` detail when the server on `port` runs in status-only mode
+ * (its `/health` answers 503): the reason from its marker on this host, so
+ * the check reads "status-only" with the cause instead of a timeout.
+ */
+export function statusOnlyHealthDetail(port: number): string | null {
+ const m = liveStatusMarkerFor(port);
+ return m ? `status-only (${m.reason}): the server runs but cannot open its brain; \`gbrain doctor --only harness_wiring\` names the fix` : null;
+}
diff --git a/src/commands/mcp-expose.ts b/src/commands/mcp-expose.ts
index cdb22523c2..c0fee29110 100644
--- a/src/commands/mcp-expose.ts
+++ b/src/commands/mcp-expose.ts
@@ -35,7 +35,7 @@ import {
type CommandResult, type CommandRunner, type ServeHandler, type ServeStatusView, type TailscaleStatus,
} from '../core/tailscale.ts';
import {
- defaultLookup, defaultTcpProbe, pollHealth, probeHealth, probeOccupied, tryFetch, unresolvedDetail,
+ defaultLookup, defaultTcpProbe, pollHealth, probeHealth, probeOccupied, statusOnlyHealthDetail, tryFetch, unresolvedDetail,
type FetchOutcome, type HostLookup, type ProbeFetch, type TcpProbe,
} from './mcp-expose-probe.ts';
// The probes were peeled into `mcp-expose-probe.ts`; the default TCP probe keeps its import site here.
@@ -964,7 +964,7 @@ async function runPublish(d: Resolved, s: Session, opts: ExposeOptions): Promise
s.check('verify.local', 'skipped', 'manual service: start the wrapper, then run --status');
} else {
localHealth = (await pollHealth(d, localHealthUrl, d.localHealthMs)).ok ? 'ok' : 'timeout';
- s.check('verify.local', localHealth === 'ok' ? 'ok' : 'warn', `${localHealthUrl}: ${localHealth}`);
+ s.check('verify.local', localHealth === 'ok' ? 'ok' : 'warn', `${localHealthUrl}: ${localHealth === 'ok' ? localHealth : statusOnlyHealthDetail(opts.port) ?? localHealth}`);
}
if (!opts.noTailscale && localHealth === 'ok') {
const tn = await pollHealth(d, `${publicUrl}/health`, d.tailnetHealthMs);
@@ -1104,7 +1104,8 @@ async function runStatus(d: Resolved, s: Session, opts: ExposeOptions): Promise<
}
// health
if (!localOk) allOk = false;
- s.check('verify.local', localOk ? 'ok' : 'fail', `${localUrl}: ${localOk ? 'ok' : 'no answer'}`);
+ const statusOnly = localOk ? null : statusOnlyHealthDetail(receipt.port);
+ s.check('verify.local', localOk ? 'ok' : statusOnly ? 'warn' : 'fail', `${localUrl}: ${localOk ? 'ok' : statusOnly ?? 'no answer'}`);
if (tailnetUrl && tailnet) {
if (tailnet.res?.ok) s.check('verify.tailnet', 'ok', `${tailnetUrl}: ok`);
else if (tailnet.unresolved) s.check('verify.tailnet', 'warn', `${tailnetUrl}: ${unresolvedDetail(receipt.tailscale.dns_name ?? receipt.public_url.slice('https://'.length))}`);
diff --git a/src/core/readiness.ts b/src/core/readiness.ts
index 8af63b7742..9214e0e591 100644
--- a/src/core/readiness.ts
+++ b/src/core/readiness.ts
@@ -41,6 +41,8 @@ import { validateMountId } from './brain-registry.ts';
import { agentProcessMarker } from './interaction.ts';
import { resolveGbrainBin } from './gbrain-bin.ts';
import { resolveWritebackConfigFromFile } from './facts/writeback-config.ts';
+import { liveStatusMarkers, type HttpStatusMarker } from './serve-http-status-marker.ts';
+import { initialStatusState, statusFix, statusHeadline, type StatusReason } from '../mcp/status-mode.ts';
export type ReadinessState = 'ok' | 'disabled_by_choice' | 'not_applicable' | 'missing' | 'degraded' | 'unknown';
export type CapabilityId =
@@ -59,6 +61,8 @@ export interface ReadinessEntry {
asset?: string;
/** false → stripped from the HTTP view. */
http_visible: boolean;
+ /** harness_wiring `serve_status_only`: the transport of the status-only server. */
+ transport?: Transport;
}
export interface LockOwner { pid: number; transport: 'stdio' | 'http'; started_at?: string; is_self: boolean }
@@ -93,7 +97,7 @@ export const MIGRATIONS_REASONS = ['current', 'pending', 'engine_unreachable', '
export const LOCAL_TRANSCRIPTS_REASONS = ['transcripts_cli_only', 'no_transcripts', 'engine_unreachable', 'probe_failed', 'probe_timeout'] as const;
export const HARNESS_WIRING_REASONS = [
'wired_running', 'registration_unverified', 'http_serve_running', 'multiple_sessions', 'multiple_harnesses',
- 'no_harness_detected', 'binary_unresolved', 'remote_transport',
+ 'no_harness_detected', 'binary_unresolved', 'remote_transport', 'serve_status_only',
] as const;
const VERIFY = (check: string) => ({ argv: ['gbrain', 'doctor', '--only', check, '--json'] });
@@ -383,6 +387,8 @@ export interface HarnessWiringInput {
lockOwner: LockOwner | null;
/** Absolute gbrain binary; null when it cannot be resolved (never registered bare). */
gbrainBin: string | null;
+ /** A live status-only `serve --http` on this machine (its marker), when there is one. */
+ httpStatusServer?: HttpStatusMarker | null;
}
const HARNESS_LABEL: Record<ReadinessHarness, string> = { 'claude-code': 'Claude Code', codex: 'Codex', opencode: 'opencode' };
@@ -417,11 +423,28 @@ function sharedHttpWiring(selector: ReadinessHarness | 'all'): Action {
};
}
+const STATUS_REASONS: readonly string[] = ['lock_held', 'no_brain', 'config_unreadable', 'missing_brain', 'brain_unopenable', 'repair_failed'];
+
+/**
+ * A shared `gbrain serve --http` exists but answers in status-only mode: the
+ * fix is its status reason's fix (classified again here, file reads only),
+ * never "start `gbrain serve --http`" on a port it already holds.
+ */
+export function httpStatusServerEntry(m: HttpStatusMarker): ReadinessEntry {
+ const state = initialStatusState((STATUS_REASONS.includes(m.reason) ? m.reason : 'brain_unopenable') as StatusReason);
+ return {
+ capability: 'harness_wiring', tier: 'config', http_visible: false, state: 'degraded', reason: 'serve_status_only', transport: 'http',
+ why: `A shared \`gbrain serve --http\` (PID ${m.pid}, port ${m.port}) is running in status-only mode: ${statusHeadline(state)} It re-checks every 5 s and serves the full tool list once the brain opens.`,
+ fix: statusFix(state, 'http').fix,
+ };
+}
+
/** `harness_wiring` for a concrete detection result. Doctor (Lane E) passes filesystem-detected harnesses. */
export function harnessWiringEntry(input: HarnessWiringInput): ReadinessEntry {
const base = { capability: 'harness_wiring' as const, tier: 'config' as const, http_visible: false };
if (input.transport === 'stdio') return { ...base, state: 'ok', reason: 'wired_running', why: 'An agent harness launched this gbrain MCP server over stdio.' };
if (input.transport === 'http') return { ...base, state: 'not_applicable', reason: 'remote_transport', why: 'Harness wiring is a property of the brain host.' };
+ if (input.httpStatusServer) return httpStatusServerEntry(input.httpStatusServer);
const { harnesses, lockOwner } = input;
if (harnesses.length === 0) {
return { ...base, state: 'missing', reason: 'no_harness_detected', why: 'No agent harness was detected.',
@@ -458,7 +481,7 @@ function harnessConfigEntry(transport: Transport, lockOwner: LockOwner | null):
const marker = agentProcessMarker();
const harness = marker ? MARKER_HARNESS[marker] : undefined;
cachedBin ??= { value: resolveGbrainBin() };
- return harnessWiringEntry({ transport, harnesses: harness ? [harness] : [], lockOwner, gbrainBin: cachedBin.value });
+ return harnessWiringEntry({ transport, harnesses: harness ? [harness] : [], lockOwner, gbrainBin: cachedBin.value, httpStatusServer: liveStatusMarkers()[0] ?? null });
}
// ── config plane ───────────────────────────────────────────────────────────