Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Refuse a loops fact at preparation too when its entity's page rule or an unreadable access state arrives after admission

garrytan52c5df80f350
diff --git a/src/core/persistence/facts-prepare.ts b/src/core/persistence/facts-prepare.ts
index 19043c14d3..d326a992c6 100644
--- a/src/core/persistence/facts-prepare.ts
+++ b/src/core/persistence/facts-prepare.ts
@@ -8,7 +8,7 @@ import type { RegistryCode } from '../error-registry.ts';
import { withHeldFactsFence } from '../facts/unfenced-facts.ts';
import { factsFenceEditor, factsFenceSection, parseFactsFenceFor, formatFenceDate, isHoldingSlug } from '../facts-fence.ts';
import { getWorktreeBinding } from './ownership.ts';
-import { holdingHome } from '../facts/held-fact-move.ts';
+import { holdingHome, refuseUnheldFact } from '../facts/held-fact-move.ts';
import { serializePageToMarkdown } from '../markdown.ts';
import { wholeBodySnapshot } from './segmented-apply.ts';
import { assertFactNotWithdrawn, decideSingleFact, factWithdrawnRefusal, type FactCandidate } from '../facts/single-prepare.ts';
@@ -177,6 +177,8 @@ export async function prepareManagedFactsMutation(engine: BrainEngine, row: Writ
const holdable = async (fact: { entity_slug: string | null }) => {
if (!holding) return false;
const home = await holdingHome(engine, row.source_id, fact.entity_slug === row.slug ? null : fact.entity_slug);
+ // GST-2635: a fallback fact whose home became refused after admission refuses here too, never stored outside Git.
+ if (home && 'refused' in home && fallback(fact)) await refuseUnheldFact(engine, row.source_id, fact.entity_slug!, home.refused, false);
return home !== null && 'slug' in home && home.slug === row.slug;
};
if (!facts.length || facts.some(fact => !fallback(fact) && (fact.entity_slug !== null && fact.entity_slug !== row.slug || fact.entity_slug !== null && !stored))) {
diff --git a/test/strict-fallback-refusal-gst2635.test.ts b/test/strict-fallback-refusal-gst2635.test.ts
index 88b52f2a99..7080ba95df 100644
--- a/test/strict-fallback-refusal-gst2635.test.ts
+++ b/test/strict-fallback-refusal-gst2635.test.ts
@@ -37,6 +37,7 @@ import { holdingPageFor } from '../src/core/facts/held-fact-move.ts';
import { writeSingleFact } from '../src/core/facts/write-single.ts';
import { publishManagedEntityFacts } from '../src/core/facts/managed-fact-write.ts';
import { runLoopsExtract } from '../src/core/google/loops-extract.ts';
+import { installFaultHook } from '../src/core/persistence/fault-points.ts';
import { durableGitRepo, git } from './helpers/git-publication.ts';
import { managedBrain, settleManagedGitEffects, type ManagedBrain } from './helpers/managed-brain.ts';
import { isolatedSharedSkillsEngine } from './helpers/shared-skills-engine.ts';
@@ -252,6 +253,26 @@ for (const backend of testBackends()) describe(`[${backend}] GST-2635: the attri
expect(git(b.root, 'show', `HEAD:${HOLD}.md`)).toContain(claim);
}), 300_000);
+ for (const arm of ['page_rule', 'access_unreadable'] as const) {
+ test(`${arm === 'page_rule' ? 'a page rule' : 'an unreadable access state'} that arrives after admission, before preparation, refuses there too and writes nothing`, () => brain(true, async b => {
+ const claim = `Bob example wants the invoice summary split by project (${arm}).`;
+ let armed = true;
+ installFaultHook(async (point, detail) => {
+ if (!armed || point !== 'consumer:preparing' || detail.operation !== 'extract_facts') return;
+ armed = false;
+ if (arm === 'page_rule') await addPageRule(b.engine); else await unreadableAccess(b.engine);
+ });
+ const { reply, refusal } = await loopsWrite(b.engine, claim).finally(() => installFaultHook(undefined));
+ expect(armed).toBe(false);
+ expect(reply).toBeNull();
+ expect(refusal?.code).toBe(arm === 'page_rule' ? 'git_home_required' : 'access_policy_pending');
+ expect(refusal!.message).toContain(ENTITY);
+ expect(await factRows(b.engine, claim)).toEqual([]);
+ expect(filesHolding(b.root, claim)).toEqual([]);
+ expect(commitsHolding(b.root, claim)).toEqual([]);
+ }), 300_000);
+ }
+
for (const arm of ['missing', 'present', 'access_unreadable'] as const) {
test(`the loops job keeps the loop row and logs the refusal with the entity's page (${arm} arm)`, () => brain(true, async b => {
if (arm === 'present') await seedHoldingPage(b.ctx);