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 comparison is exact: the raw launchTemplateData bytes must match with only the direct userData element cut by its byte span. Any other difference (an unknown field, whitespace, layout), a malformed answer, a second item or a second userData refuses observation, nothing is written, and the release falls back to today's pin-back. The raw bytes come from boundBody's existing bounded read. The new test file carries the linux || darwin tag its harness has. Spec V19 and section 7.1 (Paul approved option b, 2026-11-11); census proposal updated. Reviewed by Astra (two rounds) and Fable (r1 ready, no P1/P2; P3-2/3/4 applied). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Squashed from group-observation-carry into main. Co-Authored-By: claude <claude~paul@keymail.dev>
12 files changed,
+593
−5
docs/superpowers/notes/census-proposal-group-observation-carry.md+23 −0docs/superpowers/specs/2026-11-09-group-roll-verb-design.md+40 −0internal/grouproll/engine.go+71 −1internal/grouproll/fake_test.go+19 −0internal/grouproll/observation_carry_test.go+131 −0internal/grouproll/plan.go+5 −1internal/grouproll/provider.go+4 −0internal/grouprollaws/group.go+152 −0internal/grouprollaws/group_test.go+125 −2internal/grouprollaws/transport.go+12 −1internal/provision/testdata/plan14-root-reads-chain.tsv+1 −0internal/provision/testdata/plan14-root-reads-group-observation-carry.tsv+10 −0
CI cancelled — superseded by a newer push — run details
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..68d776061 |
| --- /dev/null |
| +++ b/docs/superpowers/notes/census-proposal-group-observation-carry.md |
| @@ -0,0 +1,23 @@ |
| +# 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 | |
| +| `internal/grouprollaws/transport.go` `boundBody.HandleDeserialize` | body | unchanged (1) | the same bounded read of the AWS answer; the buffered bytes are kept on a typed body (bufferedBody) so TemplateData can compare the raw launchTemplateData without a second read; no new read | |
| + |
| +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) |
| +- `internal/grouprollaws/transport.go` `boundBody.HandleDeserialize`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-group-roll-verb;basis=reads an AWS API answer body under the 4 MiB cap |
| + |
| +Seal: `75b32391a24d2c9269fc579aae68ac80b7b1d4ccf0be55f0373490e43a2a652a` → `587f6e92c5e594b9bb6436a2d0066849454407202e311f43483bed3be4591940`. |
| + |
| +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..78ea8b7fe 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,45 @@ 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 byte for byte, with only its direct `userData` |
| + child element cut out by its byte span: no canonical form, so a field |
| + the SDK does not know (and its decoder skips), its whitespace or any |
| + layout difference refuses. A malformed answer, a second item or a |
| + second `userData` refuses too; the cost of a false refusal is the |
| + pin-back, as before. 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..16ccf79be |
| --- /dev/null |
| +++ b/internal/grouproll/observation_carry_test.go |
| @@ -0,0 +1,131 @@ |
| +//go:build linux || darwin |
| + |
| +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/grouprollaws/group.go b/internal/grouprollaws/group.go| index 511b93a02..62ca5c3fa 100644 |
| --- a/internal/grouprollaws/group.go |
| +++ b/internal/grouprollaws/group.go |
| @@ -5,6 +5,8 @@ import ( |
| "compress/gzip" |
| "context" |
| "encoding/base64" |
| + "encoding/json" |
| + "encoding/xml" |
| "errors" |
| "io" |
| "math" |
| @@ -640,6 +642,156 @@ 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 beside the decoded fields |
| +// the map carries the answer's own launchTemplateData element, byte for |
| +// byte with only its userData element cut ("LaunchTemplateDataXML"): any |
| +// other difference, a field this SDK does not know included, shows. |
| +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 { |
| + // Just outside boundBody, which has read the whole answer. |
| + return st.Deserialize.Insert(captureBody(&body), boundBodyID, middleware.Before) |
| + }) |
| + }) |
| + }) |
| + 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() |
| + } |
| + exact, 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"] = exact |
| + return m, nil |
| +} |
| + |
| +// captureBody keeps the answer boundBody read (its bufferedBody's bytes) |
| +// for the caller. An answer that is not a bufferedBody is left alone, and |
| +// TemplateData then finds no launchTemplateData and refuses as malformed. |
| +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 |
| + } |
| + if r, ok := out.RawResponse.(*smithyhttp.Response); ok && r != nil && r.Response != nil { |
| + if b, ok := r.Body.(*bufferedBody); ok { |
| + *dst = b.data |
| + } |
| + } |
| + return out, md, nil |
| + }) |
| +} |
| + |
| +// launchDataXML is the single answered version's launchTemplateData |
| +// element exactly as the provider sent it, byte for byte, with only its |
| +// direct userData child element cut out by its byte span (8a3d302, |
| +// 2026-11-11, after Astra r2): no canonical form, so any other difference |
| +// (a field this SDK does not know, its whitespace, CDATA, namespaces) |
| +// refuses. A second launchTemplateData, a second direct userData, or an |
| +// answer that is not well formed is not one ("", false). |
| +func launchDataXML(body []byte) (string, bool) { |
| + dec := xml.NewDecoder(bytes.NewReader(body)) |
| + var path []string |
| + found, depth := 0, 0 |
| + var start, end, udStart int64 = -1, -1, -1 |
| + var cuts [][2]int64 |
| + for { |
| + before := dec.InputOffset() |
| + 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++ |
| + // From the start tag itself, so its attributes count too |
| + // (Fable P3-2). |
| + depth, start = 1, before |
| + continue |
| + } |
| + if depth > 0 { |
| + depth++ |
| + if depth == 2 && t.Name.Local == "userData" { |
| + if len(cuts) > 0 || udStart >= 0 { |
| + return "", false |
| + } |
| + udStart = before |
| + } |
| + } |
| + case xml.EndElement: |
| + if len(path) > 0 { |
| + path = path[:len(path)-1] |
| + } |
| + if depth > 0 { |
| + depth-- |
| + if depth == 1 && udStart >= 0 { |
| + cuts = append(cuts, [2]int64{udStart, dec.InputOffset()}) |
| + udStart = -1 |
| + } |
| + if depth == 0 { |
| + end = dec.InputOffset() |
| + } |
| + } |
| + } |
| + } |
| + if found != 1 || start < 0 || end < start || end > int64(len(body)) { |
| + return "", false |
| + } |
| + var b strings.Builder |
| + at := start |
| + for _, c := range cuts { |
| + b.Write(body[at:c[0]]) |
| + at = c[1] |
| + } |
| + b.Write(body[at:end]) |
| + return b.String(), true |
| +} |
| + |
| 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..dd569c76a 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,125 @@ 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) |
| + } |
| +} |
| + |
| +// TemplateData's LaunchTemplateDataXML is the answer's launchTemplateData |
| +// exactly, only its direct userData element cut (Astra r1/r2): a field the |
| +// SDK does not know, its whitespace, CDATA or a layout difference all |
| +// show; the user data never does. A nested userData is kept. Two |
| +// answered versions, two userData elements or broken XML are malformed. |
| +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>` |
| + } |
| + tpl := func(v string) map[string]any { |
| + return map[string]any{"LaunchTemplateId": "lt-0abc", "LaunchTemplateName": "carlos-dev", "Version": v} |
| + } |
| + get := func(version, data string) (map[string]any, error) { |
| + return testAdapter(t, newRecorder().on("DescribeLaunchTemplateVersions", resp(version, data))).TemplateData(ctx, tpl(version)) |
| + } |
| + must := func(version, data string) map[string]any { |
| + t.Helper() |
| + d, err := get(version, data) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + return d |
| + } |
| + base := must("7", `<imageId>ami-0123</imageId><userData>QQ==</userData><futureSetting></futureSetting>`) |
| + if got := base["LaunchTemplateDataXML"]; got != `<launchTemplateData><imageId>ami-0123</imageId><futureSetting></futureSetting></launchTemplateData>` { |
| + t.Fatalf("exact bytes %q", got) |
| + } |
| + if same := must("8", `<imageId>ami-0123</imageId><userData>Qg==</userData><futureSetting></futureSetting>`); !reflect.DeepEqual(base, same) { |
| + t.Fatalf("user data only, yet %v != %v", base, same) |
| + } |
| + for name, data := range map[string]string{ |
| + "unknown field": `<imageId>ami-0123</imageId><userData>QQ==</userData><futureSetting></futureSetting><other>x</other>`, |
| + "whitespace in a value": `<imageId>ami-0123</imageId><userData>QQ==</userData><futureSetting> </futureSetting>`, |
| + "cdata": `<imageId>ami-0123</imageId><userData>QQ==</userData><futureSetting><![CDATA[]]></futureSetting>`, |
| + "layout": "<imageId>ami-0123</imageId>\n<userData>QQ==</userData><futureSetting></futureSetting>", |
| + "nested userData": `<imageId>ami-0123</imageId><userData>QQ==</userData><futureSetting><userData>Q</userData></futureSetting>`, |
| + } { |
| + if d := must("9", data); reflect.DeepEqual(base, d) { |
| + t.Errorf("%s: no difference seen: %v", name, d["LaunchTemplateDataXML"]) |
| + } |
| + } |
| + // A self-closing userData, or one with attributes, is cut like any |
| + // other; a version whose user data is absent equals one that has it. |
| + for name, data := range map[string]string{ |
| + "self-closing": `<imageId>ami-0123</imageId><userData/><futureSetting></futureSetting>`, |
| + "with attributes": `<imageId>ami-0123</imageId><userData kind="x">QQ==</userData><futureSetting></futureSetting>`, |
| + "absent": `<imageId>ami-0123</imageId><futureSetting></futureSetting>`, |
| + } { |
| + if d := must("9", data); !reflect.DeepEqual(base["LaunchTemplateDataXML"], d["LaunchTemplateDataXML"]) { |
| + t.Errorf("%s: %q", name, d["LaunchTemplateDataXML"]) |
| + } |
| + } |
| + // The real answer starts with an XML prolog; the element is the same. |
| + withProlog := `<?xml version="1.0" encoding="UTF-8"?>` + "\n" + resp("7", `<imageId>ami-0123</imageId><userData>QQ==</userData><futureSetting></futureSetting>`) |
| + if got, ok := launchDataXML([]byte(withProlog)); !ok || got != base["LaunchTemplateDataXML"] { |
| + t.Errorf("prolog: %q, %v", got, ok) |
| + } |
| + for name, data := range map[string]string{ |
| + "two userData": `<imageId>ami-0123</imageId><userData>QQ==</userData><userData>QQ==</userData>`, |
| + } { |
| + if _, err := get("9", data); uncertainKey(t, err).Key != "api" { |
| + t.Errorf("%s: %v", name, err) |
| + } |
| + } |
| + 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, tpl("7")); uncertainKey(t, err).Key != "api" { |
| + t.Fatalf("two items: %v", err) |
| + } |
| + if _, ok := launchDataXML([]byte(resp("7", `<imageId>a</imageId>`) + "<broken")); ok { |
| + t.Fatal("broken XML accepted") |
| + } |
| +} |
diff --git a/internal/grouprollaws/transport.go b/internal/grouprollaws/transport.go| index ee7164049..667f7e35a 100644 |
| --- a/internal/grouprollaws/transport.go |
| +++ b/internal/grouprollaws/transport.go |
| @@ -100,11 +100,22 @@ func (boundBody) HandleDeserialize(ctx context.Context, in middleware.Deserializ |
| if err != nil { |
| return out, md, err |
| } |
| - resp.Body = io.NopCloser(bytes.NewReader(data)) |
| + resp.Body = &bufferedBody{Reader: bytes.NewReader(data), data: data} |
| resp.ContentLength = int64(len(data)) |
| return out, md, nil |
| } |
| +// bufferedBody is the whole bounded answer (a pointer, so bodies stay |
| +// comparable; Fable P3-3): the operation's deserializer |
| +// reads it, and a middleware outside boundBody can take its bytes without |
| +// another read (TemplateData's captureBody). |
| +type bufferedBody struct { |
| + *bytes.Reader |
| + data []byte |
| +} |
| + |
| +func (*bufferedBody) Close() error { return nil } |
| + |
| type boundedBody struct { |
| rc io.ReadCloser |
| n int64 |
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv| index 7499b8d79..d760c3897 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-chain.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-chain.tsv |
| @@ -170,3 +170,4 @@ plan14-root-reads-group-verb-followups.tsv 9c74b9876a13a3a3802860fe44406898c8bcb |
| plan14-root-reads-group-read-transport-retry.tsv 9c74b9876a13a3a3802860fe44406898c8bcbfd3bd22e8172a59a02674c3b4af |
| plan14-root-reads-linked-deployments-slice1.tsv 40c8459580c3e62a53637e9989f1616e5735ce78796ec6ea1b22655a5eb4ad63 |
| plan14-root-reads-stats-prune-400.tsv 75b32391a24d2c9269fc579aae68ac80b7b1d4ccf0be55f0373490e43a2a652a |
| +plan14-root-reads-group-observation-carry.tsv 587f6e92c5e594b9bb6436a2d0066849454407202e311f43483bed3be4591940 |
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..daf9dc07c |
| --- /dev/null |
| +++ b/internal/provision/testdata/plan14-root-reads-group-observation-carry.tsv |
| @@ -0,0 +1,10 @@ |
| +# 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. |
| +# 3 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 |
| +@legacy e4be70749edd7ee592f3d45d442141733639e2e105602702b4beb2b599481a4c internal/grouprollaws/transport.go boundBody.HandleDeserialize legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=reads an AWS API answer body under the 4 MiB cap;rev3=census-ruling-group-observation-carry;basis=the same bounded read of the AWS answer; the buffered bytes are kept on a typed body (bufferedBody) so TemplateData can compare the raw launchTemplateData without a second read; no new read file:ReadAll@436 8a54d323a71cbc8b179e367d700747b2c4102e13c1322d5afa27ed15cbf54601 |
| +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 |
| +internal/grouprollaws/transport.go boundBody.HandleDeserialize legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=reads an AWS API answer body under the 4 MiB cap;rev3=census-ruling-group-observation-carry;basis=the same bounded read of the AWS answer; the buffered bytes are kept on a typed body (bufferedBody) so TemplateData can compare the raw launchTemplateData without a second read; no new read file:ReadAll@436 8a54d323a71cbc8b179e367d700747b2c4102e13c1322d5afa27ed15cbf54601 |
| +@coverage internal/grouproll d0decee68f572b1fc022493d7721f5efdba74ddfe9b1438f78cf3aee716405c0 |
| +@coverage internal/grouprollaws 287bd94344295b8618f577f0d5dd4bee809d99cb7342b53c6cc1e955e66ae01d |