Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
repair visibility --class facts counts the fact rows it could not make private and says they stay readable (U1)
garrytan019eec1483ab
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 1714c902b7..4c2875d7de 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -20,7 +20,7 @@ identifiers and attribution are available in the pre-removal Git revision- `src/core/persistence/page-prepare.ts`: a `managed_maintenance_page` write that carries `label_edit` publishes the canonical file's own bytes with only its label lines edited (`labelEditFile`), keeping its body when it reads as the write's body, and refuses instead of re-rendering when no line edit reads back as the write.- `src/core/persistence/prepared-maintenance.ts`: maintenance page publications carry `labelEdit`.- `src/core/repair/label-write.ts` (new): the label-only write door both repairs use (the maintenance door with `keep_trust` on a managed brain; the import under the page lock and `withTrustKeep` otherwise); `filesInCheckout` and `importAtRevision` moved here from `private-labels.ts`.-- `src/core/repair/visibility.ts`: page and fenced-fact items write through the label door instead of `put_page`; on a brain without managed persistence a page whose file sits in a checkout gets the same label-line edit in that file, imported with its tier kept; a segmented page is held (`segmented_page`); new `--slug` selection (class `pages`), preview-bound, tighten-only.+- `src/core/repair/visibility.ts`: page and fenced-fact items write through the label door instead of `put_page`; on a brain without managed persistence a page whose file sits in a checkout gets the same label-line edit in that file, imported with its tier kept; a segmented page is held (`segmented_page`); new `--slug` selection (class `pages`), preview-bound, tighten-only; a fenced fact row it could not make private is reported `fact_left_readable` (`NOT CLOSED` in the text output) instead of a plain skip, because remote callers can still read it.- `src/core/repair/private-labels.ts`: clears and restores carry their label edit, so the file loses or regains only those lines.- `src/core/trust/label-lowerings.ts` (new), `src/cli/commands/trust.ts`: `gbrain trust backfill --label-lowerings [--source ID] [--json]`, read-only.- Tests: `test/label-only-repairs.test.ts` (managed Git source and repo-less brain, PGLite and Postgres).diff --git a/docs/guides/repair.md b/docs/guides/repair.mdindex 4e97f9a578..e585e40778 100644--- a/docs/guides/repair.md+++ b/docs/guides/repair.md@@ -92,6 +92,14 @@ without managed persistence, a page whose file sits in its source's checkout getthe same edit in that file and in the database together, so the next sync readsthe same page.+A fenced fact row the apply could not make private is counted as+`fact_left_readable` in the outcomes (`--json`: `outcomes.fact_left_readable`,+each row in `outcome_items`), and the text output says `NOT CLOSED`: those rows+are still world and remote callers can still read them. Today that happens when+the original row is more trusted than the repair (it is kept beside the new+private row), when the page is stored in segments, or when the row is not found+in the page's facts fence.+The apply touches only the listed items and resumes after its last applieditem if it stops. Apply the window (or decide not to), then preview again forthe next one. Each plan statement is bounded at 120 s; a class that overruns isdiff --git a/src/commands/repair.ts b/src/commands/repair.tsindex 2eab1f51c3..323f03b769 100644--- a/src/commands/repair.ts+++ b/src/commands/repair.ts@@ -456,6 +456,9 @@ export function renderRepairResult(result: RepairResult, opts: { diff: boolean }const render = repairSpec(result.kind).handler.render;if (result.details && render) lines.push(...render(result.details, opts));if (result.mode === 'apply' && result.outcomes) lines.push(` outcomes: ${Object.entries(result.outcomes).map(([k, v]) => `${k}=${v}`).join(', ')}`);+ if (result.mode === 'apply' && result.outcomes?.fact_left_readable) {+ lines.push(` NOT CLOSED: ${result.outcomes.fact_left_readable} fact row(s) could not be made private and stay readable by remote callers (listed below).`);+ }for (const outcome of result.mode === 'apply' ? result.outcome_items ?? [] : []) {if (!outcome.detail) continue;lines.push(` ${outcome.outcome}: ${outcome.item} ${Object.entries(outcome.detail).filter(([key]) => key !== 'commit_step' && key !== 'fix').map(([k, v]) => `${k}=${v}`).join(', ')}${outcome.reason ? ` (${outcome.reason})` : ''}`);diff --git a/src/core/repair/visibility.ts b/src/core/repair/visibility.tsindex 1f20dc3b56..5164eb5bd3 100644--- a/src/core/repair/visibility.ts+++ b/src/core/repair/visibility.ts@@ -258,8 +258,11 @@ export async function prepareFactVisibilityTighten(engine: BrainEngine, row: Wri* One fact item: a fenced row gets `private` in its page's `## Facts` fence by a* revision-bound label write (labelWrite; the projection then stores it private); a* database-only row is updated in place (a database-only maintenance request- * on a managed brain). A page stored in segments is left for the owner.+ * on a managed brain). A page stored in segments is left for the owner. A fenced row that stays world and live is+ * reported `fact_left_readable` (counted in the apply's outcomes), never as done: remote callers still read it.*/+const leftReadable = (factId: number, why: string): RepairItemOutcome => ({ applied: false, outcome: 'fact_left_readable', detail: { fact_id: factId },+ reason: `${why}; the fact row is still world, so remote callers can still read it` });async function applyFactItem(ctx: Parameters<RepairHandler['apply']>[0], item: RepairItem, factId: number): Promise<boolean | RepairItemOutcome> {const [fact] = await worldFactsFromPrivateSources(ctx.engine, [item.source_id], [factId]);if (!fact) return false;@@ -276,13 +279,15 @@ async function applyFactItem(ctx: Parameters<RepairHandler['apply']>[0], item: Rreturn ((receipt.tightened as number[] | undefined) ?? []).includes(factId);}const snapshot = fact.source_markdown_slug ? await ctx.engine.readPageSnapshot(fact.source_markdown_slug, { sourceId: item.source_id }) : null;- if (!snapshot || isSegmentedPage(snapshot.page)) return false;+ if (!snapshot) return false;+ if (isSegmentedPage(snapshot.page)) return leftReadable(factId, 'its page is stored in segments, which this repair does not rewrite');const body = strikeFenceRow(snapshot.page.compiled_truth ?? '', fact.row_num, row => ({ ...row, visibility: 'private' }));- if (body === null) return false;+ if (body === null) return leftReadable(factId, 'its row was not found in the page\'s facts fence');const held = await labelWrite(ctx, item, snapshot, serializePageToMarkdown({ ...snapshot.page, compiled_truth: body }, snapshot.tags), { set: {}, remove: [] });if (held) return held;- const [stored] = await ctx.engine.executeRaw<{ visibility: string }>('SELECT visibility FROM facts WHERE id=$1', [factId]);- return stored?.visibility === 'private';+ const [stored] = await ctx.engine.executeRaw<{ visibility: string; live: boolean }>('SELECT visibility, expired_at IS NULL AS live FROM facts WHERE id=$1', [factId]);+ if (!stored || stored.visibility === 'private' || !stored.live) return true;+ return leftReadable(factId, 'its fence row was written private, but the original row is more trusted than the repair and was kept beside it');}/**diff --git a/test/label-only-repairs.test.ts b/test/label-only-repairs.test.tsindex b46cc074e0..71f92a4c8b 100644--- a/test/label-only-repairs.test.ts+++ b/test/label-only-repairs.test.ts@@ -24,7 +24,7 @@ import { importFromContent } from '../src/core/import-file.ts';import { withCoordinatedWrite, withTrustBackfill } from '../src/core/persistence/context.ts';import { performManagedSync } from '../src/core/persistence/sync-run.ts';import { disposePersistenceConsumer } from '../src/core/persistence/service.ts';-import { runRepairCommand } from '../src/commands/repair.ts';+import { renderRepairResult, runRepairCommand } from '../src/commands/repair.ts';import { _resetCliExitVerdictForTests } from '../src/core/cli-force-exit.ts';import { listLabelLowerings, renderLabelLowerings } from '../src/core/trust/label-lowerings.ts';import { durableGitRepo, git } from './helpers/git-publication.ts';@@ -126,8 +126,14 @@ for (const backend of testBackends()) describe('[' + backend + '] label-only ope+ '<!--- gbrain:facts:begin -->' + NL + NL + header + '| 1 | Alice Example works at acme-example. | fact | 1.0 | ' + visibility + ' | medium | 2026-10-01 | | test | |' + NL+ '<!--- gbrain:facts:end -->' + NL);await seed(engine, root, { [slug]: withFacts('world') });- await previewApply(engine, ['visibility', '--class', 'facts']);+ const { applied } = await previewApply(engine, ['visibility', '--class', 'facts']);await settleManagedGitEffects(engine);+ // The original world row is more trusted than the repair and stays live (GST-2487): the apply must say so, never "done".+ expect(applied.applied).toBe(0);+ expect(applied.outcomes).toMatchObject({ fact_left_readable: 1 });+ expect(applied.outcome_items).toEqual([expect.objectContaining({ item: 'default:' + slug, outcome: 'fact_left_readable' })]);+ expect(renderRepairResult(applied)).toContain('NOT CLOSED: 1 fact row(s) could not be made private and stay readable by remote callers');+ expect(await engine.executeRaw("SELECT visibility FROM facts WHERE source_markdown_slug=$1 AND expired_at IS NULL AND visibility='world'", [slug])).toEqual([{ visibility: 'world' }]);expect((await page(engine, slug)).tier).toBe('operator_curated');expect(await engine.executeRaw("SELECT id FROM trust_proposals WHERE action='lower_page'")).toEqual([]);expect(onDisk(root, slug)).toBe(withFacts('private'));