Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Repair open-facts keeps lapsed facts private and opens facts tables below the timeline (#9572)
Garry Tan0a56554d745d
diff --git a/behavior-changes.d/open_facts_lapsed_timeline_8194.md b/behavior-changes.d/open_facts_lapsed_timeline_8194.mdnew file mode 100644index 0000000000..58251f40a1--- /dev/null+++ b/behavior-changes.d/open_facts_lapsed_timeline_8194.md@@ -0,0 +1,4 @@+---+kind: fix+---+gbrain repair open-facts now leaves a fact private when its valid_until date has passed, and counts it as lapsed in the preview. It also opens a fenced fact whose ## Facts table sits below the timeline sentinel; before, such a fact was always reported fact_left_private. The preview now warns that a fact saved private on purpose before the cut looks the same as a legacy one, and that --ids-file narrows the set.diff --git a/changelog.d/capy-open-facts-lapsed-and-timeline.md b/changelog.d/capy-open-facts-lapsed-and-timeline.mdnew file mode 100644index 0000000000..1825c465b7--- /dev/null+++ b/changelog.d/capy-open-facts-lapsed-and-timeline.md@@ -0,0 +1,8 @@+**`gbrain repair open-facts` now keeps a fact private once its end date has passed, and opens facts tables that sit below the timeline.**++<!-- behavior-change: open_facts_lapsed_timeline_8194 -->++### Fixed+- A private fact whose `valid_until` date has passed stays private, and the preview counts it under a new reason, `lapsed`. Before, the repair could open a fact that was no longer true.+- A fact in a `## Facts` table below the timeline sentinel now opens in place. Before, the apply looked only above the timeline and reported every such fact `fact_left_private`.+- The preview warns that a fact saved private on purpose before the cut looks the same as a legacy one, and that `--ids-file` limits the run to the ids you list.diff --git a/docs/guides/memory-trust.md b/docs/guides/memory-trust.mdindex 437ed99f97..8672ac6b70 100644--- a/docs/guides/memory-trust.md+++ b/docs/guides/memory-trust.md@@ -51,6 +51,12 @@ token at a terminal on the brain host. `--yes` never confirms.`gbrain trust review` lists flagged items; confirming one clears its flag.- **Flagged items still reach proactive context, labeled**(`trust.agent_activation` is `allow`).+- **A restated private fact stays private.** When a remote `remember`+ repeats the exact claim of a private fact that a more trusted writer saved+ on the same entity, the new fact is stored private and a proposal waits in+ `gbrain trust review`; `gbrain trust confirm tp<N>` makes it world. A+ reworded claim isn't matched, and the held claim's text can still appear+ in the page body that remote readers fetch.These defaults come from a preregistered paid eval with Opus 5.5, Sonnet 5.5and GPT-6.1 Sol (gbrain-evalsdiff --git a/docs/guides/repair.md b/docs/guides/repair.mdindex 6372693a8f..fbbb08166b 100644--- a/docs/guides/repair.md+++ b/docs/guides/repair.md@@ -2477,8 +2477,13 @@ open only when you name that class, for example `--class unpaged:mail:extract`(quote a lane that contains spaces).`--ids-file <file>` (one fact id per line) narrows the set.+A fact someone saved private on purpose before the cut looks the same as a+legacy one, so it is opened with them. The preview says so and shows samples+and every listed fact; when some must stay private, put the ids you do want+opened in a file and pass `--ids-file`.+The preview also counts every fact it leaves private, by reason: `expired`,-`superseded`, `member_page`, `withdrawn` (forgotten or purged, at any+`superseded`, `lapsed` (its `valid_until` has passed), `member_page`, `withdrawn` (forgotten or purged, at anyvisibility), `contested` (an open trust proposal, or a widening the ownerrejected or undid), `holding_page_private`, `holding_page_missing`,`holding_page_quarantined`, `provenance_private`, `provenance_unresolved`,@@ -2493,7 +2498,8 @@ eligible inside the window since the preview refuses `preview_changed`. Eachwrite locks the pages the fact names and checks it again, so a page madeprivate while the apply waits keeps its facts private. A fenced row has itstable cell set to `world` by the same label-only write the other privacy-repairs use. A fact the apply could not open is reported `fact_left_private`+repairs use, in the table where it sits, above or below the timeline+sentinel. A fact the apply could not open is reported `fact_left_private`with the reason, never as applied.The command refuses remote callers and any CLI running underdiff --git a/src/core/repair/open-facts.ts b/src/core/repair/open-facts.tsindex 613d7eae3d..c1f0ffcdf8 100644--- a/src/core/repair/open-facts.ts+++ b/src/core/repair/open-facts.ts@@ -104,6 +104,7 @@ export function openFactsReasonSql(f: string): string {return `(CASEWHEN ${f}.expired_at IS NOT NULL THEN 'expired'WHEN ${f}.superseded_by IS NOT NULL THEN 'superseded'+ WHEN ${f}.valid_until IS NOT NULL AND ${f}.valid_until <= now() THEN 'lapsed'WHEN ${member(`${f}.source_markdown_slug`)} OR ${member(`${f}.entity_slug`)} OR ${member(prov)} THEN 'member_page'WHEN EXISTS (SELECT 1 FROM fact_withdrawals w WHERE w.source_id = ${f}.source_idAND w.fact_hash IN (gbrain_fact_fingerprint(${f}.fact), gbrain_fact_fingerprint_v1(${f}.fact)) AND (w.subject = '*' OR w.subject = ${f}.entity_slug))@@ -325,6 +326,8 @@ export const openFactsRepair: RepairHandler = {warnings: ['Opening a fact widens what remote callers that are not the brain owner can read, and that is one-way for anything they read before an undo. '+ `Each opened fact is recorded in ${request.ledger.path}; undo with: gbrain repair open-facts --source ${sel.source_id} --undo ${request.ledger.path}`,+ 'A fact someone saved private on purpose before the cut looks the same as a legacy one and is opened with them. Read the samples and the listing, '+ + 'and when some must stay private, list the ids to open in a file (one per line) and pass --ids-file <file>.',...(next ? [`This preview lists one window of ${window.length} fact(s); more may follow it. Apply this window (or decide not to), then preview the next one: ${next}`] : []),...(counts ? [] : [`The counts by reason did not finish within the ${PLAN_STATEMENT_MS} ms statement bound and are not listed; the window is.`]),...(notNamed.length ? [`${notNamed.map(([cls, n]) => `${n} ${cls}`).join(', ')} fact(s) are not in this preview: they come from no page the brain can judge, or from a class not named. `@@ -474,17 +477,20 @@ async function applyFence(ctx: OperationContext, item: OpenItem): Promise<Repairconst snapshot = await ctx.engine.readPageSnapshot(group.slug, { sourceId: group.source_id });if (!snapshot) return settle(item, '', [], 'its page is gone');if (isSegmentedPage(snapshot.page)) return settle(item, '', [], 'its page is stored in segments, which this repair does not rewrite; edit the facts fence by hand on the brain host');- let body = snapshot.page.compiled_truth ?? '';+ const sections: { compiled_truth: string; timeline?: string } = { compiled_truth: snapshot.page.compiled_truth ?? '' };const struck: FactRef[] = [];for (const fact of group.facts) {- let hit = false;- const next = strikeFenceRow(body, fact.row_num!, row => row.claim === fact.fact && row.visibility === from ? (hit = true, { ...row, visibility: to }) : row);- if (next === null || !hit) continue;- body = next;- struck.push(fact);+ for (const key of ['compiled_truth', 'timeline'] as const) {+ let hit = false;+ const next = strikeFenceRow(sections[key] ?? snapshot.page[key] ?? '', fact.row_num!, row => row.claim === fact.fact && row.visibility === from ? (hit = true, { ...row, visibility: to }) : row);+ if (next === null || !hit) continue;+ sections[key] = next;+ struck.push(fact);+ break;+ }}if (!struck.length) return settle(item, '', [], 'its rows were not found in the page\'s facts fence as previewed, or the fence does not parse cleanly');- const content = serializePageToMarkdown({ ...snapshot.page, compiled_truth: body }, snapshot.tags);+ const content = serializePageToMarkdown({ ...snapshot.page, ...sections }, snapshot.tags);const edit = { set: {}, remove: [] };const rows = pinned(struck);const requestId = requestIdOf(item, snapshot.revision);diff --git a/test/repair-open-facts-8194.test.ts b/test/repair-open-facts-8194.test.tsindex 170f48aec0..21f740fdad 100644--- a/test/repair-open-facts-8194.test.ts+++ b/test/repair-open-facts-8194.test.ts@@ -707,3 +707,56 @@ describe('remote page rewrite keeps hidden private fence rows (Discussion #8194,}}), 180_000);});++/**+ * Test 18 (second-model review of #9523's code): a fact whose validity has ended is left private under its own reason,+ * `lapsed`, by the preview and the locked apply alike; and a facts fence that lives below the timeline sentinel is+ * opened where it lives, leaving the section above it unchanged. Managed and unmanaged, repo-less.+ */+describe('test 18: a lapsed fact stays private, and a fence in the timeline opens in place', () => {+ for (const managed of [false, true]) {+ test(`a fact past its valid_until is counted lapsed and left private (${managed ? 'managed' : 'unmanaged'})`, async () => withEnv({ GBRAIN_HOME: home }, async () => {+ for (const engine of engines) {+ const b = await brain(engine, managed);+ const slug = 'companies/lapsed-example';+ const body = fence([[1, 'Orchardline current row', 'private']]).replace('| | fixture | |',+ '| | fixture | |\n| 2 | Orchardline lapsed row | fact | 1.0 | private | medium | 2019-01-01 | 2020-01-01 | fixture | |');+ await run(b.local, 'put_page', { slug, content: `---\ntype: company\ntitle: ${slug}\n---\n\n# ${slug}\n\nOrchardline body.\n\n${body}\n` });+ const lapsedDb = await dbOnly(b, 'Orchardline lapsed database-only fact', slug);+ await coordinated(b, `UPDATE facts SET valid_until = '2020-01-01' WHERE id = $1`, [lapsedDb]);+ const [lapsedRow] = await facts(b, 'Orchardline lapsed row');+ expect(lapsedRow?.visibility).toBe('private');++ const { planned, applied } = await previewAndApply(b);+ expect(planned.details.excluded).toMatchObject({ lapsed: 2 });+ expect(planned.listing.map((l: { detail: string }) => l.detail)).toEqual([expect.stringContaining('(fenced row 1)')]);+ expect(applied!.applied).toBe(1);+ expect(await visibilityOf(b, lapsedRow!.id)).toBe('private');+ expect(await visibilityOf(b, lapsedDb)).toBe('private');+ expect((await fenceCell(b, slug, 2))?.visibility).toBe('private');+ expect((await facts(b, 'Orchardline current row')).map(f => f.visibility)).toEqual(['world']);+ }+ }), 180_000);++ test(`a fence below the timeline sentinel is opened there and the body above is unchanged (${managed ? 'managed' : 'unmanaged'})`, async () => withEnv({ GBRAIN_HOME: home }, async () => {+ for (const engine of engines) {+ const b = await brain(engine, managed);+ const slug = 'companies/timeline-fence-example';+ await run(b.local, 'put_page', { slug, content: `---\ntype: company\ntitle: ${slug}\n---\n\n# ${slug}\n\nOrchardline body above the timeline.\n\n<!-- timeline -->\n\n${fence([[1, 'Orchardline timeline row', 'private']])}\n` });+ const [stored] = await engine.executeRaw<{ compiled_truth: string; timeline: string }>('SELECT compiled_truth, timeline FROM pages WHERE source_id=$1 AND slug=$2', [b.sourceId, slug]);+ expect(stored!.timeline).toContain('Orchardline timeline row');+ const [before] = await facts(b, 'Orchardline timeline row');+ expect(before?.visibility).toBe('private');++ const { applied } = await previewAndApply(b);+ expect(applied!.applied).toBe(1);+ expect(applied!.outcomes?.fact_left_private).toBeUndefined();+ expect((await facts(b, 'Orchardline timeline row')).map(f => [f.id, f.visibility])).toEqual([[before!.id, 'world']]);+ const [after] = await engine.executeRaw<{ compiled_truth: string; timeline: string }>('SELECT compiled_truth, timeline FROM pages WHERE source_id=$1 AND slug=$2', [b.sourceId, slug]);+ expect(after!.compiled_truth).toBe(stored!.compiled_truth);+ expect(parseFactsFence(after!.timeline).facts.find(f => f.rowNum === 1)).toMatchObject({ claim: 'Orchardline timeline row', visibility: 'world' });+ }+ }), 180_000);+ }+});+