grouproll: canonical journal bytes on read; bound pointer nesting
Review fixes for Task 8. An integer literal outside int64 is refused, never rounded through float64, and a saved row must equal its canonical re-encoding, so the values kept are the values hashed. The strict router-pointer walk refuses nesting deeper than 64 before any signature is read. Comments on the float contract updated.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
internal/grouproll/box.go+2 −1internal/grouproll/journal.go+15 −1internal/grouproll/journal_test.go+33 −0internal/release/systemlookup.go+14 −4internal/release/systemlookup_test.go+41 −0
CI failed — run details
Intent
<task-notification> <task-id>a030cd856fcf6708b</task-id> <tool-use-id>toolu_019y15q7Ui3zvakihyjWeoyW</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/669506ff-23ec-45f1-9035-1d29593f2c37/tasks/a030cd856fcf6708b.output</output-file> <status>completed</status> <summary>Agent "Implement Task 8: floor + SHA map" finished</summary> <note>A task-notification fires each time this agent stops with no live background children of its own. The user can send it another message and resume it, so the same task-id may notify more than once.</note> <result>Both rulings are done and committed as d6e5bfc4 on group-roll-verb (on top of 06848c36), not pushed. All the checks you asked for now pass, including the full `go test ./internal/release`. **A. The CI break is fixed.** `internal/release/openers_test.go` now lists `internal/grouprollaws/objects.go:Bucket` among the other bucket openers: a read-only operator store on the region's own endpoint, whose Put and Delete refuse. `TestS3StoreOpenersClassified` passes. **B. The journal now takes finite floats.** - **Encoding:** a whole-number float is written as an integer, so `1.0` and `1e0` become `1`. Any other finite number is written in Go's shortest form, so `0.10` becomes `0.1` and `1e21` becomes `1e+21`. NaN, Inf and `1e400` are still refused. - **Permit encoder:** it still refuses floats. It must match Python's `json.dumps` byte for byte, and Python writes `1.0` as `1.0`, not `1`. - **Status:** the status line now prints a saved `0.5` instead of refusing the journal. - **Tests:** the new `TestJournalFloats` pins the exact row bytes and checks they reload. The old "float refused" assertions now assert that NaN, Inf and `1e400` are refused. The golden file is unchanged. **The floor matches the script on `ha_take`.** Only the JSON integer `1` counts as the floor value. The decoder already kept `1.0` and `1e0` as their raw text, so the floor's check needed no change; only the journal refusal had been in the way. The test covers `1` (drain) and `1.0`, `1e0`, `true`, `"1"`, `2`, `0` and absent, each a DR-4 reason (`floor_box`), never a refusal. It also checks that the journaled edges row records `1.0` as `1`. **Remaining concerns:** 1. The four escaped-timestamp cases are not on held-floor-sha-map, so the Go tests generate them. 2. Go commands still need the sandbox off, because the Go build cache is read-only inside it. 3. Git again reported another process's `packed-refs.lock`, but the commit landed. I left the lock alone. The old concern about a `1.0` in an edges file making the floor refuse is withdrawn. Report (with the A/B follow-up appended): `/home/paulca/amadan.net/carlos/platform/.claude/worktrees/design-group-roll-verb/.superpowers/sdd/2026-11-09-group-roll-verb/task-8-report.md`</result> <usage><subagent_tokens>278607</subagent_tokens><tool_uses>101</tool_uses><duration_ms>1987734</duration_ms></usage> </task-notification>
<task-notification> <task-id>b9dqevbiw</task-id> <tool-use-id>toolu_01A5xmqLfgK3Rxpqzk6Wbsj2</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/669506ff-23ec-45f1-9035-1d29593f2c37/tasks/b9dqevbiw.output</output-file> <status>completed</status> <summary>Background command "Wait for Astra Task 8 review" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 25.2 g CO₂e (3,229,312 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on group-roll-verb, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/internal/grouproll/box.go b/internal/grouproll/box.go| index 7ce31b2ef..d543a4cc3 100644 |
| --- a/internal/grouproll/box.go |
| +++ b/internal/grouproll/box.go |
| @@ -165,7 +165,8 @@ func shellQuote(s string) string { |
| // separators=(",", ":"), allow_nan=False) with Python's default |
| // ensure_ascii, so every character outside printable ASCII is a \u escape |
| // (a surrogate pair above U+FFFF). It takes the values the strict decoder |
| -// produces and refuses floats, as the journal encoder does. |
| +// produces and refuses every non-integer number (integersOnly): Python |
| +// writes 1.0 as 1.0, where the journal encoder would write 1. |
| func pythonEncoded(v any) ([]byte, error) { |
| n, err := integersOnly(v) |
| if err != nil { |
diff --git a/internal/grouproll/journal.go b/internal/grouproll/journal.go| index e40dc905f..db3fa9a6d 100644 |
| --- a/internal/grouproll/journal.go |
| +++ b/internal/grouproll/journal.go |
| @@ -145,6 +145,11 @@ func normalizeValue(v any, floats bool) (any, error) { |
| if i, ok := integer(string(x)); ok { |
| return i, nil |
| } |
| + if !strings.ContainsAny(string(x), ".eE") { |
| + // An integer literal outside int64: refused, never rounded |
| + // through float64 (two such integers could share a hash). |
| + return nil, fmt.Errorf("grouproll: integer %s out of range", x) |
| + } |
| if !floats { |
| return nil, fmt.Errorf("grouproll: values are integers, not %s", x) |
| } |
| @@ -211,7 +216,9 @@ func integer(s string) (int64, bool) { |
| // decodeStrict is the script's decode (:508-513): one JSON value, refusing |
| // duplicate object keys, NaN and Infinity, invalid UTF-8 and trailing data. |
| // Integers within int64 come back as int64; any other number stays a |
| -// json.Number, which encodeRow refuses. |
| +// json.Number, which encodeRow writes in its canonical form (an integral |
| +// one as an integer, a finite one in Go's shortest form) or refuses (an |
| +// integer literal outside int64, or a number beyond float64's range). |
| func decodeStrict(raw []byte) (any, error) { |
| if !utf8.Valid(raw) { |
| return nil, errors.New("grouproll: invalid UTF-8") |
| @@ -354,6 +361,13 @@ func (j *Journal) read(create bool) error { |
| return refuse("record") |
| } |
| row["hash"] = digest |
| + // The saved bytes must be the row's canonical encoding, so the |
| + // values kept are exactly the values hashed: a number written |
| + // 1.0, 1e0 or 0.10 (which normalizes to the same hash as 1 or |
| + // 0.1) refuses. |
| + if canon, err := encodeRow(row); err != nil || !bytes.Equal(canon, line) { |
| + return refuse("record") |
| + } |
| j.rows = append(j.rows, Row(row)) |
| previous = digest |
| } |
diff --git a/internal/grouproll/journal_test.go b/internal/grouproll/journal_test.go| index 7f33f0832..652f8d1cc 100644 |
| --- a/internal/grouproll/journal_test.go |
| +++ b/internal/grouproll/journal_test.go |
| @@ -116,6 +116,39 @@ func TestJournalFloats(t *testing.T) { |
| if !reflect.DeepEqual(r.Rows(), j.Rows()) { |
| t.Fatalf("reloaded rows differ:\n%#v\n%#v", r.Rows(), j.Rows()) |
| } |
| + // An integer literal outside int64 is refused, never rounded. |
| + w, _ := newJournal(t) |
| + if _, err := w.Add("begin", map[string]any{"transaction": "t"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := w.Add("response", map[string]any{"n": json.Number("1000000000000000000001")}); refusalKey(err) != "record" { |
| + t.Fatalf("out-of-range integer: %v", err) |
| + } |
| + // A saved row must be its canonical bytes: numbers that normalize to |
| + // the hashed value but are written differently refuse on load, so the |
| + // value kept is the value hashed (review 2026-11-10, item 1). |
| + for name, swap := range map[string][2]string{ |
| + "1e+21 as a 22-digit integer": {`"big":1e+21`, `"big":1000000000000000000001`}, |
| + "1 as 1.0": {`"e":1,`, `"e":1.0,`}, |
| + "1 as 1e0": {`"v":1}`, `"v":1e0}`}, |
| + "0.5 as 0.50": {`"half":0.5`, `"half":0.50`}, |
| + } { |
| + t.Run(name, func(t *testing.T) { |
| + if !bytes.Contains(raw, []byte(swap[0])) { |
| + t.Fatalf("%s not in the saved row", swap[0]) |
| + } |
| + bad := filepath.Join(t.TempDir(), "tx.v2.jsonl") |
| + if err := os.WriteFile(bad, bytes.Replace(raw, []byte(swap[0]), []byte(swap[1]), 1), 0o600); err != nil { |
| + t.Fatal(err) |
| + } |
| + if j, err := openJournal(bad, currentOwner(), false, true); refusalKey(err) != "record" { |
| + if err == nil { |
| + j.Close() |
| + } |
| + t.Fatalf("load: %v, want record", err) |
| + } |
| + }) |
| + } |
| // The permit encoder still matches Python byte for byte, so it still |
| // refuses a non-integer (TestPythonEncoded); the journal does not. |
| if _, err := pythonEncoded(map[string]any{"x": 1.0}); err == nil { |
diff --git a/internal/release/systemlookup.go b/internal/release/systemlookup.go| index 36ebe7cb2..03e5b30ac 100644 |
| --- a/internal/release/systemlookup.go |
| +++ b/internal/release/systemlookup.go |
| @@ -360,7 +360,7 @@ func strictJSON(raw []byte) (any, error) { |
| } |
| dec := json.NewDecoder(bytes.NewReader(raw)) |
| dec.UseNumber() |
| - v, err := strictTree(dec) |
| + v, err := strictTree(dec, 0) |
| if err != nil { |
| return nil, err |
| } |
| @@ -370,13 +370,23 @@ func strictJSON(raw []byte) (any, error) { |
| return v, nil |
| } |
| -func strictTree(dec *json.Decoder) (any, error) { |
| +// maxPointerDepth bounds the nesting strictTree walks: a wrapper is one |
| +// object deep and a router payload at most five (a history entry's |
| +// artifact: payload, history, release, artifacts, artifact). json.Decoder. |
| +// Token applies no nesting limit of its own and this walk recurses, so an |
| +// object or array deeper than this refuses before any signature is read. |
| +const maxPointerDepth = 64 |
| + |
| +func strictTree(dec *json.Decoder, depth int) (any, error) { |
| tok, err := dec.Token() |
| if err != nil { |
| return nil, err |
| } |
| switch t := tok.(type) { |
| case json.Delim: |
| + if depth >= maxPointerDepth { |
| + return nil, fmt.Errorf("nested deeper than %d", maxPointerDepth) |
| + } |
| switch t { |
| case '{': |
| obj, folded := map[string]any{}, map[string]bool{} |
| @@ -394,7 +404,7 @@ func strictTree(dec *json.Decoder) (any, error) { |
| return nil, fmt.Errorf("duplicate key %q", key) |
| } |
| folded[f] = true |
| - v, err := strictTree(dec) |
| + v, err := strictTree(dec, depth+1) |
| if err != nil { |
| return nil, err |
| } |
| @@ -407,7 +417,7 @@ func strictTree(dec *json.Decoder) (any, error) { |
| case '[': |
| arr := []any{} |
| for dec.More() { |
| - v, err := strictTree(dec) |
| + v, err := strictTree(dec, depth+1) |
| if err != nil { |
| return nil, err |
| } |
diff --git a/internal/release/systemlookup_test.go b/internal/release/systemlookup_test.go| index 46feb66ed..6f94fc785 100644 |
| --- a/internal/release/systemlookup_test.go |
| +++ b/internal/release/systemlookup_test.go |
| @@ -12,6 +12,7 @@ import ( |
| "reflect" |
| "strings" |
| "testing" |
| + "time" |
| ) |
| // The router pointer fixtures come from the parked branch |
| @@ -431,3 +432,43 @@ func TestReleaseForArtifactConservative(t *testing.T) { |
| } |
| } |
| } |
| + |
| +// TestReleaseForArtifactNestingBound: the strict walk recurses, and |
| +// json.Decoder.Token has no nesting limit, so a deeply nested wrapper or |
| +// payload must refuse at maxPointerDepth, before any signature is read |
| +// (the wrapper) or any field is typed (the payload), and quickly. |
| +func TestReleaseForArtifactNestingBound(t *testing.T) { |
| + ctx := context.Background() |
| + pub := lookupPubKey(t) |
| + const n = 1 << 20 |
| + deep := strings.Repeat("[", n) + strings.Repeat("]", n) |
| + payload := routerPayload(t, "v0.35.1", lookupCurrent, "stable", nil) |
| + nestedPayload := bytes.Replace(payload, []byte(`"source": "release:v0.35.1"`), []byte(`"source": `+deep), 1) |
| + for name, body := range map[string][]byte{ |
| + "wrapper": []byte(`{"payload": ` + deep + `, "sig": "AA=="}`), |
| + "wrapper top level": []byte(deep), |
| + "payload": lookupSign(t, nestedPayload), |
| + } { |
| + t.Run(name, func(t *testing.T) { |
| + s := &lookupStore{pointers: map[string][]byte{"stable": body}} |
| + start := time.Now() |
| + _, err := ReleaseForArtifact(ctx, s, pub, []string{"stable"}, "linux-arm64", lookupCurrent) |
| + var pe *PointerError |
| + if !errors.As(err, &pe) || pe.Fault != PointerInvalid || !strings.Contains(err.Error(), "nested deeper than 64") { |
| + t.Fatalf("err = %v, want invalid for nesting", err) |
| + } |
| + if d := time.Since(start); d > 2*time.Second { |
| + t.Fatalf("refusal took %s", d) |
| + } |
| + }) |
| + } |
| + // The bound itself: 64 nested levels decode (a top-level object and |
| + // 63 arrays); a 65th refuses. |
| + at := strings.Repeat("[", 63) + strings.Repeat("]", 63) |
| + if _, err := strictJSON([]byte(`{"a": ` + at + `}`)); err != nil { |
| + t.Fatalf("depth 64: %v", err) |
| + } |
| + if _, err := strictJSON([]byte(`{"a": [` + at + `]}`)); err == nil { |
| + t.Fatal("depth 65 read") |
| + } |
| +} |