fix(selfoptimize): repair 3 dashboard metrics that were stuck at 0

1. gap_closure_rate: RecordMiss now increments Dash.TotalGaps; Close
   calls Dash.RecordGapClosed(). Previously denominator was never written.
2. auto_resolve_rate: scanConflicts now calls Dash.RecordConflictResolved
   after each AutoResolve. Previously consolidation path bypassed Dashboard.
3. avg_distill_loss: merge-count heuristic scaled from 0.01 to 0.002
   with 0.05 cap. Previously 50 merges = 0.50 loss (same weight as 50 LLM
   distillations), corrupting the average.
This commit is contained in:
xiaowei
2026-05-30 18:03:49 +08:00
parent 35f78ed14b
commit 5927f7d740
3 changed files with 10 additions and 1 deletions
@@ -9,6 +9,7 @@ import (
"github.com/xiaoxue/memoryweave/internal/consolidate"
"github.com/xiaoxue/memoryweave/internal/governance"
"github.com/xiaoxue/memoryweave/internal/selfoptimize"
"github.com/xiaoxue/memoryweave/internal/storage"
)
@@ -226,6 +227,7 @@ func (cp *ConsolidationPipeline) scanConflicts() (int, error) {
for _, c := range conflicts {
if c.Strategy == "latest_wins" {
cp.conflicts.AutoResolve(c)
selfoptimize.Dash.RecordConflictResolved(true)
}
}
}
+6 -1
View File
@@ -717,7 +717,12 @@ func NewServer() http.Handler {
if err == nil && report != nil {
// 注入 consolidate 报告 → Dashboard
if report.Merged > 0 {
selfoptimize.Dash.RecordDistillLoss(float64(report.Merged) * 0.01) // 合并数越低越好
// 合并启发式: 按合并数比例缩放, 但限定单次贡献 ≤ 0.05, 防止污染 avg_distill_loss
loss := float64(report.Merged) * 0.002
if loss > 0.05 {
loss = 0.05
}
selfoptimize.Dash.RecordDistillLoss(loss)
}
if report.ConflictsFound > 0 {
selfoptimize.Dash.RecordConflictResolved(true)
+2
View File
@@ -303,6 +303,7 @@ func (gd *GapDetector) RecordMiss(topic string) *Gap {
}
gd.gaps[topic] = gap
gd.persistGaps()
Dash.TotalGaps++ // 同步仪表盘
return gap
}
}
@@ -390,6 +391,7 @@ func (gd *GapDetector) Close(topic string) {
if g, ok := gd.gaps[topic]; ok {
g.Closed = true
gd.persistGaps()
Dash.RecordGapClosed() // 同步仪表盘
}
}