Keep native execution membership presentation stable

This commit is contained in:
2026-11-23 16:58:46 +00:00
parent 59f353348b
commit c554eecaec
5 changed files with 73 additions and 6 deletions

View File

@@ -1,6 +1,8 @@
package processreport
import (
"slices"
"strings"
"time"
"gitea.maximumdirect.net/eric/audita/v4/internal/framework/llm"
@@ -49,14 +51,27 @@ func BuildLLMExecution(snapshot llm.ObservationSnapshot) any {
RequestedPromptID: call.RequestedPromptID, CallID: call.CallID, Context: call.Context,
Prompt: call.Prompt, Started: call.Started, Finished: finished,
ElapsedMS: call.WallDuration.Milliseconds(), Failure: call.Failure,
PromptKit: group.Snapshot(),
PromptKit: orderedMembers(group.Snapshot()),
})
}
return struct {
Summary llm.ExecutionSummary `json:"summary"`
Calls []executionCall `json:"calls"`
Events []llm.ExecutionObservation `json:"events"`
}{llm.Summarize(snapshot), calls, events}
}{orderedExecutionSummary(snapshot), calls, events}
}
// orderedMembers changes only the detached diagnostic presentation.
func orderedMembers(summary pk.ExecutionGroupSummary) pk.ExecutionGroupSummary {
summary.Members = slices.Clone(summary.Members)
slices.SortFunc(summary.Members, func(a, b pk.ExecutionGroupMember) int { return strings.Compare(a.RunID, b.RunID) })
return summary
}
func orderedExecutionSummary(snapshot llm.ObservationSnapshot) llm.ExecutionSummary {
summary := llm.Summarize(snapshot)
summary.PromptKit = orderedMembers(summary.PromptKit)
return summary
}
// IndexLLMObservations assigns the same proposal identities used by the ledger.

View File

@@ -160,3 +160,43 @@ func TestPerCallGroupsRetainCoverageAndDeduplicateTerminals(t *testing.T) {
t.Fatalf("complete: %+v", complete)
}
}
func TestNativeMembersHaveStableDetachedPresentation(t *testing.T) {
members := []pk.ExecutionGroupMember{{RunID: "z", TerminalObserved: true}, {RunID: "a"}}
snapshot := llm.ObservationSnapshot{
Calls: []llm.LogicalCall{{CallID: 1}},
Group: &pk.ExecutionGroupSummary{Members: members, Attempts: 7},
Events: []llm.ExecutionObservation{
{CallID: 1, PromptKit: pk.ExecutionEvent{RunID: "z", Kind: pk.ExecutionFinished, Attempts: 2}},
{CallID: 1, PromptKit: pk.ExecutionEvent{RunID: "a", Kind: pk.ExecutionAttempt}},
},
}
raw, err := json.Marshal(BuildLLMExecution(snapshot))
if err != nil {
t.Fatal(err)
}
var report struct {
Summary llm.ExecutionSummary
Calls []executionCall
Events []llm.ExecutionObservation
}
if err := json.Unmarshal(raw, &report); err != nil {
t.Fatal(err)
}
for _, summary := range []pk.ExecutionGroupSummary{report.Summary.PromptKit, report.Calls[0].PromptKit} {
if len(summary.Members) != 2 || summary.Members[0].RunID != "a" || summary.Members[1].RunID != "z" || summary.Members[0].TerminalObserved || !summary.Members[1].TerminalObserved {
t.Fatalf("members: %+v", summary.Members)
}
}
if members[0].RunID != "z" || report.Summary.PromptKit.Attempts != 7 || report.Calls[0].PromptKit.Attempts != 2 || report.Events[0].PromptKit.RunID != "z" {
t.Fatal("rendering changed evidence or input")
}
snapshot.Group.Members = []pk.ExecutionGroupMember{members[1], members[0]}
again, err := json.Marshal(BuildLLMExecution(snapshot))
if err != nil {
t.Fatal(err)
}
if string(raw) != string(again) {
t.Fatal("membership permutation changed presentation")
}
}