Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Wave B lane 1d: chunk-visibility markers on the write-path chunk readers
garrytana14ad806307a
diff --git a/src/core/page-body/ingest.ts b/src/core/page-body/ingest.tsindex 499758e1c9..d0350999db 100644--- a/src/core/page-body/ingest.ts+++ b/src/core/page-body/ingest.ts@@ -306,6 +306,7 @@ export async function occurrencesWithoutChunks(engine: Pick<BrainEngine, 'executrows: readonly ManifestRowInput[]): Promise<ManifestRowInput[]> {if (!rows.length) return [];const chunked = new Set((await engine.executeRaw<{ occurrence_id: number }>(`SELECT DISTINCT occurrence_id FROM content_chunks+ -- chunk-visibility-ok: write path; the generation predicate is explicit, at the generation the caller diffed againstWHERE page_id=$1 AND occurrence_id=ANY($2::bigint[]) AND body_generation<=$3 AND retired_generation IS NULL`,[pageId, rows.map(row => row.occurrenceId), generation])).map(row => Number(row.occurrence_id)));return rows.filter(row => !chunked.has(row.occurrenceId));diff --git a/src/core/page-body/projection.ts b/src/core/page-body/projection.tsindex 7b6941f5c5..ec03ecbe56 100644--- a/src/core/page-body/projection.ts+++ b/src/core/page-body/projection.ts@@ -45,7 +45,8 @@ async function retireStaleChunks(engine: Pick<BrainEngine, 'executeRaw' | 'kind'for (;;) {const rows = await engine.executeRaw<{ id: number }>(`UPDATE content_chunks c SET retired_generation=$2,body_generation=COALESCE(c.body_generation, 0)- WHERE c.id IN (SELECT s.id FROM content_chunks s WHERE s.page_id=$1 AND s.retired_generation IS NULL+ WHERE c.id IN (SELECT s.id FROM content_chunks s -- chunk-visibility-ok: retirement selects the rows the live generation does not hold+ WHERE s.page_id=$1 AND s.retired_generation IS NULLAND (s.body_generation IS NULLOR (s.body_generation<=$2 AND NOT (s.occurrence_id=ANY($3::bigint[])))OR (s.body_generation<=$2 AND EXISTS (SELECT 1 FROM content_chunks n WHERE n.page_id=s.page_id AND n.occurrence_id=s.occurrence_id