Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: adversarial review fixes
garrytan976a67124005
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex acd2fe657e..88a215f46a 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -12,14 +12,14 @@ identifiers and attribution are available in the pre-removal Git revision## [Unreleased]-**A file Git puts back after sync deleted its page brings the page back, and the retention purge never deletes a committed file.** On a managed brain, a commit that removed a Markdown file made sync soft-delete its page. When the same file came back (a `git revert`, switching to a branch and back, a collaborator's delete-then-restore, a file missing from disk for one working-tree sync), sync settled the path as "deleted, file unchanged" and left the page out of get, search and recall while `gbrain sync status` said synced. `gbrain pages purge-deleted --yes` then deleted the restored file from the checkout. Sync now tells a tombstone it made from a missing file apart from a person's delete and imports the file over it, so the same page comes back; a brain an older version left in that state heals on its next sync. The purge leaves a file committed at the source's last synced commit or at HEAD alone, unless a person deleted the page and the file stayed only because another page shared it. A page purge also stops leaving timeline text in the write journal.+**A file Git puts back after sync deleted its page brings the page back, and the retention purge never deletes a committed file.** On a managed brain, a commit that removed a Markdown file made sync soft-delete its page. When the same file came back (a `git revert`, switching to a branch and back, a collaborator's delete-then-restore, a file missing from disk for one working-tree sync), sync settled the path as "deleted, file unchanged" and left the page out of get, search and recall while `gbrain sync status` said synced. `gbrain pages purge-deleted --yes` then deleted the restored file from the checkout. Sync now tells a tombstone it made from a missing file apart from a person's delete and imports the file over it, so the same page comes back; a brain an older version left in that state heals on its next sync. The purge leaves a file committed at the source's last synced commit or at HEAD alone, unless a person's delete of the page never removed the file (for example because another page shared it). A page purge also stops leaving timeline text in the write journal.### Itemized changes- `src/core/persistence/sync-pass.ts`, `sync-classify.ts`: the level read marks a tombstone a managed sync deletion made (its open `sync-delete-tombstone` record or uncompacted `managed_sync_delete` receipt); once its file is back with clean committed bytes it classifies `import` (the import revives the same page row), and a `file_drift` hold an older version raised over it re-runs. A person's tombstone keeps `deleted_same` / `deleted_edited`.- `src/core/persistence/sync-pass-run.ts`: the selection fingerprint carries `sync_deleted_restore`, so the first sync after the upgrade reads the whole source once and brings back pages left deleted beside their file.-- `src/core/persistence/page-prepare.ts`, `sync-markers.ts`: a retention purge of a tombstone whose file is committed at the source's `last_commit` or HEAD removes no file: a sync-made tombstone defers (`revision_conflict`) to the sync that restores it; any other is purged database-only (`write_through.skipped: committed_file`), except a person's delete that kept the file only because another live page shared it (`write_through.skipped: shared_origin`), which still removes the file once the tombstone owns it alone. An unreadable checkout counts as committed; a checkout with no commit yet does not. Repo-less sources are unchanged.-- `src/core/persistence/page-purge.ts`: a page purge redacts the `entry` and `bullet` text of the page's `add_timeline_entry` receipts, compacted ones included.+- `src/core/persistence/page-prepare.ts`, `sync-markers.ts`: a retention purge of a tombstone whose file is committed at the source's `last_commit` or HEAD removes no file: a sync-made tombstone defers (`revision_conflict`) to the sync that restores it; any other is purged database-only (`write_through.skipped: committed_file`), except a person's delete that made the tombstone and never removed its file (`write_through.written: false`, for example because another live page shared it), which still has the purge finish that removal. Publication re-checks, so a file committed while the purge was prepared is kept too. A sync-made tombstone defers only while its file is on disk; off disk (working-tree mode) it is purged database-only without a deletion marker, so the file's later return imports it. An unreadable checkout counts as committed; a checkout with no commit yet does not. Repo-less sources are unchanged.+- `src/core/persistence/page-purge.ts`: a page purge redacts the `entry` summary and source and the `bullet` text of the page's `add_timeline_entry` receipts, compacted ones included (up to 10,000 per page; past that `journal_sweep.complete` is false).- Tests: `test/sync-restored-file-purge.test.ts` (PGLite and Postgres), `test/sync-classify-6712.test.ts`, `test/purge-eval-fixes.test.ts`.## [0.60.625.0] - 2026-11-09diff --git a/plugin-variants/gbrain-coding/skills/data-loss-gate/SKILL.md b/plugin-variants/gbrain-coding/skills/data-loss-gate/SKILL.mdindex 6697effde6..e3e3fcfe80 100644--- a/plugin-variants/gbrain-coding/skills/data-loss-gate/SKILL.md+++ b/plugin-variants/gbrain-coding/skills/data-loss-gate/SKILL.md@@ -93,7 +93,7 @@ Brain / database level (gbrain-specific):first; the command itself asks (exit 3 without a terminal) and runs with`--yes` only after the user agrees. It keeps a file committed at the source'slast synced commit or at HEAD (the page waits or goes database-only), unless a- person deleted the page and the file stayed only because another page shared it.+ person's delete of the page never removed the file (e.g. another page shared it).- **Source removal** — `gbrain sources remove <id>` deletes the source ANDevery page in it. The `--confirm-destructive` flag does not substitute forthe card. A managed removal deletes pages in committed batches: one thatdiff --git a/plugin/skills/data-loss-gate/SKILL.md b/plugin/skills/data-loss-gate/SKILL.mdindex 6697effde6..e3e3fcfe80 100644--- a/plugin/skills/data-loss-gate/SKILL.md+++ b/plugin/skills/data-loss-gate/SKILL.md@@ -93,7 +93,7 @@ Brain / database level (gbrain-specific):first; the command itself asks (exit 3 without a terminal) and runs with`--yes` only after the user agrees. It keeps a file committed at the source'slast synced commit or at HEAD (the page waits or goes database-only), unless a- person deleted the page and the file stayed only because another page shared it.+ person's delete of the page never removed the file (e.g. another page shared it).- **Source removal** — `gbrain sources remove <id>` deletes the source ANDevery page in it. The `--confirm-destructive` flag does not substitute forthe card. A managed removal deletes pages in committed batches: one thatdiff --git a/skills/data-loss-gate/SKILL.md b/skills/data-loss-gate/SKILL.mdindex f333d1e2b0..3bb82c7c7c 100644--- a/skills/data-loss-gate/SKILL.md+++ b/skills/data-loss-gate/SKILL.md@@ -92,7 +92,7 @@ Brain / database level (gbrain-specific):first; the command itself asks (exit 3 without a terminal) and runs with`--yes` only after the user agrees. It keeps a file committed at the source'slast synced commit or at HEAD (the page waits or goes database-only), unless a- person deleted the page and the file stayed only because another page shared it.+ person's delete of the page never removed the file (e.g. another page shared it).- **Source removal** — `gbrain sources remove <id>` deletes the source ANDevery page in it. The `--confirm-destructive` flag does not substitute forthe card. A managed removal deletes pages in committed batches: one thatdiff --git a/skills/skills.lock.json b/skills/skills.lock.jsonindex 2f5e7139dc..f84794187c 100644--- a/skills/skills.lock.json+++ b/skills/skills.lock.json@@ -72,7 +72,7 @@"daily-task-manager/SKILL.md": "e93264a83b5fd0a19b2f06a322b3a4ad92d418f6a968c1cd51f4bea79cbca4d9","daily-task-manager/routing-eval.jsonl": "e98b2592e65c26952242436a960d8b2061e375b269004a18c230cbcf1d692ff9","daily-task-prep/SKILL.md": "5ea839012b48761ed8d7a9bab056a2566587d6f7fe044e3907d77b20f8eec5ac",- "data-loss-gate/SKILL.md": "99ab81bd998f5e5f7cb203d79a9ba16d852c3764a3a9ebb6e8296692284c2fd7",+ "data-loss-gate/SKILL.md": "8628ca47c450c8e4563565a1dfa264db8b909161c6bbb9b9a0ead124e4870dad","data-loss-gate/routing-eval.jsonl": "825358a5600641061a02b25097cd84c1c28bb0359a7608a10b9f25f661bd88f9","data-research/SKILL.md": "39f9648a21a7074d6ad7db789e93e6d7085449a6cdaffacf8b1660eb68636b9d","db-repair/SKILL.md": "87a34fe18812f3b6ec37381ae69c205e30747300098ebe3fe41f8460d0ba8346",diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.tsindex f914d9f366..b5a11ad64a 100644--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@ -1494,7 +1494,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;{ since: '0.60.622.0', id: 'purge_cancels_deferred_write_gst1602', text: 'With `persistence.refresh_barrier` on, `gbrain forget <id> --purge` no longer refuses `purge_blocked_pending_recovery` while a write deferred behind a refresh holds the claim in its staged body: the deferred write was never claimed, so the purge cancels it with `purged_content`, as it does a queued one, and removes the content at once instead of up to 15 minutes later.' },{ since: '0.60.623.0', id: 'owner_reads_private_gst2059', text: 'A brain can now name its owner: `gbrain access owner set <member>` (config `access.owner_member`, an enabled member). Every remote credential or stdio server bound to that member reads the whole brain, `visibility: private` pages, privacy-alias pages (`access: private`, ...), derived and pinned-question pages included, through `get_page`, `search`, `query`, `recall` and the other page reads in the sources its grant reads, and `recall` returns its private facts. `readable_by` and folder rules still bind it, and it is not relaxed when it speaks for a shared-room audience. A page the owner\'s credential creates in `default` through `put_page` is not kept to the owner (no `readable_by: [member:<id>]`). Other members, unbound and public callers are unchanged. `_meta.access.relaxation` reads `owner` for such a call, and `gbrain access check --token <name>` reports it. `gbrain repair private-labels` (named runs only) previews the `access: private` labels stamped on ordinary pages with counts per category, keeps real restrictions, and clears the rest in reviewed batches (`--apply --expect <hash>`), recording each change so `--class restore` can put it back. The bulk-ingestion page template no longer writes an `access:` line; what each designation means is in docs/guides/access-designations.md.' },{ since: '0.60.625.0', id: 'sync_restored_file_gst2201', text: 'On a managed source, a page sync deleted because its file was gone comes back on the next sync once the file returns (a `git revert`, a branch or detached checkout and back, a later commit that re-adds it with the same or edited bytes, a file missing from disk for one working-tree sync). It used to stay deleted (`deleted_same`, or a `file_drift` hold whose suggested fix removed the file) while `gbrain sync status` said synced. The first sync after the upgrade reads the whole source once, so pages an older version left deleted beside their file come back and such holds clear without a manual step. A page a person deleted keeps its deletion.' },- { since: '0.60.625.0', id: 'purge_keeps_committed_file_gst2201', text: 'The retention purge (the autopilot purge phase, the `purge` job and `gbrain pages purge-deleted`) never removes a soft-deleted page\'s file that is committed at its source\'s last synced commit or at HEAD. A page sync deleted whose file is back is left for the sync that restores it (counted as deferred); any other such page is removed database-only (receipt `write_through.skipped: committed_file`) and its file stays. A page whose file is gone, or a person\'s delete that kept the file only because another page shared it, purges as before. A page purge (`gbrain delete <slug> --purge` and the retention purge) now also redacts the timeline text the page\'s `add_timeline_entry` receipts kept (`entry`, `bullet`), compacted ones included.' },+ { since: '0.60.625.0', id: 'purge_keeps_committed_file_gst2201', text: 'The retention purge (the autopilot purge phase, the `purge` job and `gbrain pages purge-deleted`) never removes a soft-deleted page\'s file that is committed at its source\'s last synced commit or at HEAD. A page sync deleted whose file is back is left for the sync that restores it (counted as deferred); any other such page is removed database-only (receipt `write_through.skipped: committed_file`) and its file stays. A page whose file is gone, or a person\'s delete that never removed its file (for example because another page shared it), purges as before. A page purge (`gbrain delete <slug> --purge` and the retention purge) now also redacts the timeline text the page\'s `add_timeline_entry` receipts kept (the entry\'s summary and source, `bullet`), compacted ones included.' },];/** The newest disclosed change's release: the notice id moves only when a release adds rows. */diff --git a/src/core/persistence/page-prepare.ts b/src/core/persistence/page-prepare.tsindex e83a09c716..a07b091237 100644--- a/src/core/persistence/page-prepare.ts+++ b/src/core/persistence/page-prepare.ts@@ -661,12 +661,15 @@ async function prepareDeletePageMutation(engine: BrainEngine, row: WriteRequest,}// GST-2201: a retention purge never removes a file committed at the source's last commit or at HEAD. A tombstone sync made// from the file's absence waits for the sync that restores it; a person's tombstone is removed database-only and the file stays.- // A person's delete that kept the file only because another live page shared it (`write_through.skipped: shared_origin`)- // still removes the file once the tombstone owns it alone.- const committedFile = purge && p.retention === true && snapshot.page.deleted_at != null && !!file && !shared && excludedPath === null- && await originCommitted(engine, row.source_id, snapshot.page.source_path)- && (await engine.executeRaw(`SELECT 1 FROM persistence_requests r WHERE r.source_id=$1 AND r.slug=$2 AND (r.page_id IS NULL OR r.page_id=$3) AND r.operation='delete_page'- AND r.state='committed' AND r.outcome->'write_through'->>'skipped'='shared_origin' LIMIT 1`, [row.source_id, row.slug, snapshot.page.id])).length === 0;+ // A person's delete that made this tombstone and never removed its file (`write_through.written: false`: another live page+ // shared it, the source was unbound, ...) still has the purge finish that removal. Publication re-checks, so a commit made after preparation is kept too.+ const retentionFile = purge && p.retention === true && snapshot.page.deleted_at != null && !!file && !shared && excludedPath === null;+ const committedNow = async (exec: BrainEngine) => await originCommitted(exec, row.source_id, snapshot.page.source_path)+ && (await exec.executeRaw(`SELECT 1 FROM persistence_requests r JOIN pages p ON p.id=$3 WHERE r.source_id=$1 AND r.slug=$2 AND (r.page_id IS NULL OR r.page_id=$3)+ AND r.operation='delete_page' AND r.state='committed' AND r.outcome->'write_through'->>'written'='false' AND NOT ${syncDeleteOrigin('p')}+ AND NOT EXISTS (SELECT 1 FROM persistence_requests l WHERE l.source_id=r.source_id AND l.slug=r.slug AND l.state='committed' AND l.sequence > r.sequence+ AND l.operation IN ('restore_page', 'delete_page')) LIMIT 1`, [row.source_id, row.slug, snapshot.page.id])).length === 0;+ const committedFile = retentionFile && await committedNow(engine);let keepOrigin = false;if (committedFile) {const [made] = await engine.executeRaw<{ sync: boolean }>(`SELECT ${syncDeleteOrigin('p')} AS sync FROM pages p WHERE p.id=$1`, [snapshot.page.id]);@@ -695,6 +698,10 @@ async function prepareDeletePageMutation(engine: BrainEngine, row: WriteRequest,...(excludedPath !== null ? { databaseOnlyReason: 'sync_excluded' as const } : {}), ...(shared ? { databaseOnlyReason: 'shared_origin' as const } : {}),...(committedFile ? { databaseOnlyReason: 'committed_file' as const } : {}),...(shared ? { validate: async (tx: BrainEngine) => { prepared.databaseOnlyWarning = await validateSharedOrigin(tx, row, shared, sharedRetention); } } : {}),+ ...(retentionFile && !committedFile ? { validate: async (tx: BrainEngine) => {+ if (await committedNow(tx)) throw pageRefusal('revision_conflict', 'The page\'s file was committed while the retention purge was prepared, so the purge left the page and the file alone; the next run re-reads it.', row,+ `Page ${row.slug}'s file is committed in source ${row.source_id}'s checkout.`, pageFix(row.source_id, row.slug));+ } } : {}),apply: async tx => {if (purge && excludedPath !== null) await assertStillSyncExcluded(tx, row, excludedPath);// #7311: the tombstone forgets the survivor's file, as an origin_twin page has, so its purge writes no deletion marker for it.diff --git a/src/core/persistence/page-purge.ts b/src/core/persistence/page-purge.tsindex 00dd46f49b..b7cc701b4a 100644--- a/src/core/persistence/page-purge.ts+++ b/src/core/persistence/page-purge.ts@@ -332,24 +332,23 @@ export async function purgePageInTransaction(tx: BrainEngine, row: WriteRequest,// #6511 [R2]: the preparation sweep's targets, plus the tail past its ceiling and the rows pending at scan time, re-tested here.const recheck = await lookup('tail_recheck', () => recheckRequestsCarrying(tx, sourceId, needles, prepared.sweep,{ exclude: row.id, beforePending: () => faultPoint('purge:pending_recheck', { requestId: row.request_id, sourceId, operation: row.operation }) }));- // The page's add_timeline_entry receipts keep the entry text in their outcome (`entry`, `bullet`), compacted ones included.- // In those receipts the text is matched whole (a set lookup, linear in the receipts); in the page's other requests it is a- // needle, as its reasons are. A page past the cap leaves the journal sweep incomplete instead of claiming every receipt.- const timeline = await lookup('slug_lookup', () => tx.executeRaw<IntentRedactionTarget & { summary: string | null; bullet: string | null }>(`SELECT id::text AS id, principal_kind, principal_id,- outcome->'entry'->>'summary' AS summary, outcome->>'bullet' AS bullet FROM persistence_requests- WHERE source_id=$1 AND slug=$2 AND operation='add_timeline_entry' AND outcome ? 'entry' ORDER BY sequence LIMIT $3`, [sourceId, slug, TIMELINE_RECEIPT_CAP]));- const timelineText = new Set(timeline.flatMap(t => [t.summary, t.bullet]).map(text => text?.trim() ?? '').filter(Boolean));- const timelineIds = new Set(timeline.map(t => t.id));+ // The page's add_timeline_entry receipts keep the entry text in their outcome (`entry` summary and source, `bullet`), compacted+ // ones included. That text is matched whole in the page's own requests (a set lookup, linear in their strings). A page past+ // the cap leaves the journal sweep incomplete instead of claiming every receipt.+ const timelineRows = await lookup('slug_lookup', () => tx.executeRaw<IntentRedactionTarget & { summary: string | null; source: string | null; bullet: string | null }>(`SELECT id::text AS id,+ principal_kind, principal_id, outcome->'entry'->>'summary' AS summary, outcome->'entry'->>'source' AS source, outcome->>'bullet' AS bullet FROM persistence_requests+ WHERE source_id=$1 AND slug=$2 AND operation='add_timeline_entry' AND outcome ? 'entry' ORDER BY sequence LIMIT $3`, [sourceId, slug, TIMELINE_RECEIPT_CAP + 1]));+ const timeline = timelineRows.slice(0, TIMELINE_RECEIPT_CAP);+ const timelineText = new Set(timeline.flatMap(t => [t.summary, t.source, t.bullet]).map(text => text?.trim() ?? '').filter(Boolean));const forSlug = await lookup('slug_lookup', async () => [...await findRequestsForSlugs(tx, sourceId, [slug]), ...reasons.length ? await requestsRecordingReasons(tx, sourceId, slug) : [], ...timeline]);const own = new Set(forSlug.map(r => r.id));const requests = [...new Map([...forSlug, ...prepared.sweep.targets, ...recheck.targets].map(r => [r.id, r])).values()];// GBRA-217: the page's reasons are needles in its own requests only, so a short reason never redacts another page's receipt.- removed.persistence_requests = await lookup('redaction_read', async () => await redactRequestIntents(tx, requests.filter(r => timelineIds.has(r.id)), row.id,- { skipPending: true, needles: [...needles, ...reasons], exact: timelineText }) + await redactRequestIntents(tx, requests.filter(r => own.has(r.id) && !timelineIds.has(r.id)), row.id,- { skipPending: true, needles: [...needles, ...reasons, ...timelineText] }) + await redactRequestIntents(tx, requests.filter(r => !own.has(r.id)), row.id, { skipPending: true, needles }));+ removed.persistence_requests = await lookup('redaction_read', async () => await redactRequestIntents(tx, requests.filter(r => own.has(r.id)), row.id,+ { skipPending: true, needles: [...needles, ...reasons], exact: timelineText }) + await redactRequestIntents(tx, requests.filter(r => !own.has(r.id)), row.id, { skipPending: true, needles }));removed.persistence_effects = await stripPageGitNotes(tx, sourceId, slug);const journalSweep = { scanned: prepared.sweep.scanned, ceiling: prepared.sweep.ceiling, watermark: prepared.sweep.watermark ?? null, batch: prepared.sweep.batch ?? 1,- tail: recheck.tail, pending_rechecked: recheck.pendingRechecked, complete: prepared.sweep.complete && recheck.complete && timeline.length < TIMELINE_RECEIPT_CAP };+ tail: recheck.tail, pending_rechecked: recheck.pendingRechecked, complete: prepared.sweep.complete && recheck.complete && timelineRows.length <= TIMELINE_RECEIPT_CAP };const files = await tx.executeRaw<{ storage_path: string }>(`DELETE FROM files WHERE (page_id=$1 OR (page_id IS NULL AND page_slug=$2 AND (source_id=$3 OR source_id IS NULL)))RETURNING storage_path`, [page.id, slug, sourceId]);removed.files = files.length;diff --git a/test/purge-eval-fixes.test.ts b/test/purge-eval-fixes.test.tsindex 12dfe857f9..ef7e27391f 100644--- a/test/purge-eval-fixes.test.ts+++ b/test/purge-eval-fixes.test.ts@@ -95,10 +95,11 @@ describe('purge eval fixes', () => {test('W3: a page purge leaves no timeline text in its add_timeline_entry receipts, compacted ones included', async () => {await seed();- const kept = await call('add_timeline_entry', { slug: 'people/alice-example', date: '2026-02-03', summary: 'Moved house TIMELINE-MARK-ONE', request_id: randomUUID() });+ const kept = await call('add_timeline_entry', { slug: 'people/alice-example', date: '2026-02-03', summary: 'Moved house TIMELINE-MARK-ONE', source: 'https://private.example/TIMELINE-MARK-SOURCE', request_id: randomUUID() });const compacted = await call('add_timeline_entry', { slug: 'people/alice-example', date: '2026-02-04', summary: 'Changed banks TIMELINE-MARK-TWO', request_id: randomUUID() });expect([kept.status, compacted.status]).toEqual(['ok', 'ok']);await engine.executeRaw(`UPDATE persistence_requests SET intent=NULL, compacted=true WHERE operation='add_timeline_entry' AND outcome->'entry'->>'summary' LIKE '%MARK-TWO'`);+ expect(await journalCarries('TIMELINE-MARK-SOURCE')).toBe(1);expect(await journalCarries('TIMELINE-MARK')).toBe(2);expect((await purgePage('people/alice-example')).status).toBe('purged');expect(await journalCarries('TIMELINE-MARK')).toBe(0);diff --git a/test/sync-restored-file-purge.test.ts b/test/sync-restored-file-purge.test.tsindex 61ae7fb430..37f9bcb455 100644--- a/test/sync-restored-file-purge.test.ts+++ b/test/sync-restored-file-purge.test.ts@@ -29,6 +29,7 @@ import { SYNC_DELETE_TOMBSTONE_OP } from '../src/core/persistence/sync-delete-toimport { declarePersistenceProtocol } from '../src/core/persistence/protocol.ts';import { __resetTreeReuseForTests } from '../src/core/persistence/sync-tree-reuse.ts';import { runPages } from '../src/commands/pages.ts';+import { installFaultHook } from '../src/core/persistence/fault-points.ts';import { managedBrain, settleManagedGitEffects } from './helpers/managed-brain.ts';import { requirePostgresTestDatabase, testBackends } from './helpers/test-backends.ts';import { withEnv } from './helpers/with-env.ts';@@ -264,6 +265,52 @@ for (const backend of testBackends()) {expect(git(root, 'status', '--porcelain', '--', `${A}.md`)).toBe('');}, { setup, databaseUrl }), 300_000);+ test("an old shared-origin delete of the same slug does not exempt a later sync-made tombstone: the restored file stays", () => managedBrain(async ({ engine, ctx, root }) => {+ await sync(engine);+ await personDelete(engine, ctx, USER);+ // That old delete is recorded as one that kept the file because another page shared it (a fixture write); the page is restored.+ await engine.transaction(async tx => {+ await declarePersistenceProtocol(tx);+ await tx.executeRaw(`UPDATE persistence_requests SET outcome = jsonb_set(COALESCE(outcome, '{}'::jsonb), '{write_through}', '{"written": false, "skipped": "shared_origin"}')+ WHERE operation='delete_page' AND slug=$1`, [USER]);+ });+ const tombstone = await engine.readPageSnapshot(USER, { sourceId: 'default', includeDeleted: true });+ await submitPageMutation(ctx, { operation: 'restore_page', params: { slug: USER, expected_revision: tombstone!.revision, request_id: randomUUID() } });+ await settleManagedGitEffects(engine);+ if (git(root, 'status', '--porcelain', '--', `${USER}.md`)) commit(root, 'restore user note');+ await sync(engine);+ expect((await page(engine, USER))?.deleted_at).toBeNull();+ await removeAndSync(engine, root, [USER]);+ git(root, '-c', 'user.name=Example', '-c', '[email protected]', 'revert', '--no-edit', 'HEAD');+ await age(engine, 100);+ await purge(engine, root, 'CLI purge-deleted');+ expect((await page(engine, USER))?.deleted_at).not.toBeNull();+ expect(existsSync(join(root, `${USER}.md`))).toBe(true);+ expect(git(root, 'status', '--porcelain', '--', `${USER}.md`)).toBe('');+ }, { setup, databaseUrl }), 300_000);++ test('a file committed between the purge\'s preparation and its publication is not removed', () => managedBrain(async ({ engine, ctx, root }) => {+ await sync(engine);+ await personDelete(engine, ctx, USER);+ if (git(root, 'status', '--porcelain', '--', `${USER}.md`)) commit(root, 'remove user note');+ await sync(engine);+ writeFileSync(join(root, `${USER}.md`), BODY[USER]!);+ await age(engine, 100);+ let committed = false;+ installFaultHook(async (point, detail) => {+ if (point !== 'consumer:prepared' || detail.operation !== 'delete_page' || committed) return;+ committed = true;+ commit(root, 'restore user note');+ });+ const { purgeDeletedPagesCoordinated } = await import('../src/core/persistence/purge-deleted.ts');+ try { await purgeDeletedPagesCoordinated(engine, 72); } finally { installFaultHook(undefined); }+ expect(committed).toBe(true);+ fileKept(root, USER);+ await purgeDeletedPagesCoordinated(engine, 72);+ expect(await page(engine, USER)).toBeUndefined();+ fileKept(root, USER);+ }, { setup, databaseUrl }), 300_000);+test("an older version purged the page and committed the file's removal; a revert of that commit imports the file as a new page", () => managedBrain(async ({ engine, root }) => {await sync(engine);const before = await page(engine, A);