ekg-memory integration: record repeated-error incidents to memory and use memory-linked signatures for earlier escalation

This commit is contained in:
DBT
2026-03-01 06:21:04 +00:00
parent c46c0b9d2d
commit cc48c028ca
4 changed files with 70 additions and 2 deletions

View File

@@ -340,6 +340,7 @@ func (e *Engine) tick() {
st.BlockReason = "repeated_error_signature"
st.RetryAfter = now.Add(5 * time.Minute)
e.enqueueAutoRepairTaskLocked(st, errSig)
e.appendMemoryIncidentLocked(st, errSig, advice.Reason)
e.sendFailureNotification(st, "repeated error signature detected; escalate")
continue
}
@@ -753,6 +754,34 @@ func (e *Engine) enqueueAutoRepairTaskLocked(st *taskState, errSig string) {
e.writeReflectLog("infer", st, "generated auto-repair task due to repeated error signature")
}
func (e *Engine) appendMemoryIncidentLocked(st *taskState, errSig string, reasons []string) {
if st == nil || strings.TrimSpace(e.opts.Workspace) == "" {
return
}
errSig = ekg.NormalizeErrorSignature(errSig)
if errSig == "" {
errSig = "unknown_error_signature"
}
marker := "[EKG_INCIDENT] errsig=" + errSig
line := fmt.Sprintf("- [EKG_INCIDENT] errsig=%s task=%s reason=%s time=%s", errSig, shortTask(st.Content), strings.Join(reasons, ";"), time.Now().UTC().Format(time.RFC3339))
appendIfMissing := func(path string) {
_ = os.MkdirAll(filepath.Dir(path), 0755)
b, _ := os.ReadFile(path)
if strings.Contains(string(b), marker) {
return
}
f, err := os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
return
}
defer f.Close()
_, _ = f.WriteString(line + "\n")
}
dayPath := filepath.Join(e.opts.Workspace, "memory", time.Now().UTC().Format("2006-01-02")+".md")
appendIfMissing(dayPath)
appendIfMissing(filepath.Join(e.opts.Workspace, "MEMORY.md"))
}
func (e *Engine) sendFailureNotification(st *taskState, reason string) {
e.writeReflectLog("blocked", st, reason)
e.writeTriggerAudit("blocked", st, reason)