Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(GST-1209): Step 11 voices: hold a file a privacy alias or private-by-default type makes private, or the content gate would quarantine, flag or stop embedding
garrytan98a1feaafc3a
diff --git a/docs/guides/repair.md b/docs/guides/repair.mdindex adef4631e0..e7611e42cd 100644--- a/docs/guides/repair.md+++ b/docs/guides/repair.md@@ -448,10 +448,13 @@ is listed `held` and never written. So is a file that another sync holdwithholds (any hold but the `page_write_failed` one a sync opens when itcannot read the stored body), and a file the next sync's import screen wouldhold: purged page content, a write-gate reject, private visibility it would-not store, a fence it refuses. A file that changes who can read the page-(`visibility` or `readable_by`) is held too, because the apply keeps the-stored frontmatter, and so is a file over 24 MiB, the most the import screen-reads whole. A source without a Git checkout, a+not store, a fence it refuses. The apply keeps the stored frontmatter, so a+file that changes who can read the page is held too (`visibility`,+`readable_by`, a privacy alias such as `access` or `confidentiality`, or a+type that is private by default), as is one the next sync's content gate+would quarantine, flag or stop embedding when the stored page carries no+such marker. So is a file over 24 MiB, the most the import screen reads+whole. A source without a Git checkout, arepo-less brain included, refuses with `not_a_git_repo`: this repairrepublishes the copy Git holds, and there the database has no other copy.On such a brain, rewrite the page from a copy you hold (`put_page`).diff --git a/src/core/repair/segmented-tiling.ts b/src/core/repair/segmented-tiling.tsindex 969b3715a9..8dc08c6c37 100644--- a/src/core/repair/segmented-tiling.ts+++ b/src/core/repair/segmented-tiling.ts@@ -11,7 +11,8 @@* file, a file HEAD does not hold or one over pages.max_bytes is listed held and never written, as is one another sync* hold withholds (any but the unreadable-body `page_write_failed` hold) or one the next sync's import screen would hold* (purged page content, the write gate, private visibility, a fence it refuses), one that changes who can read the page- * (the apply keeps the stored frontmatter) or one over the 24 MiB the screen reads whole. A source without a Git+ * or one the next sync's content gate would quarantine, flag or skip embedding (the apply keeps the stored frontmatter),+ * or one over the 24 MiB the screen reads whole. A source without a Git* checkout (a repo-less brain) refuses: this repair republishes the copy Git holds, and the database has no other.** `--apply --expect <hash>` re-checks every page (`preview_changed`), then per page, in one transaction under the page's@@ -50,7 +51,11 @@ import { PAGE_MAX_BYTES } from '../page-size-policy.ts';import { assertPreparedFactWithdrawals } from '../facts/withdrawal.ts';import { buildSegmentedProjection } from '../page-body/projection.ts';import { untiledSegmentedPages, type UntiledPage } from '../page-body/body-tiling.ts';-import { isQuarantined } from '../quarantine.ts';+import { CONTENT_FLAG_KEY, isQuarantined, QUARANTINE_KEY } from '../quarantine.ts';+import { EMBED_SKIP_KEY } from '../embed-skip.ts';+import { settleContentDisposition, stripGateOwnedMarkers } from '../import-screen.ts';+import { ownerSourceGateInput } from '../trust/channel.ts';+import { isPrivatePage, PRIVACY_ALIASES } from '../search/private-visibility.ts';import { createAuditWriter } from '../audit/audit-writer.ts';import { afterCursor, type RepairHandler, type RepairItem, type RepairItemOutcome, type RepairListing, type RepairPlan, type RepairScope } from './core.ts';@@ -141,11 +146,21 @@ async function stageable(engine: BrainEngine, page: { source_id: string; slug: ssnapshot: await engine.readPageSnapshot(page.slug, { sourceId: page.source_id }) });if (screen.status === 'refused') return { held: `the next sync would hold the file (${screen.refusal.code}): ${screen.refusal.message}` };const parsed = screen.status === 'importable' && screen.parsed ? screen.parsed : parseMarkdown(content, `${page.slug}.md`);- const [stored] = await engine.executeRaw<{ frontmatter: Record<string, unknown> | null }>('SELECT frontmatter FROM pages WHERE source_id=$1 AND slug=$2', [page.source_id, page.slug]);- const access = (fm: Record<string, unknown> | null | undefined) => JSON.stringify([fm?.visibility ?? null, fm?.readable_by ?? null]);- if (access(parsed.frontmatter) !== access(stored?.frontmatter)) {- return { held: 'the file changes who can read the page (visibility or readable_by), and this repair republishes the body under the stored frontmatter' };+ const [stored] = await engine.executeRaw<{ type: string; frontmatter: Record<string, unknown> | null }>('SELECT type, frontmatter FROM pages WHERE source_id=$1 AND slug=$2', [page.source_id, page.slug]);+ const storedFrontmatter = stored?.frontmatter ?? {};+ const access = (fm: Record<string, unknown>) => JSON.stringify(['visibility', 'readable_by', 'pinned_question', ...Object.keys(PRIVACY_ALIASES)].map(key => fm[key] ?? null));+ if (access(parsed.frontmatter) !== access(storedFrontmatter)+ || isPrivatePage({ type: parsed.type, frontmatter: parsed.frontmatter }) !== isPrivatePage({ type: stored?.type ?? null, frontmatter: storedFrontmatter })) {+ return { held: 'the file changes who can read the page (visibility, readable_by, a privacy alias such as access or confidentiality, or a type that is private by default), and this repair republishes the body under the stored frontmatter' };}+ const settled = structuredClone(parsed);+ const writeGate = await ownerSourceGateInput(engine, page.source_id, settled.frontmatter);+ stripGateOwnedMarkers(settled, { preserveGateMarkers: true, writeGate });+ try { await settleContentDisposition(engine, settled, { slug: page.slug, sourceId: page.source_id, stripped: false, writeGate }); } catch (error) {+ return { held: `the next sync's content gate refuses the file: ${error instanceof Error ? error.message : String(error)}` };+ }+ const marked = [QUARANTINE_KEY, EMBED_SKIP_KEY, CONTENT_FLAG_KEY].filter(key => settled.frontmatter[key] != null && storedFrontmatter[key] == null);+ if (marked.length) return { held: `the next sync's content gate would mark the page ${marked.join(', ')}, and this repair republishes the body under the stored frontmatter` };const body = screen.status === 'importable' && screen.fences ? screen.fences.after : { compiled_truth: parsed.compiled_truth, timeline: parsed.timeline ?? '' };return { hold, truth: (await preserveWithdrawnFenceRows(engine, page.source_id, body.compiled_truth, page.slug)).trim(),timeline: (await preserveWithdrawnFenceRows(engine, page.source_id, body.timeline ?? '', page.slug)).trim() };diff --git a/test/large-pages/segmented-tiling-repair.test.ts b/test/large-pages/segmented-tiling-repair.test.tsindex 4bdcdf14b8..9b09961b31 100644--- a/test/large-pages/segmented-tiling-repair.test.ts+++ b/test/large-pages/segmented-tiling-repair.test.ts@@ -7,7 +7,8 @@* version by reference, writes a receipt, clears the sync hold, and the next managed sync completes with no hold.* A source with no Git checkout refuses the preview (not_a_git_repo); a remote caller is refused.* 2. Fails when: doctor misses the page or writes, an apply runs without the previewed hash or against a changed page,- * the republished generation does not tile, the hold survives, or a repo-less source reads as republishable.+ * the republished generation does not tile, the hold survives, a repo-less source reads as republishable, or a file+ * that narrows who can read the page or that the content gate would quarantine is republished under the stored frontmatter.* 3. PGLite; the managed fixture follows test/large-pages/managed-sync-segmented-freeze.test.ts.*/import { afterAll, beforeAll, expect, test } from 'bun:test';@@ -175,6 +176,26 @@ test('a file the next sync would hold, or one that changes who can read the page}}), 300_000);+test('a file a privacy alias makes private, or one the content gate would quarantine, is listed held and never written', async () => withEnv(env, async () => {+ const f = await managedFixture();+ await damage(f.sourceId, f.pageId);+ const scope = await resolveRepairScope(engine, f.sourceId);+ const run = (apply: boolean, expect?: string) => repairRunner(engine, { apply, logger }).then(runner => runner.run('segmented-tiling', scope, { explicit: true, sourceFlag: f.sourceId, ...(expect ? { expect } : {}) }));+ const [damaged] = await untiledSegmentedPages(engine, { sourceIds: [f.sourceId] });+ const cases = [[person(1260 * 1024).replace('type: person\n', 'type: person\naccess: private\n'), 'changes who can read the page'],+ [person(1260 * 1024).replace('type: person\n', 'type: person\nconfidentiality: secret\n'), 'changes who can read the page'],+ [person(1260 * 1024).replace('# Person Example\n\n', '# Person Example\n\nCloudflare Ray ID: 0000example\n\n'), 'content gate would mark the page quarantine']] as const;+ for (const [content, detail] of cases) {+ writeFileSync(join(f.root, FILE), content);+ commit(f.root);+ const preview = await run(false);+ expect(preview.listing).toEqual([expect.objectContaining({ class: 'held', detail: expect.stringContaining(detail) })]);+ expect(await run(true, preview.preview_hash!)).toMatchObject({ applied: 0 });+ expect(await untiledSegmentedPages(engine, { sourceIds: [f.sourceId] })).toEqual([damaged!]);+ }+ expect(await engine.executeRaw('SELECT count(*)::int AS n FROM content_chunks WHERE page_id=$1 AND chunk_text LIKE $2', [f.pageId, '%0000example%'])).toEqual([{ n: 0 }]);+}), 300_000);+test('the apply refuses preview_changed when HEAD moved after the preview, and writes nothing', async () => withEnv(env, async () => {const f = await managedFixture();await damage(f.sourceId, f.pageId);