carlos / platform Public

console: fresh boxes' certificates are judged beside a stale box (R-40b)

Replaces R-40's whole-rule skip. cert_expiring is judged from the fresh
boxes' readings as usual, so new fires and clears still come from fresh
data. While any listed box is stale, an open member missing from those
readings keeps its state instead of going gone, because the stale box may
be the one serving it. Gone is emitted only when no listed box is stale.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 23aaa902963ed4c435be29ac38583f9f93bafc99 parent 9e4f6ad
2 files changed, +64 −21
  • internal/console/alertengine_pass_test.go +48 −10
  • internal/console/alertsignals.go +16 −11

Intent

Human

<task-notification> <task-id>a5e9692bdfdc91a99</task-id> <tool-use-id>toolu_01WBB7DYvag49w8J7KApmMcr</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/6112a34e-476e-4b5e-8e07-f93a46fc6d50/tasks/a5e9692bdfdc91a99.output</output-file> <status>completed</status> <summary>Agent "Final fix wave (Astra R1)" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>**Status:** DONE_WITH_CONCERNS. All 9 items are done, code and docs. Nothing is pushed. **Commits** (base 8fda1c91): - 08c3bc3c R-37: unsubscribing also clears the confirmation and drops unused confirm links. A test can no longer resubscribe a connector; only the recipient opening a new confirm link does. Unconfirmed email connectors get a "Send a new confirm link" button on the 5/h, 20/day limit, as a new route. - 8d98ae9e R-38: every process's first pass tries the key on each sealed target and marks the ones it can't open as needing re-entry. The drain's `seal` hold now records the same mark. - 9e4f6ad2 R-38: the authority census lists the new `seal.Open` site. - e251997f R-39: a flapping incident holds for an hour however its members leave. The reviewer's A/B timeline is a test, and the simulation has a new invariant for it. - 1a8ce24a R-40: certificates are not judged while any listed heartbeat is stale. - 6669ad0e R-41: a failed conditional GET or `ListMod` returns its error with no plain retry. `errors.ErrUnsupported` counts as a missing capability, so that store still uses the plain call. - 69a0b6e6 R-42: saving a rule Off deletes its queued incident rows in the same transaction, and the drain checks the rule again before sending. - a7a181ae item 7: the census comment no longer names the retired watcher. NewServer's digest is re-pinned, because its only change is the new route. - 03178af1 items 8-9: the Luna rows, R-44 and the Task 11 minors, with the Luna result file committed. **Tests:** each new test failed before its fix and passes after. The brief's console set, all route probes (`TestClaimConsoleMutationInvariant`), the provision census pair, the docs tests and `go vet` all pass. The retired-name guard prints nothing. **Concerns:** 1. I did not apply three Luna README rows word for word, because each would have made the README wrong. 1049: "remain open" reverses the meaning. 1087: "a test reactivates an unsubscribed connector" is false under R-37. 1092: "how long it has lasted" misreads the time-left field. These three sentences and the new page text (the "confirm link is on its way" notice, and the unsubscribed status with "Send a test to turn them back on." dropped) need a copy ruling. 2. I read "fresh confirm" as a link sent after the unsubscribe, so older unused confirm links are deleted at unsubscribe. If the ruling meant any unexpired link, drop that one DELETE. 3. Side effects of the rulings: - R-39: a flapping incident whose members all went gone closes as "cleared", not "no further reports". - R-40: while any box is stale, which can last up to 24 h, no certificate is judged at all. - R-42: a deleted fire leaves its incident marked as already sent. Report: `.superpowers/sdd/2026-10-30-fleet-alerts-1-engine-connectors/final-fix-report.md`</result> <usage><subagent_tokens>351227</subagent_tokens><tool_uses>123</tool_uses><duration_ms>2731580</duration_ms></usage> </task-notification>

diff --git a/internal/console/alertengine_pass_test.go b/internal/console/alertengine_pass_test.go
index db7f33bcb..592d4744b 100644
--- a/internal/console/alertengine_pass_test.go
+++ b/internal/console/alertengine_pass_test.go
@@ -986,34 +986,72 @@ func TestEnginePassUnreadHeartbeatKeepsCertExpiring(t *testing.T) {
ef.openAndQuiet(t, "cert_expiring")
}
-// Ruling R-40: a box whose heartbeat has gone stale is left out of the
+// certReadings is a heartbeat's metrics serving hosts, each with a
+// certificate expiring 3 days after alertT0.
+func certReadings(hosts ...string) *status.BoxMetrics {
+ m := &status.BoxMetrics{Aliases: map[string]status.AliasReading{}}
+ for _, h := range hosts {
+ m.Aliases[h] = status.AliasReading{Route: h, CertExpiresAt: alertT0.Add(3 * 24 * time.Hour).Unix()}
+ }
+ return m
+}
+
+// Ruling R-40b: a box whose heartbeat has gone stale is left out of the
// certificate readings, which is not the same as its host no longer being
-// served. Its expiring certificate stays open, unjudged, until the box
-// reports again or drops out of the listing.
+// served. A host only it reported stays a member of the open incident;
+// fresh boxes are still judged, so a fresh box's expiring host still fires.
func TestEnginePassStaleHeartbeatKeepsCertExpiring(t *testing.T) {
ef := newEngineFixture(t, nil)
ef.operator(t, opA)
- expiring := &status.BoxMetrics{Aliases: map[string]status.AliasReading{
- "shop.example.com": {Route: "shop.example.com", CertExpiresAt: alertT0.Add(3 * 24 * time.Hour).Unix()}}}
- ef.heartbeat(t, "box-1", alertT0, expiring)
+ ef.heartbeat(t, "box-1", alertT0, certReadings("shop.example.com"))
ef.heartbeat(t, "box-2", alertT0, nil)
ef.passesTo(t, 0, 5*time.Minute)
if n := ef.count(t, `SELECT COUNT(*) FROM alert_incidents WHERE closed_at IS NULL AND rule = 'cert_expiring'`); n != 1 {
t.Fatalf("%d open cert_expiring incidents, want 1", n)
}
- // box-1 stops reporting; box-2 goes on. Past 15 minutes box-1 is stale.
+ // box-1 stops reporting; box-2 goes on. Past 15 minutes box-1 is stale,
+ // and from minute 20 box-2 serves a host of its own expiring.
for m := 6; m <= 30; m++ {
- ef.heartbeat(t, "box-2", alertT0.Add(time.Duration(m)*time.Minute), nil)
+ var metrics *status.BoxMetrics
+ if m >= 20 {
+ metrics = certReadings("pay.example.com")
+ }
+ ef.heartbeat(t, "box-2", alertT0.Add(time.Duration(m)*time.Minute), metrics)
ef.passAt(t, time.Duration(m)*time.Minute)
}
- if n := ef.count(t, `SELECT COUNT(*) FROM alert_incidents WHERE closed_at IS NULL AND rule = 'cert_expiring'`); n != 1 {
- t.Fatalf("%d open cert_expiring incidents with box-1 stale, want 1", n)
+ var members string
+ if err := ef.st.db.QueryRow(`SELECT members FROM alert_incidents WHERE closed_at IS NULL AND rule = 'cert_expiring'`).Scan(&members); err != nil {
+ t.Fatalf("no open cert_expiring incident with box-1 stale: %v", err)
+ }
+ if !strings.Contains(members, "shop.example.com") || !strings.Contains(members, "pay.example.com") {
+ t.Fatalf("members %s, want the stale box's host kept and the fresh box's host joined", members)
+ }
+ if n := ef.count(t, `SELECT COUNT(*) FROM alert_fires WHERE rule = 'cert_expiring' AND subject = 'pay.example.com'`); n != 1 {
+ t.Fatalf("%d fires for the fresh box's expiring host, want 1", n)
}
if n := ef.count(t, `SELECT COUNT(*) FROM alert_outbox WHERE kind = 'clear'`); n != 0 {
t.Fatalf("%d clears queued while box-1 is stale, want none", n)
}
}
+// Ruling R-40b: with no listed box stale, a host no fresh box serves any
+// more is gone, and its incident closes as no further reports.
+func TestEnginePassCertHostGoneWithNoStaleBox(t *testing.T) {
+ ef := newEngineFixture(t, nil)
+ ef.operator(t, opA)
+ for m := 0; m <= 15; m++ {
+ var metrics *status.BoxMetrics
+ if m < 6 {
+ metrics = certReadings("shop.example.com")
+ }
+ ef.heartbeat(t, "box-1", alertT0.Add(time.Duration(m)*time.Minute), metrics)
+ ef.passAt(t, time.Duration(m)*time.Minute)
+ }
+ if n := ef.count(t, `SELECT COUNT(*) FROM alert_incidents WHERE rule = 'cert_expiring' AND close_reason = 'box gone'`); n != 1 {
+ t.Fatalf("%d cert_expiring incidents closed as gone, want 1", n)
+ }
+}
+
// An alert object that does not parse is stepped over: the box beside it
// still fires, and the junk box's state is left as it was.
func TestEnginePassSurvivesJunk(t *testing.T) {
diff --git a/internal/console/alertsignals.go b/internal/console/alertsignals.go
index e91b817aa..e63936fc7 100644
--- a/internal/console/alertsignals.go
+++ b/internal/console/alertsignals.go
@@ -231,8 +231,11 @@ type alertSignals struct {
list []alertSignal
has map[alertKey]bool
// covered is each console rule a source reported this pass, with the
- // subjects whose state could not be read.
- covered map[string]map[string]bool
+ // subjects whose state could not be read. keepMissing is a covered rule
+ // whose source may have left out subjects it still has: its members
+ // with no signal keep their state rather than go gone.
+ covered map[string]map[string]bool
+ keepMissing map[string]bool
// boxRules is whether alerts/boxes/ was listed this pass; boxUnknown
// the boxes listed whose object could not be read or parsed.
boxRules bool
@@ -242,8 +245,8 @@ type alertSignals struct {
}
func newAlertSignals() *alertSignals {
- return &alertSignals{has: map[alertKey]bool{}, covered: map[string]map[string]bool{}, boxUnknown: map[string]bool{},
- firedAt: map[alertKey]time.Time{}}
+ return &alertSignals{has: map[alertKey]bool{}, covered: map[string]map[string]bool{}, keepMissing: map[string]bool{},
+ boxUnknown: map[string]bool{}, firedAt: map[alertKey]time.Time{}}
}
func (g *alertSignals) add(sg alertSignal) {
@@ -281,7 +284,7 @@ func (g *alertSignals) withGone(open []alertIncident, now time.Time) []alertSign
if !alertConsoleRules[in.Rule] {
unknown, read = g.boxUnknown, g.boxRules
}
- if !read {
+ if !read || g.keepMissing[in.Rule] {
continue
}
for _, m := range in.Members {
@@ -385,9 +388,10 @@ func alertReadFailed(ctx context.Context, err error) {
// (Review Focus 3: every box with an object is a member, whether or not it
// ever fired anything) and alert_delivery_broken, and cert_expiring for
// every host the fresh boxes serve. Certificates are judged only when every
-// heartbeat was read and none is stale (ruling R-40): aliasReadingsFrom
-// leaves a stale box out, so a host only it reports would otherwise be
-// taken for gone, closed, and fired again when the box came back.
+// heartbeat was read. While a listed box is stale, the fresh boxes' hosts
+// are still judged, but a host missing from their readings does not go
+// gone (ruling R-40b): aliasReadingsFrom leaves a stale box out, and that
+// box may be the one serving it.
func heartbeatBoxSignals(boxes []status.Box, unread map[string]bool, settings map[string]alertRuleSetting, now time.Time, sig *alertSignals) {
silentAfter := time.Duration(alertThreshold(settings, "box_silent")) * time.Minute
for _, b := range boxes {
@@ -403,9 +407,7 @@ func heartbeatBoxSignals(boxes []status.Box, unread map[string]bool, settings ma
}
sig.cover("box_silent", unread)
sig.cover("alert_delivery_broken", unread)
- if len(unread) > 0 || slices.ContainsFunc(boxes, func(b status.Box) bool {
- return status.BoxStale(b, now, status.SnapshotPeriod)
- }) {
+ if len(unread) > 0 {
return
}
within := time.Duration(alertThreshold(settings, "cert_expiring")*24) * time.Hour
@@ -418,6 +420,9 @@ func heartbeatBoxSignals(boxes []status.Box, unread map[string]bool, settings ma
Firing: left <= within, Value: left.Hours() / 24, At: now})
}
sig.cover("cert_expiring", nil)
+ sig.keepMissing["cert_expiring"] = slices.ContainsFunc(boxes, func(b status.Box) bool {
+ return status.BoxStale(b, now, status.SnapshotPeriod)
+ })
}
// serviceSignals adds service_down for every service fleet.json lists. A