Claims cleanup R1 plan and golden vectors before any move
Pins hostclaim.Incarnation (legacy and created forms, malformed inputs), the park placement rules over a full input table, the group box reference and hostbox.RequestLimit, with hex values derived outside Go.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+226
−0
docs/superpowers/plans/2026-10-25-claims-cleanup-r1.md+68 −0internal/host/claimsoff_golden_test.go+30 −0internal/provision/incarnation_golden_test.go+51 −0internal/regionname/region_golden_test.go+77 −0
diff --git a/docs/superpowers/plans/2026-10-25-claims-cleanup-r1.md b/docs/superpowers/plans/2026-10-25-claims-cleanup-r1.md| new file mode 100644 |
| index 000000000..1b3f70a7c |
| --- /dev/null |
| +++ b/docs/superpowers/plans/2026-10-25-claims-cleanup-r1.md |
| @@ -0,0 +1,68 @@ |
| +# Claims cleanup R1: move the live slices out of the claim packages |
| + |
| +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. |
| + |
| +**Goal:** No claims-off production caller imports a claim package (hostclaim, park, hostops, hostbox, hostactors) for live behaviour, with no behaviour change. |
| + |
| +**Architecture:** Each live slice gets a neutral home (`provision`, `regionname`, `console`, `host`, `instancectl`). Claim packages that still use a symbol keep it as a thin delegate to the new home, or as a test-pinned twin where the import direction forbids delegation. Golden vectors land first and must pass unchanged after every move. |
| + |
| +**Tech Stack:** Go. |
| + |
| +**Spec:** `docs/superpowers/notes/claims-inventory.md` (on design-live-moves-ha) §2.4, §3, §4 row R1; `docs/superpowers/plans/2026-10-25-claims-cleanup.md` row R1. |
| + |
| +## Global Constraints |
| + |
| +- Claims-off behaviour byte-identical: Incarnation bytes (legacy and created forms), placement codes, offline-door statuses and messages. |
| +- Targeted tests only locally (`nice -n 19 go test ./internal/<pkg>/ -run <X>`); `go build ./...` plus `GOOS=darwin` and `GOOS=windows` before the push; `go vet` on touched packages. |
| +- Census: `make census-card`, CLAIMS file, `make census-propose NAME=claims-cleanup-r1`. A refused class (`removed`, `new`, `reads`, `other`) stops the branch for a report. |
| + |
| +## Review Focus |
| + |
| +- A present-but-malformed `control/hosts/<host>.json`: today a 502 (decode/validate failure); console-local presence check answers 409. Pinned by a test; called out in the report. |
| +- A backfill plan at phase `done` must still be allowed; the console-local verify must re-encode canonically, so the local plan type copies `hostops.BackfillPlan`'s shape exactly (pinned by a test that signs a `hostops.BackfillPlan` and reads it locally). |
| +- An invalid host or account shape must still give 502 on the claim and admission checks. |
| +- `hostclaim.Incarnation` must keep returning `hostclaim.ErrMalformed` for its claim callers. |
| + |
| +--- |
| + |
| +### Task 1: Golden vectors |
| + |
| +**Files:** Test: `internal/provision/incarnation_test.go`, `internal/regionname/region_golden_test.go`, `internal/host/boxreference_golden_test.go` |
| + |
| +- [ ] Pin `hostclaim.Incarnation` today for one legacy (zero time) and one created (`2026-10-01T12:34:56.789Z`) record, plus one malformed account, as literal hex strings (computed from main before any move). |
| +- [ ] Pin `HomePlacementCode`, `PlacementRegion`, `SameRegion`, `PlacementMatches` over a table (home "", "ie"; codes "", "ie", "uk", "@home", "Bad", 17 chars) through `park.*`. |
| +- [ ] Pin `hostactors.GroupBoxReference("123456789012", "i-0a61f580df1acfa65")` and `hostbox.RequestLimit == 120s`. |
| +- [ ] Run; commit. |
| + |
| +### Task 2: Incarnation into provision |
| + |
| +- [ ] `provision.Incarnation(account, app, host string, created time.Time) (string, error)` in `internal/provision/incarnation.go`; `provision.ErrIncarnation`. |
| +- [ ] Golden test runs against `provision.Incarnation` too; `hostclaim.Incarnation` delegates and maps errors to `ErrMalformed`. |
| +- [ ] Switch `dbreads/agent.go`, `host/runexec.go`, `console/apidbforward.go`, `console/apiruns.go`, the `runs/runs.go` comment. |
| +- [ ] Run dbreads, runs, host `-run Run`, console `-run 'DBRead|Run'`; commit. |
| + |
| +### Task 3: Placement helpers into regionname |
| + |
| +- [ ] `regionname.PlacementMatches(home, code, engine string) bool`; `park.PlacementMatches` delegates. |
| +- [ ] Golden table runs against `regionname.*` too. |
| +- [ ] Switch `console/apiinstancemove.go` `homePlacementCode`, `host/movesoffline.go`, `host/movesoffline_seal.go`, `host/movessources.go` `parkRegion`. |
| +- [ ] Run host `-run Offline`, console `-run 'Offline|Region|InstanceCreate'`; commit. |
| + |
| +### Task 4: The offline door's checks, console-local; dead sentinels |
| + |
| +- [ ] `offlineClaimEvidence` reads `control/hosts/<host>.json`, `apps/<acct>/<app>/admission.json` and `control/hosts-backfill.json` itself (`offlineHostClaimKey`, `offlineAdmissionKey`, `offlineBackfillKey`, `offlineBackfillPlan` mirroring `hostops.BackfillPlan`). |
| +- [ ] Tests: keys equal hostops'/hostclaim's; a signed `hostops.BackfillPlan` reads locally; malformed claim present gives 409; unreadable gives 502. |
| +- [ ] Delete the `hostops.ErrPending`/`ErrContract` comparisons at `domainattach.go` (record delete, claim delete), `apidomains.go` (attach, detach), `apisystem.go`, `scandeliver.go`: each error source is `domains`/`provision`/`objstore`/`appconfig` on an ungated store when `HostClaim` is false. |
| +- [ ] Run console `-run 'Offline|Domain|Scan|System'`; commit. |
| + |
| +### Task 5: RequestLimit, GroupBoxReference, the unit control group |
| + |
| +- [ ] `host.claimsShutdownLimit = 120 * time.Second` replaces `hostbox.RequestLimit` in `agent.go`; `host.groupBoxReference` replaces `hostactors.GroupBoxReference` in `boxreference.go`; golden tests pin both against the claim twins. |
| +- [ ] Rename `instancectl.ClaimUnitControlGroup` to `RunUnitControlGroup` (all callers). |
| +- [ ] Run host `-run 'BoxReference|Joining|Group'`, instancectl, activator `-run RoleLaunch`; commit. |
| + |
| +### Task 6: Census, builds, push |
| + |
| +- [ ] `make census-card`; CLAIMS; `make census-propose NAME=claims-cleanup-r1 CLAIMS=<file>`; `TestPlan14RootReadCensus`, `TestPlan14RootInputInventoryCoverage`. |
| +- [ ] `go build ./...`, darwin, windows; `go vet` touched packages; `gofmt -l`. |
| +- [ ] Commit, push, `amadan ci status carlos/platform -branch claims-cleanup-r1`. |
diff --git a/internal/host/claimsoff_golden_test.go b/internal/host/claimsoff_golden_test.go| new file mode 100644 |
| index 000000000..50580d726 |
| --- /dev/null |
| +++ b/internal/host/claimsoff_golden_test.go |
| @@ -0,0 +1,30 @@ |
| +package host |
| + |
| +import ( |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/hostactors" |
| + "github.com/carlosframework/platform/internal/hostbox" |
| +) |
| + |
| +// Golden vectors for the two claim-package values the claims-off agent |
| +// uses (claims cleanup R1). The group reference was derived independently: |
| +// "g-" + the first 20 hex digits of |
| +// sha256("carlos-box-ref-v1|123456789012|i-0a61f580df1acfa65"). |
| +func TestGroupBoxReferenceGolden(t *testing.T) { |
| + impls := map[string]func(string, string) string{ |
| + "hostactors.GroupBoxReference": hostactors.GroupBoxReference, |
| + } |
| + for name, f := range impls { |
| + if got := f("123456789012", "i-0a61f580df1acfa65"); got != "g-c48ba25b2d17574d23d9" { |
| + t.Errorf("%s = %q, want g-c48ba25b2d17574d23d9", name, got) |
| + } |
| + } |
| +} |
| + |
| +func TestClaimsShutdownLimitGolden(t *testing.T) { |
| + if hostbox.RequestLimit != 120*time.Second { |
| + t.Fatalf("hostbox.RequestLimit = %v, want 2m0s", hostbox.RequestLimit) |
| + } |
| +} |
diff --git a/internal/provision/incarnation_golden_test.go b/internal/provision/incarnation_golden_test.go| new file mode 100644 |
| index 000000000..4bf960252 |
| --- /dev/null |
| +++ b/internal/provision/incarnation_golden_test.go |
| @@ -0,0 +1,51 @@ |
| +package provision_test |
| + |
| +import ( |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/hostclaim" |
| +) |
| + |
| +// incarnationVectors are the identities db forward and carlos run carry |
| +// (console and box compute them apart and must agree). The hex values were |
| +// derived independently of the Go code: the legacy form is |
| +// sha256("carlos-legacy-incarnation-v1\x00" + account + "\x00" + app + "\x00" + host), |
| +// the created form maintenanceguard.RecordIdentity's length-prefixed digest |
| +// over account, app, host and the RFC 3339 nano stamp. Claims cleanup R1 |
| +// moved the function; these bytes must never move. |
| +var incarnationVectors = []struct { |
| + name string |
| + acct, app, host string |
| + at time.Time |
| + want string |
| +}{ |
| + {"legacy", "bab", "shop", "alpha.shop.example.com", time.Time{}, "b3d6855bf26845a17dcfa39fd8f94a00815ecc257aaf0540a6d5522efb1d976e"}, |
| + {"created", "bab", "shop", "alpha.shop.example.com", time.Date(2026, 10, 1, 12, 34, 56, 789000000, time.UTC), "e5250d740fc808db6befc8174112bbc3bb33033672030c9ce40472800fd0ebf6"}, |
| + {"created nanosecond", "bab", "shop", "alpha.shop.example.com", time.Date(2026, 10, 1, 12, 34, 56, 789000001, time.UTC), "a37493f256a913a376898eee3f332449ea2d96103a64c58b5e11a4c59b930c02"}, |
| + {"created non-UTC zone", "bab", "shop", "alpha.shop.example.com", time.Date(2026, 10, 1, 13, 34, 56, 789000000, time.FixedZone("x", 3600)), "e5250d740fc808db6befc8174112bbc3bb33033672030c9ce40472800fd0ebf6"}, |
| + {"legacy malformed account", "BAD", "shop", "alpha.shop.example.com", time.Time{}, ""}, |
| + {"created malformed account", "BAD", "shop", "alpha.shop.example.com", time.Date(2026, 10, 1, 12, 34, 56, 789000000, time.UTC), ""}, |
| + {"legacy malformed host", "bab", "shop", "", time.Time{}, ""}, |
| +} |
| + |
| +var incarnationImpls = map[string]func(string, string, string, time.Time) (string, error){ |
| + "hostclaim.Incarnation": hostclaim.Incarnation, |
| +} |
| + |
| +func TestIncarnationGoldenVectors(t *testing.T) { |
| + for name, f := range incarnationImpls { |
| + for _, v := range incarnationVectors { |
| + got, err := f(v.acct, v.app, v.host, v.at) |
| + if v.want == "" { |
| + if err == nil || got != "" { |
| + t.Errorf("%s %s = %q, %v; want an error and no identity", name, v.name, got, err) |
| + } |
| + continue |
| + } |
| + if err != nil || got != v.want { |
| + t.Errorf("%s %s = %q, %v; want %q", name, v.name, got, err, v.want) |
| + } |
| + } |
| + } |
| +} |
diff --git a/internal/regionname/region_golden_test.go b/internal/regionname/region_golden_test.go| new file mode 100644 |
| index 000000000..a39a30983 |
| --- /dev/null |
| +++ b/internal/regionname/region_golden_test.go |
| @@ -0,0 +1,77 @@ |
| +package regionname_test |
| + |
| +import ( |
| + "crypto/sha256" |
| + "encoding/hex" |
| + "fmt" |
| + "strings" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/park" |
| +) |
| + |
| +// The placement rules the console's create, regions and move doors and the |
| +// box's offline move round share (claims cleanup R1 moved the callers off |
| +// park). placementTable renders every rule over every combination of these |
| +// inputs; its digest is pinned, and a few rows are pinned outright so a |
| +// failure says which rule moved. |
| +var placementHomes = []string{"", "ie", "@home", "Bad"} |
| +var placementCodes = []string{"", "ie", "uk", "@home", "home", "Bad", "a-1", "abcdefghijklmnopq"} |
| + |
| +type placementRules struct { |
| + region func(string) string |
| + code func(string, string) string |
| + same func(string, string, string) bool |
| + matches func(string, string, string) bool |
| +} |
| + |
| +var placementImpls = map[string]placementRules{ |
| + "park": {park.PlacementRegion, park.HomePlacementCode, park.SameRegion, park.PlacementMatches}, |
| +} |
| + |
| +func placementTable(r placementRules) string { |
| + var b strings.Builder |
| + for _, c := range placementCodes { |
| + fmt.Fprintf(&b, "PR %q=%q\n", c, r.region(c)) |
| + } |
| + for _, h := range placementHomes { |
| + for _, c := range placementCodes { |
| + fmt.Fprintf(&b, "HPC %q %q=%q\n", h, c, r.code(h, c)) |
| + for _, e := range placementCodes { |
| + fmt.Fprintf(&b, "SR %q %q %q=%v PM=%v\n", h, c, e, r.same(h, c, e), r.matches(h, c, e)) |
| + } |
| + } |
| + } |
| + return b.String() |
| +} |
| + |
| +const placementTableDigest = "c47389f9e56f7a07d074d825372bcf9fe858614fd52c28c4fd806cd73f922500" |
| + |
| +func TestPlacementGoldenVectors(t *testing.T) { |
| + for name, r := range placementImpls { |
| + sum := sha256.Sum256([]byte(placementTable(r))) |
| + if got := hex.EncodeToString(sum[:]); got != placementTableDigest { |
| + t.Errorf("%s: placement table digest = %s, want %s", name, got, placementTableDigest) |
| + } |
| + for _, v := range []struct { |
| + got, want string |
| + }{ |
| + {r.region(""), "@home"}, {r.region("ie"), "ie"}, {r.region("@home"), ""}, {r.region("Bad"), ""}, {r.region("abcdefghijklmnopq"), ""}, |
| + {r.code("ie", "ie"), ""}, {r.code("ie", "uk"), "uk"}, {r.code("", "ie"), "ie"}, {r.code("ie", ""), ""}, |
| + } { |
| + if v.got != v.want { |
| + t.Errorf("%s: got %q, want %q", name, v.got, v.want) |
| + } |
| + } |
| + for _, v := range []struct { |
| + got, want bool |
| + }{ |
| + {r.same("ie", "ie", "@home"), true}, {r.same("", "ie", "@home"), false}, {r.same("ie", "", ""), false}, {r.same("@home", "@home", "@home"), true}, |
| + {r.matches("ie", "", "ie"), true}, {r.matches("ie", "", "@home"), true}, {r.matches("", "", "ie"), false}, {r.matches("ie", "uk", "uk"), true}, {r.matches("ie", "Bad", "Bad"), false}, |
| + } { |
| + if v.got != v.want { |
| + t.Errorf("%s: got %v, want %v", name, v.got, v.want) |
| + } |
| + } |
| + } |
| +} |