Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
feat(fence-repair): record the last repair state on a fence hold; document the fences outcome and verification shapes (#6188)
garrytan67a737e5057b
diff --git a/src/core/persistence/sync-holds.ts b/src/core/persistence/sync-holds.tsindex 7c605881ba..4dc48cfe10 100644--- a/src/core/persistence/sync-holds.ts+++ b/src/core/persistence/sync-holds.ts@@ -28,7 +28,7 @@ import type { Action } from '../agent-output.ts';import type { ContentRefusal } from '../import-screen.ts';import { RECOVERY_VERSION, type InvalidFrontmatterReason } from '../markdown.ts';import { FENCE_REASONS, type FenceMessageLocation } from '../fence-repair/reasons.ts';-import type { FenceReason } from '../fence-repair/types.ts';+import type { FenceReason, FenceTier, GateLetter } from '../fence-repair/types.ts';import { FENCE_VERSION, fenceWhere } from '../fence-repair/refusal.ts';import { STRUCTURED_WRITE_ADVICE, type FencesNormalized } from '../fence-repair/report.ts';import type { SyncRename } from './sync-discovery.ts';@@ -69,6 +69,18 @@ export interface GitHoldMeta {working?: boolean;/** The held file is a rename destination: the page it moves when the hold clears. */rename_from?: SyncRename;+ /** #6188: the last fence repair attempt (repair kind or maintenance phase) that left this hold in place; location and reason only. */+ fence_repair?: FenceHoldRepairState;+}++/** #6188: why the last fence repair left a hold in place, and when the maintenance run tries it again (null: it does not). */+export interface FenceHoldRepairState {+ reason: FenceReason;+ tier: FenceTier;+ at: string;+ next_attempt_after: string | null;+ gate?: GateLetter;+ rows?: number[];}export interface GitHoldRecord {@@ -197,6 +209,17 @@ export async function clearGitHold(tx: Exec, input: { sourceId: string; incarnatreturn true;}+/**+ * #6188: records on a fence hold why the last repair left it held (the repair kind and the maintenance phase call it),+ * without touching its observation time or counts. False when the hold is gone or is not a fence hold.+ */+export async function recordFenceHoldRepair(engine: Exec, input: { sourceId: string; incarnation: string; path: string; state: FenceHoldRepairState }): Promise<boolean> {+ const rows = await engine.executeRaw(`UPDATE op_checkpoints SET completed_keys=jsonb_set(completed_keys,'{0,meta,fence_repair}',$3::text::jsonb),updated_at=now()+ WHERE op=$1 AND fingerprint=$2 AND completed_keys->0->>'code'='invalid_fence' RETURNING 1`,+ [GIT_HOLD_OP, gitHoldFingerprint(input.sourceId, input.incarnation, input.path), JSON.stringify(input.state)]);+ return rows.length === 1;+}+export async function readGitHold(engine: Exec, sourceId: string, incarnation: string, path: string): Promise<GitHoldRecord | null> {return readRow(engine, sourceId, incarnation, path);}diff --git a/src/core/repair/fences.ts b/src/core/repair/fences.tsindex fa99f76d30..bfa8593ca6 100644--- a/src/core/repair/fences.ts+++ b/src/core/repair/fences.ts@@ -2,9 +2,32 @@* `gbrain repair fences` (#6188): repairs malformed facts and takes fences.* Skeleton: the kind is registered so the CLI, the cycle phase and the* surfaces can wire to it; the plan and apply land next.+ *+ * Per-item outcomes (RepairItemOutcome) this kind returns:+ * - `repaired` (applied): detail `{ tier, classes, mode, path?, slug }`, `llm_usd` for a Tier 3 repair.+ * - `held` (not applied): `reason` is a FenceReason (gate, llm_*, budget_exhausted, llm_disabled, no_pricing,+ * manual-only residual, ...), detail `{ tier, mode, path?, slug, gate?, rows? }`.+ * - `skipped` (not applied): `reason` owner_unavailable | sync_in_progress | changed_since_read | changed_since_preview.*/+import type { FenceTier } from '../fence-repair/types.ts';import type { RepairHandler, RepairPlan } from './core.ts';+/** The fences result's `verification` (report hook): what the run did and what is left, for the CLI and the cycle phase report. */+export interface FenceRepairVerification {+ /** Candidates the plan found (after selection). */+ candidates: number;+ repaired_by_tier: Record<Exclude<FenceTier, 'manual'>, number>;+ /** Candidates still waiting after the run, by reason (manual-only residuals, gates, budget, ...). */+ held_by_reason: Record<string, number>;+ /** Oldest unresolved `invalid_fence` hold in scope (ISO), or null. */+ oldest_hold_at: string | null;+ /** Successful Tier 3 repairs in this run and the USD per repair (null when none). */+ llm_repairs: number;+ llm_usd_per_repair: number | null;+ /** The scan behind the plan did not finish. */+ partial: boolean;+}+export const fencesRepair: RepairHandler = {kind: 'fences',outcomeItemsLimit: 200,