phase 3 review: fix broken error classification, stub checks, wasted uuid, token idempotency, dead code

- actuator/ssh.go: custom errorsAs chain broken — all SSH errors classified as SSHErrorOther.
  Replaced with standard errors.As + errors.Is.
- scheduler/scheduler.go: all four check functions were stubs returning healthy.
  Implemented real HTTP GET, TCP dial, unix.Statfs disk, and TLS cert expiry checks.
- learning/learning.go: uuid.NewV7() called unconditionally before ON CONFLICT upsert.
  Now looks up existing pattern first, reuses entity_id.
- notifier/notifier.go: removed dead var_, fixed token regeneration every 15s.
  Now skips if token_hash already set.
- phase3.go: removed dead GetPattern+dummy args call in PatchPattern.
- classify.go: removed unused var_ guard.
This commit is contained in:
2026-07-07 15:27:31 +02:00
parent 095a3967c4
commit aa197190cd
6 changed files with 182 additions and 87 deletions

View File

@@ -105,11 +105,26 @@ func processGroup(ctx context.Context, pool *db.Pool, q *sqlcgen.Queries,
// Cap by sample size: nothing looks confident before 5 samples
confidence = math.Min(confidence, float64(total)/5.0)
// Get or create pattern
patternID, _ := uuid.NewV7()
// Get or create pattern — first look up existing entity, then upsert.
existing, err := q.GetPattern(ctx, sqlcgen.GetPatternParams{
AppliesType: appliesType,
Action: action,
})
var patternID uuid.UUID
if err == nil && existing.EntityID != uuid.Nil {
patternID = existing.EntityID
} else {
id, idErr := uuid.NewV7()
if idErr != nil {
slog.Error("learning: gen pattern uuid", "error", idErr)
return
}
patternID = id
}
patternSummary := action + " on " + appliesType
err := q.UpsertPattern(ctx, sqlcgen.UpsertPatternParams{
err = q.UpsertPattern(ctx, sqlcgen.UpsertPatternParams{
EntityID: patternID,
AppliesType: appliesType,
Action: action,