Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(fences): re-copy the lane reason table with a neutral next step; guard against unshipped commands (#6188)

garrytan97250b11a21c
diff --git a/src/core/fence-repair/reasons.ts b/src/core/fence-repair/reasons.ts
index 11bd71661c..662f21a694 100644
--- a/src/core/fence-repair/reasons.ts
+++ b/src/core/fence-repair/reasons.ts
@@ -31,7 +31,8 @@ export interface FenceReasonSpec {
}
const DOCS = 'docs/guides/write-refusals.md#fence-';
-const REPAIR = 'Preview the repair with `gbrain repair fences`.';
+// PR4 switches this next step to `gbrain repair fences`, routed through the hold-repair router.
+const REPAIR = 'Edit the fence by hand, then sync or write the page again.';
type Base = Pick<FenceReasonSpec, 'stage' | 'tier' | 'manualOnly' | 'autoRetry'>;
const tier3: Base = { stage: 'screen', tier: 'llm', manualOnly: false, autoRetry: true };
@@ -54,7 +55,7 @@ const SPECS: Record<FenceReason, Omit<FenceReasonSpec, 'docs'>> = {
short_row: entry(tier3, 'Row(s) {rows} of the {fence} fence in the {section} (line {line}) are missing a cell in the middle of the row, so its columns are ambiguous. Add the missing cell so every column lines up. ' + REPAIR),
extra_cells: entry(tier3, 'Row(s) {rows} of the {fence} fence in the {section} (line {line}) have more cells than the header, often an unescaped `|` in a cell. Escape it as `\\|` or remove the extra cell. ' + REPAIR),
holder_unresolved: entry({ stage: 'screen', tier: 'resolver', manualOnly: false, autoRetry: true },
- 'Column `who` of row(s) {rows} in the {fence} fence ({section}, line {line}) is not a holder gbrain recognizes. Write `world`, `brain`, `people/<slug>` or `companies/<slug>`; the repair pass resolves it only when exactly one existing page matches.'),
+ 'Column `who` of row(s) {rows} in the {fence} fence ({section}, line {line}) is not a holder gbrain recognizes. Write `world`, `brain`, `people/<slug>` or `companies/<slug>`.'),
missing_begin: entry(manual, 'The {fence} fence in the {section} has an end marker at line {line} with no begin marker before it. Add the begin marker above the table, or delete the stray end marker.'),
split_rows: entry(manual, 'The {fence} fence that begins at line {line} in the {section} has no end marker and its rows are split by blank lines or text. Join the rows into one table and add the end marker after the last row.'),
unclosed_trailing_content: entry(manual, 'The {fence} fence that begins at line {line} in the {section} has no end marker and other text follows its table. Add the end marker directly after the last table row, or wrap the marker in backticks if the text only mentions it; gbrain does not guess where the fence ends.'),
diff --git a/test/fence-refusal.test.ts b/test/fence-refusal.test.ts
index 4fd3972958..7402f3bde6 100644
--- a/test/fence-refusal.test.ts
+++ b/test/fence-refusal.test.ts
@@ -9,7 +9,12 @@
import { describe, expect, test } from 'bun:test';
import { compileCanonicalProjections } from '../src/core/persistence/canonical-projections.ts';
import { screenImportContent, isContentRefusal, contentRefusalFromReceipt } from '../src/core/import-screen.ts';
-import { fenceMessage, FENCE_REASON_CODES } from '../src/core/fence-repair/reasons.ts';
+import { fenceMessage, FENCE_REASON_CODES, type FenceMessageLocation } from '../src/core/fence-repair/reasons.ts';
+import type { FenceReason } from '../src/core/fence-repair/types.ts';
+import { gitHoldFix, holdRepairSteps } from '../src/core/persistence/sync-holds.ts';
+import { prepareTimeFenceHold } from '../src/core/persistence/sync-screen.ts';
+import { writeFailureDiagnostic } from '../src/core/persistence/verb-errors.ts';
+import { RECOVERY_VERSION } from '../src/core/markdown.ts';
import { CODES } from '../src/core/error-registry.ts';
import { completeFenceLocation, fenceFailureDetail, fenceLocationFromDetail, fenceLocationFromMessage, fenceOperationError, fenceReceiptLocation,
parseFenceMessage, scanCanonicalFences } from '../src/core/fence-repair/refusal.ts';
@@ -85,6 +90,35 @@ describe('the shared fence check', () => {
});
});
+/**
+ * Every reason PR1 can put in a refusal, hold or receipt. `gbrain repair fences`
+ * ships in a later release, so none of their messages or fixes may name it.
+ */
+const PR1_REASONS: readonly FenceReason[] = ['repeated_marker', 'missing_begin', 'marker_near_miss', 'unparseable', 'no_header', 'row_before_header',
+ 'short_row', 'extra_cells', 'enum_unmapped', 'takes_kind_unsupported', 'confidence_out_of_range', 'claim_value_invalid', 'weight_missing',
+ 'holder_unresolved', 'row_collision', 'quoted_fence_rows', 'stored_row_collision', 'withdrawn_claim_in_malformed_fence', 'prepare_time'];
+const UNSHIPPED = /repair fences|repair pass/;
+
+describe('no PR1 message or fix names a command that has not shipped', () => {
+ test('every reason the screen and the projection emit is one PR1 accounts for', () => {
+ for (const [, body, timeline] of cases) expect(PR1_REASONS).toContain(scanCanonicalFences(page(body, timeline)).defects[0]!.reason);
+ });
+
+ test('messages, suggestions and fixes for every PR1 reason point at the page read, the fence edit and the sync', () => {
+ for (const reason of PR1_REASONS) {
+ const location: FenceMessageLocation = { reason, fence: 'takes', section: 'body', rows: [2], columns: ['who'], line: 5 };
+ const error = fenceOperationError(location, 'notes/example', 'default');
+ const receipt = contentRefusalFromReceipt('invalid_params', error.message);
+ const hold = prepareTimeFenceHold({ path: 'notes/example.md', sourcePath: 'notes/example.md', working: false }, 'notes/example', 1, location, 'Body.', null);
+ const fix = gitHoldFix({ source_id: 'default', path: 'notes/example.md', code: 'invalid_fence', slug: 'notes/example', page_id: 1,
+ meta: { reason, recovery_version: RECOVERY_VERSION, fence: location } });
+ const texts = [error.message, error.suggestion, JSON.stringify(error.fix), receipt?.suggestion, hold.message, JSON.stringify(fix),
+ writeFailureDiagnostic('invalid_params', error.message).suggestion, holdRepairSteps('default', { fences: 1, others: 0 }).text];
+ for (const text of texts) expect(text ?? '').not.toMatch(UNSHIPPED);
+ }
+ });
+});
+
describe('the receipt grammar', () => {
const locations = [
{ reason: 'enum_unmapped', fence: 'facts', section: 'body', rows: [1, 3], columns: ['kind'], line: 6 },
diff --git a/test/persistence-sync-fence-holds.test.ts b/test/persistence-sync-fence-holds.test.ts
index 8e02cbd133..caffd2c05a 100644
--- a/test/persistence-sync-fence-holds.test.ts
+++ b/test/persistence-sync-fence-holds.test.ts
@@ -114,6 +114,8 @@ test('a malformed fence among clean files: the sync finishes, holds that file wi
// Privacy sentinel: no claim, holder or kind text in holds, results, printed output or status.
const rows = await engine.executeRaw<{ completed_keys: unknown }>("SELECT completed_keys FROM op_checkpoints WHERE op LIKE 'sync-hold%' AND fingerprint LIKE $1", [`${s.id}:%`]);
for (const blob of [JSON.stringify(rows), JSON.stringify(result), text, lines, JSON.stringify(status)]) expectNoSecrets(blob);
+ // `gbrain repair fences` has not shipped: nothing PR1 prints may send an agent to it.
+ for (const blob of [JSON.stringify(result), text, lines]) expect(blob).not.toMatch(/repair fences|repair pass/);
// Doctor routes a fence-only source to the status read and the sync, never to frontmatter repair.
const doctor = await gitHeldFilesCheck(engine, [s.id]);
expect(doctor).toMatchObject({ status: 'warn', fix: { argv: ['gbrain', 'sources', 'status', s.id, '--json'] } });
@@ -154,7 +156,7 @@ test('forced probe: a fence that passes the screen but collides with a stored ta
expect((await engine.readPageSnapshot('people/probe', { sourceId: s.id }))!.revision).toBe(before);
expect(await engine.executeRaw('SELECT row_num,claim FROM takes k JOIN pages p ON p.id=k.page_id WHERE p.source_id=$1 AND p.slug=$2 ORDER BY row_num', [s.id, 'people/probe']))
.toEqual([{ row_num: 1, claim: 'Synthetic take' }, { row_num: 2, claim: 'Database-only take' }]);
- for (const blob of [JSON.stringify(result), printed(result), JSON.stringify(failed)]) expectNoSecrets(blob);
+ for (const blob of [JSON.stringify(result), printed(result), JSON.stringify(failed)]) { expectNoSecrets(blob); expect(blob).not.toMatch(/repair fences|repair pass/); }
// The next run neither re-admits the held bytes nor mints another receipt.
expect(await s.sync()).toMatchObject({ status: 'up_to_date', holds_outstanding: 1 });
expect(await s.failedRequests()).toHaveLength(1);