Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(repair): a file-drift preview whose recreates or removals stay uncommitted leads with what the next sync does to them (GBRA-133)
garrytan87b32245131b
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.tsindex 32d5f2ad5c..1b1f455898 100644--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@ -1085,7 +1085,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;{ since: '0.60.351.0', text: 'Remote (MCP and HTTP) page reads now hide a page marked private only by a privacy alias (`access: private|restricted|confidential` or `confidentiality: confidential|secret|private|restricted`, with no `visibility`), as they hide `visibility: private` pages; local CLI reads are unchanged. To keep showing such pages to remote callers: `gbrain config set visibility.honor_aliases false`.' },{ since: '0.60.351.0', text: '`gbrain repair visibility` previews one class at a time, in the order remote callers are exposed: world facts from a private page (remotely readable ones first), Life Chronicle events, alias-only pages, then atoms and concepts; only that last class (`--class lineage`) reads concept-provenance links, and `--class facts|events|aliases|lineage` previews one. A preview lists one window (1,000 items, `--limit` up to 10,000), reports progress on stderr and prints `--apply --expect <hash>`, which applies exactly that window and resumes after its last applied item; apply it, then preview again for the next window. A bare `--apply` (`--all`, the remediation plan) still applies every class. Each plan statement is bounded at 120 s; a class that overruns is reported and skipped while the others are listed. The fact and concept-lineage plans are set-based now (a large brain timed out on them), and doctor `derived_visibility` counts facts first and reports derived-page counts as unknown when they overrun the same bound. A doctor rerun hint capped to fit an agent tool call also names the uncapped `--budget-ms` to use in a terminal.' },// GBRA-133 (held file-drift preview windows). `since` is stamped at the merge slot.- { since: 'TBD', text: '`gbrain repair file-drift --held` previews one window of the selected holds at a time, in held-path order: at most 200 pages, starting no page after 60 seconds of work, with each page reported on stderr. The hash and apply command cover only that window; a partial window prints `next_cursor` and the next preview command (`--cursor <next_cursor>`). Before, the preview prepared every held page (up to 1,000, silently dropping the rest) before printing anything, so a large held set against a remote database printed nothing for an hour. The apply reports each page on stderr too, and reads the preview artifact once instead of parsing it again for every page (seconds per page with large pages).' },+ { since: 'TBD', text: '`gbrain repair file-drift --held` previews one window of the selected holds at a time, in held-path order: at most 200 pages, starting no page after 60 seconds of work, with each page reported on stderr. The hash and apply command cover only that window; a partial window prints `next_cursor` and the next preview command (`--cursor <next_cursor>`). Before, the preview prepared every held page (up to 1,000, silently dropping the rest) before printing anything, so a large held set against a remote database printed nothing for an hour. The apply reports each page on stderr too, and reads the preview artifact once instead of parsing it again for every page (seconds per page with large pages). With Git durability off, a preview that recreates or removes files now leads with "The next sync undoes this repair unless …" and the commit command, and reports `undone_by_next_sync_unless_committed`.' },];/** 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.tsindex 90f85be0ab..99bb4ac03c 100644--- a/src/core/repair/file-drift.ts+++ b/src/core/repair/file-drift.ts@@ -702,12 +702,14 @@ export const fileDriftRepair: RepairHandler = {const removed = pages.flatMap(page => 'remove_file' in page ? [page.remove_file.path] : []);let warnings: string[] = nextCommand ? [`This preview covered ${previewed} of the ${held!.targets.length} selected held pages${opts.cursor ? ' after its cursor' : ''} (one window stops at ${HELD_WINDOW_PAGES} pages or ${HELD_WINDOW_BUDGET_MS / 1000} s); its hash and apply command cover only these. `+ `After applying this window (or deciding not to), preview the next one: ${nextCommand}`] : [];+ let undoneBySync: { recreated: number; removed: number } | null = null;if (recreated.length || removed.length) {const binding = await getWorktreeBinding(engine, sourceId);const root = join(binding!.local_path!, binding!.relative_path);if (!(await gitDurabilityPolicy(binding, root).catch(() => ({ durable: false }))).durable) {- if (recreated.length) warnings.push(`Git durability is off for ${sourceId}, so the apply leaves each recreated file uncommitted. Commit it afterwards (git -C ${root} add -- ${recreated.join(' ')} && git -C ${root} commit), or the next sync imports the committed deletion again.`);- if (removed.length) warnings.push(`Git durability is off for ${sourceId}, so the apply leaves each removed file's deletion uncommitted. Commit it afterwards (git -C ${root} add -- ${removed.join(' ')} && git -C ${root} commit), or the next sync holds the committed file again.`);+ if (removed.length) warnings.unshift(`The next sync undoes this repair unless the removals are committed: Git durability is off for ${sourceId}, so the apply leaves each removed file's deletion uncommitted (${removed.length} file(s)) and the next sync holds the committed file again. Commit them right after the apply: git -C ${root} add -- ${removed.join(' ')} && git -C ${root} commit`);+ if (recreated.length) warnings.unshift(`The next sync undoes this repair unless the recreated files are committed: Git durability is off for ${sourceId}, so the apply leaves each recreated file uncommitted (${recreated.length} file(s)) and the next sync imports their committed deletion again. Commit them right after the apply: git -C ${root} add -- ${recreated.join(' ')} && git -C ${root} commit`);+ undoneBySync = { recreated: recreated.length, removed: removed.length };}}let artifact: string | undefined;@@ -720,6 +722,7 @@ export const fileDriftRepair: RepairHandler = {return { items: pages.map((page, index) => item({ source_id: sourceId, slug: page.slug, artifact_digest: digest(page), selection }, index, hash, index === pages.length - 1, opts.prefer)),preview_hash: hash, residuals, listing, ...(warnings.length ? { warnings } : {}),details: { prefer: opts.prefer, ...(artifact ? { artifact } : {}),+ ...(undoneBySync ? { undone_by_next_sync_unless_committed: undoneBySync } : {}),...(held ? { window: { previewed, remaining, complete: remaining === 0, ...(nextCursor ? { next_cursor: nextCursor, next_command: nextCommand } : {}) } } : {}),pages: pages.map(page => 'soft_delete' in page ? { slug: page.slug, action: 'soft_delete', path: page.soft_delete.ghost.path, verb: fileDriftActionVerb('deleted', 'file_gone', 'file'), exceptions: page.exceptions }: 'remove_file' in page ? { slug: page.slug, action: 'remove_file', state: page.remove_file.state, path: page.remove_file.path, verb: fileDriftActionVerb('deleted', page.remove_file.state, 'database'), exceptions: page.exceptions }diff --git a/test/repair-file-drift-held-window-gbra133.test.ts b/test/repair-file-drift-held-window-gbra133.test.tsindex ebc3e12f52..60499e0a9e 100644--- a/test/repair-file-drift-held-window-gbra133.test.ts+++ b/test/repair-file-drift-held-window-gbra133.test.ts@@ -151,6 +151,9 @@ for (const backend of testBackends()) describe(`GBRA-133: a held file-drift prevconst slugs = await fileGone(f, 3);const preview = await run(f.sourceId, {});const hash = preview.preview_hash!;+ // Git durability is off in this fixture: the preview leads with what the next sync does to an uncommitted recreate.+ expect(preview.warnings![0]).toStartWith('The next sync undoes this repair unless the recreated files are committed');+ expect(preview.details).toMatchObject({ undone_by_next_sync_unless_committed: { recreated: 3, removed: 0 } });const command = `gbrain repair file-drift --source ${f.sourceId}`;const first = readArtifact(hash, command);expect([...first.keys()]).toEqual(slugs);