feat(evidence): record provenance and stop derived evidence counting as corroboration
Every evidence row now records its derivation (direct, assertion, operator, external, prediction, consolidation, inference, reflection, dream, retrieval), its independent-source family (an actor, an integration, an operator, a prediction) and its root event or memory ids. Confidence groups evidence by family: the strongest primary item counts in full, each further primary item adds a quarter, capped at 1.5x, and derived items count only when the family has no primary member. Three derived re-expressions of one utterance therefore weigh exactly what the utterance weighs, while three independent families still add up. Producers (conversation, association, consolidation, predictions, metacognition, dreaming, operator and seed input, contradictions) supply their ancestry. Existing rows are marked legacy_unknown with family = source; nothing is invented. The belief page shows per-family contributions and the replay test checks that provenance is reconstructed identically in the sandbox. Migration 0017 is additive.
This commit is contained in:
@@ -3,12 +3,17 @@ package replay
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/andydixon/noema/internal/beliefs"
|
||||
|
||||
evstore "github.com/andydixon/noema/internal/events"
|
||||
"github.com/andydixon/noema/internal/minds"
|
||||
"github.com/andydixon/noema/internal/replay/replaytest"
|
||||
"github.com/andydixon/noema/pkg/events"
|
||||
"github.com/andydixon/noema/pkg/ids"
|
||||
)
|
||||
|
||||
func TestReplayIsExactWithoutModel(t *testing.T) {
|
||||
@@ -51,6 +56,11 @@ func TestReplayIsExactWithoutModel(t *testing.T) {
|
||||
if err != nil || sandbox.Status != minds.StatusDisabled || sandbox.ForkedFromSnapshot == nil {
|
||||
t.Fatalf("sandbox mind wrong: %+v %v", sandbox, err)
|
||||
}
|
||||
// Provenance is reconstructed: beliefs in the sandbox cite the same
|
||||
// families in the same derivations as the source's.
|
||||
if a, b := provenanceDigest(t, h, src.ID), provenanceDigest(t, h, sandbox.ID); a != b {
|
||||
t.Fatalf("provenance differs after replay:\nsource: %s\nsandbox: %s", a, b)
|
||||
}
|
||||
// The source's history is untouched by the replay.
|
||||
after, _ := h.Events.Query(ctx, evstore.Filter{MindID: src.ID, Limit: 1})
|
||||
if after[0].Seq != last[0].Seq {
|
||||
@@ -62,3 +72,27 @@ func TestReplayIsExactWithoutModel(t *testing.T) {
|
||||
}
|
||||
_ = events.Observation
|
||||
}
|
||||
|
||||
// provenanceDigest summarises a mind's beliefs as proposition → sorted
|
||||
// (derivation, family) pairs, ignoring ids that differ between minds.
|
||||
func provenanceDigest(t *testing.T, h *replaytest.Harness, mind ids.ID) string {
|
||||
t.Helper()
|
||||
ctx := context.Background()
|
||||
bs := h.Brain.Services.Beliefs
|
||||
list, err := bs.List(ctx, mind, beliefs.Filter{Limit: 200})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var lines []string
|
||||
for _, b := range list {
|
||||
rows, _ := bs.EvidenceFor(ctx, nil, mind, b.ID)
|
||||
var ev []string
|
||||
for _, r := range rows {
|
||||
ev = append(ev, r.Derivation+"/"+r.Family+"/"+r.ProvenanceStatus)
|
||||
}
|
||||
sort.Strings(ev)
|
||||
lines = append(lines, strings.ToLower(b.Proposition)+" ← "+strings.Join(ev, ","))
|
||||
}
|
||||
sort.Strings(lines)
|
||||
return strings.Join(lines, "\n")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user