Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(repair): rows-behind never re-imports a no-record row where both sides moved
garrytana63f03d88445
diff --git a/docs/guides/repair.md b/docs/guides/repair.mdindex fcf1487a9a..57de82ce39 100644--- a/docs/guides/repair.md+++ b/docs/guides/repair.md@@ -1636,7 +1636,9 @@ Listed but left out of the set: rows with no import recordrecord whose older version equals the committed file, so the database movedsince and a re-import would replace that edit (`excluded:database_moved`, neverjoined; `gbrain repair file-drift --source <id> --slug <slug> --prefer database`-keeps it), rows whose+keeps it), rows with no import record whose page and file both moved since the+last state they shared (`excluded:both_moved`, never joined; `gbrain repair+file-drift --source <id> --slug <slug>` decides each one), rows whoseworking-tree file differs from the committed one (`excluded:worktree_differs`:commit the edit and sync), and rows whose import would keep page data thefile does not carry (`excluded:import_overlay`; resolve them withdiff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.tsindex b1e5e2bc4f..e1c863eb5b 100644--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@ -1452,7 +1452,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;{ since: '0.60.583.0', id: 'managed_sync_dry_run_counts_7087', text: 'A managed `gbrain sync --dry-run` now reports the files the run would add, modify, soft-delete and rename, and prints them as one line (#7087). It used to report the cursor\'s committed counts: zero before a run, or the previous run\'s counts when nothing had changed.' },// Convergence PR A (GST-1500, evidence-based baseline). since is stamped at the merge slot.{ since: '0.60.585.0', id: 'conversion_content_evidence_pr_a', text: '`gbrain sources canonical <id> --to git` now decides a page with no import record by content evidence instead of calling it database-ahead: an older version equal to the committed file adopts it, a page equal to an older committed blob lets Git win (`git_wins.by.file_moved`), and a page where both moved or nothing is shared is a new discard (`no_record_both_moved`, `no_record_no_evidence`) until the owner decides it. `--list-out <file>` writes the review list, `--decisions <file>` applies the decisions (bound into the hash), and `--approval-out` / `--approved` apply an approval across time: only items unchanged since the approval apply, and the rest returns as `git_conversion_delta` with counts. These files are written 0600 and refused inside a source checkout. A page that changes during the apply is held instead of overwritten, and a failed apply reports `recovery` (mode, commits, push, writes, rollback). See docs/guides/git-canonical.md#review-list-and-decisions.' },- { since: '0.60.585.0', id: 'git_gap_live_pages_pr_a', text: '`gbrain sources git-gap` and doctor `db_ahead_of_git` now report each source\'s live pages (`live_pages`) beside the pages read, and a scan the time budget stopped reads `PARTIAL, <read> of <live> live page(s) read` instead of a bare count. `sources git-gap` also reports `direction_evidence` for pages with no import record. `gbrain repair rows-behind` never re-imports a row with no import record whose older version equals its committed file (the database moved since), even with `--include-ambiguous`: it is listed `excluded:database_moved`.' },+ { since: '0.60.585.0', id: 'git_gap_live_pages_pr_a', text: '`gbrain sources git-gap` and doctor `db_ahead_of_git` now report each source\'s live pages (`live_pages`) beside the pages read, and a scan the time budget stopped reads `PARTIAL, <read> of <live> live page(s) read` instead of a bare count. `sources git-gap` also reports `direction_evidence` for pages with no import record. `gbrain repair rows-behind` never re-imports a row with no import record whose older version equals its committed file (the database moved since), even with `--include-ambiguous`: it is listed `excluded:database_moved`. Nor one whose page and file both moved since the last state they shared: it is listed `excluded:both_moved`, and `gbrain repair file-drift` decides it.' },{ since: '0.60.583.0', id: 'frontmatter_missing_source_dir_7889', text: 'A registered source whose directory does not exist is no longer reported frontmatter-clean (#7889). The frontmatter audit marks it `missing` (and lists it under `missing_sources`), and doctor `frontmatter_integrity` and `frontmatter_repairable` warn with the path and ask you to restore it or run `gbrain sources set-path <id> <path>`; they no longer call it clean or blame a timeout.' },];diff --git a/src/core/repair/rows-behind.ts b/src/core/repair/rows-behind.tsindex d293020624..125a2c57fa 100644--- a/src/core/repair/rows-behind.ts+++ b/src/core/repair/rows-behind.ts@@ -10,7 +10,7 @@* holds those bytes, so no file is written, and the import record is rewritten). `hold:<code>`: the import of the* checkpoint file is refused (or it is over the sync read bound), so the apply opens the hold sync would have opened, with* the code and message of the refusal the apply recomputes (not the one saved with the preview). Left out of the set and listed: rows with no import record (`excluded:unproven`, joined- * by --include-ambiguous; d4: one whose older version equals its committed file never joins, `excluded:database_moved`), rows whose working-tree file differs from the checkpoint blob (`excluded:worktree_differs`: an+ * by --include-ambiguous; d4: one whose older version equals its committed file never joins, `excluded:database_moved`, nor one whose content evidence says both sides moved, `excluded:both_moved`), rows whose working-tree file differs from the checkpoint blob (`excluded:worktree_differs`: an* uncommitted edit; commit it and sync), and rows whose import would keep page data the file does not carry* (`excluded:import_overlay`). `--apply --expect <hash>` applies exactly that set; a row whose page, checkpoint or file* changed since is `changed_since_preview`. Never runs on upgrade, from --all or from the remediation plan.@@ -111,6 +111,7 @@ export const rowsBehindRepair: RepairHandler = {// edit, so it never joins, flag or not.const evidence = row.record === 'none' ? row.evidence?.kind ?? 'no_evidence' : null;if (evidence === 'adopt_db_moved') { listing.push({ item: entry, class: 'excluded:database_moved', detail: `${describe(row)}; an older version of the page equals its committed file, so the database moved since and re-importing would replace that edit; gbrain repair file-drift --source ${sourceId} --slug ${row.slug} --prefer database keeps it` }); continue; }+ if (evidence === 'both_moved') { listing.push({ item: entry, class: 'excluded:both_moved', detail: `${describe(row)}; the page and its file both moved since the last state they shared, so re-importing would replace a database edit; gbrain repair file-drift --source ${sourceId} --slug ${row.slug} decides it per page` }); continue; }if (evidence !== null && !selection.include_ambiguous) { listing.push({ item: entry, class: 'excluded:unproven', detail: `${describe(row)}; no import record proves the database did not move since (content evidence: ${evidence}), so it joins only with --include-ambiguous` }); continue; }if (row.overlay) { listing.push({ item: entry, class: 'excluded:import_overlay', detail: `${describe(row)}; importing it would keep page data the file does not carry (tags, a withdrawal or sanitized text), so it is not re-imported here; gbrain repair file-drift --source ${sourceId} --slug ${row.slug} --prefer file resolves it` }); continue; }if (row.refusal) {diff --git a/test/rows-behind-checkpoint-8071.test.ts b/test/rows-behind-checkpoint-8071.test.tsindex 22b1f35b7f..99f7167e13 100644--- a/test/rows-behind-checkpoint-8071.test.ts+++ b/test/rows-behind-checkpoint-8071.test.ts@@ -201,20 +201,23 @@ for (const backend of testBackends()) describe(`[${backend}] #8071: rows behindexpect((await pageOf(engine, 'notes/c')).body).toContain('The committed body of notes/c.');}, { databaseUrl, setup }), 240_000);- test('d4: a row with no record whose database moved never joins, even with --include-ambiguous; one whose file moved does', () => managedBrain(async ({ engine, ctx, root }) => {+ test('d4: a row with no record whose database moved, alone or with its file, never joins, even with --include-ambiguous; one whose file moved does', () => managedBrain(async ({ engine, ctx, root }) => {expect((await performManagedSync(engine, OPTS)).status).toBe('first_sync');await putDatabaseOnly(engine, ctx, 'notes/a', 'A database-only edit of notes/a.');+ await putDatabaseOnly(engine, ctx, 'notes/c', 'A database-only edit of notes/c.');await seedBehind(engine, root, {'notes/a': { content: note('notes/a', 'The committed body of notes/a.'), record: 'none' },+ 'notes/c': { content: note('notes/c', 'A Git edit of notes/c.'), record: 'none' },'notes/d': { content: note('notes/d', 'The redacted body of notes/d.'), record: 'none' },});const scan = await scanRowsBehind(engine, 'default', { evidence: true });- expect(scan.unproven.map(row => [row.slug, row.evidence?.kind])).toEqual([['notes/a', 'adopt_db_moved'], ['notes/d', 'git_wins_file_moved']]);- expect(scan).toMatchObject({ live_pages: 5, unproven_by: { adopt_db_moved: 1, git_wins_file_moved: 1, both_moved: 0, no_evidence: 0 } });+ expect(scan.unproven.map(row => [row.slug, row.evidence?.kind])).toEqual([['notes/a', 'adopt_db_moved'], ['notes/c', 'both_moved'], ['notes/d', 'git_wins_file_moved']]);+ expect(scan).toMatchObject({ live_pages: 5, unproven_by: { adopt_db_moved: 1, git_wins_file_moved: 1, both_moved: 1, no_evidence: 0 } });const widened = await repair(engine, { includeAmbiguous: true });- expect(listing(widened)).toEqual([['default:notes/a', 'excluded:database_moved'], ['default:notes/d', 'reimport']]);+ expect(listing(widened)).toEqual([['default:notes/a', 'excluded:database_moved'], ['default:notes/c', 'excluded:both_moved'], ['default:notes/d', 'reimport']]);await repair(engine, { apply: true, expect: widened.preview_hash, includeAmbiguous: true });expect((await pageOf(engine, 'notes/a')).body).toContain('A database-only edit of notes/a.');+ expect((await pageOf(engine, 'notes/c')).body).toContain('A database-only edit of notes/c.');expect((await pageOf(engine, 'notes/d')).body).toContain('The redacted body of notes/d.');}, { databaseUrl, setup }), 240_000);