carlos / platform Public

console: seed each operator address once ever (R-24)

An alert_meta row seeded:<lowercased address> is written in the same
transaction as the connector it creates, by the cutover and by every
later pass. An operator who deletes their seeded connector does not get
it back; one granted later is still seeded within a minute. The cutover
queues fires only to operators who have a connector.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 92e60520e4543618f2d2125ac0b08638d141ed83 parent 4aaa411
3 files changed, +62 −13
  • internal/console/alertengine_pass.go +7 −6
  • internal/console/alertengine_pass_test.go +32 −0
  • internal/console/alertstore.go +23 −7

CI cancelled — superseded by a newer push — run details

Intent

Human

<task-notification> <task-id>a228356c85f7c1bde</task-id> <tool-use-id>toolu_01HU6s68MiPMjnDDSpkBN3jz</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/6112a34e-476e-4b5e-8e07-f93a46fc6d50/tasks/a228356c85f7c1bde.output</output-file> <status>completed</status> <summary>Agent "Implement Task 8: alert engine worker" 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 - **Commits:** - b14accf7 `console: move the alert engine's worker into alertengine_pass.go; drop unused alertMessage` (the pure move, plus deleting `alertMessage`) - 4aaa411e `console: alert engine fix round 1 (drain on a failed step, read failures close nothing, seeding every pass)` (all other items) - **Tests:** - All 25 engine tests pass. Six are new: the drain when the listing fails, one per source showing a failed read keeps its incident with no clear (four), and a later operator seeded. - The covering set passes: engine, Alert, Dashboard, Jobs, StoreNotify, the log-also-fails check and the route census. - The StartAlertEngine claim probe passes when run alone. Running it alone makes its parent test report every other door as uncovered, so ignore those lines. I did not rerun the full Claim group, as you asked. - `go vet` is clean and the Step 5 guard prints nothing. - Breaking the code on purpose fails the new tests that cover each change, and they pass again once restored. - The five-cycle request counts are unchanged. Old heartbeats are now read last within the 200-key cap rather than dropped, so there is still one listing and one conditional GET per heartbeat object. - **Concerns:** - With seeding every pass (R-20), an operator whose email connector is deleted gets it back within a minute. Task 10's unsubscribe must switch the connector off rather than delete it. - For R-21 I added a general job-status note (`jobNoteOn` and `JobStatus.Note` in jobs.go); the jobs table shows it beside a run that succeeded. - Heartbeat read failures now fail the run, as alert-file failures do; before, they were only logged. - **Report:** /home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-fleet-alerts/.superpowers/sdd/2026-10-30-fleet-alerts-1-engine-connectors/task-8-report.md (fix round 1 appended)</result> <usage><subagent_tokens>423873</subagent_tokens><tool_uses>24</tool_uses><duration_ms>459691</duration_ms></usage> </task-notification>

Attributed to this commit: 26.0 g CO₂e (3,296,352 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-fleet-alerts, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/internal/console/alertengine_pass.go b/internal/console/alertengine_pass.go
index 39035c04a..6941f0ee4 100644
--- a/internal/console/alertengine_pass.go
+++ b/internal/console/alertengine_pass.go
@@ -27,8 +27,9 @@ import (
// The first pass of a process opens the connector seal and, once per
// database, migrates the watcher's delivery history (alert_seen) so nobody
// is told twice, or not told a clear they are owed. Every pass seeds each
-// operator an email connector, idempotently, so an operator made later is
-// reached within a minute (ruling R-20).
+// operator not yet seeded an email connector, so an operator made later is
+// reached within a minute (ruling R-20); each address is seeded once ever,
+// so one whose connector was deleted does not get it back (ruling R-24).
//
// One console per deployment runs it (spec §5.2): on a host-claim console,
// which may be one of several, the worker is off. It says so in the log and
@@ -232,8 +233,8 @@ func (s *Server) openAlertSeal() {
e.reentryPending = created
}
-// seedOperatorConnectors gives every operator their email connector,
-// idempotently (ruling R-20). An operator made since the last pass is
+// seedOperatorConnectors gives every operator not yet seeded their email
+// connector (rulings R-20, R-24). An operator made since the last pass is
// reached from this one.
func (s *Server) seedOperatorConnectors(now time.Time) error {
ops, err := s.store.Operators()
@@ -492,8 +493,8 @@ func planAlertCutover(boxes boxAlerts, seen map[[2]string][]string, ops []string
return nil, nil, fmt.Errorf("encode a fire for %s on %s: %w", rule, box, err)
}
for _, op := range ops {
- if !slices.Contains(told, op) {
- opened[i].fires = append(opened[i].fires, alertOutboxRow{ConnectorID: conns[op], Kind: alertKindFire, Body: body, NextAt: now})
+ if id, ok := conns[op]; ok && !slices.Contains(told, op) {
+ opened[i].fires = append(opened[i].fires, alertOutboxRow{ConnectorID: id, Kind: alertKindFire, Body: body, NextAt: now})
}
}
continue
diff --git a/internal/console/alertengine_pass_test.go b/internal/console/alertengine_pass_test.go
index 1d6165775..6764ed1f1 100644
--- a/internal/console/alertengine_pass_test.go
+++ b/internal/console/alertengine_pass_test.go
@@ -671,6 +671,38 @@ func TestEnginePassSeedsALaterOperator(t *testing.T) {
}
}
+// Ruling R-24: each address is seeded once ever. The cutover's seeding
+// records it too; an operator who deletes their connector does not get it
+// back, on the next pass or after a restart, while a new operator is still
+// seeded.
+func TestEnginePassSeedsEachAddressOnce(t *testing.T) {
+ ef := newEngineFixture(t, nil)
+ ef.operator(t, opA)
+ ef.passAt(t, 0) // the cutover seeds A
+ if n := ef.count(t, `SELECT COUNT(*) FROM alert_meta WHERE k = 'seeded:`+opA+`'`); n != 1 {
+ t.Fatalf("%d seeded markers for A after the cutover, want 1", n)
+ }
+ conns, err := ef.st.AlertConnectors(alertScopeFleet)
+ if err != nil || len(conns) != 1 {
+ t.Fatalf("connectors %+v (%v), want A's", conns, err)
+ }
+ if err := ef.st.DeleteAlertConnector(alertScopeFleet, conns[0].ID); err != nil {
+ t.Fatal(err)
+ }
+ ef.passAt(t, time.Minute)
+ ef.restart()
+ ef.passAt(t, 2*time.Minute)
+ ef.operator(t, opB)
+ ef.passAt(t, 3*time.Minute)
+ conns, err = ef.st.AlertConnectors(alertScopeFleet)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(conns) != 1 || conns[0].OwnerAddress != opB {
+ t.Fatalf("connectors %+v, want B's alone: A deleted theirs", conns)
+ }
+}
+
// A failed step does not hold up rows already owed: the drain runs anyway,
// and the beat is not written, so engine_silent can still trip.
func TestEnginePassDrainsWhenTheListingFails(t *testing.T) {
diff --git a/internal/console/alertstore.go b/internal/console/alertstore.go
index f4e70fe8e..eadae919e 100644
--- a/internal/console/alertstore.go
+++ b/internal/console/alertstore.go
@@ -499,19 +499,35 @@ func alertSeenFiring(tx *sql.Tx) (map[[2]string][]string, error) {
// seedOperatorAlertConnectors gives each operator in ops a personal email
// connector in scope fleet for their sign-in address, already confirmed
-// (spec §5.2: signing in proved they own it), inside tx. One that already
-// has one keeps it: the (scope, owner_address) index makes this idempotent.
-// The result is each operator's connector id.
+// (spec §5.2: signing in proved they own it), inside tx. Each address is
+// seeded once ever (ruling R-24): an alert_meta row seeded:<address>,
+// written with the connector, records it, so an operator who deletes their
+// connector does not get it back. One that already has a connector keeps
+// it: the (scope, owner_address) index makes the insert idempotent. The
+// result is each operator's connector id, for those that have one.
func seedOperatorAlertConnectors(tx *sql.Tx, ops []string, now time.Time) (map[string]int64, error) {
out := map[string]int64{}
for _, addr := range ops {
- if _, err := tx.Exec(`INSERT OR IGNORE INTO alert_connectors (scope, kind, name, target_plain, target_hint, owner_address,
- confirmed_at, created_by, created_at) VALUES (?, ?, '', ?, ?, ?, ?, ?, ?)`,
- alertScopeFleet, alertConnectorEmail, addr, addr, addr, now.Unix(), addr, now.Unix()); err != nil {
+ marker := "seeded:" + strings.ToLower(strings.TrimSpace(addr))
+ res, err := tx.Exec(`INSERT OR IGNORE INTO alert_meta (k, v) VALUES (?, ?)`, marker, now.UTC().Format(time.RFC3339))
+ if err != nil {
return nil, err
}
+ if n, err := res.RowsAffected(); err != nil {
+ return nil, err
+ } else if n == 1 {
+ if _, err := tx.Exec(`INSERT OR IGNORE INTO alert_connectors (scope, kind, name, target_plain, target_hint, owner_address,
+ confirmed_at, created_by, created_at) VALUES (?, ?, '', ?, ?, ?, ?, ?, ?)`,
+ alertScopeFleet, alertConnectorEmail, addr, addr, addr, now.Unix(), addr, now.Unix()); err != nil {
+ return nil, err
+ }
+ }
var id int64
- if err := tx.QueryRow(`SELECT id FROM alert_connectors WHERE scope = ? AND owner_address = ?`, alertScopeFleet, addr).Scan(&id); err != nil {
+ err = tx.QueryRow(`SELECT id FROM alert_connectors WHERE scope = ? AND owner_address = ?`, alertScopeFleet, addr).Scan(&id)
+ if errors.Is(err, sql.ErrNoRows) {
+ continue // seeded before and since deleted
+ }
+ if err != nil {
return nil, err
}
out[addr] = id