Retain matched resolution evidence in history

This commit is contained in:
2026-11-02 14:46:13 +00:00
parent d120fe907b
commit c61597d137
6 changed files with 53 additions and 7 deletions

View File

@@ -12,15 +12,16 @@ type resolutionReplayGroup struct {
}
type historyResolutionPayload struct {
snapshots []resolutionSnapshot
replayGroups []resolutionReplayGroup
snapshots []resolutionSnapshot
replayGroups []resolutionReplayGroup
correspondence resolutionCorrespondence
}
// observeResolutionEvidence retains audited records in producer order and
// indexes the concrete shapes in every original before/after subtree. Snapshot
// roots are already detached by runResolution and are shared with the replay
// group that refers to their covering record.
func (builder *historyBuilder) observeResolutionEvidence(snapshots []resolutionSnapshot) {
func (builder *historyBuilder) observeResolutionEvidence(snapshots []resolutionSnapshot, correspondence ...resolutionCorrespondence) {
builder.requireOpen()
if len(snapshots) == 0 {
return
@@ -36,10 +37,14 @@ func (builder *historyBuilder) observeResolutionEvidence(snapshots []resolutionS
snapshots: make([]resolutionSnapshot, len(snapshots)),
replayGroups: coalescedResolutionSnapshots(snapshots),
}
if len(correspondence) != 0 {
payload.correspondence = correspondence[0].clone()
}
attributions := make([]historyAttributionRef, len(snapshots))
lookup := buildDocumentLookup(builder.scratch)
for recordID, snapshot := range snapshots {
snapshot.change = cloneChange(snapshot.change)
snapshot.entryPath = snapshot.entryPath.clone()
payload.snapshots[recordID] = snapshot
ref := builder.nextPayload(historyPhaseResolution)
@@ -48,8 +53,12 @@ func (builder *historyBuilder) observeResolutionEvidence(snapshots []resolutionS
}
attribution := builder.addAttribution(snapshot.change.Origin, snapshot.change.Reasons, snapshot.change.Dependencies)
attributions[recordID] = attribution
beforePath, beforeFound := historyConcretePathAt(builder.scratch, snapshot.change.Path, lookup)
if beforeFound {
entryPath, hasEntry := snapshot.change.Path, true
if len(correspondence) != 0 {
entryPath, hasEntry = snapshot.entryPath, snapshot.hasEntry
}
beforePath, beforeFound := historyConcretePathAt(builder.scratch, entryPath, lookup)
if hasEntry && beforeFound {
observeResolutionSubtree(builder, snapshot.before, beforePath, snapshot.change.Path, ref, attribution, true, false)
}
}