Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(doctor): withhold the worker registry path from remote doctor callers (#6933)

time-attack2de07f980003
diff --git a/src/commands/doctor/checks/queue-jobs.ts b/src/commands/doctor/checks/queue-jobs.ts
index 5221a0764b..5664cbc840 100644
--- a/src/commands/doctor/checks/queue-jobs.ts
+++ b/src/commands/doctor/checks/queue-jobs.ts
@@ -13,6 +13,22 @@ import { queueWorkerAlive, runWaitingJobsFix } from '../../../core/minions/no-wo
/** Local alias; the shared warn-once memo lives in core so it can't fork per module. */
const _resolveEnvNumber = resolveEnvNumber;
+type RegistryFailure = { errno: string; path: string | null };
+
+/** A remote doctor caller never sees the host's filesystem path to the worker registry. */
+function registryFailureDetails(failure: RegistryFailure, remote: boolean): Record<string, unknown> {
+ return {
+ worker_registry_unreadable: true,
+ worker_registry_errno: failure.errno,
+ ...(remote ? { worker_registry_path_redacted: true } : { worker_registry_path: failure.path }),
+ };
+}
+
+function registryFailureLabel(failure: RegistryFailure, remote: boolean): string {
+ if (remote) return `${failure.errno}; path withheld from remote callers, run \`gbrain doctor\` on the brain host`;
+ return `${failure.errno}${failure.path ? ` at ${failure.path}` : ''}`;
+}
+
/**
* v0.41.18.0 batch_retry_health doctor check (codex H-9 thresholds).
*
@@ -47,6 +63,7 @@ export async function computeQueueHealthCheck(
waitingDepthThreshold?: number;
oldWaitingHours?: number;
readWorkers?: () => Array<{ queue: string }>;
+ remote?: boolean;
} = {},
): Promise<Check> {
if (engine.kind === 'pglite') return computePgliteQueueHealth(engine, opts.readWorkers);
@@ -170,7 +187,7 @@ export async function computeQueueHealthCheck(
null,
),
worker_alive: liveWorkerQueues === null ? null : waitingByQueue.every((r) => liveWorkerQueues.has(r.queue)),
- ...(registryFailure ? { worker_registry_unreadable: true, worker_registry_errno: registryFailure.errno, worker_registry_path: registryFailure.path } : {}),
+ ...(registryFailure ? registryFailureDetails(registryFailure, opts.remote === true) : {}),
};
const problems: string[] = [];
@@ -198,7 +215,7 @@ export async function computeQueueHealthCheck(
if (registryFailure) {
problems.push(
`${row.depth} ${row.name} job(s) have waited on queue '${row.queue}' for up to ${hours}h; ` +
- `the worker registry is unreadable (${registryFailure.errno}${registryFailure.path ? ` at ${registryFailure.path}` : ''}), ` +
+ `the worker registry is unreadable (${registryFailureLabel(registryFailure, opts.remote === true)}), ` +
`so worker liveness is unknown. Check that directory's permissions, then run \`gbrain jobs supervisor status\`.`
);
continue;
@@ -370,7 +387,7 @@ async function computePgliteQueueHealth(engine: BrainEngine, readWorkers?: () =>
*/
export async function computeWedgedQueueCheck(
engine: BrainEngine,
- opts: { readWorkers?: () => Array<{ queue: string }> } = {},
+ opts: { readWorkers?: () => Array<{ queue: string }>; remote?: boolean } = {},
): Promise<Check> {
if (engine.kind !== 'postgres') {
return { name: 'wedged_queue', status: 'ok', message: 'PGLite — no queue to check' };
@@ -438,16 +455,14 @@ export async function computeWedgedQueueCheck(
name: 'wedged_queue',
status: 'fail',
message:
- `Wedged queue(s) — worker registry unreadable (${registryFailure.errno}${registryFailure.path ? ` at ${registryFailure.path}` : ''}), worker liveness unknown: ` +
+ `Wedged queue(s) — worker registry unreadable (${registryFailureLabel(registryFailure, opts.remote === true)}), worker liveness unknown: ` +
`${wedged.map((w) => w.label).join('; ')}. ` +
`If a worker is running for the queue, restart it: ` +
'`gbrain jobs supervisor stop && gbrain jobs supervisor start [--queue <name>]`; ' +
'if none is, start one: `gbrain jobs supervisor start --queue <name> --detach`.',
details: {
wedged_queues: wedged.length,
- worker_registry_unreadable: true,
- worker_registry_errno: registryFailure.errno,
- worker_registry_path: registryFailure.path,
+ ...registryFailureDetails(registryFailure, opts.remote === true),
threshold_minutes: thresholdMin,
},
};
diff --git a/src/commands/doctor/report-remote.ts b/src/commands/doctor/report-remote.ts
index e3a4f49147..a868a4cd91 100644
--- a/src/commands/doctor/report-remote.ts
+++ b/src/commands/doctor/report-remote.ts
@@ -318,10 +318,10 @@ export async function doctorReportRemote(
// 5. Queue health (Postgres-only). PGLite has no minion_jobs in the same
// shape; skip the check there with an informational message.
- checks.push(await computeQueueHealthCheck(engine));
+ checks.push(await computeQueueHealthCheck(engine, { remote: opts.remote !== false }));
// issue #1801 — wedged_queue (cross-surface parity with buildChecks).
- checks.push(await computeWedgedQueueCheck(engine));
+ checks.push(await computeWedgedQueueCheck(engine, { remote: opts.remote !== false }));
checks.push(await computeOrphanedPrivateQueueCheck(engine));
// #2194 fix #5 — warn when autopilot fan-out exceeds worker concurrency.
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.ts
index f3b0e87c87..aed47c0700 100644
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@ -935,7 +935,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;
{ since: '0.60.312.0', text: 'The `advisor` MCP operation now judges the cached backup verdict the way the doctor does: a remote readback older than one hour, a future-dated cache or a degraded compute reports the `backup_coverage_aggregate` warning instead of no finding. It still reads the cache only and names reason counts, never source ids.' },
{ since: '0.60.312.0', text: '`gbrain advisor` (and the `advisor` MCP operation) reports a database read that fails inside the `usage-shape` or `stalled-jobs` check as `collector_failed:<check>` and exits 1, instead of returning no findings for that check and possibly reporting a healthy brain. A brain with no pages, and an older brain without `minion_jobs`, `sources` or `sources.last_sync_at`, still report nothing for those checks.' },
{ since: '0.60.312.0', text: '`gbrain search tune --apply` now writes before it reports: `--json` lists in `applied` and `revert_commands` only the changes that landed, adds per-item `results` (`applied`, `unsupported`, `failed`, `outcome_unknown`, `not_attempted`), `not_applied` and `apply_error`, and the text output marks a failed or unrecognized change with ✗ instead of ✓. The batch stops at the first write that does not land and the command exits non-zero; changes that already landed stay in place with their revert commands.' },
- { since: '0.60.312.0', text: 'A worker registry directory that exists but cannot be listed (permission denied, or a file where the directory should be) now reads as unknown worker liveness instead of no workers. Doctor `queue_health` reports `worker_alive: null` with a liveness-unknown message and no start-a-worker fix, `legacy_job_authority` reports `live_workers: null`, `gbrain jobs supervisor status --json` reports `workers: null`, a submitted job\'s `queue_state` omits `worker_alive` and warns that liveness is unknown, `gbrain jobs stats` reports a wedge instead of `no_worker`, and the `migrate-embeddings` plan warns about an unknown worker count. Each names the errno and path in `worker_registry_errno` and `worker_registry_path`. A missing registry directory still means no workers.' },
+ { since: '0.60.312.0', text: 'A worker registry directory that exists but cannot be listed (permission denied, or a file where the directory should be) now reads as unknown worker liveness instead of no workers. Doctor `queue_health` reports `worker_alive: null` with a liveness-unknown message and no start-a-worker fix, `legacy_job_authority` reports `live_workers: null`, `gbrain jobs supervisor status --json` reports `workers: null`, a submitted job\'s `queue_state` omits `worker_alive` and warns that liveness is unknown, `gbrain jobs stats` reports a wedge instead of `no_worker`, and the `migrate-embeddings` plan warns about an unknown worker count. Each names the errno and path in `worker_registry_errno` and `worker_registry_path`, except that the remote doctor (`run_doctor`, `gbrain remote doctor`) shows a remote caller only the errno: its `queue_health` and `wedged_queue` carry `worker_registry_path_redacted: true` in place of the path, and the message says to run `gbrain doctor` on the brain host. A missing registry directory still means no workers.' },
{ since: '0.60.312.0', text: '`gbrain sources attach` with an invalid source id now refuses with `invalid_params` (a caller error) and a fix that lists the existing ids (`gbrain sources list --json`), instead of an `internal_error`. Nothing is written in either case.' },
{ since: '0.60.312.0', text: 'On a managed brain, a dream synthesis output or summary whose publish is refused because the principal or brain outstanding-request cap (`persistence.limits.principal_outstanding`, `persistence.limits.brain_outstanding`) is full is now deferred like a pending publish: the phase warns with `publish_pending`, leaves the cooldown unstamped and the next cycle retries the same request, instead of failing the phase. A zero cap and cumulative quotas still fail it.' },
// #6799 (Codex tool approvals).
diff --git a/test/doctor-queue-divergence.test.ts b/test/doctor-queue-divergence.test.ts
index 610df9f24a..afb87239ec 100644
--- a/test/doctor-queue-divergence.test.ts
+++ b/test/doctor-queue-divergence.test.ts
@@ -143,6 +143,20 @@ describe('queue_health — unreadable worker registry', () => {
});
expect(check.message).toContain('unreadable (EACCES at /home/alice-example/.gbrain/workers)');
});
+
+ it('withholds the registry path from a remote caller; the local caller keeps it', async () => {
+ await seed('default', 'embed-backfill', 'waiting', { createdAtSql: "now() - interval '3 hours'" });
+ const { WorkerRegistryUnreadableError } = await import('../src/core/minions/worker-registry.ts');
+ const readWorkers = () => { throw new WorkerRegistryUnreadableError('/home/alice-example/.gbrain/workers', 'EACCES', null); };
+ const remote = await computeQueueHealthCheck(pgLike, { readWorkers, remote: true });
+ expect(JSON.stringify(remote)).not.toContain('/home/alice-example');
+ expect(remote.details).toMatchObject({ worker_alive: null, worker_registry_unreadable: true, worker_registry_errno: 'EACCES', worker_registry_path_redacted: true });
+ expect(remote.details).not.toHaveProperty('worker_registry_path');
+ expect(remote.message).toContain('unreadable (EACCES; path withheld from remote callers');
+ const local = await computeQueueHealthCheck(pgLike, { readWorkers, remote: false });
+ expect(local.details?.worker_registry_path).toBe('/home/alice-example/.gbrain/workers');
+ expect(local.message).toContain('unreadable (EACCES at /home/alice-example/.gbrain/workers)');
+ });
});
describe('malformed_path_pages discovery check (buildChecks seam)', () => {
diff --git a/test/doctor-wedged-queue.test.ts b/test/doctor-wedged-queue.test.ts
index 94faa6bfc6..6b4e9deced 100644
--- a/test/doctor-wedged-queue.test.ts
+++ b/test/doctor-wedged-queue.test.ts
@@ -130,6 +130,21 @@ describe('issue #1801 fix #3 — computeWedgedQueueCheck', () => {
expect(check.details?.worker_registry_path).toBeNull();
});
+ it('a remote caller never sees the registry path; the local caller does', async () => {
+ await seed('default', 'cycle', 'waiting');
+ await seed('default', 'cycle', 'completed', { updatedAtSql: "now() - interval '20 min'" });
+ const { WorkerRegistryUnreadableError } = await import('../src/core/minions/worker-registry.ts');
+ const readWorkers = () => { throw new WorkerRegistryUnreadableError('/home/alice-example/.gbrain/workers', 'EACCES', null); };
+ const remote = await computeWedgedQueueCheck(pgLike, { readWorkers, remote: true });
+ expect(remote.status).toBe('fail');
+ expect(JSON.stringify(remote)).not.toContain('/home/alice-example');
+ expect(remote.details).toMatchObject({ worker_registry_unreadable: true, worker_registry_errno: 'EACCES', worker_registry_path_redacted: true });
+ expect(remote.details).not.toHaveProperty('worker_registry_path');
+ const local = await computeWedgedQueueCheck(pgLike, { readWorkers });
+ expect(local.details?.worker_registry_path).toBe('/home/alice-example/.gbrain/workers');
+ expect(local.message).toContain('EACCES at /home/alice-example/.gbrain/workers');
+ });
+
it('mixed stuck + no-worker queues → both messages, details count each subset', async () => {
await seed('default', 'cycle', 'waiting');
await seed('default', 'cycle', 'completed', { updatedAtSql: "now() - interval '20 min'" });
diff --git a/test/e2e/doctor-remote-registry-path-postgres.test.ts b/test/e2e/doctor-remote-registry-path-postgres.test.ts
new file mode 100644
index 0000000000..50d927406c
--- /dev/null
+++ b/test/e2e/doctor-remote-registry-path-postgres.test.ts
@@ -0,0 +1,53 @@
+/**
+ * Wave 20 review: the remote doctor (run_doctor / gbrain remote doctor) must
+ * not show a remote caller the brain host's filesystem path to the worker
+ * registry when that registry can't be read. The local doctor keeps it.
+ *
+ * Run: DATABASE_URL=... bun test test/e2e/doctor-remote-registry-path-postgres.test.ts
+ */
+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { dirname, join } from 'node:path';
+import { hasDatabase, setupDB, teardownDB } from './helpers.ts';
+import type { PostgresEngine } from '../../src/core/postgres-engine.ts';
+import { doctorReportRemote } from '../../src/commands/doctor.ts';
+import { workerRegistryDir } from '../../src/core/minions/worker-registry.ts';
+import { withEnv } from '../helpers/with-env.ts';
+
+const describeE2E = hasDatabase() ? describe : describe.skip;
+let engine: PostgresEngine;
+let home: string;
+
+describeE2E('remote doctor withholds the worker registry path (Postgres)', () => {
+ beforeAll(async () => {
+ engine = await setupDB();
+ home = mkdtempSync(join(tmpdir(), 'gbrain-remote-registry-'));
+ await engine.executeRaw(
+ `INSERT INTO minion_jobs (submission_authority, name, queue, status, created_at, updated_at)
+ VALUES ('{"version":1,"kind":"application"}'::jsonb, 'embed-backfill', 'default', 'waiting', now() - interval '3 hours', now())`,
+ );
+ }, 120_000);
+ afterAll(async () => {
+ await teardownDB();
+ rmSync(home, { recursive: true, force: true });
+ });
+
+ test('queue_health names the path to the local doctor only', async () => {
+ await withEnv({ GBRAIN_HOME: home }, async () => {
+ const dir = workerRegistryDir();
+ mkdirSync(dirname(dir), { recursive: true });
+ writeFileSync(dir, 'not a directory');
+
+ const remote = await doctorReportRemote(engine, { remote: true });
+ const remoteCheck = remote.checks.find((c) => c.name === 'queue_health')!;
+ expect(remoteCheck.details).toMatchObject({ worker_alive: null, worker_registry_unreadable: true, worker_registry_errno: 'ENOTDIR', worker_registry_path_redacted: true });
+ expect(JSON.stringify(remote)).not.toContain(home);
+
+ const local = await doctorReportRemote(engine, { remote: false });
+ const localCheck = local.checks.find((c) => c.name === 'queue_health')!;
+ expect(localCheck.details?.worker_registry_path).toBe(dir);
+ expect(localCheck.message).toContain(`ENOTDIR at ${dir}`);
+ });
+ }, 120_000);
+});