Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
A labels-only accept no longer clears the owner tier an earlier dropped lowering left (GST-2521)
garrytanaae3b87f2bbe
diff --git a/src/core/trust/page-write.ts b/src/core/trust/page-write.tsindex 6986904f81..c66ee98e0e 100644--- a/src/core/trust/page-write.ts+++ b/src/core/trust/page-write.ts@@ -147,7 +147,8 @@ export interface LabelGuard { tier: TrustTier | null; owner: { member: string; i* tier holds a page that is private by its labels or names readers when the write is below it: the stored tier (an* unclassified `unknown` page reads as operator_curated lowered by its frontmatter caps, as its marker does), raised to* the tier the owner's label door left (GST-2521, `page_label_guards`) and to the prior tier of every `lower_page`- * proposal of the page since the owner last accepted one (pending, dismissed, reverted or undone). So owner-set labels,+ * proposal of the page since the owner last accepted one (pending, dismissed, reverted or undone; an accept that wrote only+ * the labels and kept an agent tier, `labels_applied`, vouches for nothing and is no cutoff). So owner-set labels,* earlier lowering edits, or a rejected or undone widening do not let an equal-tier write widen the page.* GST-2521: `owner` is set when the brain owner reads the page by its readers now (and the owner opt-in to read restricted* pages is off), so the write cannot take the owner out of them. `incoming` is the written frontmatter when known; a write@@ -163,7 +164,8 @@ export async function privacyLabelGuard(engine: BrainEngine, row: Pick<WriteRequconst [guard] = await engine.executeRaw<{ owner_set: string | null; priors: (string | null)[] | null }>(`SELECT(SELECT tier FROM page_label_guards WHERE page_id = $1) AS owner_set,ARRAY(SELECT before_state->>'prior_tier' FROM trust_proposals WHERE target_table = 'pages' AND target_id = $1 AND action = 'lower_page' AND status <> 'accepted'- AND id > COALESCE((SELECT max(id) FROM trust_proposals WHERE target_table = 'pages' AND target_id = $1 AND action = 'lower_page' AND status = 'accepted'), 0)) AS priors`,+ AND id > COALESCE((SELECT max(id) FROM trust_proposals WHERE target_table = 'pages' AND target_id = $1 AND action = 'lower_page' AND status = 'accepted'+ AND after_state->>'resolution' IS DISTINCT FROM 'labels_applied'), 0)) AS priors`,[Number(page.id)]);tier = maxTrust(stored === 'unknown' ? minTrust(OWNER_TIER_FLOOR, ...frontmatterTrustCaps(labels)) : stored,...[guard?.owner_set ?? null, ...(guard?.priors ?? [])].filter(isTrustTier));diff --git a/test/owner-label-guard.test.ts b/test/owner-label-guard.test.tsindex 5a43334934..9b36b34d0b 100644--- a/test/owner-label-guard.test.ts+++ b/test/owner-label-guard.test.ts@@ -242,6 +242,21 @@ for (const backend of testBackends()) describe('[' + backend + '] owner-set labeexpect(await readsOf(reads, slug, canary)).toEqual({ unbound: false, bob: false, owner: true });}), 180_000);+ test('a labels-only accept keeps the owner tier an earlier dropped lowering left: a later agent drop is still held', () => repoless(async (b, reads) => {+ const slug = 'notes/accept-after-drop-example', canary = 'canaryacceptdrop';+ const labels = ['visibility: private', 'readable_by: [alice-example, ' + OWNER + ']'];+ await seedOwnerPage(b.engine, SRC, slug, file(slug, labels, canary));+ const rewrite = await put(b, slug, file(slug, labels, canary, 'An agent rewrote the body.'));+ await decide(b, rewrite.trust_lowered.proposal_ref, 'reject');+ expect((await pageRow(b.engine, SRC, slug)).tier).toBe('agent_written');+ const widened = await put(b, slug, file(slug, ['visibility: private', 'readable_by: [alice-example, bob-example, ' + OWNER + ']'], canary, 'An agent rewrote the body.'));+ const accepted = await decide(b, widened.privacy_labels_kept.proposal_ref, 'accept');+ expect(accepted.detail).toMatchObject({ status: 'labelled', tier: 'agent_written' });+ const dropped = await put(b, slug, file(slug, [], canary, 'An agent dropped the labels.'));+ expect([...dropped.privacy_labels_kept?.keys ?? []].sort()).toEqual(['readable_by', 'visibility']);+ expect(await readsOf(reads, slug, canary)).toEqual({ unbound: false, bob: false, owner: true });+ }), 180_000);+test('a label door that clears the labels leaves no guard: the agent\'s own later label is its own to drop', () => repoless(async (b) => {const slug = 'notes/cleared-example', canary = 'canarycleared';await call(b, 'put_page', { slug, content: file(slug, ['readable_by: [alice-example, ' + OWNER + ']'], canary) });