replay

package
v0.49.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 27, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadCorpus

func LoadCorpus(dir string) ([]*model.IncidentFrame, []string, error)

LoadCorpus reads every *.json file in dir as an IncidentFrame. Files that fail to parse are skipped with a warning string in the returned slice (one entry per error).

func LoadFrame

func LoadFrame(path string) (*model.IncidentFrame, error)

LoadFrame reads a single IncidentFrame from disk. Rejects frames from a future schema version (operator must upgrade xtop) and rebuilds the entity-graph byID index after deserialization.

Types

type CorpusSummary

type CorpusSummary struct {
	// Frames is the total number of frames analyzed.
	Frames int

	// LabeledFrames is the subset that had an operator-provided Label.
	LabeledFrames int

	// PerMechanism maps mechanism → its TP/FP/FN counts. Precision is
	// TP/(TP+FP); recall is TP/(TP+FN).
	PerMechanism map[string]*MechanismStats

	// FlipFlops is the total count of mechanisms whose tier changed
	// between capture and replay across the entire corpus.
	FlipFlops int
}

CorpusSummary is the per-mechanism precision rollup over a labeled corpus. Computed by SummarizeCorpus.

func SummarizeCorpus

func SummarizeCorpus(frames []*model.IncidentFrame) *CorpusSummary

SummarizeCorpus aggregates replay results across a labeled corpus. Frames without a Label contribute to FlipFlops + tier rank but not to precision/recall (we don't know the ground truth).

type MechanismStats

type MechanismStats struct {
	TP, FP, FN, TN int
	// AvgTier is the average tier rank for replayed outputs
	// (A=4, B=3, C=2, D=1, unknown=0).
	AvgTierRank float64
}

MechanismStats is one mechanism's count breakdown.

func (*MechanismStats) Precision

func (m *MechanismStats) Precision() float64

Precision returns TP / (TP + FP), or 0 if no positives ever observed.

func (*MechanismStats) Recall

func (m *MechanismStats) Recall() float64

Recall returns TP / (TP + FN), or 0 if no actuals ever observed.

type ReplayResult

type ReplayResult struct {
	FrameFile string

	// Original is what the engine emitted at capture time.
	Original []model.VerifiedCause

	// Replayed is what the verifier emits NOW on the same inputs.
	Replayed []model.VerifiedCause

	// TierMatch reports per-mechanism whether the replayed tier
	// equals the original tier. true → deterministic, the engine
	// has not drifted; false → behavior changed since capture.
	TierMatch map[string]bool

	// FlipFlops counts mechanisms whose tier CHANGED between
	// capture and replay. Sentinel for engine non-determinism or
	// behavioral regression.
	FlipFlops int
}

ReplayResult is the per-frame harness output.

func Replay

func Replay(frame *model.IncidentFrame) *ReplayResult

Replay re-runs the configured verifier against the frame's stored facts + entity graph. Returns a ReplayResult comparing original versus fresh output. Uses verifier.Default() — to test a custom gate set, build your own Verifier and call its Verify method directly on each candidate derived from the frame.

Determinism contract: with verifier.Default() AND no engine code changes since the frame was captured, Replayed MUST equal Original tier-for-tier. Any divergence is reported in FlipFlops.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL