Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(reconcile): identify private fact rows by row number and claim (#6137)

garrytanf55aa15920e8
diff --git a/docs/architecture/key-files/canonical-reconciliation.md b/docs/architecture/key-files/canonical-reconciliation.md
index d05c09c074..206402a2d8 100644
--- a/docs/architecture/key-files/canonical-reconciliation.md
+++ b/docs/architecture/key-files/canonical-reconciliation.md
@@ -2,7 +2,7 @@
- `src/commands/sync-diagnostics.ts` + `src/core/persistence/{sync-run,verb-errors}.ts` — bounded source/slug/path/reason diagnostics derive from immutable managed-sync receipts, including when the local failure ledger is unavailable. Direct and resident-owner JSON carry the same receipt; human memory errors lead with the specific write reason without widening frozen v1 error codes. Pending requests retain their original UUID, terminal corrections require a new UUID, and neither retry nor line-ending diagnostics bypasses raw-byte or skip guards.
-- `src/core/persistence/reconcile*.ts` — trusted-local exact-page reconciliation: loss-preserving semantic preview, explicit JSON Pointer choices, pinned identity/revision/raw-file/policy checks, durable private preimages and same-ID replay through the existing coordinator. Normal overwrite protection stays unchanged. The bounded audit reports source-scoped drift without repair or checkpoint changes; a database-only page (`isDatabaseOnlyPage`, with no file at its slug-derived path) counts as `database_only` with no reconcile suggestion, never as drift, while a legacy row that merely lacks `source_path` is audited as usual. `src/commands/source-reconcile.ts` provides strict CLI parsing, private artifact I/O, brain routing and resident-owner delegation; the operations stay outside public MCP. Operator flow: `docs/guides/concurrent-writes.md`. Tests cover merge choices, both engines, grants, stale previews, read-only audit, and private files. A database-only page (no `source_path`, no `source_uri`; `isDatabaseOnlyPage` in `src/core/persistence/unbound-pages.ts`) is matched to the canonical file at its slug-derived path (`ReconcileState.origin: 'slug_derived'`), and apply records that path as its `source_path` (the #5254 unbound collision; `test/reconcile-unbound-collision.test.ts`).
+- `src/core/persistence/reconcile*.ts` — trusted-local exact-page reconciliation: loss-preserving semantic preview, explicit JSON Pointer choices, pinned identity/revision/raw-file/policy checks, durable private preimages and same-ID replay through the existing coordinator. Normal overwrite protection stays unchanged. The bounded audit reports source-scoped drift without repair or checkpoint changes; a database-only page (`isDatabaseOnlyPage`, with no file at its slug-derived path) counts as `database_only` with no reconcile suggestion, never as drift, while a legacy row that merely lacks `source_path` is audited as usual. `src/commands/source-reconcile.ts` provides strict CLI parsing, private artifact I/O, brain routing and resident-owner delegation; the operations stay outside public MCP. Operator flow: `docs/guides/concurrent-writes.md`. Tests cover merge choices, both engines, grants, stale previews, read-only audit, and private files. A database-only page (no `source_path`, no `source_uri`; `isDatabaseOnlyPage` in `src/core/persistence/unbound-pages.ts`) is matched to the canonical file at its slug-derived path (`ReconcileState.origin: 'slug_derived'`), and apply records that path as its `source_path` (the #5254 unbound collision; `test/reconcile-unbound-collision.test.ts`). Private fact rows (#6137): `reconcile-prepare.ts` `privateFactViolation` identifies a fact row by (row number, claim), as `restoreHiddenFactRows` does. A stored non-world row carried at its identity must be unchanged; a row at no stored identity may not carry a stored private claim under another visibility, and a world row may not carry (or newly gain) a stored private row's context of 24 or more characters verbatim; sources are not compared. The `permission_denied` refusal names only the row number, with a `gbrain get` read fix. It guards verbatim copies, not reworded text.
- `src/core/persistence/reconcile-additive.ts` (#5974) — pure structural drift classifier over the complete file/database delta: inserted whole lines (two-pointer subsequence, CRLF-normalized; fence, heading and table insertions excluded) are `suggested`; an append-only `contacts` list, an allowlisted activity date moving forward, and one-sided ordinary fields are `auto`; policy/privacy/identity/tag changes and everything else are `review`. `--auto-additive` previews write `take_file` only for `auto` (and `suggested` with `--accept-suggested`), recorded as format-2 `auto_decisions` with an evidence digest that apply and owner preparation recheck. `--audit --classify` reports per-page verdicts and counts, never values.
diff --git a/docs/guides/write-refusals.md b/docs/guides/write-refusals.md
index 6158f62dfb..93bc81c66a 100644
--- a/docs/guides/write-refusals.md
+++ b/docs/guides/write-refusals.md
@@ -69,6 +69,7 @@ of making a duplicate.
| <a id="managed_pull_skipped"></a>`managed_pull_skipped` (cycle warn); doctor `sync_freshness` "upstream unknown" or "upstream N commit(s) ahead" | `managed_pull_skipped` | A managed brain never runs `git pull` inside a cycle: Git pull needs an explicit drained maintenance window, so an explicit `gbrain sync` without `--no-pull` is refused with `writer_coordinator_required`. An unattended cycle asked to pull (autopilot passes `pull: true`, `gbrain dream --pull`) instead syncs the checkout as it is and reports it: the sync phase result carries `details.upstream_refresh` (`pulled`, `failed`, `skipped_managed` or `not_requested`), and when the checkout tracks an upstream the phase is `warn` with `details.warning` (`code`, `cause`, `fix`, `docs`). Every sync also records the checkout's last upstream observation (the upstream commit, when it was last fetched or pushed, and how many upstream commits the synced commit lacks) in the source row. Doctor `sync_freshness` reports that separately from the local projection: a source with a `remote_url` whose observation is missing or older than 24 hours is "upstream unknown", and any source whose observation saw upstream commits it has not synced is "behind"; neither is reported fresh. `details.upstream_unknown_count` and `details.upstream_behind_count` count them. | `gbrain sources refresh <source>` (the printed `fix` fills in the source). It drains writes to the source's checkout, fast-forwards it to its upstream and runs the managed sync for every source bound to that checkout; see [worktree refresh refusals](#worktree-refresh-refusals) for what it can refuse. On a brain that is not managed, `gbrain sync --source <source>` pulls and records the observation. |
| <a id="facts_absorb_write_refused"></a>`facts_absorb_write_refused (<code>)`; `ingest_log` `write_refused: <code> …` | `facts_absorb_write_refused` | A durable `facts-absorb` job extracted facts but the write path refused to store them, for example `writer_coordinator_required` because the entity's Markdown file sits in a claimed canonical worktree before `sources writer activate`, or `permission_denied`, `invalid_params` or `writer_registration_required`. These refusals do not change on retry, so the job goes straight to `dead` on its first attempt instead of re-running inference; on a brain that is not yet activated, a job whose source root is a claimed worktree is refused before extraction starts, so it makes no model call; the `facts:absorb` row in `ingest_log` (and doctor `facts_extraction_health`) records `write_refused` with the real code, not a provider failure. The source page itself was already saved. | Fix the named cause first: `gbrain sources writer status <source>`, then finish the [claim and activate runbook](../architecture/topologies.md#claim-and-activate-runbook) for a claimed worktree, or fix the grant. Then `gbrain jobs retry <job id>` (the error names the id). |
| <a id="no_pricing"></a>`no_pricing` | `no_pricing` | A cost cap you set (`--max-cost`, `--max-usd`, `--max-cost-usd`, or an explicit cap in config such as `cycle.extract_atoms.budget_usd`) cannot be enforced, because gbrain has no price for the model the run was about to call. The run stops before that call. Under a default cap an unpriced model warns and runs instead. The message names the model, provider and kind, and JSON output carries the same guidance as fields: `code`, `model`, `provider`, `kind`, `units`, `lookup`, `register_command`, `register_scope` and `docs`. | Look up the provider's current price for the model, for example by searching the web for its pricing page. A chat model needs USD per 1M input tokens and USD per 1M output tokens; an embedding or reranker model needs USD per 1M tokens. On the brain host, run `gbrain pricing set <model> --input <usd> --output <usd> --source <pricing-page-url>` (or `--rate <usd>`), then retry. An agent connected over MCP cannot register prices: give the command to the brain's operator. See [registering a model price](../operations/spend-controls.md#registering-a-model-price). |
+| <a id="reconcile-private-facts"></a>reconcile private facts | `permission_denied` | `gbrain sources reconcile --apply` (and its preview) found a `## Facts` row that would edit, renumber or change the visibility of a stored private fact, copy a stored private claim into a row under another visibility, or copy a stored private row's context (24 characters or longer) verbatim into a world row. A row is identified by its row number and claim, so a world row that only shares a private row's claim is not a private row and publishes. The refusal names the row number, never its text. It guards against verbatim copies only; reworded text is not detected, so it is not a confidentiality proof. Sources are not compared, because rows share provenance such as "Slack import". Nothing was written. | Read the stored page with the printed `gbrain get --source <id> -- <slug>`, keep the named row as stored in the file (or remove the copied text), then run a fresh `gbrain sources reconcile <id> <slug> --preview` and apply it. Change private facts with `remember` and `forget`. |
### Other error codes
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.ts
index 2f41a3bc43..3d270b644a 100644
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@ -258,6 +258,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText }
{ since: '0.60.98.0', text: 'Managed sync now holds a file whose facts or takes fence cannot be imported (code `invalid_fence`; `gbrain sources status <id>` names the fence, section and rows) instead of blocking the whole source, and a source such a fence blocked before recovers on its next sync. Coordinated writes refuse such a fence with `invalid_fence` (wire `error` stays `invalid_params`, or `take_row_collision`). `gbrain config set sync.holds fail` keeps fail-closed blocking.' },
{ since: '0.60.99.0', text: 'Fixable facts and takes fences are now rewritten instead of held or refused: managed sync, put_page and the fact and take writers normalize a fence whose meaning is unambiguous (a missing end marker after the table, two-dash takes markers, zero or duplicate row numbers, header aliases, invented kinds and enum synonyms, assistant holders, percent confidences) without changing a claim or an existing row number, and managed sync commits the rewritten file. Results report `fences_normalized`; `gbrain sync --dry-run` lists `would_normalize`. `gbrain config set fences.normalize false` turns it off (such fences are then held or refused).' },
{ since: '0.0.0-wave11', text: '`gbrain repair <kind> --apply` and `gbrain doctor --remediate` now wait for each publication with the CLI write wait (`--wait`, `GBRAIN_WRITE_WAIT_MS`, `persistence.write_wait_ms`, else 30 s) instead of 5 s, so one run repairs a slow source; `--wait 0` stops at the first pending write and the rerun resumes.' },
+ { since: '0.0.0-wave11', text: '`gbrain sources reconcile` now identifies a private fact row by its row number and claim, so a page whose world row shares a private row\'s claim publishes instead of being refused; it now also refuses a world row that copies a stored private row\'s context (24 or more characters) verbatim, naming only the row number.' },
];
/** The newest disclosed change's release: the notice id moves only when a release adds rows. */
diff --git a/src/core/persistence/reconcile-prepare.ts b/src/core/persistence/reconcile-prepare.ts
index 5a48444a1d..8c76e60f07 100644
--- a/src/core/persistence/reconcile-prepare.ts
+++ b/src/core/persistence/reconcile-prepare.ts
@@ -4,7 +4,7 @@ import type { BrainEngine } from '../engine.ts';
import type { GBrainConfig } from '../config.ts';
import { importFromContent, type ParsedPage } from '../import-file.ts';
import { parseMarkdown, serializePageToMarkdown } from '../markdown.ts';
-import { parseFactsFence, renderFactsTable, replaceOrInsertFactsFence, restoreHiddenFactRows } from '../facts-fence.ts';
+import { parseFactsFence, renderFactsTable, replaceOrInsertFactsFence, restoreHiddenFactRows, type ParsedFact } from '../facts-fence.ts';
import { opError } from '../ops/contract.ts';
import { readFix, trustedCliRequired } from '../ops/op-fix.ts';
import type { Action } from '../agent-output.ts';
@@ -30,15 +30,56 @@ const receiptFix = (row: WriteRequest): Action => readFix('Reads the reconcile r
{ argv: ['gbrain', 'write-request', '--', row.request_id] });
const freshPreview = (sourceId: string, slug: string) => `Generate a fresh preview with gbrain sources reconcile ${sourceId} ${slug} --preview (with the same --brain), review it and apply that file; nothing from this attempt was written.`;
-function preservePrivateFacts(incoming: string, stored: string): string {
+/** A copied private context shorter than this is too common to count as a copy ("Slack import", "meeting notes"). */
+export const PRIVATE_CONTEXT_COPY_MIN_CHARS = 24;
+
+/**
+ * #6137: the first incoming fact row reconcile must refuse, or null. A row's
+ * identity is its (row number, claim), as `restoreHiddenFactRows` uses.
+ * - Identity rule: a stored non-world row that the incoming fence carries at
+ * the same identity must be unchanged (same digest, so same visibility).
+ * - Copy rule: a row at no stored identity must not carry a stored private
+ * claim under another visibility, and a world row must not carry a stored
+ * private row's context verbatim when it is at least
+ * PRIVATE_CONTEXT_COPY_MIN_CHARS long (nor may a stored world row's
+ * context be changed to one). Sources are never compared: rows share
+ * provenance such as "Slack import".
+ * A row at a stored world identity is a world row, whatever private row shares
+ * its claim. This guards against verbatim copying; reworded text is not
+ * detected, so it is not a confidentiality proof.
+ */
+export function privateFactViolation(next: readonly ParsedFact[], prior: readonly ParsedFact[]): number | null {
+ const identity = (f: ParsedFact) => `${f.rowNum}\u0000${f.claim}`;
+ const stored = new Map(prior.map(f => [identity(f), f]));
+ const hidden = prior.filter(f => f.visibility !== 'world');
+ const copiedContext = (f: ParsedFact) => {
+ const context = f.context?.trim() ?? '';
+ return context.length >= PRIVATE_CONTEXT_COPY_MIN_CHARS && hidden.some(h => h.context?.trim() === context);
+ };
+ for (const fact of next) {
+ const at = stored.get(identity(fact));
+ if (at) {
+ if (at.visibility !== 'world' && digest(fact) !== digest(at)) return fact.rowNum;
+ if (fact.visibility === 'world' && fact.context?.trim() !== at.context?.trim() && copiedContext(fact)) return fact.rowNum;
+ continue;
+ }
+ if (hidden.some(h => h.claim === fact.claim && h.visibility !== fact.visibility)) return fact.rowNum;
+ if (fact.visibility === 'world' && copiedContext(fact)) return fact.rowNum;
+ }
+ return null;
+}
+
+function preservePrivateFacts(incoming: string, stored: string, section: string, sourceId: string, slug: string): string {
const next = parseFactsFence(incoming), prior = parseFactsFence(stored);
if (next.warnings.length || prior.warnings.length) throw opError('invalid_params', 'Fact fences must parse losslessly before reconciliation.',
'The ## Facts table of the file or of the stored page has rows that do not parse cleanly, so reconciliation cannot prove its private facts are kept; nothing was written. Repair the malformed rows in the file, then generate a fresh preview and apply it.');
- for (const fact of prior.facts.filter(f => f.visibility !== 'world')) {
- if (next.facts.some(f => f.claim === fact.claim && (f.visibility !== fact.visibility || f.rowNum === fact.rowNum && digest(f) !== digest(fact)))) {
- throw opError('permission_denied', 'Reconciliation cannot modify protected private facts; use the scoped fact workflow.',
- 'The reconciled page would edit, renumber or change the visibility of a private fact, which reconcile never does; nothing was written. Keep those fact rows as stored, generate a fresh preview, and change private facts through the fact tools (remember, forget) instead.');
- }
+ const row = privateFactViolation(next.facts, prior.facts);
+ if (row !== null) {
+ throw opError('permission_denied', 'Reconciliation cannot modify protected private facts; use the scoped fact workflow.',
+ `Row ${row} of the ## Facts table in the reconciled ${section} would edit, renumber or change the visibility of a private fact, or copy a private fact's claim or context into another row, which reconcile never does; nothing was written. `
+ + `Read the stored page with the command in fix, keep row ${row} as stored in the file (or remove the copied text), then ${freshPreview(sourceId, slug).replace(/^Generate/, 'generate')} Change private facts through the fact tools (remember, forget) instead.`,
+ { why: `Row ${row} conflicts with a private fact row stored for ${slug}; reconcile only publishes rows whose (row number, claim) identity it can prove is not a private row edited or copied.`,
+ fix: pageFix(sourceId, slug), docs: 'docs/guides/write-refusals.md#reconcile-private-facts' });
}
const merged = restoreHiddenFactRows(next, prior);
return merged ? replaceOrInsertFactsFence(incoming, renderFactsTable(merged.merged)) : incoming;
@@ -48,7 +89,8 @@ export async function prepareReconcileResult(engine: BrainEngine, state: Reconci
if (merged.conflicts.length) return { ...merged, ready: undefined };
const result = merged.result;
for (const key of ['compiled_truth', 'timeline'] as const) {
- result[key] = preservePrivateFacts(preserveProtectedTakes(result[key], state.snapshot.page[key] ?? ''), state.snapshot.page[key] ?? '');
+ result[key] = preservePrivateFacts(preserveProtectedTakes(result[key], state.snapshot.page[key] ?? ''), state.snapshot.page[key] ?? '',
+ key === 'timeline' ? 'timeline' : 'page body', state.pins.source_id, state.pins.slug);
}
// #5567: reconcile renders from the merged database state; an operator-approved
// body decision edits the file side, every other merge preserves history.
diff --git a/test/persistence-reconcile.test.ts b/test/persistence-reconcile.test.ts
index 7340643617..aec769b39e 100644
--- a/test/persistence-reconcile.test.ts
+++ b/test/persistence-reconcile.test.ts
@@ -22,7 +22,7 @@ import { retainReconcileBackup } from '../src/core/persistence/reconcile-backup.
import { prepareReconcileMutation } from '../src/core/persistence/reconcile-prepare.ts';
import { publishMutation } from '../src/core/persistence/coordinator.ts';
import { localHostId } from '../src/core/persistence/identity.ts';
-import { parseFactsFence, renderFactsTable, upsertFactRow } from '../src/core/facts-fence.ts';
+import { parseFactsFence, renderFactsTable, replaceOrInsertFactsFence, upsertFactRow } from '../src/core/facts-fence.ts';
import { sha256 } from '../src/core/persistence/digest.ts';
import type { OperationContext } from '../src/core/ops/contract.ts';
import { operationsByName } from '../src/core/operations.ts';
@@ -694,3 +694,73 @@ test('a fact withdrawn between reconciliation preparation and publication leaves
});
}
}), 120_000);
+
+// #6137: private fact rows are identified by (row number, claim), never by claim text alone.
+type FenceRow = { rowNum: number; claim: string; visibility: 'private' | 'world'; context?: string; source?: string; confidence?: number; forgotten?: boolean };
+const LONG_PRIVATE_CONTEXT = 'Told in confidence at the example offsite';
+function factsBody(rows: FenceRow[], prose = 'A durable example biography.') {
+ const facts = rows.map(r => ({ rowNum: r.rowNum, claim: r.claim, kind: 'fact' as const, confidence: r.confidence ?? 1, visibility: r.visibility,
+ notability: 'medium' as const, source: r.source, active: !r.forgotten, ...(r.forgotten ? { forgotten: true, context: 'forgotten: user request' } : { context: r.context }) }));
+ return replaceOrInsertFactsFence(prose, renderFactsTable(facts));
+}
+const TWIN: FenceRow[] = [{ rowNum: 1, claim: 'Prefers the example venue', visibility: 'private' }, { rowNum: 2, claim: 'Prefers the example venue', visibility: 'world' }];
+const FORGOTTEN_TWIN: FenceRow[] = [{ ...TWIN[0], forgotten: true }, TWIN[1]];
+const PRIVATE_AND_WORLD: FenceRow[] = [{ rowNum: 1, claim: 'Holds a private example account', visibility: 'private', context: LONG_PRIVATE_CONTEXT, source: 'Slack import' },
+ { rowNum: 2, claim: 'Works at acme-example', visibility: 'world', source: 'Slack import' }];
+const reconcileCases: Array<{ name: string; stored: FenceRow[]; incoming?: FenceRow[]; prose?: string; refusedRow?: number }> = [
+ { name: 'a frontmatter-only edit with an active private twin', stored: TWIN },
+ { name: 'a frontmatter-only edit with a forgotten private twin', stored: FORGOTTEN_TWIN },
+ { name: 'a take_file body edit with an active private twin', stored: TWIN, incoming: TWIN, prose: 'A revised public biography.' },
+ { name: 'a take_file body edit with a forgotten private twin', stored: FORGOTTEN_TWIN, incoming: FORGOTTEN_TWIN, prose: 'A revised public biography.' },
+ { name: 'an edit of the world twin', stored: TWIN, incoming: [TWIN[0], { ...TWIN[1], claim: 'Now prefers the new example venue' }] },
+ { name: 'a new unrelated world row', stored: PRIVATE_AND_WORLD, incoming: [...PRIVATE_AND_WORLD, { rowNum: 3, claim: 'Lives in example-city', visibility: 'world' }] },
+ { name: 'a new world row sharing a short context and the source', stored: [{ ...PRIVATE_AND_WORLD[0], context: 'Slack import' }, PRIVATE_AND_WORLD[1]],
+ incoming: [{ ...PRIVATE_AND_WORLD[0], context: 'Slack import' }, PRIVATE_AND_WORLD[1], { rowNum: 3, claim: 'Joined the example guild', visibility: 'world', context: 'Slack import', source: 'Slack import' }] },
+ { name: 'an existing world row whose context equals the private context', stored: [PRIVATE_AND_WORLD[0], { ...PRIVATE_AND_WORLD[1], context: LONG_PRIVATE_CONTEXT }],
+ incoming: [PRIVATE_AND_WORLD[0], { ...PRIVATE_AND_WORLD[1], context: LONG_PRIVATE_CONTEXT }], prose: 'A revised public biography.' },
+ { name: 'editing the private twin', stored: TWIN, incoming: [{ ...TWIN[0], confidence: 0.5 }, TWIN[1]], refusedRow: 1 },
+ { name: 'making a private fact world', stored: TWIN, incoming: [{ ...TWIN[0], visibility: 'world' }, TWIN[1]], refusedRow: 1 },
+ { name: 'copying a private claim into a new world row', stored: PRIVATE_AND_WORLD, incoming: [...PRIVATE_AND_WORLD, { rowNum: 3, claim: PRIVATE_AND_WORLD[0].claim, visibility: 'world' }], refusedRow: 3 },
+ { name: 'writing a private claim over an existing world row', stored: PRIVATE_AND_WORLD, incoming: [PRIVATE_AND_WORLD[0], { ...PRIVATE_AND_WORLD[1], claim: PRIVATE_AND_WORLD[0].claim }], refusedRow: 2 },
+ { name: 'copying a private context into an existing world row', stored: PRIVATE_AND_WORLD,
+ incoming: [PRIVATE_AND_WORLD[0], { ...PRIVATE_AND_WORLD[1], context: LONG_PRIVATE_CONTEXT }], refusedRow: 2 },
+ { name: 'copying a private context into a new world row', stored: PRIVATE_AND_WORLD,
+ incoming: [...PRIVATE_AND_WORLD, { rowNum: 3, claim: 'Mentioned an example plan', visibility: 'world', context: LONG_PRIVATE_CONTEXT }], refusedRow: 3 },
+];
+for (const c of reconcileCases) {
+ test(`#6137 reconcile private facts: ${c.refusedRow ? 'refuses' : 'publishes'} ${c.name}`, async () => isolated(async engine => {
+ const f = await fixture(engine, false, factsBody(c.stored));
+ if (c.incoming || c.prose) {
+ writeFileSync(f.file, serializePageToMarkdown({ ...f.snapshot.page, compiled_truth: factsBody(c.incoming ?? c.stored, c.prose) }, f.snapshot.tags));
+ }
+ await local(engine, f.registration, async () => {
+ const preview = async () => {
+ const initial = await runReconcilePreview(engine, { source_id: f.id, slug: f.slug });
+ const decisions = initial.preview.conflicts.map(conflict => ({ path: conflict.path, action: 'take_file' }));
+ return decisions.length ? runReconcilePreview(engine, { source_id: f.id, slug: f.slug, from: initial.preview, decisions }) : initial;
+ };
+ if (c.refusedRow) {
+ const error = await preview().then(() => null, (e: unknown) => e as { code: string; message: string; suggestion: string; why?: string; fix?: { argv?: string[] } });
+ expect(error).toMatchObject({ code: 'permission_denied' });
+ const text = `${error!.message} ${error!.suggestion} ${error!.why ?? ''}`;
+ expect(text).toContain(`Row ${c.refusedRow} `);
+ for (const row of [...c.stored, ...(c.incoming ?? [])]) {
+ expect(text).not.toContain(row.claim);
+ if (row.context) expect(text).not.toContain(row.context);
+ }
+ expect(error!.fix?.argv).toEqual(['gbrain', 'get', '--source', f.id, '--', f.slug]);
+ expect((await engine.readPageSnapshot(f.slug, { sourceId: f.id }))!.revision).toBe(f.snapshot.revision);
+ return;
+ }
+ const resolved = await preview();
+ const receipt = await runReconcileApply(engine, { source_id: f.id, slug: f.slug, preview: resolved.preview, request_id: randomUUID() });
+ expect(receipt.state).toBe('committed');
+ const stored = (await engine.readPageSnapshot(f.slug, { sourceId: f.id }))!;
+ const fileFence = parseFactsFence(parseMarkdown(readFileSync(f.file, 'utf8'), f.slug).compiled_truth);
+ expect(renderFactsTable(fileFence.facts)).toBe(renderFactsTable(parseFactsFence(stored.page.compiled_truth).facts));
+ const privateRow = parseFactsFence(stored.page.compiled_truth).facts.find(fact => fact.rowNum === 1)!;
+ expect(privateRow.visibility).toBe(c.stored[0].visibility);
+ expect(privateRow.claim).toBe(c.stored[0].claim);
+ });
+ }), 120_000);
+}