Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(fences): keep frontmatter-only hold text unchanged and re-copy the lane anchor fix (#6188)

garrytand3f5da21e371
diff --git a/src/commands/doctor/checks/git-holds.ts b/src/commands/doctor/checks/git-holds.ts
index 7dd238c460..4cdc1af583 100644
--- a/src/commands/doctor/checks/git-holds.ts
+++ b/src/commands/doctor/checks/git-holds.ts
@@ -48,7 +48,8 @@ export async function gitHeldFilesCheck(engine: BrainEngine, sourceIds?: string[
message: `${held} file(s) in Git sources are held and not imported; the rest of each sync continues. ${lines.join('; ')}. `
+ (escalated.length ? `Escalated: ${escalated.map(source => source.source_id).join(', ')} hold more than ${policy.escalateCount} files (sync.hold_escalate_count), so a generator or an upgrade is likely writing or reading them wrong; fix the cause first. ` : '')
+ 'A page whose newer file is held is read-only for put_page until the file is repaired, so do not retry a refused write. '
- + `Inspect with ${sources.map(source => source.status).join('; ')}; then ${sources.map(source => `${source.source_id}: ${source.next}`).join('; ')}.`,
+ + `Inspect with ${sources.map(source => source.status).join('; ')}; `
+ + (sources.some(source => source.fences) ? `then ${sources.map(source => `${source.source_id}: ${source.next}`).join('; ')}.` : `preview the fix with ${sources.map(source => source.repair).join('; ')}.`),
fix: single
? agentFix(single.argv, fenceOnly ? `Lists each held file of ${single.source_id} with the fence and reason that hold it; edit that fence in the file, commit, then run gbrain sync --source ${single.source_id} --no-pull.`
: 'Previews the minimal line fix for each held file (or names the line to fix by hand) and prints the hash-bound apply command; it writes nothing.', 'git_held_files', { docs: 'docs/guides/repair.md#held-files' })
diff --git a/src/commands/sources-retry-held.ts b/src/commands/sources-retry-held.ts
index 9406b8668f..8d5649c4b1 100644
--- a/src/commands/sources-retry-held.ts
+++ b/src/commands/sources-retry-held.ts
@@ -71,7 +71,7 @@ function gitNextStep(sourceId: string, dryRun: boolean, scheduled: Scheduled): {
why: `Schedules a re-screen of ${count} held file(s) on the next sync of ${sourceId}; nothing runs now.` } };
const fences = scheduled.items.filter(item => item.code === 'invalid_fence').length;
return { text: `${count} held file(s) scheduled for a re-screen; none has run yet. ${automatic} Run it now with: ${sync}, then verify with: gbrain sources status ${sourceId}. `
- + `A file that still refuses stays held; ${holdRepairSteps(sourceId, { fences, others: count - fences }).text}`,
+ + `A file that still refuses stays held; ${fences ? holdRepairSteps(sourceId, { fences, others: count - fences }).text : `preview its fix with: gbrain repair frontmatter --source ${sourceId}`}`,
fix: { argv: scheduled.sync, consent: [], actor: 'agent', requires_exclusive: false, verify,
why: `The sync re-screens the ${count} scheduled file(s): each one that now passes imports and its hold clears; the rest stay held without blocking the sync.` } };
}
diff --git a/src/core/fence-repair/reasons.ts b/src/core/fence-repair/reasons.ts
index 662f21a694..99af6efcf7 100644
--- a/src/core/fence-repair/reasons.ts
+++ b/src/core/fence-repair/reasons.ts
@@ -30,7 +30,8 @@ export interface FenceReasonSpec {
fix: string;
}
-const DOCS = 'docs/guides/write-refusals.md#fence-';
+// The anchor is built per reason, so no partial `write-refusals.md#...` literal reads as a broken link (write-refusals-coverage).
+const DOCS = 'docs/guides/write-refusals.md';
// 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.';
@@ -102,7 +103,7 @@ const SPECS: Record<FenceReason, Omit<FenceReasonSpec, 'docs'>> = {
};
export const FENCE_REASONS: Readonly<Record<FenceReason, FenceReasonSpec>> = Object.fromEntries(
- Object.entries(SPECS).map(([reason, spec]) => [reason, { ...spec, docs: `${DOCS}${reason}` }]),
+ Object.entries(SPECS).map(([reason, spec]) => [reason, { ...spec, docs: `${DOCS}#fence-${reason}` }]),
) as Record<FenceReason, FenceReasonSpec>;
/** Every reason code, in table order (the registry's `invalid_fence.reasons`). */
diff --git a/src/core/persistence/sync-holds.ts b/src/core/persistence/sync-holds.ts
index 43ac8fd438..04dead761c 100644
--- a/src/core/persistence/sync-holds.ts
+++ b/src/core/persistence/sync-holds.ts
@@ -537,7 +537,8 @@ export async function buildHoldReport(engine: Exec, input: { sourceId: string; i
why: `${outstanding} file(s) in source ${input.sourceId} are held and not imported; only the brain host can inspect and repair them.`,
user_message: `Some files in source ${input.sourceId} could not be imported. Please run 'gbrain sources status ${input.sourceId}' on the brain host, then: ${steps.text}.` } };
const fix: Action = { argv: steps.argv, consent: [], actor: 'agent', requires_exclusive: false, verify,
- why: `${runHolds.length} file(s) held this run, ${outstanding} held in source ${input.sourceId}; they do not block sync. Inspect them with 'gbrain sources status ${input.sourceId}'; then ${steps.text}.`
+ why: `${runHolds.length} file(s) held this run, ${outstanding} held in source ${input.sourceId}; they do not block sync. Inspect them with 'gbrain sources status ${input.sourceId}'; `
+ + (fences ? `then ${steps.text}.` : 'the repair preview proposes each fix and writes nothing.')
+ (escalated ? ' Escalated: more files are held than a source should carry, so a generator or a gbrain upgrade is likely writing or reading them wrong; fix the cause before the backlog grows.' : '') };
return { held: runHolds.slice(0, input.policy.cap).map(gitHoldItem), held_count: runHolds.length, holds_outstanding: outstanding,
...(escalated ? { holds_escalated: true } : {}), ...(runHolds.length > input.policy.cap ? { holds_truncated: true } : {}),
diff --git a/test/fence-refusal.test.ts b/test/fence-refusal.test.ts
index 7402f3bde6..f360a59fb3 100644
--- a/test/fence-refusal.test.ts
+++ b/test/fence-refusal.test.ts
@@ -9,7 +9,9 @@
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, type FenceMessageLocation } from '../src/core/fence-repair/reasons.ts';
+import { readFileSync } from 'node:fs';
+import { join } from 'node:path';
+import { fenceMessage, FENCE_REASON_CODES, FENCE_REASONS, 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';
@@ -104,6 +106,15 @@ describe('no PR1 message or fix names a command that has not shipped', () => {
for (const [, body, timeline] of cases) expect(PR1_REASONS).toContain(scanCanonicalFences(page(body, timeline)).defects[0]!.reason);
});
+ test('every PR1 reason links to an anchor the refusal guide defines', () => {
+ const guide = readFileSync(join(import.meta.dir, '..', 'docs/guides/write-refusals.md'), 'utf8');
+ for (const reason of PR1_REASONS) {
+ const [path, anchor] = FENCE_REASONS[reason].docs.split('#');
+ expect(path).toBe('docs/guides/write-refusals.md');
+ expect(guide).toContain(`<a id="${anchor}"></a>`);
+ }
+ });
+
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 };