carlos / platform Public

group verb: take TemplateData's raw answer from boundBody; census

Astra r1 P2: the SDK skips unknown XML, so TemplateData also compares
the canonical launchTemplateData XML. boundBody keeps the bytes it
already read, and captureBody takes them without a second read.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude pushed by paul@keymail.dev 8b3531859af337e4e37128fde6561ec0864b090f parent 02186a0
5 files changed, +28 −21
  • docs/superpowers/notes/census-proposal-group-observation-carry.md +3 −1
  • internal/grouprollaws/group.go +9 −16
  • internal/grouprollaws/transport.go +11 −1
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −1
  • internal/provision/testdata/plan14-root-reads-group-observation-carry.tsv +4 −2

CI failed — run details

diff --git a/docs/superpowers/notes/census-proposal-group-observation-carry.md b/docs/superpowers/notes/census-proposal-group-observation-carry.md
index 1696796f8..796393f9a 100644
--- a/docs/superpowers/notes/census-proposal-group-observation-carry.md
+++ b/docs/superpowers/notes/census-proposal-group-observation-carry.md
@@ -6,6 +6,7 @@ Ruling `census-ruling-group-observation-carry`. The independent reviewer approve
|---|---|---|---|
| `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`.
@@ -15,7 +16,8 @@ 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: `40c8459580c3e62a53637e9989f1616e5735ce78796ec6ea1b22655a5eb4ad63` → `9cc09223a67041265c64d3918821b30ea3fa064e81f9dc8ec95af2b653e8f3af`.
+Seal: `40c8459580c3e62a53637e9989f1616e5735ce78796ec6ea1b22655a5eb4ad63` → `55cbab59f71de378573e93a87d00ae6aba819f87786a2ead08d743051b936a01`.
Overlay: `internal/provision/testdata/plan14-root-reads-group-observation-carry.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/internal/grouprollaws/group.go b/internal/grouprollaws/group.go
index e1cc0a086..290417d1b 100644
--- a/internal/grouprollaws/group.go
+++ b/internal/grouprollaws/group.go
@@ -667,7 +667,8 @@ func (a *Adapter) TemplateData(ctx context.Context, tpl map[string]any) (map[str
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)
+ // Just outside boundBody, which has read the whole answer.
+ return st.Deserialize.Insert(captureBody(&body), boundBodyID, middleware.Before)
})
})
})
@@ -703,8 +704,9 @@ func (a *Adapter) TemplateData(ctx context.Context, tpl map[string]any) (map[str
return m, nil
}
-// captureBody keeps the raw answer (at most outputCap bytes) for the
-// caller and hands the operation's deserializer the same bytes.
+// 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) {
@@ -712,20 +714,11 @@ func captureBody(dst *[]byte) middleware.DeserializeMiddleware {
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
+ if r, ok := out.RawResponse.(*smithyhttp.Response); ok && r != nil && r.Response != nil {
+ if b, ok := r.Body.(bufferedBody); ok {
+ *dst = b.data
+ }
}
- *dst = b
- r.Body = io.NopCloser(bytes.NewReader(b))
return out, md, nil
})
}
diff --git a/internal/grouprollaws/transport.go b/internal/grouprollaws/transport.go
index ee7164049..3e0ff3134 100644
--- a/internal/grouprollaws/transport.go
+++ b/internal/grouprollaws/transport.go
@@ -100,11 +100,21 @@ 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: 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 5be457e16..e8b82d4dd 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -169,4 +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
+plan14-root-reads-group-observation-carry.tsv 55cbab59f71de378573e93a87d00ae6aba819f87786a2ead08d743051b936a01
diff --git a/internal/provision/testdata/plan14-root-reads-group-observation-carry.tsv b/internal/provision/testdata/plan14-root-reads-group-observation-carry.tsv
index ac7e4be58..58ead0829 100644
--- a/internal/provision/testdata/plan14-root-reads-group-observation-carry.tsv
+++ b/internal/provision/testdata/plan14-root-reads-group-observation-carry.tsv
@@ -1,8 +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.
-# 2 body, 0 sites, 2 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+# 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 e088fa6b63cb030eedd9d2c356659dccccbe64eca464ec6625fa8b75c287cfaf 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 22970b4b6bdf5bd90b25183ee33b702ebfea6070781aa4bac9cd5f461fd17280
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 22970b4b6bdf5bd90b25183ee33b702ebfea6070781aa4bac9cd5f461fd17280
@coverage internal/grouproll d0decee68f572b1fc022493d7721f5efdba74ddfe9b1438f78cf3aee716405c0
-@coverage internal/grouprollaws 5f62b555afee15c7dd70c40d8b3337481fab36fc65818ad0504eef408ac38bb5
+@coverage internal/grouprollaws 52b7cadf4843cdfd91a2fde8c2ac8db9ad5027c71c3cfb8c2cc135288d59928b