Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(visibility): remote extract_facts writes private when its source page is private or unseen

garrytanafd81cd4a964
diff --git a/docs/architecture/system-of-record.md b/docs/architecture/system-of-record.md
index 8f567bdc33..7dd9821163 100644
--- a/docs/architecture/system-of-record.md
+++ b/docs/architecture/system-of-record.md
@@ -304,6 +304,7 @@ or a physical projection that leaves attribution untouched):
- `src/core/repair/take-supersession.ts` (1): `gbrain repair take-supersession` reprojection: a receipted `managed_maintenance_take_reproject` request on managed brains, `maintenanceTransaction` on unmanaged ones; fence edits go through a revision-bound `put_page`.
- `src/core/repair/timeline-comments.ts` (1): `gbrain repair timeline-comments` row cleanup: `withCoordinatedWrite` under the page key on managed brains, `maintenanceTransaction` otherwise.
- `src/core/repair/url-clone-fences.ts` (2): `gbrain repair url-clone-fences` (#6946), unmanaged brains only (a managed brain previews nothing); keeping the appended fence rows database-only (clearing `row_num`, inserting a row the database lost) runs in one `maintenanceTransaction` under the page lock after the preview recheck; HEAD's bytes then import through `importFromContent`.
+- `src/core/repair/visibility.ts` (1): `gbrain repair visibility --apply` tightening of database-only world facts from a private source: a receipted `managed_maintenance_tighten_fact_visibility` request on managed brains, `maintenanceTransaction` on unmanaged ones; fenced rows change through a revision-bound `put_page`.
- `src/core/schema-pack/page-to-alias.ts` (1): the page-to-alias conversion soft-deletes each converted page in `maintenanceTransaction`.
- `src/core/schema-pack/page-to-link.ts` (1): the page-to-link conversion soft-deletes each converted page in `maintenanceTransaction`.
- `src/core/schema-pack/retype.ts` (1): each bounded retype batch runs in `maintenanceTransaction`.
diff --git a/src/core/ops/facts.ts b/src/core/ops/facts.ts
index 7ef7c7e8a0..f1788f8d0d 100644
--- a/src/core/ops/facts.ts
+++ b/src/core/ops/facts.ts
@@ -129,13 +129,11 @@ const extract_facts: Operation = {
typeof p.source_slug === 'string' && p.source_slug.trim().length > 0
? p.source_slug.trim()
: undefined;
- // A turn taken from a private page yields private facts, even when the caller asked for world. The page is read
- // as this caller may see it, so a remote caller cannot use the result to learn that a hidden page exists.
+ // A turn taken from a private page yields private facts, even when the caller asked for world. A remote caller's
+ // facts are also private when it cannot see the source page, so a hidden page and a missing one look the same.
if (visibility === 'world' && sourceSlug) {
- const { resolveExcludePrivatePages } = await import('../search/private-visibility.ts');
- const origin = await ctx.engine.readPageSnapshot(sourceSlug.replace(/\.md$/, ''),
- { sourceId, excludePrivate: await resolveExcludePrivatePages(ctx.engine, ctx.remote) });
- visibility = tightenToPage(visibility, origin?.page);
+ const origin = await ctx.engine.readPageSnapshot(sourceSlug.replace(/\.md$/, ''), { sourceId });
+ visibility = ctx.remote !== false && !origin ? 'private' : tightenToPage(visibility, origin?.page);
}
const r = await runFactsPipeline(p.turn_text as string, {
diff --git a/test/visibility-fail-closed-derived-writes.test.ts b/test/visibility-fail-closed-derived-writes.test.ts
index 1e58f683e1..9c88b24fa4 100644
--- a/test/visibility-fail-closed-derived-writes.test.ts
+++ b/test/visibility-fail-closed-derived-writes.test.ts
@@ -164,6 +164,21 @@ describe('facts extracted from a private page stay private', () => {
expect(await remoteReadable(s.remote)).not.toContain(CLAIM);
});
}, 120_000);
+
+ test('remote extract_facts: a private or unseen source_slug writes private alike; a world source keeps world', async () => {
+ await onEachEngine(async engine => {
+ const s = await source(engine, true);
+ const extract = async (claim: string, source_slug: string) => {
+ stubExtraction(claim);
+ await operationsByName.extract_facts!.handler(s.remote, { turn_text: BODY, visibility: 'world', source_slug });
+ return (await factRows(engine, s.sourceId)).find(r => r.fact === claim)?.visibility;
+ };
+ expect(await extract(CLAIM, NOTE)).toBe('private');
+ expect(await extract('Alice Example joined the example board', 'notes/never-written-example')).toBe('private');
+ expect(await extract('Alice Example moved to the example city', PERSON)).toBe('world');
+ expect(await remoteReadable(s.remote)).not.toContain(CLAIM);
+ });
+ }, 120_000);
});
describe('remember without a visibility never widens', () => {