Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(fences): holds written before Tier 1 re-screen on the next sync (#6188)

garrytan510b2063b73f
diff --git a/src/core/fence-repair/normalize.ts b/src/core/fence-repair/normalize.ts
index 21880d2493..908ce25831 100644
--- a/src/core/fence-repair/normalize.ts
+++ b/src/core/fence-repair/normalize.ts
@@ -19,7 +19,7 @@ import { extractRawRows, rowNumOf } from './raw-rows.ts';
import { structuralPass } from './structure.ts';
import type { FenceCtx, FenceFix, FenceIssue, FencePage, FenceSection, StoredRowMap } from './types.ts';
-/** Rule-set version, stored on fence holds as `fence_version`; bump when a rule widens so older holds are re-screened. */
+/** Rule-set version; bump when a rule widens. It is part of the hold `fence_version` (`FENCE_VERSION`), so older holds are re-screened. */
export const FENCE_RULES_VERSION = 1;
export interface NormalizeResult<T extends FencePage> {
diff --git a/src/core/fence-repair/refusal.ts b/src/core/fence-repair/refusal.ts
index 20e471fa49..dea57e6f7d 100644
--- a/src/core/fence-repair/refusal.ts
+++ b/src/core/fence-repair/refusal.ts
@@ -20,11 +20,17 @@ import { opError, type OperationError } from '../ops/contract.ts';
import { readFix } from '../ops/op-fix.ts';
import { FENCE_REASONS, fenceMessage, issueLocation, renderFenceFix, type FenceMessageLocation } from './reasons.ts';
import { extractRawRows, primaryFence, rowNumOf, type RawSection } from './raw-rows.ts';
+import { FENCE_RULES_VERSION } from './normalize.ts';
import { ALLOWED, cellValid } from './schema.ts';
import type { FenceIssue, FenceKind, FenceReason, FenceSection } from './types.ts';
-/** Bumped when the fence screen changes what it refuses; an older `invalid_fence` hold is re-screened. */
-export const FENCE_VERSION = 1;
+/**
+ * The screen's version, stored on `invalid_fence` holds as `fence_version`; an
+ * older hold is re-screened. It moves when the screen changes what it refuses:
+ * 1 was the strict screen alone; Tier 1 (`FENCE_RULES_VERSION`) admits the
+ * fences it fixes, so every rule-set bump moves it too.
+ */
+export const FENCE_VERSION = 1 + FENCE_RULES_VERSION;
/** Row numbers a location carries at most. */
export const FENCE_ROWS_MAX = 20;
diff --git a/test/persistence-sync-fence-holds.test.ts b/test/persistence-sync-fence-holds.test.ts
index 06feb086df..8a83681bb8 100644
--- a/test/persistence-sync-fence-holds.test.ts
+++ b/test/persistence-sync-fence-holds.test.ts
@@ -330,12 +330,14 @@ test('fences.normalize=false: the fixable file is held like any malformed fence
expect(result.held![0]).toMatchObject({ path: 'people/fixable.md', code: 'invalid_fence', fence: { fence: 'facts', section: 'body' } });
expect(readFileSync(join(s.root, 'people/fixable.md'), 'utf8')).toBe(before);
expect(await engine.getPage('people/fixable', { sourceId: s.id })).toBeNull();
- // Turning it back on: the held file re-screens on the next sync, is normalized and imports.
+ // A hold an older screen wrote (v0.60.98.0's fence_version 1, before Tier 1 existed) re-screens on the
+ // next sync with no command once normalization is on: the file is normalized, committed and imported.
await engine.unsetConfig('fences.normalize');
- await retryHeld(engine, s.id, { dryRun: false });
+ await engine.executeRaw(`UPDATE op_checkpoints SET completed_keys=jsonb_set(completed_keys,'{0,meta,fence_version}','1'::jsonb) WHERE op='sync-hold' AND fingerprint LIKE $1`, [`${s.id}:%`]);
const after = await s.sync();
expect(after.fences_normalized).toMatchObject({ count: 1 });
expect(await s.holds()).toEqual([]);
+ expect(parseFactsFence((await engine.getPage('people/fixable', { sourceId: s.id }))!.compiled_truth).facts[0]!.kind).toBe('fact');
}), 180_000);
test('a read-only mirror keeps the normalized fence in the database only; its checkout stays the remote bytes', () => each(async engine => {