carlos / platform Public

ha: preserve AWS settings and isolate proof caller cancellation

Preserve inherited AWS settings while removing credentials and credential sources. Do not cache canceled proof operations. Repair the old-registry fixture and classify the regional proof store opener.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev ad93b78c4eee86ed659039182dc08d359cab1b66 parent 7a8fadf
6 files changed, +67 −4
  • internal/activator/backend_exec.go +9 −1
  • internal/activator/termination_credentials_test.go +16 −1
  • internal/host/egress_source_test.go +3 −0
  • internal/release/openers_test.go +1 −0
  • internal/termfence/termination_proof.go +4 −2
  • internal/termfence/termination_proof_test.go +34 −0

Intent

Human

<task-notification> <task-id>bsqc3eur2</task-id> <tool-use-id>toolu_01TpEo9VMqPyLzqgtaHYevZm</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/22c9817b-87ae-432b-b6d2-3ebbc209af38/tasks/bsqc3eur2.output</output-file> <status>completed</status> <summary>Background command "Wait for B3 continuation" completed (exit code 0)</summary> </task-notification>

Human

Check Astra B3 for P1b-3b slice T: task-B3-astra-a.md/.log and progress.md in /home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p1b3b-duties/.superpowers/sdd/2026-11-03-region-ha-p1b3b-duties/; continue SDD (Opus review, or continuation per Ruling P4).

Human

<task-notification> <task-id>b3trf60mb</task-id> <tool-use-id>toolu_019zcHryy78JUGHZpQ9Di1EQ</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/22c9817b-87ae-432b-b6d2-3ebbc209af38/tasks/b3trf60mb.output</output-file> <status>completed</status> <summary>Background command "Wait for CI on B3 tip" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>adb6e5118b69bc932</task-id> <tool-use-id>toolu_017jNSzLXLhq9iUPFL2PFAtu</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/22c9817b-87ae-432b-b6d2-3ebbc209af38/tasks/adb6e5118b69bc932.output</output-file> <status>completed</status> <summary>Agent "Opus review Task B3" 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: Needs fixes.** 0 Critical, 3 Important, 8 Minor. The termination-authority core holds up. The proof is minted only from a verified live Describe, and normal acquire is its only consumer. That acquire rebinds the owner on each CAS round, and a lock at exactly its expiry time stays held. Proofs go only to the data bucket in the lock's region, and the cache is shared and bounded. I found no path where a proof or journal row grants import, completion, start or admission. The three Important issues are all in how the host wires it in: 1. **Takeover now depends on the whole inventory being complete** (`internal/host/hadepartures_wiring.go:146-167`, `internal/provision/departure_inventory.go:49-58`). Once armed, the adapter refuses every takeover of an expired lock held by another box (visitor, due and finalizer) while the inventory is incomplete. That is the case: - during every reconcile pass; - after any scoped pass; - from startup until the first full pass; - after the record view moves ahead of the last pass; - permanently, while any single record anywhere in the deployment is protected, unread or has an explicit-null region. It fails safe, but it is a broad availability loss on the main takeover path. No test runs the production lifetime check; the lease tests stub it. 2. **The inbox can stall or deadlock** (`internal/host/hadepartures.go:212-218`, `:285-305`; `internal/registry/ha_journal.go` record; `internal/host/hadeparture_identity.go`). - Rows that can't be resolved never leave the inbox, with no escalation. Any fixed box missing from `CARLOS_HA_FIXED_BOX_IDENTITIES`, or one malformed record under `control/boxes/`, stops every unknown-iid walk from completing. - At 1,024 rows, recording fails and real departures are no longer recorded. - The only code that drains the inbox waits for Started. After a restart with a full inbox, Started never closes, so it is a deadlock. - An SQS receive outage also stops peer identities being observed, which blocks proof-mode takeovers. 3. **Startup is one-shot and ties the proof path to the queue** (`internal/host/hadepartures_wiring.go:121-141`, `internal/hadeparture/consumer.go:93-103`). One failure within the 5-second boot window turns departure handling off for the whole process lifetime. That includes the queue check, store open or journal open. As a result: - The proof adapter is never installed, so takeovers stay on the old live-only path, which cannot recover after EC2 forgets the instance. - B2 adoption identity is never wired. - Nothing retries, and the only signal is a log line. The Minor items cover: - proof GETs before Describe on the suspicion paths; - a cancelled caller's context being cached as a 10-second refusal; - signature checks and a database write on every request with no caching; - the "queue error" notice also firing for journal errors; - backoff and reset semantics that B4 needs to know about; - witness tests weaker than the brief asks; - tenants now losing all inherited `AWS_*` variables, not just credentials; - the discarded receipt handle that B4 has to close. **What I read:** all production code in the diff, plus the host, lease, edge, provision and credential tests, and six one-off checks of outside code. I did not read the termfence, consumer, journal or awsterminations test bodies in detail, or the census docs. I ran no tests. Report: `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/region-ha-p1b3b-duties/.superpowers/sdd/2026-11-03-region-ha-p1b3b-duties/task-B3-review-r1.md`</result> <usage><subagent_tokens>222568</subagent_tokens><tool_uses>30</tool_uses><duration_ms>538003</duration_ms></usage> </task-notification>

diff --git a/internal/activator/backend_exec.go b/internal/activator/backend_exec.go
index caffe9fbf..deb3acf7d 100644
--- a/internal/activator/backend_exec.go
+++ b/internal/activator/backend_exec.go
@@ -3124,13 +3124,21 @@ func childEnv(fileEnv map[string]string) []string {
values[k] = v
}
for _, kv := range os.Environ() {
- if strings.HasPrefix(kv, "CARLOS_") || strings.HasPrefix(kv, "AWS_") {
+ if strings.HasPrefix(kv, "CARLOS_") {
continue
}
k, v, ok := strings.Cut(kv, "=")
if !ok {
continue
}
+ switch k {
+ case "AWS_ACCESS_KEY_ID", "AWS_ACCESS_KEY", "AWS_SECRET_ACCESS_KEY", "AWS_SECRET_KEY", "AWS_SESSION_TOKEN", "AWS_SECURITY_TOKEN",
+ "AWS_PROFILE", "AWS_DEFAULT_PROFILE", "AWS_CONFIG_FILE", "AWS_SHARED_CREDENTIALS_FILE", "AWS_SDK_LOAD_CONFIG",
+ "AWS_WEB_IDENTITY_TOKEN_FILE", "AWS_ROLE_ARN", "AWS_ROLE_SESSION_NAME",
+ "AWS_CONTAINER_CREDENTIALS_FULL_URI", "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI", "AWS_CONTAINER_AUTHORIZATION_TOKEN", "AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE",
+ "AWS_EC2_METADATA_SERVICE_ENDPOINT", "AWS_EC2_METADATA_SERVICE_ENDPOINT_MODE":
+ continue
+ }
set(k, v)
}
keys := make([]string, 0, len(fileEnv))
diff --git a/internal/activator/termination_credentials_test.go b/internal/activator/termination_credentials_test.go
index e46559655..f1b3aee7d 100644
--- a/internal/activator/termination_credentials_test.go
+++ b/internal/activator/termination_credentials_test.go
@@ -10,7 +10,7 @@ func TestTerminationProofCredentials(t *testing.T) {
t.Setenv(key, "box-role-only")
}
for _, kv := range childEnv(nil) {
- if strings.HasPrefix(kv, "AWS_") {
+ if strings.HasSuffix(kv, "=box-role-only") {
t.Fatal("inherited box credential configuration", strings.SplitN(kv, "=", 2)[0])
}
}
@@ -25,3 +25,18 @@ func TestTerminationProofCredentials(t *testing.T) {
t.Fatal("tenant-scoped delivered credential removed")
}
}
+
+func TestTerminationChildEnvironmentKeepsAWSSettings(t *testing.T) {
+ for _, key := range []string{"AWS_REGION", "AWS_DEFAULT_REGION", "AWS_CA_BUNDLE"} {
+ t.Setenv(key, "configured")
+ found := false
+ for _, kv := range childEnv(nil) {
+ if kv == key+"=configured" {
+ found = true
+ }
+ }
+ if !found {
+ t.Errorf("lost %s", key)
+ }
+ }
+}
diff --git a/internal/host/egress_source_test.go b/internal/host/egress_source_test.go
index 3772ec691..ddfa02db4 100644
--- a/internal/host/egress_source_test.go
+++ b/internal/host/egress_source_test.go
@@ -904,6 +904,9 @@ func TestRootEgressReadsARegistryWithoutTheHAColumn(t *testing.T) {
if err != nil {
t.Fatal(err)
}
+ if _, err := db.Exec(`DROP TRIGGER IF EXISTS ha_route_update`); err != nil {
+ t.Fatal(err)
+ }
if _, err := db.Exec(`ALTER TABLE routes DROP COLUMN ha`); err != nil {
t.Fatal(err)
}
diff --git a/internal/release/openers_test.go b/internal/release/openers_test.go
index c61cffd43..624bd7cc9 100644
--- a/internal/release/openers_test.go
+++ b/internal/release/openers_test.go
@@ -43,6 +43,7 @@ type openerEntry struct {
// deployment bucket: through NewS3Store, NewS3StoreIn, an S3Store literal or
// NewDirStore.
var otherBucketOpeners = map[string]openerEntry{
+ "internal/host/hadepartures_wiring.go:armHADepartures": {"regional data bucket for termination proofs beside locks", 1},
"cmd/console/main.go:serve": {"console seed data store: the database/data bucket (seeds/), not the deployment bucket", 1},
"internal/host/seedwiring.go:seedDataOpener": {"this region's data bucket, where seeds/ lives", 1},
"internal/host/relocatepass.go:productionRelocationRuntimeInputs": {"relocation files store: the data bucket, manifests under moves/ prefixes", 1},
diff --git a/internal/termfence/termination_proof.go b/internal/termfence/termination_proof.go
index cca291102..6024d76ff 100644
--- a/internal/termfence/termination_proof.go
+++ b/internal/termfence/termination_proof.go
@@ -160,7 +160,9 @@ func (c *ProofCache) Load(ctx context.Context, api ProofStore, b ProofIdentity)
if c.entries == nil {
c.entries = map[string]proofResult{}
}
- c.entries[key] = r
+ if !errors.Is(err, context.Canceled) && !errors.Is(err, context.DeadlineExceeded) {
+ c.entries[key] = r
+ }
f.result = r
delete(c.reads, key)
close(f.done)
@@ -294,7 +296,7 @@ func (c *Confirmer) PersistTermination(ctx context.Context, api ProofStore, b Pr
}
cache.entries[key] = r
delete(cache.writeErrors, key)
- } else {
+ } else if !errors.Is(err, context.Canceled) && !errors.Is(err, context.DeadlineExceeded) {
if cache.writeErrors == nil {
cache.writeErrors = map[string]proofResult{}
}
diff --git a/internal/termfence/termination_proof_test.go b/internal/termfence/termination_proof_test.go
index 4e31631a2..f3aa0de96 100644
--- a/internal/termfence/termination_proof_test.go
+++ b/internal/termfence/termination_proof_test.go
@@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"errors"
+ "fmt"
"io"
"net/http"
"strings"
@@ -294,3 +295,36 @@ func TestTerminationProofPersistenceRetryBound(t *testing.T) {
t.Fatalf("retry lost original evidence: puts=%d gets=%d proof=%+v", p.puts, p.gets, proof)
}
}
+
+func TestTerminationProofCallerCancellation(t *testing.T) {
+ for _, write := range []bool{false, true} {
+ t.Run(fmt.Sprint(write), func(t *testing.T) {
+ b := proofIdentity(t)
+ r := proofConfirmer()
+ transport := &proofTransport{}
+ api := transport.client()
+ cache := &ProofCache{}
+ // Prime Describe independently so this exercises proof I/O cancellation.
+ if _, err := r.c.terminated(t.Context(), b.Evidence().Cloud.InstanceID); err != nil {
+ t.Fatal(err)
+ }
+ ctx, cancel := context.WithCancel(t.Context())
+ cancel()
+ if write {
+ if _, err := r.c.PersistTermination(ctx, api, b, "survivor", cache); err == nil {
+ t.Fatal("cancel accepted")
+ }
+ if _, err := r.c.PersistTermination(t.Context(), api, b, "survivor", cache); err != nil {
+ t.Fatalf("caller cancellation poisoned writer: %v", err)
+ }
+ } else {
+ if _, _, err := cache.Load(ctx, api, b); err == nil {
+ t.Fatal("cancel accepted")
+ }
+ if _, _, err := cache.Load(t.Context(), api, b); err != nil {
+ t.Fatalf("caller cancellation poisoned reader: %v", err)
+ }
+ }
+ })
+ }
+}