Files
gbrain/test
Garry TanandClaude Fable 5 2bb3424863 fix(facts): idempotent fence deposits + re-runnable fence-backfill command
Two fixes for the remote extract_facts deposit path:

#2044 — a second deposit to an already-fenced page could throw
idx_facts_fence_key and roll back the whole batch when fence and DB
row_nums diverged (e.g. legacy wrong-path fence writes). writeFactsToFence
now seeds the next row_num from MAX(fence max, DB max(row_num)) for the
(source_id, slug) pair, and insertFacts in BOTH engines adds
ON CONFLICT (source_id, source_markdown_slug, row_num) WHERE row_num IS
NOT NULL DO NOTHING so a residual collision skips one row instead of
failing the batch.

#1867 — row_num-NULL backlogs (remote deposits that predate the fence
backstop) had no remedy: the fence backfill lived only inside the one-shot
v0_32_2 migration, and the cycle guard pointed at `gbrain apply-migrations
--yes`, which never re-runs a completed migration. phaseBFenceFacts (already
idempotent on row_num IS NULL) is now exported and exposed as
`gbrain facts fence-backfill [--dry-run]`; the guard message points at it.
The backfill also routes page paths through resolvePageFilePath so
non-default sources fence into the same path the fence-write backstop uses.

Fixes #2044
Fixes #1867

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-21 14:45:53 -07:00
..