Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(doctor): maintenance_write_drift reports unknown when candidates cannot be compared here (#8115)

garrytanb14e367411ec
diff --git a/src/commands/doctor/checks/maintenance-drift.ts b/src/commands/doctor/checks/maintenance-drift.ts
index 3072336f59..f76a40d1b5 100644
--- a/src/commands/doctor/checks/maintenance-drift.ts
+++ b/src/commands/doctor/checks/maintenance-drift.ts
@@ -109,11 +109,14 @@ export async function maintenanceWriteDriftCheck(engine: BrainEngine, sourceIds?
fix: agentFix(['gbrain', 'sources', 'reconcile', auditSource!, '--brain', 'host', '--audit', '--conflicts', '--window', '1000000', '--json'],
'Read-only: pages through the conflict receipts grouped by slug, with whether each file still differs.', 'maintenance_write_drift', { docs }) };
}
+ const unknown = rows.reduce((sum, row) => sum + row.unknown, 0);
+ if (!count && !skipCount && unknown) {
+ return { name: 'maintenance_write_drift', status: 'warn', details: { ...details, health: 'unknown', exact: false }, fix_unavailable_reason: 'operator_judgement',
+ message: `Maintenance write drift unknown: no page checked on this host has a canonical file that differs from the database, but ${unknown} could not be checked here (run doctor on the canonical owner host).` };
+ }
if (!count && !skipCount) {
- const unknown = rows.reduce((sum, row) => sum + row.unknown, 0);
return { name: 'maintenance_write_drift', status: 'ok', details,
- message: unknown ? `No page checked on this host has a canonical file that differs from the database; ${unknown} could not be checked here (run doctor on the canonical owner host).`
- : `No page whose writes refuse source_changed still has a canonical file that differs from the database.${policyNote}` };
+ message: `No page whose writes refuse source_changed still has a canonical file that differs from the database.${policyNote}` };
}
const first = rows.find(row => row.drifted || row.concept_skips)!.source_id;
return { name: 'maintenance_write_drift', status: 'warn', details,
diff --git a/test/maintenance-drift-unknown-8115.test.ts b/test/maintenance-drift-unknown-8115.test.ts
new file mode 100644
index 0000000000..4cccad0a71
--- /dev/null
+++ b/test/maintenance-drift-unknown-8115.test.ts
@@ -0,0 +1,55 @@
+/**
+ * #8115: maintenance_write_drift with drift receipts whose live comparison is unavailable
+ * on this host (no canonical owner binding) must report unknown health and an incomplete
+ * report, not ok. A source with no receipts stays ok and complete.
+ */
+import { afterAll, beforeAll, beforeEach, expect, test } from 'bun:test';
+import { randomUUID } from 'node:crypto';
+import { PGLiteEngine } from '../src/core/pglite-engine.ts';
+import { resetPgliteState } from './helpers/reset-pglite.ts';
+import { maintenanceWriteDriftCheck } from '../src/commands/doctor/checks/maintenance-drift.ts';
+import { computeDoctorReport } from '../src/commands/doctor.ts';
+import { FILE_DRIFT_MESSAGE } from '../src/core/persistence/drift-conflicts.ts';
+
+let engine: PGLiteEngine;
+
+beforeAll(async () => {
+ engine = new PGLiteEngine();
+ await engine.connect({});
+ await engine.initSchema();
+});
+
+afterAll(async () => {
+ await engine.disconnect();
+});
+
+beforeEach(async () => {
+ await resetPgliteState(engine);
+});
+
+const run = { tier: 'standard' as const, startedAt: Date.now(), budgetMs: null };
+
+test('candidates whose live comparison is unavailable report unknown health and an incomplete report', async () => {
+ await engine.putPage('notes/alpha', { type: 'note', title: 'Alpha', compiled_truth: 'Alpha.', timeline: '' });
+ await engine.transaction(async (tx) => {
+ await tx.executeRaw("SELECT set_config('gbrain.persistence_protocol','2',true)");
+ await tx.executeRaw(`INSERT INTO persistence_requests(principal_kind,principal_id,request_id,operation,source_id,source_incarnation,slug,digest,authority,
+ intent_bytes,terminal_reservation,state,error_code,error_message)
+ VALUES('local_cli','fixture',$1::uuid,'put_page','default',(SELECT incarnation FROM sources WHERE id='default'),'notes/alpha',$2,'{}'::jsonb,0,0,
+ 'conflict','source_changed',$3)`, [randomUUID(), randomUUID(), FILE_DRIFT_MESSAGE]);
+ });
+ const check = await maintenanceWriteDriftCheck(engine, ['default']);
+ expect(check.details?.sources).toEqual([expect.objectContaining({ source_id: 'default', drifted: 0, unknown: 1 })]);
+ expect(check.status).toBe('warn');
+ expect(check.details?.health).toBe('unknown');
+ const report = computeDoctorReport([check], { run });
+ expect(report.complete).toBe(false);
+ expect(report.unknown_sections).toEqual(['maintenance_write_drift']);
+});
+
+test('control: a source with no drift receipts stays ok and complete', async () => {
+ const check = await maintenanceWriteDriftCheck(engine, ['default']);
+ expect(check.status).toBe('ok');
+ expect(check.details?.health).toBeUndefined();
+ expect(computeDoctorReport([check], { run }).complete).toBe(true);
+});