carlos / platform Public

console: incident step update clock per R-19 (30 min after a fire or reminder, an hour between updates)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev d588e5b0ec7cfaca4ebb2b1730ef4762cc6dfca0 parent ab44bb9
3 files changed, +51 −27
  • internal/console/alertengine.go +7 −4
  • internal/console/alertengine_test.go +40 −21
  • internal/console/alertstore.go +4 −2

CI failed — run details

diff --git a/internal/console/alertengine.go b/internal/console/alertengine.go
index 6378ae204..65ca0d60f 100644
--- a/internal/console/alertengine.go
+++ b/internal/console/alertengine.go
@@ -18,8 +18,11 @@ package console
// when (alertIncident.quiet). A firing signal wakes it with just the
// subjects firing now; an hour quiet closes it.
//
-// Every message resets the clocks after it: a reminder is due 24 hours
-// after the last message of any kind, and an update an hour after.
+// The message clocks: a fire or reminder sets LastReminderAt, an update or
+// reminder sets LastUpdateAt. A reminder is due 24 hours after the later
+// of the two, the last message of any kind. An update waits 30 minutes
+// after the last fire or reminder (§6.2's quiet half hour, counted from a
+// late fire too) and an hour after the last update (ruling R-19).
import (
"slices"
@@ -268,7 +271,7 @@ func (st incidentStep) advance(in alertIncident, keys []alertKey) (out alertInci
// fire goes out once one isn't.
if v := visible(out.Members); !now.Before(out.NotifyAt) && len(v) > 0 {
out.Notified = true
- out.LastReminderAt, out.LastUpdateAt = now, now
+ out.LastReminderAt = now
emit(alertKindFire, v, nil)
}
case !now.Before(out.OpenedAt.Add(alertReminderEvery)) && since(out.LastReminderAt, alertReminderEvery) &&
@@ -277,7 +280,7 @@ func (st incidentStep) advance(in alertIncident, keys []alertKey) (out alertInci
out.LastReminderAt, out.LastUpdateAt = now, now
emit(alertKindReminder, visible(out.Members), nil)
case !out.Flapping && len(visible(joined)) > 0 && !now.Before(out.OpenedAt.Add(alertUpdateQuiet)) &&
- since(out.LastUpdateAt, alertUpdateEvery):
+ since(out.LastReminderAt, alertUpdateQuiet) && since(out.LastUpdateAt, alertUpdateEvery):
out.LastUpdateAt = now
emit(alertKindUpdate, visible(out.Members), visible(joined))
}
diff --git a/internal/console/alertengine_test.go b/internal/console/alertengine_test.go
index 6a0497ada..bc140119c 100644
--- a/internal/console/alertengine_test.go
+++ b/internal/console/alertengine_test.go
@@ -209,14 +209,13 @@ func TestStepOneFireOneClear(t *testing.T) {
}
func TestStepLateMemberUpdateHourly(t *testing.T) {
- // The fire at 5 starts the update clock. b2 joins inside the first 30
- // minutes and b3 inside the hour after the fire: both silent. b4 at 70
- // is the first update; b5 at 100 is inside that hour: silent. b6 at 131
- // is the next.
- joins := map[string]int{"b1": 0, "b2": 10, "b3": 40, "b4": 70, "b5": 100, "b6": 131}
+ // b2 joins inside the first 30 minutes: silent. b3 at 35 is the first
+ // update; b4 at 50 is inside that hour: silent. b5 at 96 is the next,
+ // and b6 at 100 is silent again.
+ joins := map[string]int{"b1": 0, "b2": 10, "b3": 35, "b4": 50, "b5": 96, "b6": 100}
order := []string{"b1", "b2", "b3", "b4", "b5", "b6"}
sim := newStepSim(t)
- sim.run(0, 150, func(m int) []alertSignal {
+ sim.run(0, 120, func(m int) []alertSignal {
var sigs []alertSignal
for _, b := range order {
if m >= joins[b] {
@@ -227,14 +226,14 @@ func TestStepLateMemberUpdateHourly(t *testing.T) {
})
sim.emitsAre(
simWant{5, "fire", []string{"b1"}},
- simWant{70, "update", order[:4]},
- simWant{131, "update", order},
+ simWant{35, "update", order[:3]},
+ simWant{96, "update", order[:5]},
)
- if j := sim.emits[1].Joined; !slices.Equal(j, []string{"b4"}) {
- t.Fatalf("first update Joined = %v, want [b4]", j)
+ if j := sim.emits[1].Joined; !slices.Equal(j, []string{"b3"}) {
+ t.Fatalf("first update Joined = %v, want [b3]", j)
}
- if j := sim.emits[2].Joined; !slices.Equal(j, []string{"b6"}) {
- t.Fatalf("second update Joined = %v, want [b6]", j)
+ if j := sim.emits[2].Joined; !slices.Equal(j, []string{"b5"}) {
+ t.Fatalf("second update Joined = %v, want [b5]", j)
}
if sim.emits[0].Joined != nil {
t.Fatalf("fire Joined = %v, want none", sim.emits[0].Joined)
@@ -242,17 +241,23 @@ func TestStepLateMemberUpdateHourly(t *testing.T) {
}
func TestStepUpdateAfterLateFireWaits(t *testing.T) {
- // A fire held back by a snooze until 25 h resets the update clock: a
- // member joining a minute later is folded in silently.
+ // A fire held back by a snooze until 25 h starts its own quiet half
+ // hour (R-19): b2 joining a minute later is folded in silently, and b3
+ // joining 31 minutes after the fire is the first update.
+ const fire = 25 * 60
sim := newStepSim(t)
- sim.snoozedUntil[diskKey("b1")] = minute(25 * 60)
- sim.run(0, 25*60+120, func(m int) []alertSignal {
- if m > 25*60 {
- return []alertSignal{firing("b1"), firing("b2")}
+ sim.snoozedUntil[diskKey("b1")] = minute(fire)
+ sim.run(0, fire+120, func(m int) []alertSignal {
+ sigs := []alertSignal{firing("b1")}
+ if m > fire {
+ sigs = append(sigs, firing("b2"))
+ }
+ if m >= fire+31 {
+ sigs = append(sigs, firing("b3"))
}
- return []alertSignal{firing("b1")}
+ return sigs
})
- sim.emitsAre(simWant{25 * 60, "fire", []string{"b1"}})
+ sim.emitsAre(simWant{fire, "fire", []string{"b1"}}, simWant{fire + 31, "update", []string{"b1", "b2", "b3"}})
}
func TestStepFlappingAcrossIncidents(t *testing.T) {
@@ -557,7 +562,8 @@ func TestStepDoesNotModifyOpen(t *testing.T) {
// TestStepInvariantsRandom (ruling R-18) runs 500 seeded three-day
// timelines over three boxes that fire, clear and go gone at random, with
// passes that miss a box and snoozes that come and go, and checks the
-// noise rules' invariants after every step.
+// noise rules' invariants after every step: (f) and (i) are the R-19
+// update clocks.
func TestStepInvariantsRandom(t *testing.T) {
const seeds, steps = 500, 3 * 24 * 60
subjects := []string{"b1", "b2", "b3"}
@@ -584,6 +590,10 @@ func runStepInvariants(t *testing.T, seed uint64, steps int, subjects []string)
lastMsg := map[int64]time.Time{}
lastReminder := map[int64]time.Time{}
lastUpdate := map[int64]time.Time{}
+ // The R-19 clocks: the last fire or reminder, the last update or
+ // reminder.
+ lastFireOrReminder := map[int64]time.Time{}
+ lastUpdateOrReminder := map[int64]time.Time{}
cleared := map[int64]bool{}
for m := range steps {
@@ -634,6 +644,7 @@ func runStepInvariants(t *testing.T, seed uint64, steps int, subjects []string)
return fmt.Errorf("minute %d: fire for incident %d before NotifyAt", m, id)
}
notified[id] = true
+ lastFireOrReminder[id] = now
case alertKindReminder:
if !notified[id] || now.Sub(lastMsg[id]) < alertReminderEvery { // (e)
return fmt.Errorf("minute %d: reminder for incident %d %v after its last message", m, id, now.Sub(lastMsg[id]))
@@ -642,6 +653,7 @@ func runStepInvariants(t *testing.T, seed uint64, steps int, subjects []string)
return fmt.Errorf("minute %d: reminders for incident %d %v apart", m, id, now.Sub(r))
}
lastReminder[id] = now
+ lastFireOrReminder[id], lastUpdateOrReminder[id] = now, now
case alertKindUpdate:
if !notified[id] {
return fmt.Errorf("minute %d: update for unannounced incident %d", m, id)
@@ -649,7 +661,14 @@ func runStepInvariants(t *testing.T, seed uint64, steps int, subjects []string)
if u, ok := lastUpdate[id]; ok && now.Sub(u) < alertUpdateEvery { // (f)
return fmt.Errorf("minute %d: updates for incident %d %v apart", m, id, now.Sub(u))
}
+ if u, ok := lastUpdateOrReminder[id]; ok && now.Sub(u) < alertUpdateEvery { // (f)
+ return fmt.Errorf("minute %d: update for incident %d %v after its last update or reminder", m, id, now.Sub(u))
+ }
+ if f, ok := lastFireOrReminder[id]; ok && now.Sub(f) < alertUpdateQuiet { // (i)
+ return fmt.Errorf("minute %d: update for incident %d %v after its last fire or reminder", m, id, now.Sub(f))
+ }
lastUpdate[id] = now
+ lastUpdateOrReminder[id] = now
case alertKindClear:
clears[id]++
}
diff --git a/internal/console/alertstore.go b/internal/console/alertstore.go
index c090554cf..7108191dc 100644
--- a/internal/console/alertstore.go
+++ b/internal/console/alertstore.go
@@ -208,8 +208,10 @@ type alertRuleSetting struct {
// - LastSeenAt is zero while any member fires. On a flapping incident it
// is the time it went quiet, and on a closed row when it stopped.
//
-// LastReminderAt and LastUpdateAt are both set by every message, so a
-// reminder or update counts from the last message of any kind.
+// LastReminderAt is the last fire or reminder, LastUpdateAt the last
+// update or reminder. A reminder counts from the later of the two; an
+// update waits 30 minutes after LastReminderAt and an hour after
+// LastUpdateAt (ruling R-19).
type alertIncident struct {
ID int64
Scope, Rule, Level string