Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(persistence): a withheld page is stamped before its removal commit, so a crash between them never lets a mixed sync delete it (#7618)
garrytand4589dd49e9e
diff --git a/docs/designs/GIT_CANONICAL_MEMORY.md b/docs/designs/GIT_CANONICAL_MEMORY.mdindex ac76207a15..3ef3312b8d 100644--- a/docs/designs/GIT_CANONICAL_MEMORY.md+++ b/docs/designs/GIT_CANONICAL_MEMORY.md@@ -42,7 +42,7 @@ Some content deliberately has no file. In strict mode each such class is declare| Class | Handling ||---|---|-| Private, alias-private and lineage-private pages | Never committed. Making a page private is a door commit that removes its file, and the row stays database-only; making it public writes the file through the door. Content pushed before it became private stays in git history. |+| Private, alias-private and lineage-private pages | Never committed. Making a page private is a door commit that removes its file, and the row stays database-only; making it public writes the file through the door. Content pushed before it became private stays in git history. Conversion withholds a private page whose committed file differs from it; one whose committed file still equals it keeps that file in HEAD, as before the conversion (see Conversion). || `storage.db_only` prefixes and the derive-phase folders (`DERIVE_PHASE_DB_ONLY_DEFAULTS`, `src/core/storage-config.ts:425`) | The door refuses to commit under them and the indexer ignores them. || Paths the checkout's Git ignores (for example archived images) | Never committed and never given a Git effect, so they cannot park. || Database-only sources (no checkout, `sync.write_through=false`, unbound) | Outside strict mode; the whole source is the class. |@@ -83,13 +83,14 @@ G8a ships it as `gbrain sources canonical <source-id> --to git|mixed [--dry-run| Category | What the apply does ||---|---|| adopt (`database_ahead`, `undeclared_database_only`, `worktree_only`) | Writes the page's export view to its file and commits it through the door, up to 200 pages per commit. The worktree writer lock is taken per group and dropped between groups. No row changes: the bytes read back `equal`, and the strict pass after them rewrites none of those rows. A page with no import record whose row differs from HEAD counts as `database_ahead`, so it is adopted before the strict import could overwrite it. |-| declared | Nothing. A page under an ignored path is `git_ignored` and never gets a file or a Git effect. |+| declared | Nothing. A page under an ignored path is `git_ignored` and never gets a file or a Git effect. A declared page whose committed file reads back equal to it (`declared.committed_equal`) keeps that file in HEAD: a strict import of it changes nothing. Another declared page whose committed file differs is withheld when it is a privacy class, and a discard otherwise. |+| withhold (`file_committed`, `file_absent`) | G7a's private transition for a privacy-class page whose committed file differs from it, or whose recorded file a commit already removed. Group by group under the writer lock, a transaction stamps the class and moves `source_path` to `withheld_source_path`, then a committed file's removal goes through the door. The page stays live with its body unchanged. Stamped first, no sync reads the removal as a deletion; a crash before the commit leaves the file in HEAD and the rerun withholds it again. || git wins | The strict pass indexes the committed blob: Git moved and the database did not, Git deleted a page the database had not edited, a held deletion, or a held `file_drift` whose side is unknown and whose row already equals the committed file. || holds | Cleared, so Git's verdict runs over them. || parked effects | Retried once, or, for targets Git ignores, the page is stamped `git_ignored` (declared) in the same transaction that marks each parked target `declared: git_ignored`; the target stays as a record and the next preview no longer lists it. |-| discard | Refused: `git_conversion_blocked` names each category (both sides moved, a both-sides drift hold, an unknown-side drift hold whose row differs from the committed file, a database edit Git deleted, an uncommitted working-tree edit that differs from HEAD and the export, an ignored target (a fail-closed fallback when the ignore rules cannot be read), unparseable, unsafe path, segmented page, export mismatch, or a row a strict pass would overwrite unplanned). There is no override. |+| discard | Refused: `git_conversion_blocked` names each category (both sides moved, a both-sides drift hold, an unknown-side drift hold whose row differs from the committed file, a database edit Git deleted, an uncommitted working-tree edit that differs from HEAD and the export, an ignored target, a target whose ignore status Git cannot read (`ignore_status_unknown`: beyond a symlink, outside the checkout, a failed check; only that path is refused), unparseable, unsafe path, segmented page, export mismatch, or a row a strict pass would overwrite unplanned). There is no override. |-`--apply --expect <hash>` re-plans and refuses `preview_changed` on any difference, adopts group by group (a crash leaves the source mixed and the rerun preview lists only what is left), clears the holds, settles the parked effects, runs the full strict-equivalent pass, then sets `canonical: git` in the transaction that records the conversion. Writes can land between that pass and the flag, so it runs one genuine strict pass and previews again: the conversion is complete only when nothing is left; otherwise it reports `git_conversion_incomplete` with what remains and the source stays strict, because Git wins. `--to mixed` removes the flag and changes nothing else; Git keeps every door commit.+`--apply --expect <hash>` re-plans and refuses `preview_changed` on any difference, adopts group by group (a crash leaves the source mixed and the rerun preview lists only what is left), withholds group by group, rechecks what a strict pass would overwrite, clears the holds only after that recheck passes, settles the parked effects, runs the full strict-equivalent pass, then sets `canonical: git` in the transaction that records the conversion. Writes can land between that pass and the flag, so it runs one genuine strict pass and previews again: the conversion is complete only when nothing is left; otherwise it reports `git_conversion_incomplete` with what remains and the source stays strict, because Git wins. Where durability applies the apply pushes its door commits itself, after the groups and once at the end; a push that does not land leaves them local, the receipt says so, and the next page write's push-only effect sends them. The apply prints a progress line per phase and every 10 seconds on stderr, and SIGTERM, SIGINT or SIGHUP prints a partial report (phase, groups committed, items scanned, canonical state); `GBRAIN_MEMORY_TRACE` adds a memory trace. `--to mixed` removes the flag and changes nothing else; Git keeps every door commit.## The git-gap censusdiff --git a/scripts/bench/sync-pass-memory.ts b/scripts/bench/sync-pass-memory.tsindex f80379a5ea..867255c3b5 100644--- a/scripts/bench/sync-pass-memory.ts+++ b/scripts/bench/sync-pass-memory.ts@@ -287,5 +287,5 @@ if (!existsSync(dir)) mkdirSync(dir, { recursive: true });if (command === 'seed') await seed();else if (command === 'run') await run();else if (command === 'cli' || command === 'embed-seed') await cliRun();-else throw new Error('usage: seed | run');+else throw new Error('usage: seed | run | cli | embed-seed');process.exit(0);diff --git a/src/core/persistence/fault-points.ts b/src/core/persistence/fault-points.tsindex 0734ef1fde..00ac492334 100644--- a/src/core/persistence/fault-points.ts+++ b/src/core/persistence/fault-points.ts@@ -105,7 +105,7 @@ export type FaultPoint = `publication:${PublicationBoundary}` | `effect:${Effect// GBRA-161 PR 1b: as a managed generation member (an overwrite or retirement after its activation committed) is prepared.| 'generation:member'// G8a (git-conversion.ts): after a conversion group's door commit, and after the strict-equivalent pass, before the flag is set.- | 'conversion:group_committed' | 'conversion:before_flip';+ | 'conversion:group_committed' | 'conversion:withhold_committed' | 'conversion:before_flip';/*** `signal` (#6278, `consumer:preparing` only): the preparation's abort signal, so* a stalling hook can model both the reporter's cases: a preparer that honoursdiff --git a/src/core/persistence/git-conversion.ts b/src/core/persistence/git-conversion.tsindex db237ab051..03af8610bb 100644--- a/src/core/persistence/git-conversion.ts+++ b/src/core/persistence/git-conversion.ts@@ -611,11 +611,12 @@ async function adoptGroups(engine: BrainEngine, plan: GitConversionPlan, preview/*** G7a's private transition for each withheld page, mirrored from git-declared.ts `declareStrictPublication` (privacy- * branch), which runs only inside a publication: a committed file's removal goes through the door group by group under- * the writer lock, and the transaction after that commit stamps the class and moves `source_path` to- * `withheld_source_path`, so the strict pass never reads the removal as the deletion of a live page. A page whose file- * is already absent from HEAD only gets the stamp. A page whose revision or working tree moved since the preview stops- * the apply (preview_changed); after a crash between a commit and its stamp, the rerun preview lists the page as file_absent.+ * branch), which runs only inside a publication: group by group under the writer lock, a transaction stamps the class and+ * moves `source_path` to `withheld_source_path`, then the files' removal goes through the door. Stamped first, no sync+ * (the strict pass or a mixed one run before a rerun) reads the removal as the deletion of a live page; a crash between+ * the stamp and the commit leaves the file in HEAD, which a mixed sync holds and the rerun preview withholds again. A page+ * whose file is already absent from HEAD only gets the stamp. A page whose revision or working tree moved since the+ * preview stops the apply (preview_changed) before anything is stamped.*/async function withholdGroups(engine: BrainEngine, plan: GitConversionPlan, previewCommand: string,onGroup: (done: { pages: number; commits: number }) => void): Promise<GitConversionResult['withheld']> {@@ -645,10 +646,11 @@ async function withholdGroups(engine: BrainEngine, plan: GitConversionPlan, prevconst disk = diskBytes(join(root, item.path));if ((disk ? sha256(disk) : null) !== item.disk) throw previewChangedError(plan.preview.preview_hash, previewCommand);}+ await stamp(group);for (const item of group) removeConfined(root, join(root, item.path));const commit = await commitThroughDoor(root, group.map(item => ({ path: join(root, item.path), planned: null })), lock);if (commit) commits.push(commit);- await stamp(group);+ await faultPoint('conversion:withhold_committed', { sourceId: context.sourceId, round: start / CONVERSION_GROUP_MAX + 1 });} finally { await lock.release(); }onGroup({ pages: group.length, commits: commits.length });}diff --git a/test/git-canonical-conversion-g8a.test.ts b/test/git-canonical-conversion-g8a.test.tsindex 41ac959901..346ac0e56f 100644--- a/test/git-canonical-conversion-g8a.test.ts+++ b/test/git-canonical-conversion-g8a.test.ts@@ -13,7 +13,7 @@ import { execFileSync } from 'node:child_process';import { randomUUID } from 'node:crypto';import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';-import { join } from 'node:path';+import { dirname, join } from 'node:path';import type { BrainEngine } from '../src/core/engine.ts';import { operations } from '../src/core/operations.ts';import { withCoordinatedWrite } from '../src/core/persistence/context.ts';@@ -26,6 +26,7 @@ import { performManagedSync } from '../src/core/persistence/sync-run.ts';import { resolveManagedSyncContext } from '../src/core/persistence/sync-discovery.ts';import { ADOPTION_BATCH, applyGitConversion, applyMixedConversion, CONVERSION_GROUP_MAX, planGitConversion, planMixedConversion } from '../src/core/persistence/git-conversion.ts';import { renderFactsTable } from '../src/core/facts-fence.ts';+import { inlineExportMarkdown, readExportPage, readExportWithdrawals } from '../src/core/export-snapshot.ts';import { withSubmissionAuthority } from '../src/core/minions/submission-authority.ts';import { censusGitGap } from '../src/commands/sources-git-gap.ts';import { describeGitPreview, runSourcesCanonical } from '../src/commands/sources-canonical.ts';@@ -111,7 +112,7 @@ const wideSetup = ({ root }: { root: string }) => {};/*** Statements that read a page's export view: the per-page read (readExportPage), the batch read (readExportPages) and the- * fence normalization of either (overlayCanonicalBodies, overlayCanonicalBodiesBatch). Page snapshot reads by background+ * fence normalization of either (overlayCanonicalBodies, or readExportPages' batch normalization). Page snapshot reads by background* projection work normalize stored columns, never a parameter, so they do not match.*/const EXPORT_READ = /export_page AS MATERIALIZED|AS k\(id, source_id, slug\)|string_to_array\(\$1::text|AS t\(body, timeline, i\)/;@@ -154,6 +155,17 @@ async function committedPrivatePage(brain: ManagedBrain): Promise<void> {expect((await pageRow(engine, 'notes/private')).source_path).toBe('notes/private.md');}+/** setup, with a bare tracking remote beside the checkout whose pre-receive hook rejects every push. */+const remoteOf = (root: string) => join(dirname(root), 'remote.git');+const closedRemoteSetup = (brain: { root: string }) => {+ setup(brain);+ execFileSync('git', ['init', '-q', '--bare', remoteOf(brain.root)]);+ git(brain.root, 'remote', 'add', 'origin', remoteOf(brain.root));+ git(brain.root, 'push', '-q', 'origin', 'HEAD:refs/heads/main');+ git(brain.root, 'branch', '--set-upstream-to=origin/main');+ writeFileSync(join(remoteOf(brain.root), 'hooks', 'pre-receive'), '#!/bin/sh\necho "pushes are closed" >&2\nexit 1\n', { mode: 0o755 });+};+/** That private page, edited in the database, whose file is then removed by hand: sync holds it (file_drift, deleted). */async function privateRemovedByHand(brain: ManagedBrain): Promise<void> {const { engine, root } = brain;@@ -252,8 +264,17 @@ for (const backend of testBackends()) describe(`[${backend}] G8a: sources canoniconst base = git(root, 'rev-parse', 'HEAD');const { preview } = await planGitConversion(engine, 'default');expect(preview).toMatchObject({ git_wins: { by: { held_drift_unknown: 0 } }, discard: { count: 1, by: { held_drift_unknown_differs: 1 }, sample: ['notes/drift.md'] } });+ const before = await revisions(engine), status = git(root, 'status', '--porcelain');await expect(applyGitConversion(engine, 'default', preview.preview_hash, PROCESSING)).rejects.toMatchObject({ code: 'git_conversion_blocked', detail: 'held_drift_unknown_differs' });expect(git(root, 'rev-parse', 'HEAD')).toBe(base);+ expect(git(root, 'status', '--porcelain')).toBe(status);+ // Nothing the plan placed moved: the declared pages stay live with no file, and Git's verdicts are not applied.+ expect(await revisions(engine)).toEqual(before);+ expect((await page(engine, 'notes/secret'))!.deleted).toBe(false);+ expect(existsSync(join(root, 'notes/secret.md'))).toBe(false);+ expect(existsSync(join(root, 'scratch/ignored.md'))).toBe(false);+ expect((await page(engine, 'notes/removed'))!.deleted).toBe(false);+ expect((await page(engine, 'notes/gitmoved'))!.body).not.toContain('The committed edit of notes/gitmoved.');expect(await strict(engine)).toBe(false);expect(await holds(engine)).toEqual(['notes/drift.md file_drift', 'notes/removed.md file_drift']);expect((await page(engine, 'notes/drift'))!.body).toContain('Written to the database alone: notes/drift.');@@ -371,6 +392,13 @@ for (const backend of testBackends()) describe(`[${backend}] G8a: sources canoniexpect(preview.adopt).toMatchObject({ count: WIDE - 1, by: { undeclared_database_only: WIDE - 1 } });expect(preview.discard).toMatchObject({ count: 1, by: { ignore_status_unknown: 1, ignored_target: 0 }, sample: ['link/beyond.md'], detail: { ignore_status_unknown: { symlink: 1 } } });expect(describeGitPreview(preview)).toContain('ignore_status_unknown symlink 1');+ const base = git(root, 'rev-parse', 'HEAD'), before = await revisions(engine);+ await expect(applyGitConversion(engine, 'default', preview.preview_hash, PROCESSING)).rejects.toMatchObject({ code: 'git_conversion_blocked', detail: 'ignore_status_unknown' });+ expect(git(root, 'rev-parse', 'HEAD')).toBe(base);+ expect(existsSync(join(root, 'real/beyond.md'))).toBe(false);+ expect(existsSync(join(root, 'dbonly'))).toBe(false);+ expect(await revisions(engine)).toEqual(before);+ expect(await strict(engine)).toBe(false);}, { databaseUrl, setup }), 300_000);test('#7618: a hold at a declared page\'s path is judged by the strict verdict, so a page Git would overwrite is a discard', () => managedBrain(async brain => {@@ -508,6 +536,183 @@ for (const backend of testBackends()) describe(`[${backend}] G8a: sources canoniexpect((await page(engine, 'notes/same'))!.body).toContain('A late database edit.');}, { databaseUrl, setup }), 180_000);+ /**+ * Value: protects=a private page's uncommitted edit to its committed file is never removed by the withhold; fails_when=the+ * worktree==='modified' guard in planGitConversion's declared case is dropped (the withhold's disk check would match the+ * edited bytes and remove them); why_new=the withhold tests use clean or absent files only; seam=none; no_claim=none beyond protects+ */+ test('#7618: a private page whose committed file holds an uncommitted edit is an uncommitted_edit discard, and the edit stays', () => managedBrain(async brain => {+ const { engine, root } = brain;+ await committedPrivatePage(brain);+ await databaseOnlyEdit(engine, 'notes/private', 'A private note, edited in the database.');+ const edit = PRIVATE('notes/private', 'An uncommitted edit of the private note.');+ writeFileSync(join(root, 'notes/private.md'), edit);+ const before = await pageRow(engine, 'notes/private'), base = git(root, 'rev-parse', 'HEAD');+ const { preview } = await planGitConversion(engine, 'default');+ expect(preview).toMatchObject({ declared: { by: { private: 1 } }, withhold: { count: 0 },+ discard: { count: 1, by: { uncommitted_edit: 1 }, sample: ['notes/private.md'], detail: { uncommitted_edit: { modified: 1 } } } });+ await expect(applyGitConversion(engine, 'default', preview.preview_hash, PROCESSING)).rejects.toMatchObject({ code: 'git_conversion_blocked', detail: 'uncommitted_edit' });+ expect(readFileSync(join(root, 'notes/private.md'), 'utf8')).toBe(edit);+ expect(git(root, 'rev-parse', 'HEAD')).toBe(base);+ expect(atHead(root, 'notes/private.md')).toBe('notes/private.md');+ expect(await pageRow(engine, 'notes/private')).toEqual(before);+ expect(await strict(engine)).toBe(false);+ }, { databaseUrl, setup }), 180_000);++ /**+ * Value: protects=the withhold never removes a file or stamps a row that moved after the preview; fails_when=assertUnchanged+ * or the disk-hash check in withholdGroups is removed; why_new=preview_changed is otherwise tested only for a stale hash+ * before any write; seam=none; no_claim=the writer_busy and git_target_unsafe branches of withholdGroups+ */+ test('#7618: the withhold refuses preview_changed when the private page or its file moved after the preview, and removes nothing', async () => {+ for (const moved of ['page', 'file'] as const) await managedBrain(async brain => {+ const { engine, root } = brain;+ await committedPrivatePage(brain);+ await databaseOnlyEdit(engine, 'notes/private', 'A private note, edited in the database.');+ await databaseOnlyEdit(engine, 'notes/ahead', 'Written to the database alone.');+ const { body: _body, ...before } = await pageRow(engine, 'notes/private');+ const base = git(root, 'rev-parse', 'HEAD');+ const { preview } = await planGitConversion(engine, 'default');+ expect(preview).toMatchObject({ adopt: { count: 1 }, withhold: { count: 1, by: { file_committed: 1 } }, discard: { count: 0 } });+ const late = PRIVATE('notes/private', 'A late edit on disk.');+ // The adoption group commits first; the private page or its file moves before the withhold reaches it.+ installFaultHook(async point => {+ if (point !== 'conversion:group_committed') return;+ if (moved === 'page') await databaseOnlyEdit(engine, 'notes/private', 'A late database edit.');+ else writeFileSync(join(root, 'notes/private.md'), late);+ });+ try {+ await expect(applyGitConversion(engine, 'default', preview.preview_hash, PROCESSING)).rejects.toMatchObject({ code: 'preview_changed' });+ } finally { installFaultHook(undefined); }+ expect(conversionCommits(root, base)).toEqual([{ subject: expect.any(String), paths: ['notes/ahead.md'] }]);+ expect(atHead(root, 'notes/private.md')).toBe('notes/private.md');+ if (moved === 'file') expect(readFileSync(join(root, 'notes/private.md'), 'utf8')).toBe(late);+ else expect(existsSync(join(root, 'notes/private.md'))).toBe(true);+ const { body, ...after } = await pageRow(engine, 'notes/private');+ expect(after).toEqual(before);+ expect(body).toContain(moved === 'page' ? 'A late database edit.' : 'A private note, edited in the database.');+ expect(await strict(engine)).toBe(false);+ }, { databaseUrl, setup });+ }, 360_000);++ test('#7617: a database-only page whose untracked file equals its export adopts as worktree_only; a refused apply leaves the file uncommitted', () => managedBrain(async brain => {+ const { engine, root } = brain;+ expect((await performManagedSync(engine, OPTS)).status).toBe('first_sync');+ await databaseOnlyPage(brain, 'notes/untracked', note('notes/untracked', 'Only in the database, and untracked on disk.'));+ const [key] = await engine.executeRaw<{ id: string }>("SELECT id::text FROM pages WHERE source_id='default' AND slug='notes/untracked'");+ const bytes = inlineExportMarkdown(await readExportPage(engine, { id: key!.id, source_id: 'default', slug: 'notes/untracked' }, await readExportWithdrawals(engine, 'default')));+ writeFileSync(join(root, 'notes/untracked.md'), bytes);+ const base = git(root, 'rev-parse', 'HEAD'), before = await revisions(engine);+ const { preview } = await planGitConversion(engine, 'default');+ expect(preview).toMatchObject({ adopt: { count: 1, by: { worktree_only: 1, database_ahead: 0, undeclared_database_only: 0 }, sample: ['notes/untracked.md'] }, discard: { count: 0 } });+ await expect(applyGitConversion(engine, 'default', 'stale', PROCESSING)).rejects.toMatchObject({ code: 'preview_changed' });+ expect(git(root, 'rev-parse', 'HEAD')).toBe(base);+ expect(git(root, 'status', '--porcelain')).toBe('?? notes/untracked.md');+ expect(readFileSync(join(root, 'notes/untracked.md'), 'utf8')).toBe(bytes);+ expect(await revisions(engine)).toEqual(before);+ expect(await strict(engine)).toBe(false);+ expect(await applyGitConversion(engine, 'default', preview.preview_hash, PROCESSING)).toMatchObject({ status: 'converted', committed: { groups: 1, pages: 1 } });+ expect(conversionCommits(root, base)).toEqual([{ subject: expect.any(String), paths: ['notes/untracked.md'] }]);+ expect(git(root, 'status', '--porcelain')).toBe('');+ expect(readFileSync(join(root, 'notes/untracked.md'), 'utf8')).toBe(bytes);+ expect((await revisions(engine))['notes/untracked']).toBe(before['notes/untracked']);+ }, { databaseUrl, setup }), 180_000);++ test('#7618: a file_absent withhold refuses preview_changed when the private page moved after the preview, and stamps nothing', () => managedBrain(async brain => {+ const { engine, root } = brain;+ await privateRemovedByHand(brain);+ await databaseOnlyEdit(engine, 'notes/ahead', 'Written to the database alone.');+ const { body: _body, ...before } = await pageRow(engine, 'notes/private');+ expect(before).toMatchObject({ source_path: 'notes/private.md', withheld: null });+ const base = git(root, 'rev-parse', 'HEAD');+ const { preview } = await planGitConversion(engine, 'default');+ expect(preview).toMatchObject({ adopt: { count: 1 }, withhold: { count: 1, by: { file_absent: 1 } }, discard: { count: 0 } });+ // The adoption group commits first; the private page moves before the withhold reaches it.+ installFaultHook(async point => { if (point === 'conversion:group_committed') await databaseOnlyEdit(engine, 'notes/private', 'A late database edit.'); });+ try {+ await expect(applyGitConversion(engine, 'default', preview.preview_hash, PROCESSING)).rejects.toMatchObject({ code: 'preview_changed' });+ } finally { installFaultHook(undefined); }+ expect(conversionCommits(root, base)).toEqual([{ subject: expect.any(String), paths: ['notes/ahead.md'] }]);+ const { body, ...after } = await pageRow(engine, 'notes/private');+ expect(after).toEqual(before);+ expect(body).toContain('A late database edit.');+ expect(await holds(engine)).toEqual(['notes/private.md file_drift']);+ expect(await strict(engine)).toBe(false);+ }, { databaseUrl, setup }), 180_000);++ test('#7618: a hold no category places, whose strict verdict loses nothing, is cleared by a converting apply', () => managedBrain(async brain => {+ const { engine, root } = brain;+ expect((await performManagedSync(engine, OPTS)).status).toBe('first_sync');+ writeFileSync(join(root, 'notes/fresh.md'), note('notes/fresh', 'The committed body of notes/fresh.'));+ git(root, 'add', 'notes/fresh.md'); git(root, 'commit', '-qm', 'a fresh note');+ const [{ incarnation }] = await engine.executeRaw<{ incarnation: string }>("SELECT incarnation::text AS incarnation FROM sources WHERE id='default'");+ await engine.transaction(tx => writeGitHold(tx, { source_id: 'default', incarnation, path: 'notes/fresh.md', source_path: 'notes/fresh.md', slug: 'notes/fresh',+ page_id: null, code: 'concurrent_write', message: 'Held while another writer moved the page.', upstream_version: null, observed_at: new Date().toISOString(),+ run_id: 'run-1', mode: 'managed', meta: { recovery_version: 1 } }));+ const { preview } = await planGitConversion(engine, 'default');+ expect(preview).toMatchObject({ holds: { count: 1, unplaced: { count: 1, by: { concurrent_write: 1 } } }, discard: { count: 0 }, index: { imports: 1, deletes: 0 } });+ expect(await applyGitConversion(engine, 'default', preview.preview_hash, PROCESSING)).toMatchObject({ status: 'converted', holds_cleared: 1, after: { remaining: 0 } });+ expect(await holds(engine)).toEqual([]);+ expect(await strict(engine)).toBe(true);+ expect((await page(engine, 'notes/fresh'))!.body).toContain('The committed body of notes/fresh.');+ }, { databaseUrl, setup }), 180_000);++ /**+ * Value: protects=a private page whose removal commit landed is never deleted by the mixed sync that runs before the rerun;+ * fails_when=withholdGroups stamps the row after the door commit instead of before it (a crash in between leaves a live+ * row recording a file a commit removed, which a mixed sync deletes); why_new=the crash tests cover adoption groups only;+ * seam=the conversion:withhold_committed fault point; no_claim=a crash inside commitThroughDoor itself+ */+ test('#7618: a crash after a withhold commit leaves the private page live through a mixed sync, and the rerun completes', () => managedBrain(async brain => {+ const { engine, root } = brain;+ await committedPrivatePage(brain);+ // A commit sync has not read: the row still matches its import, so a mixed sync would delete a live row whose file a commit removed.+ writeFileSync(join(root, 'notes/private.md'), PRIVATE('notes/private', 'A committed edit of the private note.'));+ git(root, 'commit', '-qam', 'edit the private note');+ const before = await pageRow(engine, 'notes/private'), base = git(root, 'rev-parse', 'HEAD');+ const { preview } = await planGitConversion(engine, 'default');+ expect(preview).toMatchObject({ withhold: { count: 1, by: { file_committed: 1 } }, discard: { count: 0 } });+ installFaultHook(point => { if (point === 'conversion:withhold_committed') throw new Error('crash after the withhold commit'); });+ try { await expect(applyGitConversion(engine, 'default', preview.preview_hash, PROCESSING)).rejects.toThrow('crash after the withhold commit'); }+ finally { installFaultHook(undefined); }+ expect(conversionCommits(root, base)).toEqual([{ subject: expect.any(String), paths: ['notes/private.md'] }]);+ expect(await strict(engine)).toBe(false);+ await performManagedSync(engine, OPTS);+ expect(await pageRow(engine, 'notes/private')).toEqual({ body: before.body, deleted: false, source_path: null, withheld: 'notes/private.md', reason: 'private' });+ const rerun = (await planGitConversion(engine, 'default')).preview;+ expect(rerun).toMatchObject({ withhold: { count: 0 }, discard: { count: 0 } });+ expect(await applyGitConversion(engine, 'default', rerun.preview_hash, PROCESSING)).toMatchObject({ status: 'converted', after: { remaining: 0 } });+ expect(await strict(engine)).toBe(true);+ expect(await pageRow(engine, 'notes/private')).toMatchObject({ body: before.body, deleted: false, withheld: 'notes/private.md' });+ }, { databaseUrl, setup }), 180_000);++ /**+ * Value: protects=the text preview and receipt name the withheld page and a push that did not land, with the command that+ * pushes it; fails_when=describeGitPreview or describeResult drops the Withhold line, the withheld count or the push-pending+ * line; why_new=only JSON fields and the By-cause line were asserted; seam=none; no_claim=wording beyond the asserted fragments+ */+ test('#7618/#7644: the text preview and receipt name the withheld page and a pending push', () => managedBrain(async brain => {+ const { engine } = brain;+ await engine.executeRaw("UPDATE persistence_host_bindings SET git_durability='enabled'");+ await committedPrivatePage(brain);+ await databaseOnlyEdit(engine, 'notes/private', 'A private note, edited in the database.');+ const text = async (args: string[]) => {+ const lines: string[] = [];+ const log = console.log, write = process.stderr.write, priorExitCode = process.exitCode;+ console.log = (line: unknown) => { lines.push(String(line)); };+ process.stderr.write = (() => true) as typeof process.stderr.write;+ try { await runSourcesCanonical(engine, args); } finally { console.log = log; process.stderr.write = write; _resetCliExitVerdictForTests(); process.exitCode = priorExitCode ?? 0; }+ return lines.join('\n');+ };+ const dry = await text(['default', '--to', 'git', '--dry-run']);+ expect(dry).toContain("Withhold (a private page's committed file is removed through the door, 1 commit(s), and its row withholds its origin): 1 (file_committed 1).\n notes/private.md");+ const { preview } = await planGitConversion(engine, 'default');+ const applied = await text(['default', '--to', 'git', '--apply', '--expect', preview.preview_hash, '--no-embed', '--no-extract']);+ expect(applied).toContain('Source default is git-canonical: 0 page(s) committed in 0 door commit(s), 1 private page(s) withheld (1 removal commit(s))');+ expect(applied).toContain("Push pending (git_push_unavailable): The conversion's door commits are committed locally");+ expect(applied).toContain(`gbrain git commit-push --push-only --path ${brain.root}`);+ }, { databaseUrl, setup: closedRemoteSetup }), 180_000);+test('work that lands after the strict-equivalent pass leaves the source strict and reports incomplete', () => managedBrain(async brain => {const { engine, root } = brain;expect((await performManagedSync(engine, OPTS)).status).toBe('first_sync');