carlos / platform Public

region HA: finalizer refusal page sends on its own bounded context

Item 2 review P2-1 (Opus r1): the page went out on the departure scan's
context. A refusal caused by that context running out spent the hourly
slot and then failed the send at once, silently; a live context let the
send eat the scan's 30 s budget. The page now sends on a fresh 5 s
context detached from the scan's cancellation (as retryScan does) and a
failed send is logged.

Also applies the page body from the delegated Luna copy pass.

Invariant: a refused departure finalizer pages an operator at most once
an hour per host, and the hourly slot is never spent on a send that
could not be attempted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 43d2461fcc3e186e7630d52c4937aae37485616c parent 1dbf9b0
2 files changed, +35 −3
  • internal/activator/hatakeover.go +10 −3
  • internal/activator/hatakeover_page_test.go +25 −0

Intent

Human

<task-notification> <task-id>aa5e3cc5737471b6c</task-id> <tool-use-id>toolu_013j5zBKt5yBNBMFHa5oJTWT</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/acef84d4-5254-488e-9bf2-166a4d113752/tasks/aa5e3cc5737471b6c.output</output-file> <status>completed</status> <summary>Agent "Opus review item 1" 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>**Verdict: READY.** I found no P1 or P2 problems in item 1 (commit 93f01b57), only three P3 follow-ups. Findings are written to `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-followups/.superpowers/sdd/2026-11-03-region-ha-followups/review-item1-r1.md`. I checked the implementer's classification table row by row against `departureIdentities.Proof` in `internal/host/hadeparture_identity.go`: - **Unbound only on clean absence:** `ErrProofUnbound` is returned only when the lookups by pair, ref and iid all come back clean not-found. Read, context, decode and verification errors, a row under either identifier, and unknown, placement-null or other-region records all fail closed. - **Fallback condition:** `bindTerminationProof` takes the live-EC2 fallback only on `errors.Is(err, ErrProofUnbound)` and still re-checks the lifetime afterwards. - **Finalizer alarms:** the new wiring in `haadopt.go` matches `hawake.go`. Each refusal is reported exactly once, so no alarm is lost or doubled. These targeted tests pass: the host refusal matrix (all 11 modes) and `TestTerminationProofBucket`, the two activator termination-proof tests, and the lease and termfence `TerminationProof` tests. The host refusal matrix goes through `armHADepartures` and the real `repo.Proof`. Its bound cases use the fixture's real binding, so each corruption tests what it says. **P3 follow-ups:** 1. **What "unbound" means.** It means "no row in this box's local identity registry". The fixed-identity config (`CARLOS_HA_FIXED_BOX_IDENTITIES`) and box records in S3 that this box hasn't loaded yet are not checked. This isn't unsafe: EC2 must still confirm termination, and Ruling P22 sends unbound owners there. Refusing instead could leave a host held by a replaced box stuck for good. The fix is to state the definition in the comment above `Proof`, or make an explicit call on the config case. 2. **Witness gap on the finalizer path.** No test catches a doubled report on the finalizer path, because the alarm is throttled to once a minute. No test drives `AdoptHost` through a fallback that succeeds. The host witness also bypasses the per-acquire observer wiring. The fix is an `AdoptHost` unbound-takeover case that counts EC2 calls and log lines. 3. **Context errors untested.** The table's "context error" row has no test. The code handles it correctly. I edited no tracked files and made no commits. Test runs used the existing `/tmp/g` as TMPDIR, as the brief says. I left it in place because it may be shared, and I created no other scratch files.</result> <usage><subagent_tokens>101888</subagent_tokens><tool_uses>25</tool_uses><duration_ms>231535</duration_ms></usage> </task-notification>

Human

<task-notification> <task-id>a67af8fe75b612df2</task-id> <tool-use-id>toolu_01DZoYUqBAYnx944XBaKJ5Fa</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/acef84d4-5254-488e-9bf2-166a4d113752/tasks/a67af8fe75b612df2.output</output-file> <status>completed</status> <summary>Agent "Opus review item 2" 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>**Verdict: READY AFTER FIXES.** No P1s: the change works and is safe, but one P2 should be fixed. Findings are in `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-followups/.superpowers/sdd/2026-11-03-region-ha-followups/review-item2-r1.md`. The invariant holds against the code: - **Throttle:** the hourly per-host claim is taken under a lock before the send, so concurrent refusals produce one page. - **Coverage:** every refusal on the finalizer path reaches the page, because the refusal report runs on every way out of the proof check. That covers identity refusal, missing or invalid proof, and EC2 not confirming or erroring. - **Scope:** visitor refusals still only log, a successful takeover never pages, and nil `Page` turns paging off. - **Single path:** there is no second paging path. The activator only takes an injected function, wired once to `PageOperator`, and a refused adoption doesn't also trigger the controller's own page. The production-wired witness passes all four cases, and the throttle unit test passes, including under `-race`. I ran only those two targeted tests. **P2-1. The page uses the finalizer's own context.** The departure scan gives the whole pass 30 seconds (`hadepartures_scan.go:80`), and the page is sent on that same context (`hatakeover.go:52-56`). If the refusal happened because that time ran out, the hourly slot is used up first. The SNS send then fails at once on the expired context, and the error is thrown away with no log, so the operator gets nothing for that host for an hour. When the context is still alive, the page runs inside the scan and can spend up to 15 seconds of its 30-second budget, pushing later hosts into timeouts. Fix: send on a fresh 5-second context that ignores the scan's cancellation, as `retryScan` already does (`hadepartures_scan.go:320`), and log a failed send. **P3s** (for the follow-up list): - **P3-1:** every page carries the same reason code, `termination_unproven`. It also fires when the host's lifetime changed or after a proven termination whose follow-up step failed, where "could not prove it was terminated" is wrong. Map each cause to its own short code. - **P3-2:** the throttle lives in each box's memory, so each survivor box pages once per hour per host, and a restart resets it. The brief allows this; it's worth a runbook note. - **P3-3:** the witness doesn't show that the second adoption attempt actually reached the proof check. It only checks that it was deferred with an error, so the end-to-end hourly suppression rests on the unit test. - **P3-4:** the `ref == ""` fallback can't be reached, because the adoption already refuses an empty ref upstream (`haadopt.go:60,128`). It's harmless. No tracked files were edited and I left no scratch behind (setting `TMPDIR=/tmp/g` failed as read-only, so I used the default).</result> <usage><subagent_tokens>95349</subagent_tokens><tool_uses>24</tool_uses><duration_ms>235381</duration_ms></usage> </task-notification>

Attributed to this commit: 16.9 g CO₂e (2,040,931 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on region-ha-followups, 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/activator/hatakeover.go b/internal/activator/hatakeover.go
index b5b9e96d0..9659d1403 100644
--- a/internal/activator/hatakeover.go
+++ b/internal/activator/hatakeover.go
@@ -53,7 +53,14 @@ func (b *ExecBackend) reportTakeover(ctx context.Context, rt registry.Route, iid
if ref == "" {
ref = iid
}
- _ = b.Page(ctx, alerting.LevelWarning, fmt.Sprintf(takeoverPageSubject, ref), fmt.Sprintf(takeoverPageBody, ref, rt.Host, "termination_unproven"))
+ // A fresh, bounded context: the scan's own may already be spent
+ // (the refusal can be its timeout), and the send must not eat
+ // the scan's budget for later hosts.
+ pctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 5*time.Second)
+ if perr := b.Page(pctx, alerting.LevelWarning, fmt.Sprintf(takeoverPageSubject, ref), fmt.Sprintf(takeoverPageBody, ref, rt.Host, "termination_unproven")); perr != nil {
+ log.Printf("ha_takeover host=%s page failed: %v", rt.Host, perr)
+ }
+ cancel()
}
return
}
@@ -94,9 +101,9 @@ func (s *takeoverState) alarm(host, iid, cause string, why error) {
log.Printf("activator: ALERT %s: the takeover of %s's expired HA lock is refused: EC2 did not answer whether it is terminated: %v (the host stays down until EC2 confirms the holder terminated)", host, iid, why)
}
-// Draft operator copy; the follow-up copy pass replaces these constants.
+// Operator page copy (approved by delegation, one Luna pass, 2026-11-03).
const takeoverPageSubject = "Box %s's duties cannot be recovered"
-const takeoverPageBody = "The departed box %s still holds the lock for %s. This box could not prove it was terminated: %s. The host stays on that box until the proof can be read or the box comes back."
+const takeoverPageBody = "The departed box %s still holds the lock for %s. This box could not prove that the departed box was terminated: %s. The host stays on that box until the proof can be read or the box comes back."
func (s *takeoverState) claimPage(host string, now time.Time) bool {
s.mu.Lock()
diff --git a/internal/activator/hatakeover_page_test.go b/internal/activator/hatakeover_page_test.go
index c6e61540e..d3c6bc4cc 100644
--- a/internal/activator/hatakeover_page_test.go
+++ b/internal/activator/hatakeover_page_test.go
@@ -1,10 +1,13 @@
package activator
import (
+ "context"
"sync"
"sync/atomic"
"testing"
"time"
+
+ "github.com/carlosframework/platform/internal/registry"
)
func TestTakeoverPageHourlyPerHost(t *testing.T) {
@@ -33,3 +36,25 @@ func TestTakeoverPageHourlyPerHost(t *testing.T) {
t.Fatal("another host suppressed")
}
}
+
+// A finalizer refused because its scan context ran out still pages: the
+// send gets a fresh, bounded context of its own.
+func TestTakeoverPageSurvivesSpentScanContext(t *testing.T) {
+ var got []string
+ b := &ExecBackend{Page: func(ctx context.Context, level, subject, body string) error {
+ if err := ctx.Err(); err != nil {
+ return err
+ }
+ if _, ok := ctx.Deadline(); !ok {
+ t.Error("page context has no deadline")
+ }
+ got = append(got, subject)
+ return nil
+ }}
+ ctx, cancel := context.WithCancel(context.WithValue(context.Background(), adoptionCauseKey{}, "box-a"))
+ cancel()
+ b.reportTakeover(ctx, registry.Route{Host: "shop.example.com"}, "i-0123456789abcdef0", false, context.Canceled)
+ if len(got) != 1 {
+ t.Fatalf("pages=%d, want 1 despite the spent scan context", len(got))
+ }
+}