carlos / platform Public

fix: claim readiness names the real cause

codex agent, operated by paul@keymail.dev pushed by claude agent, operated by paul@keymail.dev d6102c9854b5e384240f2774ec096f40f89752f7 parent faca3ff
5 files changed, +379 −19
  • internal/console/demo_claim_gate_causes_test.go +321 −0
  • internal/console/demo_claim_gates_test.go +1 −1
  • internal/console/demo_claim_ready.go +17 −6
  • internal/console/demo_claim_seed.go +20 −4
  • internal/console/demo_claim_transfer.go +20 −8

Intent

Human

<task-notification> <task-id>b17x71jo6</task-id> <tool-use-id>toolu_012yShUeRdyz8i7WJZmYD4XE</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/22215d20-2b53-4378-8426-ae55e2362d13/tasks/b17x71jo6.output</output-file> <status>completed</status> <summary>Background command "S=/home/paulca/.cache/tmp/drg; until [ -f $S/done ]; do sleep 20; done; tail -1 $S/log; cat $S/final.md" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>biym02w7l</task-id> <tool-use-id>toolu_013CbZbFmWrUDHvZDYsTxiWX</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/22215d20-2b53-4378-8426-ae55e2362d13/tasks/biym02w7l.output</output-file> <status>completed</status> <summary>Background command "sleep 90; until ! amadan ci status carlos/platform -branch demo-claim-ready-gates 2&gt;&amp;1 | head -1 | grep -q 'running\|queued\|pending'; do sleep 60; done; amadan ci status carlos/platform -branch demo-claim-ready-gates 2&gt;&amp;1 | head -3" completed (exit code 0)</summary> </task-notification>

Human

<task-notification> <task-id>a4980bf10e0d5853a</task-id> <tool-use-id>toolu_01TcFdQ6FeTuurG3P3PzStty</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/22215d20-2b53-4378-8426-ae55e2362d13/tasks/a4980bf10e0d5853a.output</output-file> <status>completed</status> <summary>Agent "Review claim readiness gates branch" 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>## Review round 1 of 3: `demo-claim-ready-gates` (`ebfc08e1..38f97f5b`) There are no P1s. Commit 1's verdicts are unchanged, and commit 2 keeps the destination non-HA. Two P2s remain, both in commit 1's diagnostics: the log can name the wrong cause, or too little. They break no safety rule, but stopping silent refusals is the purpose of this branch. Under stopping rule 1, the review stops here. Apply the P2 fixes without reopening it, then run the census. ### What I ran - **Commit 1 alone:** I used a `go test -overlay` with commit 1's `demo_claim_seed.go` and `demo_claim_target.go`, and with `demo_claim_ha_gate_test.go` removed. That is exactly commit 1's tree, and nothing in the worktree changed. - **Selection:** I ran Astra's selection plus the two guards, at both commits. | Commit | Result | Note | | --- | --- | --- | | `faca3fff` | ok, 47.4 s | Needed `-vet=off` | | `38f97f5b` | ok, 48.6 s | | - **Sandbox cache block:** the default Go cache is sometimes read-only here (`open ~/.cache/go-build/35/...-a: read-only file system`). This hit `go vet -overlay` and one overlay `go test`, which is why commit 1 used `-vet=off`. I did not re-confirm Astra's clean `go vet` on commit 1. - **Witnesses:** I ran throwaway overlay tests, and the scratch is deleted. The worktree is clean. - **Not run:** the box-side HA path was traced by reading only. No test drives a claim onto a real box. ### 1. HA boundary: holds **A claimed destination cannot be born HA.** - `createDemoClaimSeed` (`demo_claim_seed.go:171`) builds the record with no `Pool` and no `HA`. - Records get `HA` from `apiinstances.go:2371`, `apisidecars.go:369` and `domainattach.go:269` and `:695`. The claim path calls none of them, and `createRecordMarkedLocked` and `createRecordWithLifetimeLocked` are not among the stamp sites. - `reflect.DeepEqual` on the manifest (`demo_claim_seed.go:168`) also rules out a pooled manifest. **The `haCreate(region, "")` cases all behave correctly.** | Scope for the region | `haCreate` | Result | | --- | --- | --- | | Not an HA region | false | Allowed, same as before | | Region-wide (no `ha_pools`) | true | Refused | | Invalid scope in an HA region | true | Refused (`haScopeInvalid`) | | `""` in pools | true | Refused, and the parser rejects it too (`hacapacity.go:139`) | | Named pools only | false | Allowed, record stays non-HA | - **Home region:** `""` maps to `HomeRegion` before the `haPools` lookup. - **Config change mid-claim:** `createDemoClaimSeed` re-runs the gate, so it refuses if the scope has changed. **Placement** - `resolveNewAppRegion` must still return `s.cfg.Region`. - `roomIn(region, "")` asks about the shared pool and fails closed on a read error. It returns nil when there is no claim authority, the same as a plain create. - `requireHACreateCapacity` is skipped for pool `""`, the same as an ordinary non-HA create. - A named-pool-only box does not count. `demoClaimEdge` excludes it, and `seedRegionReadyForEdges` refuses if no shared edge is in the region. - The leftover check `leftoverCheckApplies(region, "")` works as before. The HA data store is not checked, the same as any non-HA create. **A non-HA seed in an HA region is already a supported shape.** - The `apiinstances.go:2331` branch only brings forward refusals for pools, fleets and imports. `apiinstances.go:2369` says a seed is never stamped. The claim path does not use that door, and a claim has no pool, fleet or import anyway. - On the box, `poolServed` stops a named-only box taking pool `""`. `Restore` only refuses when `haAcquired` is true, and `rec.HA` false takes the legacy acquire, so `seededRestore` runs normally. **Guards keyed on `haRegion` still apply to the claimed app after the claim.** These are `haTransferRegion` (`seedmove.go:83`, `:86`), `refuseHAImport` (`:94`) and `apiplacements.go:748`, `:1063`, `:1075`, `:1092`. They refuse moves out and, with `RegionIngress` set, domain placements. Every non-HA record in that region gets the same refusals, so nothing breaks and they are visible refusals. No demo claim code calls them. Paul should know a claimed app inherits this limit. **This does not unblock dev by itself.** With no `ha_pools` on `ie`, `haCreate` is true and the gates still report `ha-region` (witnessed). It needs the separate console config decision. ### 2. Commit 1 verdicts: unchanged - **Gates:** I compared each original condition with its new gate, including the inverted floor-state expression and the `b.Metrics != nil` guard. None was lost or weakened. New checks only add names on a pass that already fails. - **Error values:** kept. Moved still returns the raw `LoadBoxes` error when edges are fine, and `unavailable` otherwise. Readiness still returns `ctx.Err()` only when every gate passes. - **Nil paths:** `Releases` and `SeedData` nil are safe, because `demoPublishReady`, `demoEligiblePeers` and `leftoverCheckApplies` do not touch them. `snap` is a value type, so a failed read cannot panic in the loops. See the first P3 for one new nil panic. ### 3. Cost: bounded, with one misleading result - **No new polling:** `demoClaimReady` has one production caller (`demo_claim_auth.go:26`), called on demand. The only loop is an in-flight claim, and that already called these reads. - **Worst case:** a refused pass now costs the same as a healthy pass. For one edge and one box that is 12 GET and 9 LIST, as the test pins and Astra's baseline confirms. Production has no request memo because it uses `context.Background()`. - **Change on dev:** a refused refresh goes from a few reads to the full pass, at most once per 45 s. - **Unchanged:** the 10 s context, the 45 s cache including failures, and the mutex held across reads. `c.failures` is only touched under that mutex. ### 4. Log throttling: correct - Identical sets don't log, and cache hits log nothing. Recovery logs one `ready` line, and a first healthy pass logs nothing. - The switch-off path does no reads and logs nothing. - Labels are sorted and deduplicated. They are bounded by the number of edge files, and they hold box labels only. ### 5. Commit 1 alone: yes Its tests don't depend on commit 2. `demo_claim_gates_test.go` is unchanged by commit 2, and the selection passes as shown above. ### 6. One place: yes for assembly `demoClaimReadinessGates`, `demoClaimSeedGates` and `demoClaimMovedGates` are the only evaluators, and the old entry points just wrap them. No second copy was added. The floor and protocol overlap with `seedRegionReadyForEdges` predates this branch. ### Findings Both P2s are fault family "a refusal names its real cause". This is the first round for that family, so rule 2 is not triggered. Put the fixes in commit 1 so it can still land alone. **P2-1: `demo_claim_ready.go:119-122`, a timeout blames gates that are fine** - **Failure:** one hung read uses up the 10 s, every later read then fails, and the `context` gate is skipped because the function has already returned. A healthy deployment with a hung change-index read logged this, with no sign of a deadline: `box-status,change-index,edges-evidence,no-shared-edges,seed-floor,seed-region` The operator is sent after box status and shared edges that are fine. `no-shared-edges` is the most misleading, and the per-box names disappear. - **Fix:** run `gates.check("context", ctx.Err() == nil)` before the early return, then keep the same return values. The verdict cannot change. **P2-2: `demo_claim_seed.go:50`, `seed-region` hides gates that exist nowhere else** - **Failure:** `seedRegionReadyForEdges` still short-circuits internally, and its refusal text is thrown away. These checks have no gate of their own: - box layout not nested - `HostClaimEnabled` on a box - `MovesFloorState` refusal - `floor.Min` above the protocol - unusable `min_release` - no shared edge in the region - **Witness:** a flat box logs only `refusing: seed-region`, while the dropped refusal says `box-a in the home region do not run instances nested yet`. After I fixed that box and turned on claim control instead, the set stayed `seed-region`, so **nothing was logged at all**. This is the hidden chain the branch was meant to end, because the brief requires every gate evaluated without short-circuiting. - **Fix:** in the existing box loop, for in-region boxes, add `box-layout:&lt;box&gt;` and `box-claim-control:&lt;box&gt;` from the `byLabel` data already loaded. Add `seed-region-edges` for no in-region shared edge. There are no new reads, and they cannot flip the verdict because `seed-region` already refuses in those cases. **P3s (follow-up list, these don't start a round)** 1. **Nil store panic, `demo_claim_seed.go:43`:** `claimGated` now runs even when `HostClaim` is true, so a nil store plus `HostClaim` panics (witnessed). The original short-circuited. It is unreachable in production because `demoClaimReady` and `advanceDemoClaimLocked` guard first. Fix with a `s.store != nil` check. 2. **Refusals with no log, `demo_claim_ready.go:51`:** `Demo.Enabled` off, `HostClaim` and `claimGated` all refuse silently with the switch on. The `host-claim` and `claim-gated` labels can never reach this log. 3. **Dropped names, `demo_claim_seed.go:37`:** `demoClaimSeedReady` discards its names, so a claim aborting with `capability` (`demo_claim_transfer.go:106`) doesn't say which gate failed. 4. **Inner logs reached more often:** with a failing gate earlier in the pass, `console: seeds readiness: ...` lines now appear on each refresh, about one per 45 s under demand. They are not per-request. Astra's report calls them "unchanged", which understates this. 5. **Unquoted label, `demo_claim_ready.go:68`:** labels go out with `%s`, while `seedfloor.go` uses `%q` for them. The source is the platform-written edges file. 6. **Unused wrapper:** `checkDemoClaimReady` now has only a test caller. 7. **Duplicate predicate:** `haCreate(region, "")` appears at `demo_claim_seed.go:46` and `demo_claim_target.go:142`. A small named helper would keep them from drifting apart. 8. **Stale label:** `ha-region` now means "destination would be born HA". **Verdict: READY AFTER FIXES, tip `38f97f5b`.** Apply P2-1 and P2-2 in commit 1 and run the census once; no further review round is needed. Commit 2 needs no changes.</result> <usage><subagent_tokens>160926</subagent_tokens><tool_uses>24</tool_uses><duration_ms>522916</duration_ms></usage> </task-notification>

diff --git a/internal/console/demo_claim_gate_causes_test.go b/internal/console/demo_claim_gate_causes_test.go
new file mode 100644
index 000000000..44e85bdb0
--- /dev/null
+++ b/internal/console/demo_claim_gate_causes_test.go
@@ -0,0 +1,321 @@
+package console
+
+import (
+ "bytes"
+ "context"
+ "encoding/json"
+ "errors"
+ "log"
+ "slices"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/provision"
+ "github.com/carlosframework/platform/internal/release"
+ "github.com/carlosframework/platform/internal/seeds"
+ "github.com/carlosframework/platform/internal/status"
+)
+
+type claimHungIndexStore struct{ release.Store }
+
+func (s claimHungIndexStore) Get(ctx context.Context, key string) ([]byte, string, error) {
+ if key == release.ChangeIndexKey {
+ <-ctx.Done()
+ return nil, "", ctx.Err()
+ }
+ return s.Store.Get(ctx, key)
+}
+
+func TestDemoClaimReadinessDeadlineCause(t *testing.T) {
+ s, _, _ := claimTestServer(t)
+ claimActivationFixture(t, s)
+ s.cfg.Releases = claimHungIndexStore{s.cfg.Releases}
+ ctx, cancel := context.WithTimeout(t.Context(), 20*time.Millisecond)
+ defer cancel()
+ gates, err := s.demoClaimReadinessGates(ctx)
+ if !errors.Is(ctx.Err(), context.DeadlineExceeded) || err == nil || err.Error() != demoClaimUnavailable {
+ t.Fatalf("changed deadline verdict: context=%v, verdict=%v", ctx.Err(), err)
+ }
+ if !slices.Contains(gates, "context") || !slices.Contains(gates, "change-index") {
+ t.Fatalf("missing deadline cause: %s", gates.names())
+ }
+}
+
+func claimGateFloor(t *testing.T, s *Server, min int, minRelease string) {
+ t.Helper()
+ _, tag, err := s.cfg.Releases.Get(t.Context(), seeds.FloorKey)
+ if err != nil {
+ t.Fatal(err)
+ }
+ raw, err := json.Marshal(seeds.Floor{Min: min, MinRelease: minRelease})
+ if err != nil {
+ t.Fatal(err)
+ }
+ if _, err = s.cfg.Releases.Put(t.Context(), seeds.FloorKey, raw, tag); err != nil {
+ t.Fatal(err)
+ }
+}
+
+func TestDemoClaimReadinessSeedRefusalCauses(t *testing.T) {
+ for _, tc := range []struct {
+ name, gate string
+ change func(*testing.T, *Server)
+ }{
+ {"flat", "box-layout:box-a", func(t *testing.T, s *Server) {
+ claimGateBox(t, s, func(b *status.Box) { b.Metrics.Layout.Mode = "flat" })
+ }},
+ {"missing-layout", "box-layout:box-a", func(t *testing.T, s *Server) {
+ claimGateBox(t, s, func(b *status.Box) { b.Metrics.Layout = nil })
+ }},
+ {"claim-control", "box-claim-control:box-a", func(t *testing.T, s *Server) {
+ claimGateBox(t, s, func(b *status.Box) { b.Metrics.HostClaimEnabled = true })
+ }},
+ {"moves-state", "edge-moves-floor:box-a", func(t *testing.T, s *Server) {
+ claimGateEdge(t, s, func(f map[string]any) { f["moves_floor_state"] = "accepted" })
+ }},
+ {"moves-generation", "edge-moves-floor:box-a", func(t *testing.T, s *Server) {
+ claimGateEdge(t, s, func(f map[string]any) { f["moves_floor_generation"] = 1 })
+ }},
+ {"moves-unarmed-seeds", "edge-moves-floor:box-a", func(t *testing.T, s *Server) {
+ claimGateEdge(t, s, func(f map[string]any) {
+ f["moves_floor_state"], f["seeds_floor_state"] = "accepted", "accepted"
+ })
+ }},
+ {"floor-protocol", "seed-floor-protocol", func(t *testing.T, s *Server) {
+ claimGateFloor(t, s, 3, "v1.0.0")
+ }},
+ {"floor-release-empty", "seed-floor-release", func(t *testing.T, s *Server) {
+ claimGateFloor(t, s, 2, "")
+ }},
+ {"floor-release-malformed", "seed-floor-release", func(t *testing.T, s *Server) {
+ claimGateFloor(t, s, 2, "invalid")
+ }},
+ {"no-region-edge", "seed-region-edges", func(t *testing.T, s *Server) {
+ claimGateEdge(t, s, func(f map[string]any) { f["placement"] = "other" })
+ }},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ s, _, _ := claimTestServer(t)
+ claimActivationFixture(t, s)
+ tc.change(t, s)
+ if s.seedRegionReadyForEdges(t.Context(), s.cfg.Region, false, demoClaimEdge) == nil {
+ t.Fatal("fixture did not reach an existing seed refusal")
+ }
+ var output bytes.Buffer
+ old := log.Writer()
+ log.SetOutput(&output)
+ defer log.SetOutput(old)
+ if err := s.demoClaimReady(t.Context()); err == nil || err.Error() != demoClaimUnavailable {
+ t.Fatalf("changed refusal: %v", err)
+ }
+ names := strings.Split(s.demoClaimAdmission.failures, ",")
+ if !slices.Contains(names, tc.gate) || !slices.Contains(names, "seed-region") {
+ t.Fatalf("missing cause or umbrella: %v", names)
+ }
+ if !strings.Contains(output.String(), "console: demo claim readiness: refusing: "+s.demoClaimAdmission.failures+"\n") {
+ t.Fatalf("missing diagnostic: %s", &output)
+ }
+ })
+ }
+}
+
+func TestDemoClaimReadinessSeedCauseChanges(t *testing.T) {
+ s, _, _ := claimTestServer(t)
+ claimActivationFixture(t, s)
+ claimGateBox(t, s, func(b *status.Box) { b.Metrics.Layout.Mode = "flat" })
+ var output bytes.Buffer
+ old := log.Writer()
+ log.SetOutput(&output)
+ defer log.SetOutput(old)
+ for _, want := range []string{"box-layout:box-a,seed-region", "box-claim-control:box-a,seed-region"} {
+ for range 2 {
+ s.demoClaimAdmission.expiresAt = time.Time{}
+ if s.demoClaimReady(t.Context()) == nil {
+ t.Fatal("admitted refusal")
+ }
+ }
+ if !strings.HasSuffix(output.String(), "console: demo claim readiness: refusing: "+want+"\n") {
+ t.Fatalf("missing changed cause: %s", &output)
+ }
+ claimGateBox(t, s, func(b *status.Box) {
+ b.Metrics.Layout.Mode, b.Metrics.HostClaimEnabled = "nested", true
+ })
+ }
+ if strings.Count(output.String(), "console: demo claim readiness: refusing:") != 2 {
+ t.Fatalf("want two diagnostic lines: %s", &output)
+ }
+}
+
+func TestDemoClaimSeedCauseChecksPreserveAcceptance(t *testing.T) {
+ for _, mode := range []string{"higher-protocol", "moves-with-accepted-seeds", "other-region", "named-pool"} {
+ t.Run(mode, func(t *testing.T) {
+ s, _, _ := claimTestServer(t)
+ claimActivationFixture(t, s)
+ switch mode {
+ case "higher-protocol":
+ claimGateFloor(t, s, 3, "v1.0.0")
+ claimGateEdge(t, s, func(f map[string]any) { f["seeds_protocol"] = 3 })
+ case "moves-with-accepted-seeds":
+ claimGateEdge(t, s, func(f map[string]any) {
+ f["moves_floor_state"], f["seeds_floor_state"], f["seeds_floor_generation"] = "refused", "accepted", 1
+ })
+ default:
+ fx := &consoleFixture{srv: s, rel: s.cfg.Releases}
+ seedReadyBox(t, fx, "box-b", "other", 2, "v1.0.0", "v1.0.0", "flat", true)
+ // Keep all shared readers capable, including a flat box outside the destination region.
+ boxes, err := status.LoadBoxes(t.Context(), s.cfg.Releases)
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, b := range boxes {
+ if b.Label == "box-b" {
+ b.Metrics.Capabilities = append(b.Metrics.Capabilities, seeds.DemoClaimCapability)
+ if err := status.WriteBox(t.Context(), s.cfg.Releases, b); err != nil {
+ t.Fatal(err)
+ }
+ }
+ }
+ key := "control/edges/box-b.json"
+ raw, tag, err := s.cfg.Releases.Get(t.Context(), key)
+ if err != nil {
+ t.Fatal(err)
+ }
+ var f map[string]any
+ if err := json.Unmarshal(raw, &f); err != nil {
+ t.Fatal(err)
+ }
+ f["capabilities"] = []string{seeds.DemoClaimCapability}
+ f["moves_floor_state"] = "accepted"
+ if mode == "named-pool" {
+ f["placement"], f["serves_shared_pool"] = s.cfg.Region, false
+ }
+ raw, err = json.Marshal(f)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if _, err := s.cfg.Releases.Put(t.Context(), key, raw, tag); err != nil {
+ t.Fatal(err)
+ }
+ }
+ if ref := s.seedRegionReadyForEdges(t.Context(), s.cfg.Region, false, demoClaimEdge); ref != nil {
+ t.Fatalf("existing refusal: %+v", ref)
+ }
+ if gates := s.demoClaimSeedGates(t.Context(), s.cfg.Region); len(gates) != 0 {
+ t.Fatalf("new refusal: %s", gates.names())
+ }
+ })
+ }
+}
+
+func TestDemoClaimSeedHostClaimNilStore(t *testing.T) {
+ s := &Server{cfg: Config{HostClaim: true}}
+ gates := s.demoClaimSeedGates(t.Context(), "")
+ if !slices.Contains(gates, "host-claim") || gates.err() == nil {
+ t.Fatalf("missing host-claim refusal: %s", gates.names())
+ }
+}
+
+func TestDemoClaimReadinessEarlyRefusals(t *testing.T) {
+ s, _, _ := claimTestServer(t)
+ claimActivationFixture(t, s)
+ if err := s.demoClaimReady(t.Context()); err != nil {
+ t.Fatal(err)
+ }
+ counted := &demoCountingStore{Store: s.cfg.Releases}
+ s.cfg.Releases = counted
+ var output bytes.Buffer
+ old := log.Writer()
+ log.SetOutput(&output)
+ defer log.SetOutput(old)
+ defer func() { s.store.gate = nil }()
+ for _, want := range []string{"demo-enabled", "host-claim", "claim-gated", "claim-gated,demo-enabled,host-claim"} {
+ s.cfg.Demo.Enabled = !strings.Contains(want, "demo-enabled")
+ s.cfg.HostClaim = strings.Contains(want, "host-claim")
+ s.store.gate = nil
+ if strings.Contains(want, "claim-gated") {
+ s.store.gate = &claimGate{}
+ }
+ output.Reset()
+ for i := range 3 {
+ if i == 2 {
+ s.demoClaimAdmission.expiresAt = time.Time{}
+ }
+ if err := s.demoClaimReady(t.Context()); err == nil || err.Error() != demoClaimUnavailable {
+ t.Fatalf("early refusal: %v", err)
+ }
+ }
+ if strings.Count(output.String(), "console: demo claim readiness: refusing:") != 1 ||
+ !strings.HasSuffix(output.String(), "refusing: "+want+"\n") {
+ t.Fatalf("early diagnostic: %s", &output)
+ }
+ }
+ if counted.requests() != 0 {
+ t.Fatalf("early refusal read deployment: %d", counted.requests())
+ }
+ s.cfg.Demo.Enabled, s.cfg.HostClaim, s.store.gate = true, false, nil
+ if err := s.demoClaimReady(t.Context()); err != nil {
+ t.Fatalf("stale prerequisite refusal: %v", err)
+ }
+ if !strings.HasSuffix(output.String(), "console: demo claim readiness: ready\n") {
+ t.Fatalf("missing recovery: %s", &output)
+ }
+}
+
+func TestDemoClaimTransferCapabilityCauseOnce(t *testing.T) {
+ for _, fault := range []string{"worker-peer", "box-layout:box-a,seed-region", "moved-edge:box-a"} {
+ t.Run(fault, func(t *testing.T) {
+ s, op, _ := claimTransferFixture(t)
+ switch fault {
+ case "worker-peer":
+ s.demoJobs.peers["box"].ready.ClaimCapability = ""
+ case "box-layout:box-a,seed-region":
+ claimGateBox(t, s, func(b *status.Box) { b.Metrics.Layout.Mode = "flat" })
+ case "moved-edge:box-a":
+ claimGateEdge(t, s, func(f map[string]any) { f["capabilities"] = []string{seeds.DemoClaimCapability} })
+ }
+ var output bytes.Buffer
+ old := log.Writer()
+ log.SetOutput(&output)
+ defer log.SetOutput(old)
+ claimAdvance(t, s, op)
+ claimAdvance(t, s, op)
+ p, err := s.claimProgress(t.Context(), op.ID)
+ if err != nil || p.Reason != "capability" {
+ t.Fatalf("abort reason: %+v %v", p, err)
+ }
+ if strings.Count(output.String(), "console: demo claim capability:") != 1 ||
+ !strings.Contains(output.String(), "console: demo claim capability: refusing: "+fault+"\n") {
+ t.Fatalf("abort diagnostic: %s", &output)
+ }
+ if strings.Contains(output.String(), op.ID) || strings.Contains(output.String(), op.Target.Host) {
+ t.Fatalf("operation identity leaked: %s", &output)
+ }
+ })
+ }
+}
+
+func TestDemoClaimTransferCapabilityCleanupRetry(t *testing.T) {
+ s, op, _ := claimTransferFixture(t)
+ s.demoJobs.peers["box"].ready.ClaimCapability = ""
+ store := s.cfg.Releases
+ s.cfg.Releases = &claimGateStore{Store: store, failGet: provision.RecordKey(op.Target.Sqid, op.Target.App, op.Target.Host)}
+ var output bytes.Buffer
+ old := log.Writer()
+ log.SetOutput(&output)
+ defer log.SetOutput(old)
+ for range 2 {
+ if err := s.advanceDemoClaim(t.Context(), op.ID); !errors.Is(err, errClaimGateStore) {
+ t.Fatalf("expected cleanup failure: %v", err)
+ }
+ fresh, err := s.store.demoClaimOp(t.Context(), op.ID)
+ if err != nil || fresh.Phase != "aborting" {
+ t.Fatalf("abort transition not persisted: %+v %v", fresh, err)
+ }
+ }
+ s.cfg.Releases = store
+ claimAdvance(t, s, op)
+ if strings.Count(output.String(), "console: demo claim capability: refusing: worker-peer\n") != 1 {
+ t.Fatalf("cleanup retry repeated diagnostic: %s", &output)
+ }
+}
diff --git a/internal/console/demo_claim_gates_test.go b/internal/console/demo_claim_gates_test.go
index 820fe5dcd..677504591 100644
--- a/internal/console/demo_claim_gates_test.go
+++ b/internal/console/demo_claim_gates_test.go
@@ -188,7 +188,7 @@ func TestDemoClaimReadinessAllFailuresAndTransitions(t *testing.T) {
}
}
check(false)
- want := "console: demo claim readiness: refusing: box-platform:box-a,box-status:box-a,edge-capability:box-a,edge-prev:box-a,edge-protocol:box-a,keymail,moved-box:box-a,moved-edge:box-a,seed-region,signing-key"
+ want := "console: demo claim readiness: refusing: box-platform:box-a,box-status:box-a,edge-capability:box-a,edge-prev:box-a,edge-protocol:box-a,keymail,moved-box:box-a,moved-edge:box-a,seed-floor-protocol,seed-region,signing-key"
if !strings.Contains(output.String(), want+"\n") {
t.Fatalf("missing complete sorted failures: %s", &output)
}
diff --git a/internal/console/demo_claim_ready.go b/internal/console/demo_claim_ready.go
index 7b1074247..d6e10cd40 100644
--- a/internal/console/demo_claim_ready.go
+++ b/internal/console/demo_claim_ready.go
@@ -15,7 +15,8 @@ import (
type demoClaimAdmissionCache struct {
demoAdmissionCache
- failures string
+ failures string
+ prerequisites string
}
type demoClaimGates []string
@@ -48,18 +49,26 @@ func demoClaimEdge(f edgesFilePlacementView) bool {
// Switching off bypasses the cache and performs no deployment reads.
func (s *Server) demoClaimReady(ctx context.Context) error {
refuse := func() error { return errors.New(demoClaimUnavailable) }
- if !s.cfg.Demo.ClaimEnabled || !s.cfg.Demo.Enabled || s.cfg.HostClaim || s.store.claimGated() {
+ if !s.cfg.Demo.ClaimEnabled {
return refuse()
}
c := &s.demoClaimAdmission
c.mu.Lock()
defer c.mu.Unlock()
- if c.checked && time.Now().Before(c.expiresAt) {
+ var gates demoClaimGates
+ gates.check("demo-enabled", s.cfg.Demo.Enabled)
+ gates.check("host-claim", !s.cfg.HostClaim)
+ gates.check("claim-gated", s.store == nil || !s.store.claimGated())
+ prerequisites := gates.names()
+ if c.checked && prerequisites == c.prerequisites && time.Now().Before(c.expiresAt) {
return c.err
}
- ctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 10*time.Second)
- defer cancel()
- gates, err := s.demoClaimReadinessGates(ctx)
+ err := gates.err()
+ if err == nil {
+ ctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 10*time.Second)
+ defer cancel()
+ gates, err = s.demoClaimReadinessGates(ctx)
+ }
failures := gates.names()
if failures != c.failures {
if failures == "" {
@@ -69,6 +78,7 @@ func (s *Server) demoClaimReady(ctx context.Context) error {
}
}
c.failures = failures
+ c.prerequisites = prerequisites
c.err = err
c.checked = true
c.expiresAt = time.Now().Add(demoAdmissionTTL)
@@ -117,6 +127,7 @@ func (s *Server) demoClaimReadinessGates(ctx context.Context) (demoClaimGates, e
gates = append(gates, moved...)
}
if err := gates.err(); err != nil {
+ gates.check("context", ctx.Err() == nil)
return gates, err
}
gates.check("context", ctx.Err() == nil)
diff --git a/internal/console/demo_claim_seed.go b/internal/console/demo_claim_seed.go
index 4b0e025af..91c3bb196 100644
--- a/internal/console/demo_claim_seed.go
+++ b/internal/console/demo_claim_seed.go
@@ -40,7 +40,7 @@ func (s *Server) demoClaimSeedReady(ctx context.Context, region string) error {
func (s *Server) demoClaimSeedGates(ctx context.Context, region string) demoClaimGates {
var gates demoClaimGates
gates.check("host-claim", !s.cfg.HostClaim)
- gates.check("claim-gated", !s.store.claimGated())
+ gates.check("claim-gated", s.store == nil || !s.store.claimGated())
gates.check("releases", s.cfg.Releases != nil)
gates.check("seed-region", region == s.cfg.Region)
gates.check("ha-region", !s.haRegion(region))
@@ -50,14 +50,25 @@ func (s *Server) demoClaimSeedGates(ctx context.Context, region string) demoClai
gates.check("seed-region", s.seedRegionReadyForEdges(ctx, region, false, demoClaimEdge) == nil)
floor, err := seeds.ReadFloor(ctx, s.cfg.Releases)
gates.check("seed-floor", err == nil && floor != nil && floor.Min >= seeds.DemoClaimProtocol)
+ if floor != nil {
+ ok, err := seeds.ReleaseAtOrAbove(floor.MinRelease, floor.MinRelease)
+ gates.check("seed-floor-release", ok && err == nil)
+ }
snap, err := s.liveEdges(ctx)
gates.check("edges-evidence", err == nil && snap.EvidenceComplete() && len(snap.Files) != 0)
- counted := 0
+ counted, inRegion := 0, 0
for _, f := range snap.Files {
if !demoClaimEdge(f) {
continue
}
counted++
+ if s.homeRegionIn(f.Placement) == s.homeRegionIn(region) {
+ inRegion++
+ if floor != nil {
+ gates.check("seed-floor-protocol", f.SeedsProtocol >= max(seeds.RequiredProtocol, floor.Min))
+ }
+ gates.check("edge-moves-floor:"+f.Box, (f.MovesFloorState == "" && f.MovesFloorGeneration == 0) || (f.SeedsFloorState == "accepted" && f.SeedsFloorGeneration != 0))
+ }
gates.check("edge-capability:"+f.Box, slices.Contains(f.Capabilities, seeds.DemoClaimCapability))
gates.check("edge-protocol:"+f.Box, f.SeedsProtocol >= seeds.DemoClaimProtocol)
if floor != nil {
@@ -67,6 +78,7 @@ func (s *Server) demoClaimSeedGates(ctx context.Context, region string) demoClai
gates.check("edge-floor-state:"+f.Box, (f.SeedsFloorState == "" && f.SeedsFloorGeneration == 0) || (f.SeedsFloorState == "accepted" && f.SeedsFloorGeneration != 0))
}
gates.check("no-shared-edges", counted != 0)
+ gates.check("seed-region-edges", inRegion != 0)
boxes, err := status.LoadBoxes(ctx, s.cfg.Releases)
gates.check("box-status", err == nil)
byLabel := map[string]status.Box{}
@@ -83,8 +95,12 @@ func (s *Server) demoClaimSeedGates(ctx context.Context, region string) demoClai
}
b, ok := byLabel[f.Box]
gates.check("box-status:"+f.Box, ok && !dup[f.Box] && !status.BoxStale(b, time.Now(), status.SnapshotPeriod) && b.Metrics != nil && slices.Contains(b.Metrics.Capabilities, seeds.DemoClaimCapability))
- if b.Metrics != nil && s.homeRegionIn(f.Placement) == s.homeRegionIn(region) {
- gates.check("box-platform:"+f.Box, b.Metrics.Platform == "linux-arm64")
+ if s.homeRegionIn(f.Placement) == s.homeRegionIn(region) {
+ gates.check("box-layout:"+f.Box, b.Metrics != nil && b.Metrics.Layout != nil && b.Metrics.Layout.Mode == "nested")
+ if b.Metrics != nil {
+ gates.check("box-claim-control:"+f.Box, !b.Metrics.HostClaimEnabled)
+ gates.check("box-platform:"+f.Box, b.Metrics.Platform == "linux-arm64")
+ }
}
}
return gates
diff --git a/internal/console/demo_claim_transfer.go b/internal/console/demo_claim_transfer.go
index 5ddb19eba..e8d4074b0 100644
--- a/internal/console/demo_claim_transfer.go
+++ b/internal/console/demo_claim_transfer.go
@@ -7,6 +7,7 @@ import (
"encoding/hex"
"errors"
"io"
+ "log"
"net/http"
"os"
"sort"
@@ -44,19 +45,27 @@ func (s *Server) claimBoundary(at string) error {
}
func (s *Server) demoClaimCapabilitiesReady(ctx context.Context, op claimOp) error {
+ _, err := s.demoClaimCapabilityGates(ctx, op)
+ return err
+}
+
+func (s *Server) demoClaimCapabilityGates(ctx context.Context, op claimOp) (demoClaimGates, error) {
+ var gates demoClaimGates
found := false
for _, p := range s.demoEligiblePeers() {
if p.box() == op.SourceBox && p.ready.ClaimCapability == democlaim.Capability && p.ready.MovedCapability == democlaim.MovedCapability {
found = true
}
}
- if !found {
- return errors.New(demoClaimUnavailable)
+ gates.check("worker-peer", found)
+ if err := gates.err(); err != nil {
+ return gates, err
}
- if err := s.demoClaimSeedReady(ctx, op.Target.Region); err != nil {
- return err
+ gates = s.demoClaimSeedGates(ctx, op.Target.Region)
+ if err := gates.err(); err != nil {
+ return gates, err
}
- return s.demoClaimMovedReady(ctx)
+ return s.demoClaimMovedGates(ctx)
}
// The operation mutex serializes pickup, upload, abort and recovery. It is
@@ -102,8 +111,8 @@ func (s *Server) advanceDemoClaimLocked(ctx context.Context, id string) error {
if !s.demoClaimEnabled() {
return s.beginDemoClaimAbort(ctx, op, "disabled")
}
- if err = s.demoClaimCapabilitiesReady(ctx, op); err != nil {
- return s.beginDemoClaimAbort(ctx, op, "capability")
+ if gates, err := s.demoClaimCapabilityGates(ctx, op); err != nil {
+ return s.beginDemoClaimAbort(ctx, op, "capability", gates...)
}
if err = s.pinDemoClaim(ctx, &op); err != nil {
return s.beginDemoClaimAbort(ctx, op, "source_unready")
@@ -773,7 +782,7 @@ func (s *Server) abortDemoClaimLocked(ctx context.Context, id, reason string) er
return s.beginDemoClaimAbort(ctx, op, reason)
})
}
-func (s *Server) beginDemoClaimAbort(ctx context.Context, op claimOp, reason string) error {
+func (s *Server) beginDemoClaimAbort(ctx context.Context, op claimOp, reason string, gates ...string) error {
if op.Phase == "committed" || op.Phase == "done" {
return ErrDemoToken
}
@@ -797,6 +806,9 @@ func (s *Server) beginDemoClaimAbort(ctx context.Context, op claimOp, reason str
if err = tx.Commit(); err != nil {
return err
}
+ if op.Phase == "reserved" && reason == "capability" {
+ log.Printf("console: demo claim capability: refusing: %s", demoClaimGates(gates).names())
+ }
op.Phase = "aborting"
return s.continueDemoClaimAbort(ctx, op)
}