group verb: carry the observation across a user-data-only re-pin
Every release's re-pin left the next roll needing a pin-back: the observation names one launch template version. Preflight and plan now accept the observation for another version of the same template when every other field matches and the two versions' launch template data, read from the provider and journaled (template_data), are identical once user data is removed: the SDK's decoded fields and the answer's own launchTemplateData XML in canonical form, so a field the SDK does not know still shows. Anything else refuses observation; nothing is written. Spec V19 and section 7.1 (Paul approved option b, 2026-11-11). Runbook: Paul's approved floor, fixed_boxes and default-host prose; the bucket_region, remote_said and remove_minimum texts approved.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
13 files changed,
+551
−8
docs/region-ha-runbook.md+6 −3docs/superpowers/notes/census-proposal-group-observation-carry.md+21 −0docs/superpowers/specs/2026-11-09-group-roll-verb-design.md+37 −0internal/grouproll/engine.go+71 −1internal/grouproll/fake_test.go+19 −0internal/grouproll/observation_carry_test.go+129 −0internal/grouproll/plan.go+5 −1internal/grouproll/provider.go+4 −0internal/grouproll/text_test.go+3 −1internal/grouprollaws/group.go+157 −0internal/grouprollaws/group_test.go+90 −2internal/provision/testdata/plan14-root-reads-chain.tsv+1 −0internal/provision/testdata/plan14-root-reads-group-observation-carry.tsv+8 −0
CI cancelled — superseded by a newer push — run details
diff --git a/docs/region-ha-runbook.md b/docs/region-ha-runbook.md| index 1f714babe..21061beea 100644 |
| --- a/docs/region-ha-runbook.md |
| +++ b/docs/region-ha-runbook.md |
| @@ -59,15 +59,16 @@ With neither provider nor token configured, `%s` is `CARLOS_DNSIMPLE_TOKEN missi |
| ### Before you start |
| -Every box that can send the member a request must run a release with held requests. The tool checks this before each transaction: every live box in the region, fixed forwarders included, must publish `ha_take: 1`, and for `replace` the release the launch template boots must be at or above `ha_floor`. If any box falls short, the tool prints "DR-4's lock-free rule applies" and does not drain. Replace only lock-free members then, as before. |
| +Every box that can send the member a request must run a release with held requests. Before each transaction the tool reads every edges file in the deployment, whatever its age, and each one must publish `ha_handover: 1`. Every box listed in the config's `fixed_boxes` must have an edges file. For `replace`, the release the launch template boots must be at or above `ha_floor`; for `roll`, so must the release you roll to. If anything falls short, the tool prints "DR-4's lock-free rule applies", names the box, and does not drain. Then change only members that hold no host's lease, as before. |
| -A fixed box that forwards into the region needs `CARLOS_REGION_HA=1` in its host.env. Without it, the box publishes no `ha_take`, and the region stays on DR-4. |
| +`ha_take`, which a fixed box publishes when its host.env sets `CARLOS_REGION_HA=1`, is not part of this check. It matters only for boxes that take hosts over from a member. |
| -Add three keys to the tool's JSON config: |
| +Add four keys to the tool's JSON config: |
| - `ha_floor`: the first release with held requests, for example `v0.35.0`. |
| - `data_bucket`: the region's data bucket, the same as the members' `CARLOS_HIBERNATE_BUCKET`. |
| - `data_prefix`: the prefix the hosts' `lock.json` files sit under, usually `instances`. |
| +- `fixed_boxes`: every fixed box in the deployment, by its box reference (`box-one`, `box-two`). A deployment with no fixed boxes sets `no_fixed_boxes: true` instead. Set one or the other, not both. |
| The operator's credentials need the grants in the region-host module's `group_operator_policy_json` output, and the region's session document must be at the release that adds the drain commands. |
| @@ -136,6 +137,8 @@ In that line, `hosts_moved` and `hosts_released` count the hosts that left the m |
| The region runs one member short from Standby until the replacement is healthy, usually a few minutes. With two members, the survivor carries every host meanwhile. |
| +An app enabled with `carlos instances enable --pool <pool>` gets its own default host (`<app>.<domain>`), and that host is born HA in the pool too. Deploying the app wakes it, so it holds a lease on a member even if nobody uses it. Under DR-4's lock-free rule the tool then refuses to roll or replace that member ("A lock still names the member: <host>") until the host goes idle and gives up its lease, about 15 minutes after its last request. Wait by reading the host's lock: it is free once it reads `released/v1;…` or names another box. A `released/v1` marker still carries the old member's instance ID, so judge by the prefix, not by the ID. |
| + |
| ### Resizing every member |
| Set `instance_type` in the region's group module and apply. The plan should show a new launch template version and no instance change. Set `group_launch_template_version` to that version and apply again. Then run `replace` once for each member, waiting for each to finish. |
diff --git a/docs/superpowers/notes/census-proposal-group-observation-carry.md b/docs/superpowers/notes/census-proposal-group-observation-carry.md| new file mode 100644 |
| index 000000000..1696796f8 |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-group-observation-carry.md |
| @@ -0,0 +1,21 @@ |
| +# Census approval: group-observation-carry |
| + |
| +Ruling `census-ruling-group-observation-carry`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26). |
| + |
| +| unit | change | read sites | what changed | |
| +|---|---|---|---| |
| +| `internal/grouproll/engine.go` `Engine.preflight` | body | unchanged (1) | the same provider-observation.json read; when it names another version of the same launch template, the two versions are read from the provider (template_data, a DescribeLaunchTemplateVersions read through the adapter) and compared without user data; no new file read, nothing written | |
| +| `internal/grouproll/plan.go` `Engine.Plan` | body | unchanged (1) | the same observation read and the same carry-over rule as preflight (two template_data provider reads); no new file read, nothing written | |
| + |
| +Envelopes re-pinned: `internal/grouproll`, `internal/grouprollaws`. |
| + |
| +Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner. |
| + |
| +Recorded dispositions, which each change must still satisfy: |
| + |
| +- `internal/grouproll/engine.go` `Engine.preflight`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-group-roll-verb;basis=reads provider-observation.json from the operator's own 0700 state directory |
| +- `internal/grouproll/plan.go` `Engine.Plan`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-group-roll-verb;basis=reads provider-observation.json from the operator's own 0700 state directory;rev3=census-ruling-group-verb-followups;basis=a missing or unreadable provider-observation.json is refused as observation instead of passing the read error through (same file, same read) |
| + |
| +Seal: `40c8459580c3e62a53637e9989f1616e5735ce78796ec6ea1b22655a5eb4ad63` → `9cc09223a67041265c64d3918821b30ea3fa064e81f9dc8ec95af2b653e8f3af`. |
| + |
| +Overlay: `internal/provision/testdata/plan14-root-reads-group-observation-carry.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`. |
diff --git a/docs/superpowers/specs/2026-11-09-group-roll-verb-design.md b/docs/superpowers/specs/2026-11-09-group-roll-verb-design.md| index 05e64f076..a8ade12ff 100644 |
| --- a/docs/superpowers/specs/2026-11-09-group-roll-verb-design.md |
| +++ b/docs/superpowers/specs/2026-11-09-group-roll-verb-design.md |
| @@ -379,6 +379,7 @@ build to it. |
| | V16 | `plan` reports a missing provider observation as `record` (FileNotFoundError reached check()) | `plan` says `observation`, as preflight does | REPORT follow-up 3; flagship step 4 2026-11-11 | |
| | V17 | Every provider call is made once (`--cli-read-timeout`, retries 1) | Reads (the describes, caller identity, HeadBucket, S3 GET and list) are retried while AWS throttles them: four calls at most, about 1, 2 and 4 s apart, jittered; any other failure and the last throttle fail closed as before. Writes and box sessions are never retried. Bare `carlos system group`, its -h and an unknown verb print the group's help | Step-3 dev W4 2026-11-10: the group describe refused under ASG throttling (8a3d302) | |
| | V18 | A request that gets no response is one failed call | A read whose request got no response at all (the SDK's RequestSendError: a reset or EOF on a reused connection, no call in CloudTrail) is retried as a throttle is (V17's budget); a timeout is not, and stays one bound. A failure to get credentials (AssumeRole, SSO), throttled or unanswered, is never retried, so no credential call repeats. Writes and sessions are never retried | G5 release 1, dev, 2026-11-11: the post-prepare group describe failed in 14 ms with no CloudTrail call; resume closed it (8a3d302) | |
| +| V19 | The provider observation names one launch template version; any other pinned version refuses `observation` | The observation carries across a re-pin that changes only user data (§7.1). A launch template version other than the observation's, with the same template id and name, is accepted when the two versions' launch template data are identical once UserData is removed; anything else refuses `observation` as before | G5 release 1, 2026-11-11: every release's re-pin left the next roll needing a pin-back (Paul approved option b, 11-11) | |
| Not deviations, recorded so nobody "fixes" them in the port: the drain-rerun |
| backoff and the TakeHost `wake_timeout` follow-ups from the held build stay |
| @@ -387,6 +388,42 @@ follow-ups; `check-region-group-plan.py` (the tofu plan gate), the fault harness |
| observation file `provider-observation.json` is still placed by the controller, |
| not written by `probe`. |
| +### 7.1 The observation across a user-data-only re-pin (V19) |
| + |
| +The probe observes one thing: that this group, with this hook, launching |
| +from this template, returns a member from Standby without a lifecycle hook. |
| +A release's re-pin makes a new launch template version that differs from |
| +the old one only in user data (the CARLOS release it boots), so the |
| +observation still describes the group. Rule: |
| + |
| +1. The observation is accepted as before when it names the pinned template |
| + exactly. |
| +2. Otherwise it is accepted only if every other field of the record matches |
| + (v 1, this group's ARN, this hook, documented_no_hook true), the |
| + observation's template and the pinned template have the same |
| + LaunchTemplateId and LaunchTemplateName, and their Versions are |
| + different version numbers; and |
| +3. both versions are read from the provider (`template_data`, journaled as |
| + reads like `template_release`) and their launch template data are |
| + identical once `UserData` is removed: the AMI, the instance type, the |
| + network interfaces and security groups, the IAM instance profile, the |
| + metadata options, the block devices, tags and every other field. The |
| + comparison covers both the SDK's decoded fields and the answer's own |
| + `launchTemplateData` XML in a canonical form without `userData`, so a |
| + field the SDK does not know (and its decoder skips) still shows as a |
| + difference. The group's lifecycle hook is checked as before (`hook`), |
| + and the group ARN ties the record to this group. ASG-level settings |
| + outside the launch template are not compared, as they never were for |
| + the exact-template record. |
| +4. Anything else (a different template, a field that differs, a version |
| + that cannot be read) refuses `observation`, or is the read's own |
| + Uncertain, as today. Nothing is written: the controller still places |
| + the record by hand, and the carried acceptance is re-derived on every |
| + run from the two journaled reads. |
| + |
| +`probe start` is unchanged: it still needs a member running the pinned |
| +template, and its record names that version. |
| + |
| ## 8. Serialization: one machine and account per deployment (D6) |
| Rev 2 added a claim object in the deployment bucket so any machine could run the |
diff --git a/internal/grouproll/engine.go b/internal/grouproll/engine.go| index a6c795c19..e676314f2 100644 |
| --- a/internal/grouproll/engine.go |
| +++ b/internal/grouproll/engine.go |
| @@ -856,6 +856,72 @@ func (e *Engine) observationOK(obs any, template map[string]any) bool { |
| "template": normalTemplate(template), "documented_no_hook": true}) |
| } |
| +// observationAccepted is preflight's and plan's observation rule (spec |
| +// §7.1, V19): the record names the pinned template exactly, or it carries |
| +// across a re-pin that changed only user data. Carrying needs every other |
| +// field of the record to match, the same template id and name with another |
| +// version number, and the two versions' launch template data, read now and |
| +// journaled, identical once their user data is removed. Nothing is |
| +// written; the acceptance is re-derived on every run. |
| +func (e *Engine) observationAccepted(ctx context.Context, obs any, tpl map[string]any) (bool, error) { |
| + if e.observationOK(obs, tpl) { |
| + return true, nil |
| + } |
| + rec, ok := obs.(map[string]any) |
| + if !ok || tpl == nil { |
| + return false, nil |
| + } |
| + old, ok := rec["template"].(map[string]any) |
| + if !ok || len(old) != 3 || len(tpl) != 3 { |
| + return false, nil |
| + } |
| + for _, k := range []string{"LaunchTemplateId", "LaunchTemplateName"} { |
| + a, aok := old[k].(string) |
| + b, bok := tpl[k].(string) |
| + if !aok || !bok || a == "" || a != b { |
| + return false, nil |
| + } |
| + } |
| + ov, _ := old["Version"].(string) |
| + nv, _ := tpl["Version"].(string) |
| + if !templateVersion.MatchString(ov) || !templateVersion.MatchString(nv) || ov == nv { |
| + return false, nil |
| + } |
| + swapped := make(map[string]any, len(rec)) |
| + for k, v := range rec { |
| + swapped[k] = v |
| + } |
| + swapped["template"] = tpl |
| + if !e.observationOK(swapped, tpl) { |
| + return false, nil |
| + } |
| + was, err := e.templateData(ctx, old) |
| + if err != nil { |
| + return false, err |
| + } |
| + now, err := e.templateData(ctx, tpl) |
| + if err != nil { |
| + return false, err |
| + } |
| + return was != nil && now != nil && pyEqual(was, now), nil |
| +} |
| + |
| +// templateData is one journaled read of a template version's data without |
| +// its user data (op template_data, a read like template_release). |
| +func (e *Engine) templateData(ctx context.Context, tpl map[string]any) (map[string]any, error) { |
| + var data map[string]any |
| + _, err := e.call(ctx, "template_data", map[string]any{"template": tpl}, time.Time{}, |
| + func(ctx context.Context, _ func(string)) (any, error) { |
| + d, err := e.g.TemplateData(ctx, tpl) |
| + if err != nil { |
| + return nil, err |
| + } |
| + data = d |
| + return d, nil |
| + }) |
| + return data, err |
| +} |
| + |
| func normalTemplate(t map[string]any) any { |
| if t == nil { |
| return nil |
| @@ -928,7 +994,11 @@ func (e *Engine) preflight(ctx context.Context, iid, digest string) (snapshotVie |
| if err != nil { |
| return snapshotView{}, nil, refuse("observation") |
| } |
| - if !e.observationOK(obs, snap.View.Template) { |
| + accepted, err := e.observationAccepted(ctx, obs, snap.View.Template) |
| + if err != nil { |
| + return snapshotView{}, nil, err |
| + } |
| + if !accepted { |
| return snapshotView{}, nil, refuse("observation") |
| } |
| e.memberEdges = map[string]map[string]any{} |
diff --git a/internal/grouproll/fake_test.go b/internal/grouproll/fake_test.go| index b465620cb..0b4a24201 100644 |
| --- a/internal/grouproll/fake_test.go |
| +++ b/internal/grouproll/fake_test.go |
| @@ -93,6 +93,8 @@ type fake struct { |
| targetWarmup time.Duration |
| targetReadyAt *time.Time |
| templateRelease string |
| + templateData map[string]map[string]any // by version; default the same data for every version |
| + pinned map[string]any // the group's pinned template; nil is fakeTemplate |
| userID string |
| writes []string |
| @@ -412,6 +414,9 @@ func (f *fake) view() GroupView { |
| Template: copyArgs(fakeTemplate), |
| TargetGroups: append([]string(nil), f.c.TargetGroups...), |
| } |
| + if f.pinned != nil { |
| + g.Template = copyArgs(f.pinned) |
| + } |
| for _, iid := range f.order { |
| if raw, ok := f.states[iid]; ok && raw != "Terminated" { |
| g.Members[iid] = Member{Phase: f.phaseOf(raw), Raw: raw, Healthy: true} |
| @@ -528,6 +533,20 @@ func (f *fake) TemplateRelease(ctx context.Context, tpl map[string]any) (string, |
| return r.(string), nil |
| } |
| +func (f *fake) TemplateData(ctx context.Context, tpl map[string]any) (map[string]any, error) { |
| + r, err := f.request("template_data", map[string]any{"template": tpl}, func() (any, error) { |
| + v, _ := tpl["Version"].(string) |
| + if d, ok := f.templateData[v]; ok { |
| + return d, nil |
| + } |
| + return map[string]any{"ImageId": "ami-0123", "InstanceType": "t4g.small"}, nil |
| + }) |
| + if err != nil { |
| + return nil, err |
| + } |
| + return r.(map[string]any), nil |
| +} |
| + |
| func (f *fake) SetMinimum(ctx context.Context, n int) (WriteResult, error) { |
| r, err := f.request("minimum", map[string]any{"value": n}, func() (any, error) { |
| f.minimum = n |
diff --git a/internal/grouproll/observation_carry_test.go b/internal/grouproll/observation_carry_test.go| new file mode 100644 |
| index 000000000..a851cd75c |
| --- /dev/null |
| +++ b/internal/grouproll/observation_carry_test.go |
| @@ -0,0 +1,129 @@ |
| +package grouproll |
| + |
| +import ( |
| + "reflect" |
| + "testing" |
| +) |
| + |
| +// repinned pins the fake group to fakeTemplate's version 2: the harness's |
| +// observation still names version 1. |
| +func repinned(h *harness) { |
| + p := copyArgs(fakeTemplate) |
| + p["Version"] = "2" |
| + h.f.pinned = p |
| +} |
| + |
| +func templateDataReads(h *harness) []any { |
| + var vs []any |
| + for _, r := range h.planLog().Rows() { |
| + if r["kind"] == "intent" && r["op"] == "template_data" { |
| + vs = append(vs, r["args"].(map[string]any)["template"].(map[string]any)["Version"]) |
| + } |
| + } |
| + return vs |
| +} |
| + |
| +// V19 (spec §7.1): after a re-pin that changed only user data, the |
| +// observation for the old version carries, proved by reading both |
| +// versions; plan is clean and both reads are journaled. |
| +func TestObservationCarriesUserDataOnlyRepin(t *testing.T) { |
| + h := newHarness(t, 2) |
| + repinned(h) |
| + ok, err := h.plan(fakeIID, newSHA) |
| + if err != nil || !ok { |
| + t.Fatalf("plan = %v, %v; refusals %v", ok, err, refusalsOf(t, h.planLog())) |
| + } |
| + if got := templateDataReads(h); !reflect.DeepEqual(got, []any{"1", "2"}) { |
| + t.Fatalf("template_data reads %v, want the observation's version then the pinned one", got) |
| + } |
| + // The same template, unchanged: no extra read. |
| + h = newHarness(t, 2) |
| + if ok, err := h.plan(fakeIID, newSHA); err != nil || !ok || len(templateDataReads(h)) != 0 { |
| + t.Fatalf("exact template: %v, %v, reads %v", ok, err, templateDataReads(h)) |
| + } |
| +} |
| + |
| +// Anything but user data differing refuses observation, as before. |
| +func TestObservationCarryRefusals(t *testing.T) { |
| + cases := []struct { |
| + name string |
| + setup func(h *harness) |
| + reads int |
| + }{ |
| + {"other AMI", func(h *harness) { |
| + repinned(h) |
| + h.f.templateData = map[string]map[string]any{"2": {"ImageId": "ami-other", "InstanceType": "t4g.small"}} |
| + }, 2}, |
| + {"extra field", func(h *harness) { |
| + repinned(h) |
| + h.f.templateData = map[string]map[string]any{"2": {"ImageId": "ami-0123", "InstanceType": "t4g.small", "KeyName": "k"}} |
| + }, 2}, |
| + {"other template id", func(h *harness) { |
| + p := copyArgs(fakeTemplate) |
| + p["Version"], p["LaunchTemplateId"] = "2", "lt-0fedcba9876543210" |
| + h.f.pinned = p |
| + }, 0}, |
| + {"other template name", func(h *harness) { |
| + p := copyArgs(fakeTemplate) |
| + p["Version"], p["LaunchTemplateName"] = "2", "other-group" |
| + h.f.pinned = p |
| + }, 0}, |
| + {"record for another hook", func(h *harness) { |
| + repinned(h) |
| + h.withLock(func() { |
| + if err := h.state.Write(h.state.ObservationPath(), map[string]any{"v": 1, "group_arn": h.c.GroupARN, |
| + "hook": "other-hook", "template": copyArgs(fakeTemplate), "documented_no_hook": true}); err != nil { |
| + h.t.Fatal(err) |
| + } |
| + }) |
| + }, 0}, |
| + } |
| + for _, c := range cases { |
| + t.Run(c.name, func(t *testing.T) { |
| + h := newHarness(t, 2) |
| + c.setup(h) |
| + ok, err := h.plan(fakeIID, newSHA) |
| + if err != nil || ok { |
| + t.Fatalf("plan = %v, %v", ok, err) |
| + } |
| + if rs := refusalsOf(t, h.planLog()); !reflect.DeepEqual(rs, []string{Text("observation")}) { |
| + t.Fatalf("refusals %v, want observation only", rs) |
| + } |
| + if n := len(templateDataReads(h)); n != c.reads { |
| + t.Fatalf("template_data reads %d, want %d", n, c.reads) |
| + } |
| + }) |
| + } |
| + // A read that fails is the read's own answer, never a carried record. |
| + h := newHarness(t, 2) |
| + repinned(h) |
| + h.f.before = func(op string, _ map[string]any) error { |
| + if op == "template_data" { |
| + return Uncertain{Key: "api"} |
| + } |
| + return nil |
| + } |
| + if ok, err := h.plan(fakeIID, newSHA); err != nil || ok { |
| + t.Fatalf("plan = %v, %v", ok, err) |
| + } |
| + if rs := refusalsOf(t, h.planLog()); !reflect.DeepEqual(rs, []string{Text("api")}) { |
| + t.Fatalf("refusals %v, want api", rs) |
| + } |
| +} |
| + |
| +// The roll's preflight carries the observation too, and refuses before |
| +// any group write when the data differ. |
| +func TestPreflightObservationCarry(t *testing.T) { |
| + h := newHarness(t, 2) |
| + repinned(h) |
| + h.f.templateData = map[string]map[string]any{"2": {"ImageId": "ami-other", "InstanceType": "t4g.small"}} |
| + err := h.runRoll() |
| + if r, ok := err.(Refusal); !ok || r.Key != "observation" || len(h.f.writes) != 0 { |
| + t.Fatalf("roll = %v, writes %v", err, h.f.writes) |
| + } |
| + h = newHarness(t, 2) |
| + repinned(h) |
| + if err := h.runRoll(); err != nil { |
| + t.Fatalf("roll with a carried observation: %v", err) |
| + } |
| +} |
diff --git a/internal/grouproll/plan.go b/internal/grouproll/plan.go| index fc30c23e7..37416a36b 100644 |
| --- a/internal/grouproll/plan.go |
| +++ b/internal/grouproll/plan.go |
| @@ -117,7 +117,11 @@ func (e *Engine) Plan(ctx context.Context, iid, sha string) (ok bool, err error) |
| if err != nil { |
| return refuse("observation") |
| } |
| - return require(e.observationOK(obs, snap.View.Template), "observation")() |
| + accepted, err := e.observationAccepted(ctx, obs, snap.View.Template) |
| + if err != nil { |
| + return err |
| + } |
| + return require(accepted, "observation")() |
| }) |
| for _, m := range sortedMembers(snap.View) { |
| var on bool |
diff --git a/internal/grouproll/provider.go b/internal/grouproll/provider.go| index 6490a7fe9..924f2f733 100644 |
| --- a/internal/grouproll/provider.go |
| +++ b/internal/grouproll/provider.go |
| @@ -100,6 +100,10 @@ type Group interface { |
| Membership(ctx context.Context, iid string) (row MemberRow, found bool, err error) |
| Instance(ctx context.Context, iid string) (InstanceState, error) |
| TemplateRelease(ctx context.Context, tpl map[string]any) (string, error) |
| + // TemplateData is the launch template version's data with its user data |
| + // removed (spec §7.1): what must be identical for the provider |
| + // observation to carry across a re-pin. |
| + TemplateData(ctx context.Context, tpl map[string]any) (map[string]any, error) |
| SetMinimum(ctx context.Context, n int) (WriteResult, error) |
| RaiseDesired(ctx context.Context, n int) (WriteResult, error) |
| Park(ctx context.Context, iid string) (WriteResult, error) |
diff --git a/internal/grouproll/text_test.go b/internal/grouproll/text_test.go| index 5990d811a..37b8617c3 100644 |
| --- a/internal/grouproll/text_test.go |
| +++ b/internal/grouproll/text_test.go |
| @@ -16,7 +16,9 @@ func TestTextRendersEveryKey(t *testing.T) { |
| // floor_fixed_both, drain_peers_many, floor_legacy and floor_population |
| // (held floor capability, 2026-11-10), and bucket_region (a bucket in |
| // another region than the group, 2026-11-10), and remote_said (the |
| - // member's own refusal, 2026-11-11), not yet copy-reviewed. |
| + // member's own refusal, 2026-11-11); bucket_region, remote_said and the |
| + // fixed remove_minimum approved in copy review 2026-11-11 (Paul, |
| + // unchanged). |
| if len(text) != 147 { |
| t.Fatalf("text has %d keys, want the 139 approved plus 8", len(text)) |
| } |
diff --git a/internal/grouprollaws/group.go b/internal/grouprollaws/group.go| index 511b93a02..e1cc0a086 100644 |
| --- a/internal/grouprollaws/group.go |
| +++ b/internal/grouprollaws/group.go |
| @@ -5,12 +5,15 @@ import ( |
| "compress/gzip" |
| "context" |
| "encoding/base64" |
| + "encoding/json" |
| + "encoding/xml" |
| "errors" |
| "io" |
| "math" |
| "math/rand/v2" |
| "net" |
| "regexp" |
| + "sort" |
| "strconv" |
| "strings" |
| "sync" |
| @@ -640,6 +643,160 @@ func (a *Adapter) TemplateRelease(ctx context.Context, tpl map[string]any) (stri |
| return found[0][1], nil |
| } |
| +// TemplateData is one launch template version's data as the provider |
| +// describes it, with UserData removed (spec §7.1): the evidence that two |
| +// versions differ only in the release they boot. The SDK's decoder skips |
| +// XML elements it does not know (Astra r1), so the map carries, beside |
| +// the decoded fields, the answer's own launchTemplateData element in a |
| +// canonical form without userData ("LaunchTemplateDataXML"): a field this |
| +// SDK does not know still shows as a difference. |
| +func (a *Adapter) TemplateData(ctx context.Context, tpl map[string]any) (map[string]any, error) { |
| + version, ok := tpl["Version"].(string) |
| + if tpl == nil || !ok { |
| + return nil, grouproll.Refusal{Key: "scope"} |
| + } |
| + in := &ec2.DescribeLaunchTemplateVersionsInput{Versions: []string{version}} |
| + if id, _ := tpl["LaunchTemplateId"].(string); id != "" { |
| + in.LaunchTemplateId = aws.String(id) |
| + } else { |
| + name, _ := tpl["LaunchTemplateName"].(string) |
| + in.LaunchTemplateName = aws.String(name) |
| + } |
| + var body []byte |
| + out, err := readCall(ctx, func(ctx context.Context) (*ec2.DescribeLaunchTemplateVersionsOutput, error) { |
| + body = nil |
| + return a.ec2.DescribeLaunchTemplateVersions(ctx, in, func(o *ec2.Options) { |
| + o.APIOptions = append(o.APIOptions, func(st *middleware.Stack) error { |
| + return st.Deserialize.Add(captureBody(&body), middleware.After) |
| + }) |
| + }) |
| + }) |
| + if err != nil { |
| + return nil, err |
| + } |
| + rows := out.LaunchTemplateVersions |
| + if len(rows) != 1 || rows[0].VersionNumber == nil || strconv.FormatInt(*rows[0].VersionNumber, 10) != version || |
| + rows[0].LaunchTemplateData == nil { |
| + return nil, malformed() |
| + } |
| + canonical, ok := launchDataXML(body) |
| + if !ok { |
| + return nil, malformed() |
| + } |
| + if id, _ := tpl["LaunchTemplateId"].(string); id != "" && aws.ToString(rows[0].LaunchTemplateId) != id { |
| + return nil, malformed() |
| + } |
| + data := *rows[0].LaunchTemplateData |
| + data.UserData = nil |
| + raw, err := json.Marshal(data) |
| + if err != nil { |
| + return nil, malformed() |
| + } |
| + dec := json.NewDecoder(bytes.NewReader(raw)) |
| + dec.UseNumber() |
| + var m map[string]any |
| + if err := dec.Decode(&m); err != nil || m == nil { |
| + return nil, malformed() |
| + } |
| + delete(m, "UserData") |
| + m["LaunchTemplateDataXML"] = canonical |
| + return m, nil |
| +} |
| + |
| +// captureBody keeps the raw answer (at most outputCap bytes) for the |
| +// caller and hands the operation's deserializer the same bytes. |
| +func captureBody(dst *[]byte) middleware.DeserializeMiddleware { |
| + return middleware.DeserializeMiddlewareFunc("CarlosCaptureBody", func(ctx context.Context, |
| + in middleware.DeserializeInput, next middleware.DeserializeHandler) (middleware.DeserializeOutput, middleware.Metadata, error) { |
| + out, md, err := next.HandleDeserialize(ctx, in) |
| + if err != nil { |
| + return out, md, err |
| + } |
| + r, ok := out.RawResponse.(*smithyhttp.Response) |
| + if !ok || r == nil || r.Response == nil || r.Body == nil { |
| + return out, md, err |
| + } |
| + b, rerr := io.ReadAll(io.LimitReader(r.Body, outputCap+1)) |
| + r.Body.Close() |
| + if rerr != nil { |
| + return out, md, rerr |
| + } |
| + if len(b) > outputCap { |
| + return out, md, errOutputTooLarge |
| + } |
| + *dst = b |
| + r.Body = io.NopCloser(bytes.NewReader(b)) |
| + return out, md, nil |
| + }) |
| +} |
| + |
| +// launchDataXML is the single answered version's launchTemplateData |
| +// element, canonical: element local names, attributes sorted, text with |
| +// whitespace-only runs dropped, and its direct userData child removed. |
| +// Two versions that differ in any other element, known to this SDK or |
| +// not, give different strings. |
| +func launchDataXML(body []byte) (string, bool) { |
| + dec := xml.NewDecoder(bytes.NewReader(body)) |
| + var path []string |
| + var b strings.Builder |
| + found, depth, skip := 0, 0, 0 |
| + for { |
| + tok, err := dec.Token() |
| + if err == io.EOF { |
| + break |
| + } |
| + if err != nil { |
| + return "", false |
| + } |
| + switch t := tok.(type) { |
| + case xml.StartElement: |
| + path = append(path, t.Name.Local) |
| + if depth == 0 && strings.Join(path, "/") == "DescribeLaunchTemplateVersionsResponse/launchTemplateVersionSet/item/launchTemplateData" { |
| + found++ |
| + depth = 1 |
| + continue |
| + } |
| + if depth > 0 { |
| + depth++ |
| + if skip > 0 || (depth == 2 && t.Name.Local == "userData") { |
| + skip++ |
| + continue |
| + } |
| + attrs := make([]string, 0, len(t.Attr)) |
| + for _, a := range t.Attr { |
| + attrs = append(attrs, a.Name.Local+"="+strconv.Quote(a.Value)) |
| + } |
| + sort.Strings(attrs) |
| + b.WriteString("<" + t.Name.Local) |
| + for _, a := range attrs { |
| + b.WriteString(" " + a) |
| + } |
| + b.WriteString(">") |
| + } |
| + case xml.EndElement: |
| + if len(path) > 0 { |
| + path = path[:len(path)-1] |
| + } |
| + if depth > 0 { |
| + depth-- |
| + if depth == 0 { |
| + continue |
| + } |
| + if skip > 0 { |
| + skip-- |
| + continue |
| + } |
| + b.WriteString("</" + t.Name.Local + ">") |
| + } |
| + case xml.CharData: |
| + if depth > 1 && skip == 0 && strings.TrimSpace(string(t)) != "" { |
| + b.WriteString(strconv.Quote(string(t))) |
| + } |
| + } |
| + } |
| + return b.String(), found == 1 |
| +} |
| + |
| func int32Of(n int) (int32, bool) { |
| if n < 0 || n > math.MaxInt32 { |
| return 0, false |
diff --git a/internal/grouprollaws/group_test.go b/internal/grouprollaws/group_test.go| index 3b871d33f..c742437f3 100644 |
| --- a/internal/grouprollaws/group_test.go |
| +++ b/internal/grouprollaws/group_test.go |
| @@ -516,10 +516,11 @@ func TestWriteShapes(t *testing.T) { |
| sort.Strings(names) |
| // Run, CancelSession and CheckPlugin (session.go) are the Session |
| // Manager transport: none touches the group's capacity. |
| - // Bucket (objects.go) is a read-only object store. |
| + // Bucket (objects.go) is a read-only object store. TemplateData is a |
| + // DescribeLaunchTemplateVersions read (spec §7.1). |
| want := []string{"Activities", "Bucket", "CallerIdentity", "CancelSession", "CheckPlugin", "Describe", "Hook", |
| "Instance", "Membership", "Online", "Park", "RaiseDesired", "Run", "SetMinimum", "Targets", |
| - "TemplateRelease", "Terminate", "Unpark"} |
| + "TemplateData", "TemplateRelease", "Terminate", "Unpark"} |
| if !reflect.DeepEqual(names, want) { |
| t.Fatalf("Adapter methods = %v\nwant %v", names, want) |
| } |
| @@ -545,3 +546,90 @@ func TestCallerIdentity(t *testing.T) { |
| t.Fatalf("no UserId: %v", err) |
| } |
| } |
| + |
| +// TemplateData is the version's launch template data without UserData, |
| +// every other field kept (spec §7.1): two versions that differ only in user |
| +// data compare equal, any other field shows. |
| +func TestTemplateData(t *testing.T) { |
| + xml := func(version, extra string) string { |
| + return `<DescribeLaunchTemplateVersionsResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/"><requestId>r</requestId><launchTemplateVersionSet><item><launchTemplateId>lt-0abc</launchTemplateId><versionNumber>` + |
| + version + `</versionNumber><launchTemplateData><imageId>ami-0123</imageId><instanceType>t4g.small</instanceType>` + extra + |
| + `<userData>` + base64.StdEncoding.EncodeToString([]byte("CARLOS_RELEASE='v"+version+"'")) + `</userData></launchTemplateData></item></launchTemplateVersionSet></DescribeLaunchTemplateVersionsResponse>` |
| + } |
| + tpl := func(v string) map[string]any { |
| + return map[string]any{"LaunchTemplateId": "lt-0abc", "LaunchTemplateName": "carlos-dev", "Version": v} |
| + } |
| + rec := newRecorder().on("DescribeLaunchTemplateVersions", xml("7", "")).on("DescribeLaunchTemplateVersions", xml("8", "")) |
| + a := testAdapter(t, rec) |
| + d7, err := a.TemplateData(ctx, tpl("7")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + d8, err := a.TemplateData(ctx, tpl("8")) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, ok := d7["UserData"]; ok || d7["ImageId"] != "ami-0123" || d7["InstanceType"] != "t4g.small" { |
| + t.Fatalf("data %v", d7) |
| + } |
| + if !reflect.DeepEqual(d7, d8) { |
| + t.Fatalf("user data only differs, yet %v != %v", d7, d8) |
| + } |
| + q := rec.requests() |
| + if q[0].Form.Get("LaunchTemplateId") != "lt-0abc" || q[0].Form.Get("LaunchTemplateVersion.1") != "7" { |
| + t.Fatalf("request %+v", q[0].Form) |
| + } |
| + // Another field differs: the maps differ. |
| + d9, err := testAdapter(t, newRecorder().on("DescribeLaunchTemplateVersions", xml("9", "<keyName>k</keyName>"))).TemplateData(ctx, tpl("9")) |
| + if err != nil || reflect.DeepEqual(d7, d9) || d9["KeyName"] != "k" { |
| + t.Fatalf("key name: %v, %v", d9, err) |
| + } |
| + // The wrong version, or another template's answer, is malformed. |
| + if _, err := testAdapter(t, newRecorder().on("DescribeLaunchTemplateVersions", xml("8", ""))).TemplateData(ctx, tpl("7")); uncertainKey(t, err).Key != "api" { |
| + t.Fatalf("wrong version: %v", err) |
| + } |
| + other := strings.Replace(xml("7", ""), "lt-0abc", "lt-0def", 1) |
| + if _, err := testAdapter(t, newRecorder().on("DescribeLaunchTemplateVersions", other)).TemplateData(ctx, tpl("7")); uncertainKey(t, err).Key != "api" { |
| + t.Fatalf("other template: %v", err) |
| + } |
| +} |
| + |
| +// A field this SDK does not know is skipped by its decoder, but it still |
| +// shows in TemplateData through the canonical launchTemplateData XML |
| +// (Astra r1): two versions differing only there are not equal. Layout |
| +// alone (whitespace between elements, attribute order) is not a |
| +// difference, and userData never is. |
| +func TestTemplateDataUnknownField(t *testing.T) { |
| + resp := func(version, data string) string { |
| + return `<DescribeLaunchTemplateVersionsResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/"><requestId>r</requestId><launchTemplateVersionSet><item><launchTemplateId>lt-0abc</launchTemplateId><versionNumber>` + |
| + version + `</versionNumber><launchTemplateData>` + data + `</launchTemplateData></item></launchTemplateVersionSet></DescribeLaunchTemplateVersionsResponse>` |
| + } |
| + get := func(version, data string) map[string]any { |
| + t.Helper() |
| + d, err := testAdapter(t, newRecorder().on("DescribeLaunchTemplateVersions", resp(version, data))).TemplateData(ctx, |
| + map[string]any{"LaunchTemplateId": "lt-0abc", "LaunchTemplateName": "carlos-dev", "Version": version}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return d |
| + } |
| + base := get("7", `<imageId>ami-0123</imageId><userData>QQ==</userData>`) |
| + same := get("8", "\n <imageId>ami-0123</imageId>\n <userData>Qg==</userData>\n") |
| + if !reflect.DeepEqual(base, same) { |
| + t.Fatalf("layout and user data only, yet %v != %v", base, same) |
| + } |
| + future := get("9", `<imageId>ami-0123</imageId><futureSetting>on</futureSetting><userData>QQ==</userData>`) |
| + if reflect.DeepEqual(base, future) { |
| + t.Fatalf("an unknown field went unseen: %v", future) |
| + } |
| + if base["LaunchTemplateDataXML"] != `<imageId>"ami-0123"</imageId>` { |
| + t.Fatalf("canonical %q", base["LaunchTemplateDataXML"]) |
| + } |
| + // Two answered versions, or none, is malformed. |
| + two := strings.Replace(resp("7", `<imageId>a</imageId>`), "</launchTemplateVersionSet>", |
| + `<item><launchTemplateData><imageId>b</imageId></launchTemplateData></item></launchTemplateVersionSet>`, 1) |
| + if _, err := testAdapter(t, newRecorder().on("DescribeLaunchTemplateVersions", two)).TemplateData(ctx, |
| + map[string]any{"LaunchTemplateId": "lt-0abc", "LaunchTemplateName": "carlos-dev", "Version": "7"}); uncertainKey(t, err).Key != "api" { |
| + t.Fatalf("two items: %v", err) |
| + } |
| +} |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index c67be335f..5be457e16 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -169,3 +169,4 @@ plan14-root-reads-group-capacity-damping.tsv 0c649af234a7b89a75479e59e705307e329 |
| plan14-root-reads-group-verb-followups.tsv 9c74b9876a13a3a3802860fe44406898c8bcbfd3bd22e8172a59a02674c3b4af |
| plan14-root-reads-group-read-transport-retry.tsv 9c74b9876a13a3a3802860fe44406898c8bcbfd3bd22e8172a59a02674c3b4af |
| plan14-root-reads-linked-deployments-slice1.tsv 40c8459580c3e62a53637e9989f1616e5735ce78796ec6ea1b22655a5eb4ad63 |
| +plan14-root-reads-group-observation-carry.tsv 9cc09223a67041265c64d3918821b30ea3fa064e81f9dc8ec95af2b653e8f3af |
diff --git a/internal/provision/testdata/plan14-root-reads-group-observation-carry.tsv b/internal/provision/testdata/plan14-root-reads-group-observation-carry.tsv| new file mode 100644 |
| index 000000000..ac7e4be58 |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-group-observation-carry.tsv |
| @@ -0,0 +1,8 @@ |
| +# Census overlay group-observation-carry, written by census-propose (#369). census-ruling-group-observation-carry, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-group-observation-carry.md. |
| +# 2 body, 0 sites, 2 envelope: each changed unit re-frozen at its existing disposition with its claim appended. |
| +@legacy e6723f485e963b2299144956c0e14997fd81558fded6f664a9838d4abb2cc7ae internal/grouproll/engine.go Engine.preflight legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=reads provider-observation.json from the operator's own 0700 state directory;rev3=census-ruling-group-observation-carry;basis=the same provider-observation.json read; when it names another version of the same launch template, the two versions are read from the provider (template_data, a DescribeLaunchTemplateVersions read through the adapter) and compared without user data; no new file read, nothing written file:Read@713 34851c542471ef3c75b164bd80bb63d060902ed74c438a8202af5b20684b8c48 |
| +@legacy 0732aca0e25ff830a56a0ad177aa86507e3cf14d94db509e26514a90f92aa1cf internal/grouproll/plan.go Engine.Plan legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=reads provider-observation.json from the operator's own 0700 state directory;rev3=census-ruling-group-verb-followups;basis=a missing or unreadable provider-observation.json is refused as observation instead of passing the read error through (same file, same read);rev3=census-ruling-group-observation-carry;basis=the same observation read and the same carry-over rule as preflight (two template_data provider reads); no new file read, nothing written file:Read@2300 e31735a42c7a49724f503b59406ced05c5e6d39038d8135b34c0ae463b36b415 |
| +internal/grouproll/engine.go Engine.preflight legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=reads provider-observation.json from the operator's own 0700 state directory;rev3=census-ruling-group-observation-carry;basis=the same provider-observation.json read; when it names another version of the same launch template, the two versions are read from the provider (template_data, a DescribeLaunchTemplateVersions read through the adapter) and compared without user data; no new file read, nothing written file:Read@713 34851c542471ef3c75b164bd80bb63d060902ed74c438a8202af5b20684b8c48 |
| +internal/grouproll/plan.go Engine.Plan legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=reads provider-observation.json from the operator's own 0700 state directory;rev3=census-ruling-group-verb-followups;basis=a missing or unreadable provider-observation.json is refused as observation instead of passing the read error through (same file, same read);rev3=census-ruling-group-observation-carry;basis=the same observation read and the same carry-over rule as preflight (two template_data provider reads); no new file read, nothing written file:Read@2300 e31735a42c7a49724f503b59406ced05c5e6d39038d8135b34c0ae463b36b415 |
| +@coverage internal/grouproll d0decee68f572b1fc022493d7721f5efdba74ddfe9b1438f78cf3aee716405c0 |
| +@coverage internal/grouprollaws 5f62b555afee15c7dd70c40d8b3337481fab36fc65818ad0504eef408ac38bb5 |