Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

feat(trust): atom and enrichment pages import through the page gate at their taint; managed facts label pending fence rows with the declared tier; drift guard classifies the deriver files (#5575 L1a-taint)

garrytan0da447f60338
diff --git a/src/core/cycle/extract-atoms.ts b/src/core/cycle/extract-atoms.ts
index 13ff5f0ae1..7f47369942 100644
--- a/src/core/cycle/extract-atoms.ts
+++ b/src/core/cycle/extract-atoms.ts
@@ -95,6 +95,7 @@ import { acceptedPendingReceipt } from '../persistence/accepted-pending.ts';
import { AtomPageStateError, completeAtomReceipts, readAtomPageIdentity, writeAtomPageState, type AtomPageInput } from './extract-atoms-page-state.ts';
import { maintenanceTransaction } from '../persistence/attribution.ts';
import { deriveTrust, lowerDerivedPage } from '../trust/taint.ts';
+import { derivedGateInput } from '../trust/derived-gate.ts';
import { ATOM_TYPES, ATOMS_RESPONSE_SCHEMA } from './extract-atoms-schema.ts';
import { parseAtomsOutcome } from './extract-atoms-parse.ts';
export { parseAtomsOutcome, parseAtomsResponse, type AtomsParseOutcome } from './extract-atoms-parse.ts';
@@ -1257,8 +1258,8 @@ export async function runPhaseExtractAtoms(
{ type: 'atom', title: atom.title, tags: [] },
);
if (managed) managedAtoms.push({ slug, content: md, links: [] });
- else await importFromContent(engine, slug, md, { sourceId, preserveGateMarkers: true, noEmbed: !isAvailable('embedding') }) // #5575 I2: then the atom takes its origin page's taint
- .then(async () => lowerDerivedPage(engine, await deriveTrust(engine, item.kind === 'page' ? [{ table: 'pages', sourceId, slug: item.slug }] : [], { channel: 'derive:atoms' }), sourceId, slug));
+ else { const taint = await deriveTrust(engine, item.kind === 'page' ? [{ table: 'pages', sourceId, slug: item.slug }] : [], { channel: 'derive:atoms' }); // #5575 I2/B3: gated and stamped at the origin's taint
+ await importFromContent(engine, slug, md, { sourceId, preserveGateMarkers: true, noEmbed: !isAvailable('embedding'), writeGate: derivedGateInput(taint.trust) }).then(() => lowerDerivedPage(engine, taint, sourceId, slug)); }
importedSlugs.push(slug);
if (item.kind === 'page') {
provenanceLinks.push({
diff --git a/src/core/enrichment-service.ts b/src/core/enrichment-service.ts
index 8467858489..f13f07fbd5 100644
--- a/src/core/enrichment-service.ts
+++ b/src/core/enrichment-service.ts
@@ -220,7 +220,7 @@ export async function enrichEntity(
// when a provider is configured) and reachable by the recall arms.
const md = serializeMarkdown(frontmatter, content, '', { type, title, tags: [] });
await importFromContent(engine, slug, md, {
- noEmbed: !isAvailable('embedding'),
+ noEmbed: !isAvailable('embedding'), writeGate: derivedGateInput(derivation.trust),
...(opts?.sourceId ? { sourceId: opts.sourceId } : {}),
});
await lowerDerivedPage(engine, derivation, sourceId, slug);
diff --git a/src/core/persistence/atom-maintenance.ts b/src/core/persistence/atom-maintenance.ts
index 8ae66e087e..cb7239a87f 100644
--- a/src/core/persistence/atom-maintenance.ts
+++ b/src/core/persistence/atom-maintenance.ts
@@ -21,7 +21,7 @@ import type { WriteAuthority, WriteRequest } from './model.ts';
import type { WriteReceipt } from './types.ts';
import { writeAtomPageState } from '../cycle/extract-atoms-page-state.ts';
import { effectiveVisibility } from '../search/private-visibility.ts';
-import { deriveTrust, lowerToDerivedTier, recordTaintEdges } from '../trust/taint.ts';
+import { declareDerivation, deriveTrust, lowerToDerivedTier, recordTaintEdges } from '../trust/taint.ts';
export interface AtomOrigin {
kind: 'page' | 'transcript';
@@ -505,10 +505,11 @@ export async function prepareManagedAtomMutation(engine: BrainEngine, row: Write
} };
}
await authorizeWrite(engine, row.authority, 'put_page', row.slug);
- const prepared = await preparePageMutation(engine, { ...row, operation: 'put_page' }, config, undefined, undefined, { allowMissingFile: true });
- // #5575 I2: the extractor read only the origin (a page, or a transcript file of the user's own sessions).
+ // #5575 I2: the extractor read only the origin (a page, or a transcript file of the user's own sessions); the page write carries the declaration.
const derivation = await deriveTrust(engine, p.origin.kind === 'page' && p.origin.pageId !== null ? [{ table: 'pages', id: p.origin.pageId }] : [],
{ channel: 'derive:atoms', requestId: row.id });
+ const prepared = await preparePageMutation(engine, { ...row, operation: 'put_page', intent: { ...p, derivation: declareDerivation(derivation.trust, derivation.inputs) } },
+ config, undefined, undefined, { allowMissingFile: true });
return { ...prepared, trust: derivation.trust, additionalPageKeys, validate: async tx => { await validate(tx); await authorizeWrite(tx, row.authority, 'put_page', row.slug); await prepared.validate?.(tx); }, apply: async tx => {
const result = await prepared.apply(tx);
if (p.links?.length) await tx.addLinksBatch(p.links, { auditSite: 'cycle.extract_atoms.provenance' });
diff --git a/src/core/persistence/facts-prepare.ts b/src/core/persistence/facts-prepare.ts
index 5873738be7..321c7c7adf 100644
--- a/src/core/persistence/facts-prepare.ts
+++ b/src/core/persistence/facts-prepare.ts
@@ -191,7 +191,7 @@ export async function prepareManagedFactsMutation(engine: BrainEngine, row: Writ
if (snapshot && entries.some(entry => entry.rowNum !== undefined)) {
// #5575 ENG-1: the appended rows have no facts rows yet; their chunks are cut at the append's tier.
const rowNums = entries.flatMap(entry => entry.rowNum === undefined ? [] : [entry.rowNum]);
- page = await withPendingFenceRows({ sourceId: row.source_id, slug: row.slug, rowNums, tier: fenceAppendPendingTier() },
+ page = await withPendingFenceRows({ sourceId: row.source_id, slug: row.slug, rowNums, tier: fenceAppendPendingTier(taint?.trust.tier) },
() => preparePageMutation(engine, { ...row, intent: { ...p,
content: serializePageToMarkdown({ ...snapshot.page, compiled_truth: body, timeline: target!.page.timeline }, snapshot.tags) } }, config));
if (page.observedRevision !== snapshot.revision) throw factsRefusal('revision_conflict', 'The fact entity changed during preparation.', row,
diff --git a/test/trust-write-gate-drift.test.ts b/test/trust-write-gate-drift.test.ts
index 9579f746f1..ccf5401fec 100644
--- a/test/trust-write-gate-drift.test.ts
+++ b/test/trust-write-gate-drift.test.ts
@@ -65,19 +65,15 @@ const EXEMPT: Record<string, string> = {
'src/core/trust/owner-actions.ts': 'owner release publishes a held row the owner confirmed (CEO-9); the gate already held it',
'src/core/trust/supersede-handlers.ts': 'owner accept/undo re-tiers existing rows inside the checked supersede',
'src/core/repair/conversation-labels.ts': 'owner repair of existing conversation labels',
+ 'src/commands/extract-conversation-facts.ts': 'extracted rows go through insertDerivedFacts (persistence/derived-facts.ts), which gates them; its direct writes are gbrain audit outcome rows',
+ 'src/core/cycle/dream-taint.ts': 'the dream summary index page lists the run\'s output pages (gbrain-generated), stamped at their taint',
+ 'src/core/facts/fence-write.ts': 'callers decide the gate (backstop, loops-extract) and pass the decision; it records the flag receipt on the new row',
+ 'src/core/facts/write-single.ts': 'callers gate first (loops-extract decides; remember gates in memory-prepare); it records a passed decision\'s flag receipt',
+ 'src/core/output/writer.ts': 'gbrain integrity auto-repair (owner-run local CLI) rewrites citations and back-links of existing pages',
+ 'src/core/persistence/atom-maintenance.ts': 'pending: the managed atom page carries intent.derivation; the page gate runs in page-prepare once it reads that declaration',
+ 'src/core/persistence/prepared-maintenance.ts': 'consolidation takes gate in takes-prepare; pending: derived maintenance pages carry intent.derivation for the page-prepare gate',
+ 'src/core/think/index.ts': 'pending: the think --save page (quote-grounded synthesis, unverified claims moved to frontmatter) has no page gate seam on its direct putPage',
};
-/**
- * Derivers whose gate lands with the lane L1a taint sub-lane (they compute the
- * derived tier and gate each row at the same point). Emptied when it merges.
- */
-const PENDING_TAINT_LANE = [
- 'src/commands/extract-conversation-facts.ts', 'src/core/chronicle/publish.ts', 'src/core/cycle/extract-atoms.ts', 'src/core/cycle/extract-facts.ts',
- 'src/core/cycle/extract-takes.ts', 'src/core/cycle/phases/consolidate.ts', 'src/core/cycle/synthesize.ts', 'src/core/facts/backstop.ts',
- 'src/core/facts/conversation-publication.ts', 'src/core/facts/fence-write.ts', 'src/core/facts/write-single.ts', 'src/core/output/writer.ts',
- 'src/core/persistence/atom-maintenance.ts', 'src/core/persistence/facts-prepare.ts', 'src/core/persistence/prepared-maintenance.ts',
- 'src/core/think/index.ts', 'src/commands/extract.ts', 'src/core/enrichment-service.ts', 'src/core/extract-timeline-from-meetings.ts',
-];
-for (const path of PENDING_TAINT_LANE) EXEMPT[path] ??= 'pending: deriver gate lands with the lane L1a taint sub-lane';
function inventory(): string[] {
const doc = readFileSync(join(root, 'docs/architecture/system-of-record.md'), 'utf8');