Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(reconcile): exhausted-row check reads the backfill state only, no pages scan per refused page (GST-1555)
garrytan0b1a9b8e0596
diff --git a/src/core/page-state/revision-backfill-schema.ts b/src/core/page-state/revision-backfill-schema.tsindex bc6e69f345..272fe46896 100644--- a/src/core/page-state/revision-backfill-schema.ts+++ b/src/core/page-state/revision-backfill-schema.ts@@ -66,6 +66,11 @@ export async function readRevisionBackfillStatus(engine: BrainEngine): Promise<Rreturn { column: 'nullable', pending: Number(n), failed };}+/** Read-only: whether the backfill used every attempt on this row; one config read, for a caller that already knows the row is pending. */+export async function revisionBackfillExhausted(engine: BrainEngine, id: number): Promise<boolean> {+ return (await readState(engine)).failed.some(f => f.id === id && f.attempts >= REVISION_BACKFILL_MAX_ATTEMPTS);+}+/*** Assign revisions to the given rows in one statement. A managed brain's* writer guard refuses a revision change outside a source capability, so thediff --git a/src/core/persistence/reconcile-state.ts b/src/core/persistence/reconcile-state.tsindex 45ebfd54a8..dcb48dbf45 100644--- a/src/core/persistence/reconcile-state.ts+++ b/src/core/persistence/reconcile-state.ts@@ -9,7 +9,7 @@ import { parseDataFrontmatter } from '../data-frontmatter.ts';import { OperationError, opError } from '../ops/contract.ts';import { readFix } from '../ops/op-fix.ts';import { REVISION_BACKFILL_PENDING, type PageSnapshot } from '../page-state/types.ts';-import { readRevisionBackfillStatus, REVISION_BACKFILL_MAX_ATTEMPTS, REVISION_BACKFILL_RESUME_COMMAND } from '../page-state/revision-backfill-schema.ts';+import { revisionBackfillExhausted, REVISION_BACKFILL_RESUME_COMMAND } from '../page-state/revision-backfill-schema.ts';import { isWriteTargetContained } from '../path-confine.ts';import { recordedPathFromFileUri, scannerSlugRootMode, scannerSourcePath } from '../write-through.ts';import { absentCanonicalPath, findLiveFileClaimants, recordedReconcilePath, type FileClaimTarget } from './file-claims.ts';@@ -322,7 +322,7 @@ export function reconcilePreviewAdopts(artifact: Pick<ReconcileArtifact, 'preima*/export async function assertReconcileRevision(engine: BrainEngine, snapshot: PageSnapshot, sourceId: string, slug: string): Promise<void> {if (snapshot.revision !== REVISION_BACKFILL_PENDING) return;- const exhausted = (await readRevisionBackfillStatus(engine)).failed.some(f => f.id === Number(snapshot.page.id) && f.attempts >= REVISION_BACKFILL_MAX_ATTEMPTS);+ const exhausted = await revisionBackfillExhausted(engine, Number(snapshot.page.id));const verify = { argv: ['gbrain', 'doctor', '--only', 'revision_backfill', '--json'] };throw opError('revision_backfill_pending', 'Reconciliation requires the page revision, and this page has none yet.',`Nothing changed. Page ${slug} in '${sourceId}' was written before page revisions and the revision backfill has not reached it, so no reconcile preview can bind to it. `