feat(pipeline): report when a re-ingest disagrees with the page on disk (#104)
The asymmetry that makes unattended ingest safe (#103) also discarded a real signal. When a fresh extraction produced a different version of a section already on disk, the on-disk version won and the model's version went in the bin without a word — so "the source is unchanged" and "the source changed its mind and we ignored it" were indistinguishable. wiki.MergeReport now returns the headings where the incoming version disagreed and lost, and the ingest run reports them as warnings, which AppendLog already writes into log.md. This is the simplified answer to contradiction flagging at ingest. The issue proposed calling brain-gardener's Judge from the ingest path, which needs either a shared Go module across two repos or an HTTP service that does not exist — and puts an LLM call on the write path, where a timeout must neither fail the ingest nor silently mark nothing as contested. None of that is necessary to get the signal. The merge already computes the disagreement; it was throwing it away. Surfacing it costs nothing, needs no model, no cue-word matcher, no cross-repo dependency, and is deterministic. Deliberately textual disagreement, not semantic contradiction. Deciding whether a disagreement is a genuine contradiction stays with the Judge-gated enrich pass that already runs hourly and is approval-gated by design (brain-gardener#175). Detection here, adjudication there. Merge is kept as a thin wrapper over MergeReport so existing callers are untouched. Refs #104, #103, brain-gardener#175, brain#21.
This commit is contained in:
@@ -32,10 +32,33 @@ type section struct {
|
||||
// Frontmatter is taken from a. Sections are merged by strategy:
|
||||
// bullet sections union unique lines, append sections concatenate,
|
||||
// all others keep a's version. Sections in b not present in a are appended.
|
||||
// Merge combines two pages, discarding any disagreement silently.
|
||||
// Prefer MergeReport where the caller can act on the disagreement.
|
||||
func Merge(a, b Page) Page {
|
||||
page, _ := MergeReport(a, b)
|
||||
return page
|
||||
}
|
||||
|
||||
// MergeReport is Merge, plus the headings of sections where b carried a
|
||||
// different version of a section a already had — and lost.
|
||||
//
|
||||
// That loss is the property which makes ingest safe to run unattended (#103):
|
||||
// a regenerating writer can add to a note but never rewrite it. But the
|
||||
// discarded text is also a signal, and until now it went in the bin: the source
|
||||
// now says something different about a section we already hold. Nobody could
|
||||
// tell "the source is unchanged" from "the source changed its mind and we
|
||||
// ignored it".
|
||||
//
|
||||
// Deliberately NOT a semantic contradiction check. This reports textual
|
||||
// disagreement, which is cheap, deterministic, and needs no model on the write
|
||||
// path. Deciding whether a disagreement is a genuine contradiction stays with
|
||||
// the Judge-gated enrich pass that already exists (brain-gardener#175), which
|
||||
// is approval-gated by design — detection here, adjudication there.
|
||||
func MergeReport(a, b Page) (Page, []string) {
|
||||
fmA, secsA := parseSections(a.Content)
|
||||
fmB, secsB := parseSections(b.Content)
|
||||
|
||||
var conflicts []string
|
||||
idx := make(map[string]int, len(secsA))
|
||||
for i, s := range secsA {
|
||||
idx[s.heading] = i
|
||||
@@ -54,10 +77,15 @@ func Merge(a, b Page) Page {
|
||||
secsA[i].content = mergeBullets(sA.content, sB.content)
|
||||
case appendSections[sB.heading]:
|
||||
secsA[i].content = appendNew(sA.content, sB.content)
|
||||
default:
|
||||
// a wins — but say that b disagreed, rather than dropping it mute.
|
||||
if strings.TrimSpace(sA.content) != strings.TrimSpace(sB.content) {
|
||||
conflicts = append(conflicts, sB.heading)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Page{Path: a.Path, Content: rebuildContent(refreshOwned(fmA, fmB), secsA)}
|
||||
return Page{Path: a.Path, Content: rebuildContent(refreshOwned(fmA, fmB), secsA)}, conflicts
|
||||
}
|
||||
|
||||
// generatorOwned names the frontmatter fields the ingest pipeline may refresh
|
||||
|
||||
Reference in New Issue
Block a user