Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(repair): file-drift --all-drifted lists pages the live check cannot classify as unknown (#6991)

time-attackce617c4193c1
diff --git a/docs/guides/repair.md b/docs/guides/repair.md
index df780aa5c4..e513e1e1eb 100644
--- a/docs/guides/repair.md
+++ b/docs/guides/repair.md
@@ -1808,7 +1808,18 @@ refuses [`ghost_mass_delete_refused`](error-codes.md#ghost_mass_delete_refused)
unless `GBRAIN_ALLOW_MASS_RECONCILE=1`). `gbrain sources reconcile --preview` on
such a page refuses and names the same route, and a held deletion's next step
in `gbrain sources status` is the `--prefer database` preview. `--all-drifted`
-does not select missing files.
+does not select missing files: it lists each one as `unknown`
+(`unknown_canonical_file_missing`), to preview alone with `--slug`.
+
+<a id="file-drift-unknown"></a>**Pages the live check cannot classify** (#6991). A conflicted page whose
+live file/database comparison returns no verdict (this host is not the
+source's active canonical owner, the page or its canonical file is gone, or
+the check refused or failed) is never repaired and never counted as clean.
+`--all-drifted` and the bare `gbrain repair file-drift` survey list it with
+class `unknown`, count it as `unknown_<reason>`, and say what to do for that
+reason (run on the owner host, decide the content by hand, preview it alone
+with `--slug`, or rerun the conflict audit). No `--class` preview command is
+printed for unknown pages.
The audit gives every drifted page one class: `structurally_additive`,
`additive_with_suggestions`, `review_required`, `formatting_only` or `error`.
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.ts
index dee7dfa136..6c5f8a4067 100644
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@ -909,6 +909,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;
{ since: '0.60.307.0', text: '`get_links` and `get_backlinks` (`gbrain links`, `gbrain backlinks`) now return at most 500 link rows per call instead of every edge of the page. When more match, the last row carries `truncated: true` and `next_cursor`: pass it back as `cursor` (`--cursor`) with the same filters for the next rows, raise `limit` (`--limit`, up to 5000), or use `--all` on the CLI for every row. Remote callers also get a `listing_truncated` notice naming the next call. Rows come in link order, `link_type` and the live/history filter apply before the cap so hidden former relationships never use a row, and each row\'s `context` is cut to 2000 characters (ending in an ellipsis). A cursor from another listing is refused `link_cursor_invalid`. `get_backlinks` with `limit` no longer points at `group: "page"`; it pages the rows with `cursor`.', id: 'link_read_cap' },
{ since: '0.60.307.0', id: 'google_account_credential_refusal', text: 'A managed Google source whose account cannot be read because the Google API is disabled for the OAuth project (or the grant is missing, or Google answers 403) now fails the sync with that credential error (`api_not_enabled` with the console link to enable the API, `scope_missing`, or `upstream` naming the 403) instead of `connector_account_changed`. A credential that no service can name for another reason still refuses as before.' },
{ since: '0.60.307.0', id: 'auth_rescope_client_print_only', text: '`gbrain auth rescope --client <id>` (and `gbrain auth rescope-client <id>`) with no grant flag and no `--profile` now prints the client\'s stored grants and writes nothing (`--json`: `changed: false`, `written: false`), as the help always said, instead of refusing with `invalid_grant`. An unknown client id refuses with `client_not_found`, whose fix is `gbrain auth clients --json`. `--repair` alone still refuses.' },
+ { since: '0.60.307.0', id: 'file_drift_unknown_listed', text: '`gbrain repair file-drift --all-drifted` previews and the bare `gbrain repair file-drift` survey now list a conflicted page the live check cannot classify (canonical file missing, page gone, not the owner host, a refused or failed check) as `unknown`, counted under `unknown_<reason>` with the next step for that reason. They used to drop it silently, so a preview could read as empty. Unknown pages are never repaired and get no `--class` preview command.' },
];
/** The newest disclosed change's release: the notice id moves only when a release adds rows. */
diff --git a/src/core/repair/file-drift.ts b/src/core/repair/file-drift.ts
index fa1caacf90..1150c9afda 100644
--- a/src/core/repair/file-drift.ts
+++ b/src/core/repair/file-drift.ts
@@ -183,8 +183,9 @@ function readArtifact(hash: string, command: string): Map<string, PlannedPage> {
* path (`not_selected` counts the pages they leave out), before the class check and the bound; an exact selection
* is narrowed by the plan from the same live check.
*/
-async function selectSlugs(engine: BrainEngine, sourceId: string, opts: RepairPlanOptions): Promise<{ slugs: string[]; classes: Map<string, DriftClass>; notSelected: number }> {
+async function selectSlugs(engine: BrainEngine, sourceId: string, opts: RepairPlanOptions): Promise<{ slugs: string[]; classes: Map<string, DriftClass>; notSelected: number; unknown: UnknownDrift[] }> {
const classes = new Map<string, DriftClass>();
+ const unknown: UnknownDrift[] = [];
if (opts.allDrifted) {
const drifted: string[] = [];
let notSelected = 0;
@@ -192,8 +193,9 @@ async function selectSlugs(engine: BrainEngine, sourceId: string, opts: RepairPl
do {
const page = await auditDriftConflicts(engine, sourceId, { trusted: true, excludePrivate: false }, { limit: 100, cursor });
for (const row of page.conflicts) {
- if (row.still_present.value !== true) continue;
+ if (row.still_present.value === false) continue;
if (!selectedByGlobs(row.path, opts) || !sinceSelects(row.last_seen, opts.since)) { notSelected++; continue; }
+ if (row.still_present.value === null) { unknown.push({ slug: row.slug, reason: row.still_present.reason }); continue; }
drifted.push(row.slug); classes.set(row.slug, row.class ?? 'error');
}
cursor = page.next ?? undefined;
@@ -206,7 +208,7 @@ async function selectSlugs(engine: BrainEngine, sourceId: string, opts: RepairPl
`Preview one class at a time: ${previewCommand(sourceId, { ...opts, driftClass: [...counts.keys()][0] })}, and so on for each class; or name pages with --slug.`,
{ fix: readFix('Lists the drifted pages with their drift class, read-only.', { argv: ['gbrain', 'sources', 'reconcile', sourceId, '--brain', 'host', '--audit', '--conflicts', '--json'] }) });
}
- return { slugs: drifted.filter(slug => !opts.driftClass || classes.get(slug) === opts.driftClass), classes, notSelected };
+ return { slugs: drifted.filter(slug => !opts.driftClass || classes.get(slug) === opts.driftClass), classes, notSelected, unknown };
}
const slugs = new Set(opts.slugs ?? []);
if (opts.requests?.length) {
@@ -219,7 +221,19 @@ async function selectSlugs(engine: BrainEngine, sourceId: string, opts: RepairPl
{ fix: readFix('Lists the conflict receipts of this source grouped by slug, read-only.', { argv: ['gbrain', 'sources', 'reconcile', sourceId, '--brain', 'host', '--audit', '--conflicts', '--json'] }) });
for (const row of rows) slugs.add(row.slug);
}
- return { slugs: [...slugs].sort(), classes, notSelected: 0 };
+ return { slugs: [...slugs].sort(), classes, notSelected: 0, unknown };
+}
+
+/** #6991: a conflicted page the live check could not classify; it is listed and counted, never repaired. */
+interface UnknownDrift { slug: string; reason: string }
+
+function unknownDriftDetail(sourceId: string, { slug, reason }: UnknownDrift): string {
+ const kept = 'Not classified or repaired.';
+ if (reason === 'not_owner_host') return `${reason}: ${kept} Run the drift audit for source ${sourceId} on its active canonical owner host.`;
+ if (reason === 'page_missing') return `${reason}: ${kept} The page is gone from the database; decide its content by hand, no --prefer applies to it.`;
+ if (reason === 'canonical_file_missing') return `${reason}: ${kept} Its canonical file is missing; preview it alone with --slug ${slug} to choose a side.`;
+ if (reason === 'error') return `${reason}: ${kept} The live check failed unexpectedly; rerun gbrain sources reconcile ${sourceId} --audit --conflicts --json.`;
+ return `${reason}: ${kept} The live check refused; preview it alone with --slug ${slug} to see the refusal.`;
}
function validateOptions(scope: RepairScope, opts: RepairPlanOptions | undefined): asserts opts is RepairPlanOptions & { prefer: DriftSide } {
@@ -263,7 +277,12 @@ async function survey(engine: BrainEngine, scope: RepairScope, opts: Pick<Repair
do {
const page = await auditDriftConflicts(engine, sourceId, { trusted: true, excludePrivate: false }, { limit: 100, cursor });
for (const row of page.conflicts) {
- if (row.still_present.value !== true || !sinceSelects(row.last_seen, opts.since)) continue;
+ if (row.still_present.value === false || !sinceSelects(row.last_seen, opts.since)) continue;
+ if (row.still_present.value === null) {
+ residuals[`unknown_${row.still_present.reason}`] = (residuals[`unknown_${row.still_present.reason}`] ?? 0) + 1;
+ listing.push({ item: `${sourceId}:${row.slug}`, class: 'unknown', detail: unknownDriftDetail(sourceId, { slug: row.slug, reason: row.still_present.reason }) });
+ continue;
+ }
const kind = row.class ?? 'error';
counts.set(kind, (counts.get(kind) ?? 0) + 1);
residuals[`drifted_${kind}`] = (residuals[`drifted_${kind}`] ?? 0) + 1;
@@ -373,12 +392,16 @@ export const fileDriftRepair: RepairHandler = {
const items = approved.items.map((page, index) => item(page, index, opts.expect!, index === approved.items.length - 1, opts.prefer));
return { items: items.filter(entry => afterCursor(entry.cursor, after)), preview_hash: opts.expect, residuals: {} };
}
- const { slugs, classes, notSelected } = await selectSlugs(engine, sourceId, opts);
+ const { slugs, classes, notSelected, unknown } = await selectSlugs(engine, sourceId, opts);
const assessmentAt = new Date().toISOString();
const pages: PlannedPage[] = [];
const listing: NonNullable<RepairPlan['listing']> = [];
const residuals: Record<string, number> = notSelected ? { not_selected: notSelected } : {};
const count = (key: string) => { residuals[key] = (residuals[key] ?? 0) + 1; };
+ for (const row of unknown) {
+ count(`unknown_${row.reason}`);
+ listing.push({ item: `${sourceId}:${row.slug}`, class: 'unknown', detail: unknownDriftDetail(sourceId, row) });
+ }
await asLocalCli(engine, async () => {
for (const slug of slugs) {
try {
diff --git a/test/file-drift-bulk-reconcile.test.ts b/test/file-drift-bulk-reconcile.test.ts
index 002bbfa9c2..b3d73429b9 100644
--- a/test/file-drift-bulk-reconcile.test.ts
+++ b/test/file-drift-bulk-reconcile.test.ts
@@ -226,6 +226,21 @@ for (const backend of testBackends()) describe(`C7 bulk file-drift reconcile (${
expect(await stillDrifted(sourceId, [...CONCEPTS, PERSON])).toEqual([PERSON]);
}), 240_000);
+ test('#6991 --all-drifted and the survey list a conflicted page the live check cannot classify as unknown, never repaired', () => fixture(async ({ root, sourceId, ctx }) => {
+ await driftedPages(root, ctx);
+ rmSync(join(root, `${PERSON}.md`));
+ expect((await liveFileDrift(engine, sourceId, PERSON)).still_present).toBeNull();
+ const preview = (await json(['file-drift', '--source', sourceId, '--all-drifted', '--prefer', 'database'])).results[0]!;
+ expect(preview).toMatchObject({ mode: 'dry_run', affected: 3, residuals: { unknown_canonical_file_missing: 1 } });
+ expect(preview.sample).toEqual(CONCEPTS.map(slug => `${sourceId}:${slug}`));
+ const unknown = (preview.listing as Array<{ item: string; class: string; detail: string }>).filter(entry => entry.class === 'unknown');
+ expect(unknown).toEqual([{ item: `${sourceId}:${PERSON}`, class: 'unknown', detail: expect.stringContaining('canonical_file_missing: Not classified or repaired.') }]);
+ const survey = (await json(['file-drift', '--source', sourceId])).results[0]!;
+ expect(survey.residuals).toMatchObject({ unknown_canonical_file_missing: 1 });
+ expect((survey.listing as Array<{ item: string; class: string }>).find(entry => entry.item === `${sourceId}:${PERSON}`)?.class).toBe('unknown');
+ expect(JSON.stringify((survey.details as { next_actions: string[] }).next_actions)).not.toContain('unknown');
+ }), 240_000);
+
test('the globs are bound into the preview hash: --skip narrows the set, and an apply under other globs refuses preview_changed', () => fixture(async ({ root, sourceId, ctx }) => {
await driftedPages(root, ctx);
const scope = await resolveRepairScope(engine, sourceId);