Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(repair): segmented-mirror carries the preview-approved hashes into its mirror effect
garrytan93c8ac4f8e3e
diff --git a/docs/architecture/key-files/memory-purge.md b/docs/architecture/key-files/memory-purge.mdindex b554ee78a2..52345852c7 100644--- a/docs/architecture/key-files/memory-purge.md+++ b/docs/architecture/key-files/memory-purge.md@@ -25,4 +25,4 @@ User-facing contract: [expire versus purge](../../guides/memory-boundaries.md#pu- `src/core/persistence/purge-parks.ts` — #6741 C: per-tombstone purge parks in op_checkpoints (op `purge-deleted-park`, key source+slug+deleted_at, so a re-deleted page starts fresh); park at `PURGE_PARK_LIMIT` (5) non-deferral failures, a success clears it, and parks of a source seen inactive rearm the first run its writer is active again (`notePurgeSourceWriter`). `purgeStaleCheckpoints` exempts the op; `prunePurgeParks` drops parks whose tombstone is gone. Tests: `test/purge-deleted-parks.test.ts`.-- `src/core/repair/segmented-mirror.ts` — `gbrain repair segmented-mirror` (LPH a), explicit-only, preview-bound, destructive consent, `checks: []` (no doctor scan: detection reads every segmented file). `scanSegmentedMirrors` (read-only, owner host; a non-owner source is held `not_owner_host`) walks live `body_storage='segmented'` pages of sources with a worktree binding whose snapshot ledger applies (`ledgerApplies`), runs `prepareFileTarget(..., null, { allowMissing })` (the mirror's own drift check; `file_database_drift` or any other `OperationError` is held, never rewritten), then lists the page only when overlaying the ledger on the file's facts fences changes its region digests (`fileBodyDigests` vs `overlaidFileBodyDigests` over `FileBytes`, bounded memory) and the streamed render (`unreadPageFile`) hashes differently. The hash (`segmented-mirror-v1`) binds source selection, slug, page id, revision, path and both SHA-256s; the approved set lives in `op_checkpoints`. Apply re-checks revision and file hash of every page not yet admitted (`preview_changed`), then per page admits and commits, in one transaction like a withdrawal, a `repair_segmented_mirror` request (request id derived from the hash; its receipt) that inserts a version-2 targeted `withdrawal-mirror` + `git` effect (no embedding); it wakes this process's consumer and waits up to the write wait for them (`mirrored` / `mirror_queued` / `held` / `failed`; a replay is `replayed`). Test: `test/pathological/lp-a-segmented-mirror.test.ts`.+- `src/core/repair/segmented-mirror.ts` — `gbrain repair segmented-mirror` (LPH a), explicit-only, preview-bound, destructive consent, `checks: []` (no doctor scan: detection reads every segmented file). `scanSegmentedMirrors` (read-only, owner host; a non-owner source is held `not_owner_host`) walks live `body_storage='segmented'` pages of sources with a worktree binding whose snapshot ledger applies (`ledgerApplies`), runs `prepareFileTarget(..., null, { allowMissing })` (the mirror's own drift check; `file_database_drift` or any other `OperationError` is held, never rewritten), then lists the page only when overlaying the ledger on the file's facts fences changes its region digests (`fileBodyDigests` vs `overlaidFileBodyDigests` over `FileBytes`, bounded memory) and the streamed render (`unreadPageFile`) hashes differently. The hash (`segmented-mirror-v1`) binds source selection, slug, page id, revision, path and both SHA-256s; the approved set lives in `op_checkpoints`. Apply re-checks revision and file hash of every page not yet admitted (`preview_changed`), then per page admits and commits, in one transaction like a withdrawal, a `repair_segmented_mirror` request (request id derived from the hash; its receipt) that inserts a version-2 targeted `withdrawal-mirror` + `git` effect (no embedding) whose `data.approved_file` carries the preview's file and render SHA-256 (`mirrorPage` skips the target `preview_changed` when the file's before-hash or the streamed render differs, before the gate or any recovery record; `publishGitPage` skips it when the file is not the approved render; the outcome is `refused` `preview_changed` with a read-only fix re-running the preview); it wakes this process's consumer and waits up to the write wait for them (`mirrored` / `mirror_queued` / `held` / `failed`; a replay is `replayed`). Test: `test/pathological/lp-a-segmented-mirror.test.ts`.diff --git a/docs/guides/repair.md b/docs/guides/repair.mdindex 8d3595501c..7587bd6f06 100644--- a/docs/guides/repair.md+++ b/docs/guides/repair.md@@ -365,11 +365,17 @@ from the hash). That request is the page's receipt; read it with`gbrain write-request <request id>`. It commits a withdrawal-mirror effect anda Git effect for the page, and the existing mirror does the rewrite. The mirrorkeeps its recovery record, streamed staging file, owner and lock checks, and its-own file/database check. The Git effect commits the file. Outcomes are-`mirrored`, `mirror_queued` (the owner's consumer has not run it yet; preview-again later), `held` (the mirror's own check refused the file) or `failed`+own file/database check. The effect carries the file and render SHA-256 the+preview approved: if the file or the render changed after the preview, even a+formatting-only edit made while the mirror waited, the mirror leaves the file+as it is (`skipped` reason `preview_changed`) and the Git effect commits+nothing for it. The Git effect commits the file. Outcomes are `mirrored`,+`mirror_queued` (the owner's consumer has not run it yet; preview again later),+`held` (the mirror's own check refused the file), `refused` with+`preview_changed` (its fix re-runs the preview; apply the new hash) or `failed`(the mirror's error code). Replaying an apply with the same hash finds each-receipt and writes nothing (`replayed`).+receipt and writes nothing (`replayed`), except that a page the mirror refused+reports `refused` again.The rewrite replaces the file with the page's canonical render, so any otherformatting differences in it are normalized as well. The old bytes stay indiff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.tsindex 13ee3a728c..1a68e0714c 100644--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@ -903,7 +903,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;{ since: '0.60.299.0', text: 'Doctor `segmented_storage` no longer tells you to upgrade this host when the only writes holding segmented storage off are this host\'s own from before its upgrade and the upgraded gbrain has since made the same kind of write (the same import or sync type, resident kind or managed principal), after the last of them: it reports the hold as information with the time it clears. Another host, an older `serve` or worker still running on this host, or an older write this build has not matched (a cron job or `npx` run on this host) keeps the warning and the `gbrain upgrade` fix.' },{ since: '0.60.299.0', text: 'Managed sync of a Markdown file over 24 MiB whose origin another page records (a page renamed with its file) now imports it into that page, as for a smaller file, instead of failing it `revision_conflict` ("A different page already owns this file identity") and stopping the source\'s sync at it.' },{ since: '0.60.299.0', text: '`gbrain repair stuck-recovery` now resolves a page recovery whose file is over 24 MiB, which used to be listed as refused (`recovery_large_file_unsupported`) with no exit while it stopped every write on its source\'s worktree. The preview lists it with both fingerprints and the state of the staged copy of the prior file, backs up both versions, and writes a summary instead of a full diff (both hashes and sizes, the first byte where they differ, and a window of at most 1 KiB); `--apply --expect <hash> --keep prior|disk --yes` resolves it as it does a small file. Every read, hash and copy of the large file is done in pieces of at most a segment. When the staged copy of the prior file is missing or damaged, `--keep prior` refuses with `recovery_prior_stage_unavailable`, whose fix is the `--keep disk` apply, which keeps a damaged copy in the backup directory and removes it from the checkout.' },- { since: 'TBD', text: 'New `gbrain repair segmented-mirror [--source <id>]` for brains that ran a gbrain older than v0.60.299.0 with `pages.segmented_storage` on: on those versions a withdrawal (`forget`, `forget_fact`, `purge_fact`) of a row in a page stored in segments struck it in the database but left the page\'s canonical file holding it (the mirror skipped the page with `page_body_segmented`). Upgrading does not rewrite those files. Run the preview on the source\'s owner host: it lists each file-backed segmented page whose file still holds a withdrawn or purged row and otherwise matches the database, with the file\'s SHA-256 and size and those of the page\'s canonical render (`gbrain export`\'s bytes), and prints a hash; a file that also differs from the database for another reason is listed held (`file_database_drift`) and never rewritten. `--apply --expect <hash> --yes` rewrites each listed file to that render through the withdrawal mirror (one receipted write request per page, `operation: repair_segmented_mirror`) and its Git effect commits it; a file or page that changed since the preview refuses the apply with `preview_changed`. Doctor does not scan for these files (that needs every segmented file read), so run the preview once if this brain ever ran such a version.' },+ { since: 'TBD', text: 'New `gbrain repair segmented-mirror [--source <id>]` for brains that ran a gbrain older than v0.60.299.0 with `pages.segmented_storage` on: on those versions a withdrawal (`forget`, `forget_fact`, `purge_fact`) of a row in a page stored in segments struck it in the database but left the page\'s canonical file holding it (the mirror skipped the page with `page_body_segmented`). Upgrading does not rewrite those files. Run the preview on the source\'s owner host: it lists each file-backed segmented page whose file still holds a withdrawn or purged row and otherwise matches the database, with the file\'s SHA-256 and size and those of the page\'s canonical render (`gbrain export`\'s bytes), and prints a hash; a file that also differs from the database for another reason is listed held (`file_database_drift`) and never rewritten. `--apply --expect <hash> --yes` rewrites each listed file to that render through the withdrawal mirror (one receipted write request per page, `operation: repair_segmented_mirror`) and its Git effect commits it; a file or page that changed since the preview refuses the apply with `preview_changed`, and so does a file (even a formatting-only edit) or render that changes after the apply but before the mirror rewrites it: the mirror leaves it as it is and the Git effect commits nothing for it. Doctor does not scan for these files (that needs every segmented file read), so run the preview once if this brain ever ran such a version.' },{ since: 'TBD', text: 'A publication or withdrawal-mirror recovery record of a version this gbrain does not know (one a newer gbrain wrote) is now refused with `recovery_version_unsupported` before anything reads it: the record, its staged files and the canonical file are left exactly as they are, the effect keeps retrying instead of parking, and `gbrain sources writer status` and a stalled sync name it as a blocker whose fix is `gbrain upgrade` on the owner host. Before, recovery could read a newer record as an older one: a withdrawal-mirror recovery published the bytes the record embedded, removed its staging file and cleared the record, and a request recovery tried to rewrite the record\'s staging (the database refused it with an untyped `unsupported_mutation_protocol`). v0.60.290.0 and older still read a version 2 withdrawal-mirror record as version 1 and fail every attempt with an untyped `effect_unavailable` while the record holds every write and effect on the worktree; they never delete the record or its staging file, and an upgraded owner finishes it.' },{ since: 'TBD', text: 'While a gbrain older than the segmented writer floor (v0.60.290.0 included) that doctor `segmented_storage` still warns about wrote to the brain in the last 7 days (another host, an older `serve` or worker still running on this host, or an older write this build has not matched; doctor names the host), a withdrawal (`forget`, `forget_fact`, `purge_fact`) on a page stored in segments still commits, but its withdrawal mirror no longer writes a version 2 recovery record, which that older gbrain cannot read and would wedge the worktree on. The mirror refuses `segmented_mirror_writer_gate` (its fix names the hosts to upgrade), retries, and parks after five attempts like any failed mirror, so writes on the worktree are not held; the page\'s canonical file keeps the withdrawn row and the withdrawal\'s Git effect waits meanwhile. Once the older writer is upgraded and out of the 7-day window, the parked mirror runs again by itself (checked at most once a minute), rewrites the file and the Git effect commits it. `gbrain sources writer retry-effects` retries it at any time. A hold left only by this host\'s own writes from before it upgraded, which the upgraded gbrain has since superseded with the same kind of write (doctor reports it as information), still keeps new pages inline but does not hold the mirror: an upgraded single-host brain mirrors withdrawals at once.' },{ since: 'TBD', text: 'A withdrawal (`forget`, `forget_fact`, `purge_fact`) of a claim in a facts fence that crosses a forced segment cut, when that one fence holds more than 16,384 rows (or more than 8 MiB of rows to check), is still refused `withdrawal_capacity` (the bound is unchanged), but the refusal now says why: it carries reason `split_fence_rows`, names the page, the fence\'s row count and the limit, and its fix asks you to split that fence into fences of at most 16,384 rows and write the page again. It used to say discovery "could not prove a bounded complete target set" and told you not to split the source.' },diff --git a/src/core/persistence/effect-model.ts b/src/core/persistence/effect-model.tsindex bc5a3a133c..5e4cdee6af 100644--- a/src/core/persistence/effect-model.ts+++ b/src/core/persistence/effect-model.ts@@ -30,7 +30,8 @@ export function contentRepairCommit(path: string, receipt: Pick<ContentRepairRec}export interface ParkedTarget { slug?: string; error_code: string }/** `page_body_segmented`: a segmented page an older binary's mirror or Git scan passed by; this one mirrors and commits it. */-export interface SkippedTarget { slug: string; reason: 'metafile' | 'file_database_drift' | 'page_body_segmented' | 'withdrawal_not_mirrored' }+/** `preview_changed`: a `gbrain repair segmented-mirror` target whose file or render no longer has the hash its preview approved (`data.approved_file`). */+export interface SkippedTarget { slug: string; reason: 'metafile' | 'file_database_drift' | 'page_body_segmented' | 'withdrawal_not_mirrored' | 'preview_changed' }/** The code a page behind a failed withdrawal mirror is parked with: its file may still hold the withdrawn text. */export const WITHHELD_BY_MIRROR = 'withdrawal_mirror_failed';/** A Git or withdrawal target parks after this many consecutive execution failures. */@@ -83,6 +84,8 @@ export interface PersistenceEffect {retried?: number;/** #5396: scan targets passed without a file publication (a sync-skip metafile, or a file with an uncoordinated local edit). */skipped?: SkippedTarget[];+ /** A `gbrain repair segmented-mirror` target: the file and render SHA-256 its preview approved; the mirror rewrites the file only while both still match. */+ approved_file?: { slug: string; file_sha256: string; expected_sha256: string };/** GBRA-130 A-12: pages whose file this withdrawal mirror rewrote, recorded by its recovery with the cursor step. */published?: string[];/** The SHA-256 of the bytes this mirror wrote to each published page's file, at the page revision it rendered. */diff --git a/src/core/persistence/effects.ts b/src/core/persistence/effects.tsindex f6940b13b2..4dbebffaec 100644--- a/src/core/persistence/effects.ts+++ b/src/core/persistence/effects.ts@@ -235,8 +235,11 @@ async function mirrorPage(engine: BrainEngine, effect: PersistenceEffect, bindinawait materializeAndAdvance(engine, effect, snapshot, opts.hostId);return;}+ const approved = effect.data.approved_file?.slug === snapshot.page.slug ? effect.data.approved_file : undefined;+ if (approved && file.expectedBeforeHash !== approved.file_sha256) { await materializeAndAdvance(engine, effect, snapshot, opts.hostId, 'preview_changed'); return; }if (segmented) await assertSegmentedMirrorGate(engine, effect, snapshot.page.slug, opts.hostId);content = segmented ? await unreadPageFile(engine, snapshot, keep) : file.content as string;+ if (approved && fileContentHash(content) !== approved.expected_sha256) { await materializeAndAdvance(engine, effect, snapshot, opts.hostId, 'preview_changed'); return; }} catch (error) {// A segmented page whose fence a withdrawal cannot read whole (page_body_segmented) retries and parks like any failed// target, so writer status and doctor list it; only a file that differs from the database is passed by.@@ -347,6 +350,11 @@ async function publishGitPage(engine: BrainEngine, effect: PersistenceEffect, bi{ fix: effectStatusFix(effect) });const path = file.path;if (!existsSync(path)) { await materializeAndAdvance(engine, effect, snapshot, opts.hostId); return; }+ // A repair's Git target commits only the render its preview approved (the mirror refused anything else).+ if (effect.data.approved_file?.slug === snapshot.page.slug && persistenceFileHash(path) !== effect.data.approved_file.expected_sha256) {+ await skipTarget(engine, effect, snapshot, 'preview_changed');+ return;+ }if (snapshot.page.deleted_at && existsSync(path)) { await finishPage(engine, effect, snapshot, { reason: 'deleted_page_file_present' }); return; }if (!isWriteTargetContained(path, join(root, binding.relative_path))) throw gitTargetEscaped(effect);if (isSourceDbOnlySlug(join(root, binding.relative_path), snapshot.page.slug, 'not_db_only')) {diff --git a/src/core/repair/segmented-mirror.ts b/src/core/repair/segmented-mirror.tsindex ca616f7b83..e940f35251 100644--- a/src/core/repair/segmented-mirror.ts+++ b/src/core/repair/segmented-mirror.ts@@ -24,6 +24,7 @@ import { join, relative, sep } from 'node:path';import type { BrainEngine } from '../engine.ts';import type { OperationContext } from '../ops/contract.ts';import { OperationError, opError } from '../ops/contract.ts';+import { readFix } from '../ops/op-fix.ts';import type { PageSnapshot } from '../page-state/types.ts';import { overlayCanonicalBodies } from '../page-state/snapshot.ts';import { isSegmentedPage } from '../page-body/page-shape.ts';@@ -175,7 +176,8 @@ async function admitRemirror(ctx: OperationContext, stale: StaleMirror, hash: stCROSS JOIN (VALUES ('withdrawal-mirror'),('git')) AS k(kind)WHERE s.id=$2 ON CONFLICT(request_id,kind) DO NOTHING`, [row.id, stale.source_id, JSON.stringify({ version: 2,commit_subject: `gbrain: re-mirror segmented page ${stale.slug}`, commit_line: `re-mirror ${stale.slug} without withdrawn rows`,- targets: [{ slug: stale.slug, page_id: stale.page_id, revision: stale.revision }] })]);+ targets: [{ slug: stale.slug, page_id: stale.page_id, revision: stale.revision }],+ approved_file: { slug: stale.slug, file_sha256: stale.file_sha256, expected_sha256: stale.expected_sha256 } })]);return completeWrite(tx, row, 'committed', { segmented_mirror: { ...callerIntent, revision: stale.revision, path: stale.path, effects: ['withdrawal-mirror', 'git'] } });}, requestAttribution(row));}), undefined, error => engine.reconnect({ error }));@@ -204,9 +206,16 @@ async function awaitEffects(ctx: OperationContext, requestRowId: string, waitMs:function outcomeOf(stale: StaleMirror, row: WriteRequest, effects: EffectState[], replayed: boolean): RepairItemOutcome {const detail = { request_id: row.request_id, path: stale.path, file_sha256_before: stale.file_sha256, expected_sha256: stale.expected_sha256,effects: effects.map(effect => ({ kind: effect.kind, state: effect.state, ...(effect.error_code ? { error: effect.error_code } : {}) })) };- if (replayed) return { applied: false, outcome: 'replayed', detail };const mirror = effects.find(effect => effect.kind === 'withdrawal-mirror');const skip = mirror?.skipped.find(entry => entry.slug === stale.slug);+ if (skip?.reason === 'preview_changed') {+ const preview = ['gbrain', 'repair', 'segmented-mirror', '--source', stale.source_id, '--json'];+ const failure = opError('preview_changed', `The file of ${stale.slug} or its canonical render changed after the preview, so the withdrawal mirror did not rewrite it.`,+ `Run ${preview.slice(0, -1).join(' ')} again, show the user the new listing, and apply its new hash.`,+ { fix: readFix(`Previews the segmented-mirror repair of source ${stale.source_id} again, read-only; it lists ${stale.slug} with its current file hash.`, { argv: preview }) });+ return { applied: false, outcome: 'refused', reason: 'preview_changed', failure, detail: { ...detail, fix: failure.fix } };+ }+ if (replayed) return { applied: false, outcome: 'replayed', detail };if (skip) return { applied: false, outcome: 'held', reason: skip.reason ?? 'skipped', detail };if (mirror?.state === 'committed' && !mirror.recovering) return { applied: true, outcome: 'mirrored', detail };if (mirror && (mirror.state === 'failed' || mirror.parked)) return { applied: false, outcome: 'failed', reason: mirror.error_code ?? 'mirror_failed', detail };diff --git a/test/pathological/lp-a-segmented-mirror.test.ts b/test/pathological/lp-a-segmented-mirror.test.tsindex 7e44e47176..5838747b96 100644--- a/test/pathological/lp-a-segmented-mirror.test.ts+++ b/test/pathological/lp-a-segmented-mirror.test.ts@@ -165,4 +165,67 @@ for (const { backend: kind } of pathologicalArms()) {for (const [slug, bytes] of Object.entries(files())) expect({ slug, same: bytes.equals(snapshot[slug]!) }).toEqual({ slug, same: true });}, 600_000);});+ describe(kind + ': a segmented-mirror apply whose file changes before its mirror runs refuses with preview_changed', () => {+ let brain: TwinBrain;+ const PAGE = 'people/held-mirror-example';+ const HELD_CLAIM = 'Mirror Example locker code is 5511';+ const run = (apply: boolean, expectHash?: string, env: Record<string, string> = {}): Promise<RepairResult> => withEnv({ ...brain.env(), ...env }, () => withVerifiedLocalRegistration(brain.engine, brain.cli, async () => {+ const scope = await resolveRepairScope(brain.engine, brain.sourceId);+ const runner = await repairRunner(brain.engine, { apply, logger: quiet });+ return runner.run('segmented-mirror', scope, { explicit: true, sourceFlag: brain.sourceId, ...(expectHash ? { expect: expectHash } : {}) });+ }));++ beforeAll(async () => {+ brain = await openTwinBrain(kind, [], async seed => { await seed.setSwitch(true); await seed.put(PAGE, 1_100_000); });+ await extract(brain, PAGE, [HELD_CLAIM, KEPT]);+ await settle(brain, kind);+ expect(await brain.storageOf(PAGE)).toBe('segmented');+ durableGitRepo(brain.root, [PAGE + '.md']);+ const stale = readFileSync(fileOf(brain, PAGE));+ await purge(brain, kind, PAGE, HELD_CLAIM);+ writeFileSync(fileOf(brain, PAGE), stale);+ git(brain.root, 'add', '-A'); git(brain.root, 'commit', '-q', '-m', 'older binary state');+ // The owner's consumer is held: the repair's effects are inserted unclaimable until the test releases them.+ await brain.engine.executeRaw(`CREATE OR REPLACE FUNCTION lp_a_hold_remirror() RETURNS trigger LANGUAGE plpgsql AS $$ BEGIN+ IF EXISTS (SELECT 1 FROM persistence_requests r WHERE r.id=NEW.request_id AND r.operation='repair_segmented_mirror') THEN+ NEW.next_attempt_at := now() + interval '1 day'; END IF; RETURN NEW; END $$`);+ await brain.engine.executeRaw('CREATE TRIGGER lp_a_hold_remirror BEFORE INSERT ON persistence_effects FOR EACH ROW EXECUTE FUNCTION lp_a_hold_remirror()');+ }, 900_000);++ afterAll(() => brain.close(), 120_000);++ test('a formatting-only edit made while the mirror waits is refused, not overwritten', async () => {+ const preview = await run(false);+ expect(preview.listing?.map(entry => entry.item)).toEqual([`${brain.sourceId}:${PAGE}`]);+ const applied = await run(true, preview.preview_hash, { GBRAIN_WRITE_WAIT_MS: '500' });+ expect(applied.outcomes).toEqual({ mirror_queued: 1 });++ // A formatting-only edit: the quoted title parses the same, so the mirror's own drift check still passes.+ const original = readFileSync(fileOf(brain, PAGE), 'utf8');+ const edited = original.replace(/^title: Twin Example$/m, "title: 'Twin Example'");+ expect(edited).not.toBe(original);+ writeFileSync(fileOf(brain, PAGE), edited);+ const head = (await gitAsync(brain.root, 'rev-parse', 'HEAD')).trim();++ await brain.engine.executeRaw('DROP TRIGGER lp_a_hold_remirror ON persistence_effects');+ await brain.engine.executeRaw(`UPDATE persistence_effects SET next_attempt_at=now() WHERE source_id=$1 AND state='queued'`, [brain.sourceId]);+ await settle(brain, kind);++ expect(readFileSync(fileOf(brain, PAGE), 'utf8')).toBe(edited);+ expect((await gitAsync(brain.root, 'rev-parse', 'HEAD')).trim()).toBe(head);+ const [mirror] = await brain.engine.executeRaw<{ state: string; skipped: unknown }>(`SELECT e.state, e.data->'skipped' AS skipped FROM persistence_effects e+ JOIN persistence_requests r ON r.id=e.request_id WHERE r.operation='repair_segmented_mirror' AND e.kind='withdrawal-mirror'`);+ expect({ state: mirror!.state, skipped: typeof mirror!.skipped === 'string' ? JSON.parse(mirror!.skipped) : mirror!.skipped })+ .toEqual({ state: 'committed', skipped: [{ slug: PAGE, reason: 'preview_changed' }] });++ // Replaying the apply reports the typed refusal with the preview as its fix; a new preview lists the page again.+ const replay = await run(true, preview.preview_hash);+ const refused = replay.outcome_items?.find(entry => entry.item === `${brain.sourceId}:${PAGE}`);+ expect(refused).toMatchObject({ outcome: 'refused', reason: 'preview_changed' });+ expect((refused!.detail!.fix as { argv: string[] }).argv).toEqual(['gbrain', 'repair', 'segmented-mirror', '--source', brain.sourceId, '--json']);+ const again = await run(false);+ expect(again.listing?.map(entry => entry.item)).toEqual([`${brain.sourceId}:${PAGE}`]);+ expect(again.preview_hash).not.toBe(preview.preview_hash);+ }, 600_000);+ });}