carlos / platform Public

ha departures: mark only real deliveries; narrow fallback

Astra round 2: with no alert sink armed the pager returned nil, so the
page-once hint was marked delivered though nothing was sent; and any
retry_hint_once error fell back to the ordinary retry, which could
overwrite a delivered marker. PageIdentity now pages through
alerting.PageDelivered (ErrNoSink when no sink is armed), and only
ErrHAJournal, an older server's refusal, falls back. Census overlay
re-proposed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev ed1beb3bf6aef7a9269d27969ec5dd0ae6567517 parent e1cc740
5 files changed, +63 −22
  • internal/alerting/alerting.go +17 −0
  • internal/host/hadepartures.go +8 −2
  • internal/host/hadepartures_no_observation_test.go +20 −17
  • internal/host/hadepartures_wiring.go +7 −3
  • internal/registry/ha_journal_test.go +11 −0

CI cancelled — superseded by a newer push — run details

CI log
=== gate ===
go: downloading go1.26.10 (linux/arm64)
go version go1.26.10 linux/arm64
opentofu: arm64, tofu 1.13.9, aws 6.73.0, archive 2.8.1
  tofu: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/tofu_1.13.9_linux_arm64.tar.gz
  tofu: downloaded, digest verified
  aws: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/terraform-provider-aws_6.73.0_linux_arm64.zip
  aws: downloaded, digest verified
  archive: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/terraform-provider-archive_2.8.1_linux_arm64.zip
  archive: downloaded, digest verified
  installed in /tmp/carlos-opentofu-4zhsSI
.amadan/test-gate.sh
go: downloading github.com/aws/aws-sdk-go-v2 v1.44.0
go: downloading github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.68.0
go: downloading github.com/aws/aws-sdk-go-v2/service/costexplorer v1.67.5
go: downloading github.com/aws/aws-sdk-go-v2/service/s3 v1.105.0
go: downloading github.com/aws/aws-sdk-go-v2/config v1.32.6
go: downloading github.com/aws/aws-sdk-go-v2/service/sns v1.43.0
go: downloading github.com/benbjohnson/litestream v0.5.14
go: downloading github.com/superfly/ltx v0.5.1
go: downloading golang.org/x/net v0.62.0
go: downloading modernc.org/sqlite v1.55.0
go: downloading github.com/aws/aws-sdk-go-v2/service/acm v1.45.0
go: downloading github.com/aws/aws-sdk-go-v2/service/iam v1.58.2
go: downloading github.com/aws/aws-sdk-go-v2/service/ec2 v1.324.0
go: downloading github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi v1.37.0
go: downloading github.com/aws/aws-sdk-go-v2/service/route53 v1.64.1
go: downloading golang.org/x/sys v0.49.0
go: downloading golang.org/x/crypto v0.58.0
go: downloading github.com/aws/aws-sdk-go-v2/credentials v1.19.6
go: downloading github.com/pion/logging v0.2.4
go: downloading github.com/pion/stun/v3 v3.1.5
go: downloading github.com/pion/turn/v4 v4.1.4
go: downloading github.com/pierrec/lz4/v4 v4.1.22
go: downloading github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.40
go: downloading golang.org/x/text v0.43.0
go: downloading github.com/aws/aws-sdk-go-v2/service/signin v1.0.4
go: downloading github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.40
go: downloading github.com/klauspost/compress v1.20.2
go: downloading github.com/aws/aws-sdk-go-v2/internal/v4a v1.4.38
go: downloading github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.19
go: downloading github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.40
go: downloading github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.31
go: downloading github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.23
go: downloading github.com/prometheus/client_golang v1.17.0
go: downloading github.com/lmittmann/tint v1.1.3
go: downloading golang.org/x/sync v0.24.0
go: downloading github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.20.18
go: downloading golang.org/x/crypto/x509roots/fallback v0.0.0-20260209214922-2f26647a795e
go: downloading github.com/pion/transport/v4 v4.0.2
go: downloading github.com/pion/dtls/v3 v3.1.4
go: downloading github.com/klauspost/compress v1.20.2
go: downloading github.com/pion/randutil v0.1.0
go: downloading modernc.org/sqlite v1.55.0
go: downloading github.com/prometheus/client_golang v1.17.0
go: downloading github.com/aws/aws-sdk-go-v2/service/ecs v1.91.0
go: downloading github.com/pierrec/lz4/v4 v4.1.22
go: downloading github.com/pion/dtls/v3 v3.1.4
go: downloading github.com/pion/transport/v4 v4.0.2
go: downloading github.com/prometheus/common v0.45.0
go: downloading github.com/prometheus/procfs v0.12.0
go: downloading google.golang.org/protobuf v1.36.10
go: downloading github.com/beorn7/perks v1.0.1
go: downloading github.com/cespare/xxhash/v2 v2.3.0
go: downloading github.com/prometheus/client_model v0.5.0
go: downloading github.com/prometheus/client_model v0.5.0
go: downloading github.com/prometheus/common v0.45.0
go: downloading google.golang.org/protobuf v1.36.10
go: downloading github.com/prometheus/procfs v0.12.0
go: downloading github.com/wlynxg/anet v0.0.5
go: downloading github.com/wlynxg/anet v0.0.5
go: downloading github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0
go: downloading github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0
go: downloading modernc.org/libc v1.74.1
go: downloading modernc.org/libc v1.74.1
go: downloading modernc.org/memory v1.11.0
go: downloading github.com/google/uuid v1.6.0
go: downloading modernc.org/mathutil v1.7.1
go: downloading github.com/dustin/go-humanize v1.0.1
go: downloading modernc.org/memory v1.11.0
go: downloading github.com/dustin/go-humanize v1.0.1
go: downloading modernc.org/mathutil v1.7.1
go: downloading github.com/google/uuid v1.6.0
go: downloading github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec

amadan: job cancelled — a newer push superseded it

Intent

Human

<task-notification> <task-id>b9ndt69mz</task-id> <tool-use-id>toolu_01EUE4Bg7qDtog5DvZHyeHbX</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/70d5e8d6-dd7c-4158-81af-7774784da3d3/tasks/b9ndt69mz.output</output-file> <status>completed</status> <summary>Background command "Run Astra review round 2 in the background" completed (exit code 0)</summary> </task-notification>

diff --git a/internal/alerting/alerting.go b/internal/alerting/alerting.go
index 6372bc3db..283e931c9 100644
--- a/internal/alerting/alerting.go
+++ b/internal/alerting/alerting.go
@@ -187,6 +187,23 @@ func Arm(s *Sinks) {
noSinkLogged.Store(false)
}
+// ErrNoSink is PageDelivered's answer when no sink is armed: nothing was
+// delivered, so a caller that records delivery must try again later.
+var ErrNoSink = errors.New("alerting: no sink configured, page not delivered")
+
+// PageDelivered is Page for callers that record a page as delivered: with no
+// armed sink it returns ErrNoSink instead of nil.
+func PageDelivered(ctx context.Context, level, subject, body string) error {
+ armedMu.RLock()
+ s := armed
+ armedMu.RUnlock()
+ if !s.HasWebhook() && !s.HasSNS() {
+ _ = s.Page(ctx, level, subject, body)
+ return ErrNoSink
+ }
+ return s.Page(ctx, level, subject, body)
+}
+
// Page pages an operator on the armed sinks (Sinks.Page).
func Page(ctx context.Context, level, subject, body string) error {
armedMu.RLock()
diff --git a/internal/host/hadepartures.go b/internal/host/hadepartures.go
index 2e53072d9..323c268cd 100644
--- a/internal/host/hadepartures.go
+++ b/internal/host/hadepartures.go
@@ -453,9 +453,15 @@ func (c *Controller) step(ctx context.Context) error {
onceCode := ""
var page bool
if once {
- // An older registry server refuses the op; keep its hourly retry.
- if page, e = c.cfg.Registry.RetryPendingTerminationOnce(ctx, h, c.now(), code); e == nil {
+ // Only an older registry server's refusal (ErrHAJournal) falls back
+ // to the hourly retry; any other failure must not overwrite a
+ // delivered marker, so it fails the pass.
+ page, e = c.cfg.Registry.RetryPendingTerminationOnce(ctx, h, c.now(), code)
+ switch {
+ case e == nil:
onceCode = code
+ case !errors.Is(e, registry.ErrHAJournal):
+ return e
}
}
if onceCode == "" {
diff --git a/internal/host/hadepartures_no_observation_test.go b/internal/host/hadepartures_no_observation_test.go
index cb53ab63b..1be231817 100644
--- a/internal/host/hadepartures_no_observation_test.go
+++ b/internal/host/hadepartures_no_observation_test.go
@@ -1,12 +1,12 @@
package host
import (
- "context"
"errors"
"strings"
"testing"
"time"
+ "github.com/carlosframework/platform/internal/alerting"
"github.com/carlosframework/platform/internal/boxid"
"github.com/carlosframework/platform/internal/boxid/boxidtest"
"github.com/carlosframework/platform/internal/registry"
@@ -43,20 +43,12 @@ func TestDeparturePendingWithoutObservationPagesOnce(t *testing.T) {
t.Fatal(err)
}
var codes []string
- page := func(_ context.Context, p registry.HAPendingTermination, code string) error {
- if p.IID != iid {
- t.Errorf("page for %s", p.IID)
- }
- codes = append(codes, code)
- return nil
- }
- // The first delivery fails; the page is retried within the hourly bound
- // and stops only once one is delivered.
- failed := 0
- x.c.cfg.PageIdentity = func(ctx context.Context, p registry.HAPendingTermination, code string) error {
- failed++
- return errors.New("sns down")
- }
+ // Production wiring with no sink armed: nothing is delivered, so nothing
+ // is marked. Then a failing sink: still not marked. The page is retried
+ // under the hourly bound and stops only once one is delivered.
+ alerting.Arm(nil)
+ t.Cleanup(func() { alerting.Arm(nil) })
+ x.c.cfg.PageIdentity = pageDeparturePending
run := func(c *Controller, d time.Duration) {
t.Helper()
end := x.now.Add(d)
@@ -66,16 +58,27 @@ func TestDeparturePendingWithoutObservationPagesOnce(t *testing.T) {
}
}
}
+ run(x.c, time.Hour)
+ if hints, err := x.r.PendingTerminations(t.Context(), x.now.Add(time.Hour), 32); err != nil || len(hints) != 1 || hints[0].LastError != "evidence_no_observation" {
+ t.Fatalf("no sink must not mark the page delivered: %+v %v", hints, err)
+ }
+ failed := 0
+ alerting.Arm(&alerting.Sinks{WebhookURL: "https://hooks.example.com/x", Post: func(string, []byte) error { failed++; return errors.New("webhook down") }})
run(x.c, 59*time.Minute)
if failed != 1 {
t.Fatalf("failed deliveries=%d, want 1 inside the hour", failed)
}
- x.c.cfg.PageIdentity = page
+ delivered := 0
+ alerting.Arm(&alerting.Sinks{WebhookURL: "https://hooks.example.com/x", Post: func(_ string, body []byte) error {
+ delivered++
+ codes = append(codes, string(body))
+ return nil
+ }})
run(x.c, 3*time.Hour)
// Restart: a fresh controller on the same journal.
restarted := &Controller{cfg: x.c.cfg}
run(restarted, 3*time.Hour)
- if len(codes) != 1 || !strings.HasPrefix(codes[0], "evidence_no_observation count=1") {
+ if delivered != 1 || len(codes) != 1 || !strings.Contains(codes[0], "code=evidence_no_observation count=1") || !strings.Contains(codes[0], iid) {
t.Fatalf("pages=%q, want exactly one evidence_no_observation page", codes)
}
hints, err := x.r.PendingTerminations(t.Context(), x.now.Add(time.Hour), 32)
diff --git a/internal/host/hadepartures_wiring.go b/internal/host/hadepartures_wiring.go
index 41587730e..25bae9e9c 100644
--- a/internal/host/hadepartures_wiring.go
+++ b/internal/host/hadepartures_wiring.go
@@ -120,9 +120,7 @@ func armHADepartures(ctx context.Context, a departureArm) (*Controller, hadepart
return false, err
}
return release.TrashRetired(ctx, store, provisionTickConfig(a.Getenv).ReleasePub, account, app)
- }, Invalidate: a.Service.InvalidateDutyHolder, PageIdentity: func(ctx context.Context, h registry.HAPendingTermination, code string) error {
- return PageOperator(ctx, alerting.LevelWarning, "ha_departure_pending", fmt.Sprintf("code=%s account=%s region=%s iid=%s", code, h.Account, h.Region, h.IID))
- }, Page: func(ctx context.Context, d registry.HADeparture, hosts []provision.DepartureHost) error {
+ }, Invalidate: a.Service.InvalidateDutyHolder, PageIdentity: pageDeparturePending, Page: func(ctx context.Context, d registry.HADeparture, hosts []provision.DepartureHost) error {
messages := []string{fmt.Sprintf("Duties from box %s have not been recovered. The scan will retry automatically. Check the box's wake state before removing its records.", d.Box.Ref)}
for _, h := range hosts {
if h.Kind != "sidecar" || h.HA {
@@ -245,3 +243,9 @@ func departureInventorySnapshot(inventory *provision.DepartureInventory) provisi
}
return s
}
+
+// pageDeparturePending is the controller's PageIdentity. The page-once path
+// records delivery, so "no sink" must not read as sent (alerting.PageDelivered).
+func pageDeparturePending(ctx context.Context, h registry.HAPendingTermination, code string) error {
+ return alerting.PageDelivered(ctx, alerting.LevelWarning, "ha_departure_pending", fmt.Sprintf("code=%s account=%s region=%s iid=%s", code, h.Account, h.Region, h.IID))
+}
diff --git a/internal/registry/ha_journal_test.go b/internal/registry/ha_journal_test.go
index f0b146713..dc2fda409 100644
--- a/internal/registry/ha_journal_test.go
+++ b/internal/registry/ha_journal_test.go
@@ -350,3 +350,14 @@ func TestDepartureIdentitySummaryClaim(t *testing.T) {
})
}
}
+
+// The controller falls back to the hourly retry only on ErrHAJournal, the
+// error an older server gives for an op it does not know (and that
+// remoteErrors carries across the registry RPC).
+func TestPendingTerminationOnceRefusalIsErrHAJournal(t *testing.T) {
+ r, _ := adoptRegistry(t)
+ h := HAPendingTermination{Account: "111122223333", Region: "eu-west-1", IID: "i-1123456789abcdef0", ReceivedAt: time.Now()}
+ if _, err := r.haJournal(t.Context(), haJournalRequest{Op: "retry_hint_twice", Hint: h, At: time.Now(), Code: "x"}); !errors.Is(err, ErrHAJournal) {
+ t.Fatal("unknown op", err)
+ }
+}