region HA P1a: CI fix (the HA wake's record read goes through the box's judge)
haRecordFacts read the instance record with provision.GetRecord, an unjudged read outside the permitted functions (TestNoUnjudgedRecordReads). It now takes the box's lifetime judge and reads through judgedRecord, so a record its host incarnation slot no longer vouches for reads as os.ErrNotExist and the wake fails closed. A nil judge (host claims on) is provision.GetRecord exactly. TestHARecordFactsJudgesTheLifetime pins it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 files changed,
+52
−13
internal/activator/activator.go+1 −1internal/host/agent.go+9 −7internal/host/hawake_wiring_test.go+42 −5
diff --git a/internal/activator/activator.go b/internal/activator/activator.go| index 410e0b575..bd4ed4596 100644 |
| --- a/internal/activator/activator.go |
| +++ b/internal/activator/activator.go |
| @@ -109,7 +109,7 @@ type Config struct { |
| // Record reads a host's record facts for region HA (P1a): its lifetime |
| // and whether it is born HA. ExecBackend asks it on a lifetime index |
| // miss, before the lease; an error fails the wake. The host wires it to |
| - // provision.GetRecord on the deployment store. Nil: no record source, |
| + // a judged record read on the deployment store. Nil: no record source, |
| // and only the row and the index say a host is HA. |
| Record func(ctx context.Context, rt registry.Route) (provision.LifetimeEntry, error) |
| // Self is this box's lease identity, asked at each HA wake (so an |
diff --git a/internal/host/agent.go b/internal/host/agent.go| index db2457896..e39594ae9 100644 |
| --- a/internal/host/agent.go |
| +++ b/internal/host/agent.go |
| @@ -418,7 +418,7 @@ func runAgent(args []string, buildClaims ClaimFactory) { |
| // Region HA P1a: the record facts the HA classification reads on a |
| // lifetime index miss, and the box identity the keep decision |
| // compares, set before the backend copies cfg. |
| - cfg.Record = haRecordFacts(openDeployStore) |
| + cfg.Record = haRecordFacts(openDeployStore, boxJudge) |
| cfg.Self = lease.CurrentSelf |
| // Exec children and carlos-app@ unit tenants share one state machine; |
| // the split backend dispatches per route on Backing. Note the arming |
| @@ -3541,11 +3541,13 @@ func boxProvisionConfig(judge *provision.LifetimeJudge, configure []func(*provis |
| var boxLifetimes = &provision.LifetimeIndex{} |
| // haRecordFacts is activator.Config.Record on this box: the host's record |
| -// read from the deployment store (provision.GetRecord, under the route's |
| -// effective account) and made a lifetime entry. The store is opened on |
| -// first use and kept; a store that does not open is the read's error, and |
| -// the wake fails closed. |
| -func haRecordFacts(open func(context.Context) (release.Store, error)) func(context.Context, registry.Route) (provision.LifetimeEntry, error) { |
| +// read from the deployment store under the box's judge (judgedRecord, under |
| +// the route's effective account) and made a lifetime entry. A record its |
| +// host incarnation slot no longer vouches for reads as os.ErrNotExist, so |
| +// a stale lifetime never classifies a wake; a nil judge (host claims on) is |
| +// provision.GetRecord exactly. The store is opened on first use and kept; a |
| +// store that does not open is the read's error, and the wake fails closed. |
| +func haRecordFacts(open func(context.Context) (release.Store, error), judge *provision.LifetimeJudge) func(context.Context, registry.Route) (provision.LifetimeEntry, error) { |
| var mu sync.Mutex |
| var store release.Store |
| return func(ctx context.Context, rt registry.Route) (provision.LifetimeEntry, error) { |
| @@ -3560,7 +3562,7 @@ func haRecordFacts(open func(context.Context) (release.Store, error)) func(conte |
| store = s |
| } |
| mu.Unlock() |
| - rec, err := provision.GetRecord(ctx, s, release.RouteAccount(rt), rt.App, rt.Host) |
| + rec, err := judgedRecord(ctx, s, judge, release.RouteAccount(rt), rt.App, rt.Host) |
| if err != nil { |
| return provision.LifetimeEntry{}, err |
| } |
diff --git a/internal/host/hawake_wiring_test.go b/internal/host/hawake_wiring_test.go| index 5f8b869b9..a1b942a51 100644 |
| --- a/internal/host/hawake_wiring_test.go |
| +++ b/internal/host/hawake_wiring_test.go |
| @@ -23,9 +23,19 @@ func TestBoxProvisionConfigCarriesTheLifetimeIndex(t *testing.T) { |
| } |
| // Config.Record on this box: the record from the deployment store, under |
| -// the route's effective account, as a lifetime entry; the store opened |
| -// once; a missing record or a store that will not open is an error. |
| +// the route's effective account and the box's judge, as a lifetime entry; |
| +// the store opened once; a missing record or a store that will not open is |
| +// an error. Run claims-on (nil judge) and claims-off (the box's judge). |
| func TestHARecordFactsReadsTheRecord(t *testing.T) { |
| + for _, tc := range []struct { |
| + name string |
| + judge *provision.LifetimeJudge |
| + }{{"claims on", newBoxJudge(claimsOnEnv)}, {"claims off", newBoxJudge(claimsOffEnv)}} { |
| + t.Run(tc.name, func(t *testing.T) { testHARecordFactsReadsTheRecord(t, tc.judge) }) |
| + } |
| +} |
| + |
| +func testHARecordFactsReadsTheRecord(t *testing.T, judge *provision.LifetimeJudge) { |
| ctx := context.Background() |
| s := release.NewDirStore(t.TempDir()) |
| acct := domains.Sqid(2) |
| @@ -35,7 +45,7 @@ func TestHARecordFactsReadsTheRecord(t *testing.T) { |
| t.Fatal(err) |
| } |
| opens := 0 |
| - read := haRecordFacts(func(context.Context) (release.Store, error) { opens++; return s, nil }) |
| + read := haRecordFacts(func(context.Context) (release.Store, error) { opens++; return s, nil }, judge) |
| got, err := read(ctx, registry.Route{Host: rec.Host, App: rec.App, Account: acct}) |
| want, _ := provision.LifetimeEntryOf(rec) |
| if err != nil || got != want || !got.HA { |
| @@ -47,12 +57,39 @@ func TestHARecordFactsReadsTheRecord(t *testing.T) { |
| if opens != 1 { |
| t.Fatalf("the store was opened %d times", opens) |
| } |
| - down := haRecordFacts(func(context.Context) (release.Store, error) { return nil, errors.New("no bucket") }) |
| + down := haRecordFacts(func(context.Context) (release.Store, error) { return nil, errors.New("no bucket") }, judge) |
| if _, err := down(ctx, registry.Route{Host: rec.Host, App: rec.App}); err == nil || !strings.Contains(err.Error(), "no bucket") { |
| t.Fatalf("a store that will not open: %v", err) |
| } |
| } |
| +// Claims off, the record read is judged: once the host's incarnation slot |
| +// no longer vouches for the record (its lifetime retired), the HA wake's |
| +// record read is os.ErrNotExist, never the stale record's lifetime. |
| +func TestHARecordFactsJudgesTheLifetime(t *testing.T) { |
| + ctx := context.Background() |
| + s := release.NewDirStore(t.TempDir()) |
| + acct := domains.Sqid(2) |
| + rec := provision.Record{Schema: 1, Host: "shop.example.com", App: "shop", Account: acct, Channel: "stable", |
| + CreatedAt: time.Date(2026, 10, 26, 9, 0, 0, 0, time.UTC), HA: true} |
| + if err := provision.CreateRecord(ctx, s, rec); err != nil { |
| + t.Fatal(err) |
| + } |
| + reads := &slotReads{Store: s} |
| + read := haRecordFacts(func(context.Context) (release.Store, error) { return reads, nil }, newBoxJudge(claimsOffEnv)) |
| + rt := registry.Route{Host: rec.Host, App: rec.App, Account: acct} |
| + if got, err := read(ctx, rt); err != nil || !got.HA { |
| + t.Fatalf("a live record: %+v, %v", got, err) |
| + } |
| + if reads.reads() == 0 { |
| + t.Fatal("the record read did not observe the host incarnation slot") |
| + } |
| + retireLifetime(t, s, acct, rec.App, rec.Host) |
| + if got, err := read(ctx, rt); !errors.Is(err, os.ErrNotExist) { |
| + t.Fatalf("a record its slot no longer vouches for: %+v, %v; want os.ErrNotExist", got, err) |
| + } |
| +} |
| + |
| // RunAgent wires the HA wake before the Service starts: the record facts, |
| // the identity, the index, the registry, the startup sweep's proof and the |
| // obligation store (syntactic, like the policy cache's wiring test). |
| @@ -64,7 +101,7 @@ func TestAgentWiresTheHAWake(t *testing.T) { |
| body := string(src) |
| start := strings.Index(body, "Start: svc.Start,") |
| for _, want := range []string{ |
| - "cfg.Record = haRecordFacts(openDeployStore)", |
| + "cfg.Record = haRecordFacts(openDeployStore, boxJudge)", |
| "cfg.Self = lease.CurrentSelf", |
| "eb.Lifetimes = boxLifetimes", |
| "eb.Registry = reg", |