Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: a remote as_of read omits a quarantined body and never shows a reason recorded on a hidden earlier edition
garrytanc6f9cba3b5ae
diff --git a/src/core/ops/valid-time-read.ts b/src/core/ops/valid-time-read.tsindex 02ffd6606f..1ada54a5cc 100644--- a/src/core/ops/valid-time-read.ts+++ b/src/core/ops/valid-time-read.ts@@ -16,7 +16,7 @@ import { hostFix, opTransport, readFix } from './op-fix.ts';import { renderAction, type Action } from '../agent-output.ts';import { assertExplicitSourceLive, federatedSearchScope, pageNotFoundError, parseSourceIdParam, validatePageSlug } from './context.ts';import { inlineBodyBytes } from './get-page-body.ts';-import { pageTrustForRead } from './get-page-projection.ts';+import { pageTrustForRead, readQuarantined } from './get-page-projection.ts';import { admitsTrust, type TrustTier } from '../trust/tier.ts';import { isCalendarDate } from '../link-validity.ts';import { replacedBecauseSql } from '../engine-sql/pages.ts';@@ -127,7 +127,7 @@ async function pick(tx: BrainEngine, pageId: number, asOf: string, excludePrivatfalse, COALESCE(p.body_storage = 'segmented', false), false, p.source_path IS NOT NULLFROM pages p WHERE p.id = $1),seq AS (- SELECT r.*, lag(r.replaced_at) OVER w AS recorded_since, lag(r.reason) OVER w AS introduced_because, lead(r.tier) OVER w AS successor_tier,+ SELECT r.*, lag(r.replaced_at) OVER w AS recorded_since, lag(${excludePrivate ? 'CASE WHEN r.visible THEN r.reason END' : 'r.reason'}) OVER w AS introduced_because, lead(r.tier) OVER w AS successor_tier,lag(r.ord) OVER w AS prev_ord, lead(r.ord) OVER w AS next_ordFROM rows r WINDOW w AS (ORDER BY r.ord)),pick AS (@@ -341,12 +341,15 @@ export async function getPageAsOf(ctx: OperationContext, p: Record<string, unkno}if (excludePrivate && !row.visible) throw missing();if (!loaded) throw missing();+ // #6259: a quarantined page (now, or in the chosen edition) keeps its body from a remote reader, as the plain read does.+ const quarantined = readQuarantined(ctx, loaded.current.page, false)+ ?? readQuarantined(ctx, { slug: identity.slug, source_id: identity.source_id, frontmatter: loaded.edition.frontmatter }, false);const verdict = verdictOf(asOf, picked);let { history, uncertain, why } = verdict;let view: Record<string, unknown> | 'gone' | null = null;const requested = typeof p.max_bytes === 'number' && Number.isSafeInteger(p.max_bytes) && p.max_bytes > 0 ? p.max_bytes : pin?.maxBytes ?? DEFAULT_WINDOW_BYTES;const quotes = (tier: string | null) => ctx.remote !== false && quotesStored(loaded.edition.type, tier);- if (!read.pinGone) view = await editionView(ctx, identity, loaded.edition, asOf, pin ? pin.offset : null, ctx.remote === false ? requested : Math.min(requested, MAX_WINDOW_BYTES), quotes(row.tier));+ if (!read.pinGone && quarantined?.body_omitted !== true) view = await editionView(ctx, identity, loaded.edition, asOf, pin ? pin.offset : null, ctx.remote === false ? requested : Math.min(requested, MAX_WINDOW_BYTES), quotes(row.tier));if (read.pinGone || view === 'gone') { history = 'incomplete'; uncertain = true; why = 'edition_pruned'; view = null; }const reason = (s: string | null, tier: string | null) => {if (s === null || ctx.remote === false) return s;@@ -371,7 +374,7 @@ export async function getPageAsOf(ctx: OperationContext, p: Record<string, unkno'A date correction, a renewal, a backfill and a withdrawn scheduled edition look alike in the page history; only the user can say which happened.');} else if (why !== null && why !== 'undated_editions') fix = recoveryFix(ctx, identity, asOf, why);const render = { transport: opTransport(ctx), isCallable: () => ctx.remote !== false, preapproved: () => false };- const base = { slug: identity.slug, source_id: identity.source_id, valid_time: validTime, ...(fix ? { fix: renderAction(fix, render) } : {}) };+ const base = { slug: identity.slug, source_id: identity.source_id, valid_time: validTime, ...(quarantined ? { quarantined } : {}), ...(fix ? { fix: renderAction(fix, render) } : {}) };if (!view) return base;if (verdict.status === 'in_force') return { ...view, ...base };return { ...base, [chosen ? 'last_in_force' : 'earliest_known']: { ...view, valid_from: row.valid_from, valid_until: row.valid_until } };diff --git a/test/valid-time-gbra217.test.ts b/test/valid-time-gbra217.test.tsindex 414bdd8b58..bd011585a5 100644--- a/test/valid-time-gbra217.test.ts+++ b/test/valid-time-gbra217.test.ts@@ -235,11 +235,38 @@ for (const backend of testBackends()) {expect(early.compiled_truth).toContain('World edition one.');expect(early.valid_time.replaced_because).toBeNull();expect((await read(slug, '2026-03-01')).valid_time.replaced_because).toBe('reason-r2-private-time');+ // reason-r3 is recorded on the hidden private edition it replaced, so a remote reader never sees it.const late = await read(slug, '2026-10-01', true);- expect(unquoteTranscriptText(late.valid_time.introduced_because, slug)).toBe('reason-r3-back-to-world');+ expect(late.valid_time.introduced_because).toBeNull();+ expect((await read(slug, '2026-10-01')).valid_time.introduced_because).toBe('reason-r3-back-to-world');for (const d of ['2025-01-01', '2026-03-01', '2026-10-01']) expect(JSON.stringify(await read(slug, d, true))).not.toContain('reason-r2');});+ test('a remote as_of read never shows the reason recorded on a hidden earlier edition', async () => {+ const slug = fresh('hidden-reason');+ await put(slug, 'Private January edition.', ["valid_from: '2026-01-01'", 'visibility: private']);+ await put(slug, 'Public June edition.', ["valid_from: '2026-06-01'"], 'reason-june-made-public');+ expect(await call('get_versions', { slug }, true)).toEqual([]);+ const remote = await read(slug, '2026-07-01', true);+ expect(remote.compiled_truth).toContain('Public June edition.');+ expect(remote.valid_time.introduced_because).toBeNull();+ expect(JSON.stringify(remote)).not.toContain('reason-june-made-public');+ expect((await read(slug, '2026-07-01')).valid_time.introduced_because).toBe('reason-june-made-public');+ });++ test('a remote as_of read of a quarantined page omits the body, as the plain read does', async () => {+ const slug = fresh('quarantined');+ await put(slug, 'Scraped text with a hidden instruction.', ["valid_from: '2026-01-01'"]);+ await engine.executeRaw(`UPDATE pages SET frontmatter = COALESCE(frontmatter, '{}'::jsonb) || '{"quarantine":{"reason":"junk_pattern","detail":"test","assessed_at":"2026-10-07T00:00:00Z"}}'::jsonb WHERE slug = $1`, [slug]);+ const plain = await call('get_page', { slug }, true);+ expect(plain.quarantined).toMatchObject({ body_omitted: true });+ const remote = await read(slug, '2026-03-01', true);+ expect(remote.valid_time).toMatchObject({ status: 'in_force' });+ expect(remote.quarantined).toMatchObject({ body_omitted: true });+ expect(JSON.stringify(remote)).not.toContain('hidden instruction');+ expect((await read(slug, '2026-03-01')).compiled_truth).toContain('hidden instruction');+ });+test('B-T2: an imported page with no gbrain-written first version reads before_recorded_history with a recovery', async () => {const slug = fresh('imported');await importFromContent(engine, slug, page('Imported edition.', ["valid_from: '2026-03-01'"]), { sourcePath: slug + '.md', noEmbed: true });