Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Keep the new test, the page writer and the Postgres engine within the isolation and size checks

garrytand07cf32348ac
diff --git a/scripts/function-size-baseline.tsv b/scripts/function-size-baseline.tsv
index 44bf4a2c36..b2ce58970a 100644
--- a/scripts/function-size-baseline.tsv
+++ b/scripts/function-size-baseline.tsv
@@ -49,7 +49,7 @@ src/core/minions/queue.ts MinionQueue.add>result=this.engine.transaction(#0) 359
src/core/minions/worker.ts MinionWorker.start 470 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/core/ops/facts.ts recall.handler 358 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +3 #4830 (W14 PR3): every hit names its source_id, falling back to the scope's single source (the federated case stays absent); +3 W5: recall threads the page-unit ranking cut into its hybrid page arm (logic in search/page-rank-cut.ts; delivery reports it); +3 #7043: copies of one claim collapse before the limit cut (the collapse lives in facts/capture-dedup.ts collapseFactReads) and the row names its entity_slugs/collapsed_count; +1 HARN-15: max_chars is parsed before any read (the bound lives in boundRecallChars)
src/core/ops/search.ts query.handler 338 +5 GBRA-81 item 5 per-stage search timings: the request's SearchTimings and setup-stage binding, the image branch's limit read hoisted out of the timed vector call, and its response stage wrapper (collector logic in search/stage-timings.ts); seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1); +2 GBRA-49 explain_target: one TargetTrace prep line and its HybridSearchOpts thread (diagnosis/meta live in prepareExplainTarget/finishExplainTarget); +1 W5 (#6445): query passes the page-unit ranking cut to hybrid search (logic in search/page-rank-cut.ts), merged with master growth
-src/core/persistence/page-prepare.ts prepareInlineOrSegmentedMutation 303 +3 #7841: a put_page that asks for visibility: private is kept or refused (visibility_not_applied), checked before the no-op test and after the trust stamp (logic in persistence/visibility-request.ts)
+src/core/persistence/page-prepare.ts prepareInlineOrSegmentedMutation 305 +3 #7841: a put_page that asks for visibility: private is kept or refused (visibility_not_applied), checked before the no-op test and after the trust stamp (logic in persistence/visibility-request.ts); +2 #9036: a put over a soft-deleted page starts clean, without the deleted page's tags, timeline rows or facts (logic in retireTombstoneFacts)
src/core/progressive-batch/orchestrator.ts runProgressiveBatch 348 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/core/remediation/run.ts runRemediation 428 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
src/core/skillopt/orchestrator.ts runOptimizationLoop 644 seed: W5 baseline, refactor wave 1 (decomposition deferred to wave 2, plan D1)
diff --git a/src/core/persistence/page-prepare.ts b/src/core/persistence/page-prepare.ts
index e064bb6c88..8b59a937d9 100644
--- a/src/core/persistence/page-prepare.ts
+++ b/src/core/persistence/page-prepare.ts
@@ -881,8 +881,6 @@ async function prepareInlineOrSegmentedMutation(unbounded: BrainEngine, row: Wri
if ((snapshot?.page.id ?? null) !== row.page_id) throw pageIdentityError(snapshot != null || row.page_id === null, 'The accepted page identity changed.');
const observedRevision = snapshot?.revision ?? null;
const activePack = pack?.manifest;
- // A new page written over a soft-deleted one starts clean: it takes none of the deleted page's tags, timeline rows or
- // facts (the delete recorded them in the page's history; restore_page is how the old page comes back).
const replacesTombstone = snapshot?.page.deleted_at != null && (row.operation === 'put_page' || row.operation === 'capture');
if (row.operation === 'put_page' && snapshot && !snapshot.page.deleted_at && typeof p.content === 'string'
&& `${snapshot.page.compiled_truth}\n${snapshot.page.timeline ?? ''}`.trim()) {
@@ -902,8 +900,7 @@ async function prepareInlineOrSegmentedMutation(unbounded: BrainEngine, row: Wri
let content = edited?.content ?? preparedIntent?.content ?? p.content as string;
const privateRequest = privateRequestGuarded(row.operation, p.kind) && typeof content === 'string' ? readPrivateRequest(content, () => parseMarkdown(content as string, row.slug, { activePack }).frontmatter) : null;
if (privateRequest) assertPrivateRequestAllowed(row, content as string, privateRequest.frontmatter);
- let versionTags: string[] | undefined = preparedIntent?.tags;
- if (replacesTombstone && typeof content === 'string') versionTags = parseMarkdown(content, row.slug, { activePack }).tags;
+ let versionTags: string[] | undefined = replacesTombstone && typeof content === 'string' ? parseMarkdown(content, row.slug, { activePack }).tags : preparedIntent?.tags;
// A replacement/restore publishes a live page. Only a recorded version may
// explicitly restore a tombstone; legacy versions leave this state unchanged.
let targetDeleted = false;
@@ -1161,8 +1158,9 @@ async function prepareInlineOrSegmentedMutation(unbounded: BrainEngine, row: Wri
}
/**
- * A put over a soft-deleted page: expire (not delete) the active facts the deleted page held, and those about it that no
- * live page holds, so the new page does not inherit them. Facts other live pages hold about the slug stay theirs.
+ * A put over a soft-deleted page starts clean: it takes its tags from its own content only, skips the deleted page's
+ * timeline rows, and here expires (never deletes) the active facts the deleted page held and those about it that no live
+ * page holds. Facts other live pages hold about the slug stay theirs; restore_page is how the old page comes back.
*/
async function retireTombstoneFacts(tx: BrainEngine, sourceId: string, slug: string): Promise<void> {
await tx.executeRaw(`UPDATE facts f SET expired_at = now(), row_num = NULL
diff --git a/src/core/postgres-engine.ts b/src/core/postgres-engine.ts
index bc9a076ba2..74090c19c7 100644
--- a/src/core/postgres-engine.ts
+++ b/src/core/postgres-engine.ts
@@ -2013,8 +2013,7 @@ export class PostgresEngine implements BrainEngine {
const scope = opts?.sourceIds && opts.sourceIds.length
? sql`AND source_id = ANY(${opts.sourceIds})`
: sql`AND (${opts?.sourceId ?? null}::text IS NULL OR source_id = ${opts?.sourceId ?? null})`;
- // Page-visibility gate on the provenance and entity pages, applied BEFORE DISTINCT ON
- // so the untrusted caller resolves the newest value they may see; a deleted page's observations are hidden for everyone.
+ // Provenance/entity page gates and the deleted-page hide, BEFORE DISTINCT ON: the caller gets the newest value they may see.
const privacy = sql.unsafe(`AND ${deletedPageProjectionHiddenSql('facts', 'facts')}${opts?.excludePrivate ? ` AND ${privateFactFilterForCaller('facts')}` : ''}`);
const visibility = opts?.visibility ? sql`AND visibility = ANY(${opts.visibility})` : sql``;
const rows = await sql<OntologyValue[]>`
diff --git a/test/fact-reads-page-access.test.ts b/test/fact-reads-page-access.test.ts
index 094c6e797d..b742bda3d7 100644
--- a/test/fact-reads-page-access.test.ts
+++ b/test/fact-reads-page-access.test.ts
@@ -100,14 +100,6 @@ function factReads(slug: string): Array<[string, string, Record<string, unknown>
];
}
-async function setUpEngine(kind: 'pglite' | 'postgres'): Promise<{ engine: BrainEngine; close: () => Promise<void> }> {
- if (kind === 'postgres') return isolatedPersistencePostgres(process.env.DATABASE_URL!);
- const engine = new PGLiteEngine();
- await engine.connect({ engine: 'pglite' } as never);
- await engine.initSchema();
- return { engine, close: () => engine.disconnect() };
-}
-
const PAGES = {
restricted: { slug: 'people/vesper-example', fm: 'readable_by: [alice-example]', canary: 'canaryobsrestricted' },
private: { slug: 'people/quiet-example', fm: 'visibility: private', canary: 'canaryobsprivate' },
@@ -138,7 +130,14 @@ for (const kind of testBackends()) {
beforeAll(async () => {
configureGateway({ embedding_model: 'openai:text-embedding-3-small', embedding_dimensions: DIMS, env: { OPENAI_API_KEY: 'test' } });
__setEmbedTransportForTests((async ({ values }: { values: string[] }) => ({ embeddings: values.map(vectorFor) })) as never);
- ({ engine, close } = await setUpEngine(kind));
+ if (kind === 'postgres') ({ engine, close } = await isolatedPersistencePostgres(process.env.DATABASE_URL!));
+ else {
+ const pglite = new PGLiteEngine();
+ await pglite.connect({ engine: 'pglite' } as never);
+ await pglite.initSchema();
+ engine = pglite;
+ close = () => pglite.disconnect();
+ }
__resetPrivateVisibilityCacheForTests();
await engine.executeRaw('INSERT INTO sources (id, name) VALUES ($1, $1) ON CONFLICT (id) DO NOTHING', [SRC]);
for (const key of Object.keys(PAGES) as PageKey[]) {
@@ -237,19 +236,26 @@ for (const kind of testBackends()) {
}
describe(`a deleted page takes its facts, timeline and tags with it (${kind})`, () => {
- beforeAll(() => {
+ let engine: BrainEngine;
+ let close: () => Promise<void>;
+ beforeAll(async () => {
configureGateway({ embedding_model: 'openai:text-embedding-3-small', embedding_dimensions: DIMS, env: { OPENAI_API_KEY: 'test' } });
__setEmbedTransportForTests((async ({ values }: { values: string[] }) => ({ embeddings: values.map(vectorFor) })) as never);
- });
- afterAll(() => { __setEmbedTransportForTests(null); resetGateway(); });
+ if (kind === 'postgres') ({ engine, close } = await isolatedPersistencePostgres(process.env.DATABASE_URL!));
+ else {
+ const pglite = new PGLiteEngine();
+ await pglite.connect({ engine: 'pglite' } as never);
+ await pglite.initSchema();
+ engine = pglite;
+ close = () => pglite.disconnect();
+ }
+ }, 240_000);
+ afterAll(async () => { __setEmbedTransportForTests(null); resetGateway(); await close?.(); }, 60_000);
test('repo-less source: hidden while deleted for local and remote readers, back unchanged on restore, not inherited by a new page', async () => {
- const { engine, close } = await setUpEngine(kind);
- try {
- __resetPrivateVisibilityCacheForTests();
- await engine.executeRaw("INSERT INTO sources (id, name) VALUES ('source-b', 'source-b') ON CONFLICT (id) DO NOTHING");
- await deletedPageScenario(engine, 'source-b', true);
- } finally { await close(); }
+ __resetPrivateVisibilityCacheForTests();
+ await engine.executeRaw("INSERT INTO sources (id, name) VALUES ('source-b', 'source-b') ON CONFLICT (id) DO NOTHING");
+ await deletedPageScenario(engine, 'source-b', true);
}, 240_000);
test('managed source: the same', async () => {