Repository navigation
Conversation
The engine, the Go guest and gensupport can seal a UUID, but stashgen had no Go type that mapped to the uuid kind, so a Go program could not store one through generated code. A [16]byte field was refused as a composite, and the only way to store a UUID was as text or bytes, which Rust and TypeScript would not read as a UUID. stashgen now classifies [16]byte, and any type defined over [16]byte (github.com/google/uuid.UUID, say), as a UUID and declares the field with gensupport.UUID. No field that generated before changes kind: a sealed [16]byte was refused until now, and an array of another length or of a type defined over byte is still a slice. The engine decides the indexes, as for every kind: equality is accepted, and an order or match index is refused when the code is generated. A pointer to one stores nil as a sealed null by default, since a UUID has a fixed width. Generated code reads the value as [16]byte and converts it to the field's own type, as it does for a type defined over a scalar, so it needs no reflection. gensupport's Get reads a vcvalue.UUID as [16]byte for that; any other value still goes through the array path it took before.
…r index The encrypt README said a sealed field cannot be a pointer, so an optional date had no sealed form. Optional fields declared over a pointer, with `null=sealed` or `null=sql`, exist now. The package docs listed bytes among the values ORE and OPE apply to; the engine refuses an order index on bytes, as on a UUID.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
|
coderdan
left a comment
There was a problem hiding this comment.
Code review (/code-review medium) of b692668. Three findings, checked against the code: one important and one nit inline, and one outside this PR's diff, below.
Outside the diff (nit): the engine's SealedNullType refusal (packages/stack-encrypt/src/refusal.rs) and the matching doc comment in dynamic/record.rs list the fixed-width types as "a bool, a number, a date, a timestamp or a decimal". This PR documents a UUID as fixed width and seals a nil UUID by default, so the engine's text should name a UUID too. I will add it in the pull request for #1985, which changes refusal.rs.
I will reply on each thread with what I changed.
| g.Kind, g.Elem = KindSlice, &elem | ||
| } | ||
| case *types.Array: | ||
| if uuidArray(u) { |
There was a problem hiding this comment.
A type defined over encrypt.Int128 or encrypt.Uint128 is now stored as a UUID instead of being refused. vitaminc's vcvalue declares both as [16]byte (type Int128 [16]byte). valueKind matches only the named types themselves, so for type Balance encrypt.Int128, classify falls through to the underlying array, and uuidArray returns true. valueKind's own comment says such a type is "classified by its underlying type and refused as a struct or array".
Failure scenario: type Balance encrypt.Int128 with a field tagged encrypt,index=equality was refused before. Now it generates EncryptIndex("amount", gensupport.UUID, ...), and the 128-bit integer is sealed under the uuid type. Rust and TypeScript read it back as a UUID, and adding ore later fails.
Severity: important
There was a problem hiding this comment.
Fixed in 11c794f. A field is a UUID when its type, after following aliases, is one of three things: [16]byte itself; a defined type whose own declaration is an array of 16 bytes (type ID [16]byte, [16]uint8, or a constant length of 16), as github.com/google/uuid.UUID is declared; or uuid.UUID or vcvalue.UUID, recognised by name. go/types does not record what a defined type was declared over, so stashgen/uuid.go reads the declaration from source, from pkg.Syntax or the file go/packages records for another package. Everything else with an underlying [16]byte is refused with a message that says why: type Balance encrypt.Int128, the same over Uint128 or the vcvalue types, an alias of one, a pointer to one, and a type whose declaration cannot be read. New tests cover each, including a type from another package and the vcvalue integers themselves, which keep their integer kinds.
| case *[16]byte: | ||
| // A UUID field opens as a vcvalue.UUID. Generated code reads it as | ||
| // [16]byte and converts it to the field's own type (uuid.UUID, say). | ||
| // Any other value is read as an array, as before. |
There was a problem hiding this comment.
The doc comment describes past behaviour instead of the rule: "Any other value is read as an array, as before." The same wording is in TestGetReadsAUUIDAsSixteenBytes's comment. Doc comments state the rule and never narrate history.
Failure scenario: A reader cannot tell what "as before" refers to once this change has merged.
Severity: nit
There was a problem hiding this comment.
Fixed in 09fb4f1. The doc comment and the test's comment now state the rule: any other value is read as an array of sixteen numbers.
vcvalue declares Int128 and Uint128 as [16]byte, so a type declared over encrypt.Int128 (type Balance encrypt.Int128) has the same underlying type as a UUID. stashgen looked only at the underlying type, and so generated such a field as a UUID. Before UUIDs, it refused the field, and it must still refuse it: the value is an integer, and sealing it as a UUID would store the wrong kind. go/types does not record what a defined type was declared over, so stashgen now reads the type's declaration from source. A type is a UUID when its declaration is an array of 16 bytes (type ID [16]byte, as github.com/google/uuid.UUID is), and for that one type and vcvalue.UUID also by name. A type of the struct's own package is read from the loaded syntax; a type of another package from the file its position names. A type declared over another named type is refused, even over a UUID type, and so is one whose declaration cannot be read. The refusal names the type and says what a UUID field can be.
The comments compared the behaviour with an earlier one. They now state the rule: a value that is not a UUID is read as an array of sixteen numbers.
cipherstash-agent
left a comment
There was a problem hiding this comment.
Review attestation
Reviewed 09fb4f1d · posted from Claude Code (scheduled routine) · claude-opus-5-5 · effort medium
Sources: code-review (medium) · claude-opus-5-5; mattpocock-skills:code-review standards and spec agents · model unknown (general-purpose subagents); review-cross-check verify agents · model unknown
Skills: code-review, mattpocock-skills:code-review, company-skills:rust-security (loaded; not applicable, the PR changes no Rust), company-skills:review-cross-check, company-skills:review-post
Findings (6): 1 major, 4 minor, 1 nit — 4 inline, 2 below.
languages/golang/stashgen/emit.go:224(outside diff) nitkindExpr's comment lists the special Go-type-to-kind mappings but not the one this PR adds:[16]byte, or a type declared as one, isUUID.languages/golang/stashgen/read.go:970nituuidArray(u) && isUUID(t)repeats the array testisUUIDmakes atuuid.go:46; harmless.
Checked and dropped: encrypt.KeysetID now classifying as a UUID is correct (it is documented as a UUID); the CHANGELOG code span split across lines renders as one span; TestGeneratedCodeStoresQueriesAndReadsAUUID cannot skip in CI (scripts/go-binding-test.sh fails without the deterministic guest).
Open questions, already raised in the PR's review notes: whether type MyID uuid.UUID should be accepted, and whether the README's pointer-field correction belongs in this PR (it is disclosed and accurate).
Not run here: the guests were not built, so encrypt/uuid_test.go skipped locally and device_stash.go was not regenerated.
Generated by Claude Code
| pos := r.pkg.Fset.Position(obj.Pos()) | ||
| if !pos.IsValid() || pos.Filename == "" { | ||
| return nil | ||
| } | ||
| file, ok := r.declFiles[pos.Filename] | ||
| if !ok { | ||
| parsed, err := parser.ParseFile(token.NewFileSet(), pos.Filename, nil, parser.SkipObjectResolution) |
There was a problem hiding this comment.
major typeSpec finds an imported type's declaration through the file name in its export-data position, which is not always a real path: under GOFLAGS=-trimpath it is module-relative (example.com/app/crm/ids.go), and a //line directive replaces it with the directive's file. Then ParseFile fails and a plain type Ref [16]byte from a sibling package (or gofrs/uuid, or encrypt.KeysetID) is refused; GOFLAGS=-trimpath go test -run TestUUIDTypes ./stashgen/ fails on "a UUID type of another package". Load the imported package by import path (packages.Load with NeedName|NeedFiles, same Dir, cached per path) and search its GoFiles instead of using positions; PositionFor(pos, false) does not help, as the export data already holds the adjusted name.
Source: code-review (medium), mattpocock-skills:code-review spec agent; verified by review-cross-check
Generated by Claude Code
There was a problem hiding this comment.
Fixed in 6605929. typeSpec no longer uses the export-data position. It loads a type's own package by import path, with packages.Load(NeedName|NeedFiles) in the same directory and environment as the main load, and searches that package's GoFiles. Each import path is loaded once. A new test, TestUUIDTypesOfAnotherPackageUnderTrimpath, sets GOFLAGS=-trimpath. It checks that crm.Ref from a sibling package is accepted and that crm.Amount, declared over encrypt.Int128, is refused. The test fails on the previous code and passes now, and so does GOFLAGS=-trimpath go test -run TestUUIDTypes ./stashgen/.
| if sixteen := sixteenBytes(cf.typ); sixteen != nil { | ||
| // [16]byte underneath, and not a UUID: a type declared | ||
| // over another type, such as encrypt.Int128. | ||
| return fieldErr(typeName, cf.goName, "a UUID field is [16]byte, a type whose declaration is an array of 16 bytes (type ID [16]byte), or github.com/google/uuid.UUID; %s is declared over another type, or its declaration could not be read, so it seals only as part of an opaque struct", r.typeExpr(sixteen)) |
There was a problem hiding this comment.
minor One message covers two causes, so a plain type Ref [16]byte whose source could not be read is told it "is declared over another type", which is false. It also lists github.com/google/uuid.UUID but not vcvalue.UUID, which knownUUIDs accepts too. Have isUUID report an unreadable declaration separately and give it its own message (naming -trimpath as a likely cause); the same list is in declaration.go:287 and encrypt/doc.go:128.
Source: mattpocock-skills:code-review standards and spec agents
Generated by Claude Code
There was a problem hiding this comment.
Fixed in 6605929. isUUID is built on uuidVerdict, which tells "declared over another type" apart from "declaration could not be read". Each now has its own message. The second names likely causes: a module missing from the module cache, a vendor directory without it, or a type not declared at package level. It does not name -trimpath, which no longer causes it. One uuidTypes constant now gives the list of UUID types, with vcvalue.UUID. declaration.go, encrypt/doc.go, both READMEs and the CHANGELOG say the same.
| // timestamp, vcvalue.Date, vcvalue.Decimal, vcvalue.UUID for a UUID, or a | ||
| // vcvalue.Object for a composite — and the struct's type is that type, or in the same family and |
There was a problem hiding this comment.
minor The paragraph's rule ("the struct's type is that type, or in the same family and narrower", and "a time, date, decimal or 128-bit integer is read only into its own type, which Get matches") does not describe the new path: Get[[16]byte] misses a vcvalue.UUID and convert reads it into any *[16]byte. Add a sentence such as "A UUID opens as a vcvalue.UUID and is read into [16]byte, which generated code converts to the field's type", and rewrap line 19 (99 columns).
Source: mattpocock-skills:code-review standards agent
Generated by Claude Code
There was a problem hiding this comment.
Fixed in b050cae. The paragraph is rewrapped, and now says a UUID opens as a vcvalue.UUID and is read into [16]byte, which generated code converts to the field's own type.
| var knownUUIDs = map[[2]string]bool{ | ||
| {"github.com/google/uuid", "UUID"}: true, | ||
| {vcvaluePath, "UUID"}: true, | ||
| } |
There was a problem hiding this comment.
minor knownUUIDs is a second table of types known by name beside valueKind (read.go:1004-1044), so the next known type means editing two tables. Consider returning KindUUID from valueKind for these two names, which also follows aliases already. Judgement call.
Source: mattpocock-skills:code-review standards agent
Generated by Claude Code
There was a problem hiding this comment.
Not changed. Merging knownUUIDs into valueKind would change behaviour, not just move code. valueKind is the set of types the codec writes by their exact type, and other checks treat those as one value. notDocument calls it, so a uuid.UUID field with encrypt_into=JsonSearch would start being refused as "one value, not a document". classify would also need a special case to set Basic to [16]byte for these names. The comment on knownUUIDs now gives this reasoning. The two nits from the review body are fixed too: kindExpr's comment names the UUID mapping (b050cae), and classify calls isUUID alone, without the repeated array test (6605929).
…ource stashgen decides whether a [16]byte type is a UUID from its declaration, and found the declaration of a type in another package through the file name in the position go/packages records for it. That name is not always a file on disk: under -trimpath it is a module path, and a //line directive replaces it. Then a plain type Ref [16]byte from a sibling package, or gofrs/uuid's UUID, was refused. stashgen now lists the imported package's Go files with go/packages, by import path and from the directory the package was loaded from, and parses them, once per package. The position is no longer used. The refusal of a [16]byte type that is not a UUID now has two messages: one for a type declared over another type, and one for a type whose declaration could not be read, which names the likely causes. Every list of the types a UUID field takes now names vcvalue.UUID, which stashgen accepts by name, beside github.com/google/uuid.UUID. The array check that isUUID already makes is no longer repeated in classify.
The paragraph on convert did not describe how a UUID is read, and the comment on kindExpr did not list the UUID types among the Go types with a kind of their own.
The comments this branch added for UUID fields were hard to read. The comments had sentences over 25 words, asides in brackets, clauses joined by semicolons, and Go terms with no explanation. A developer who was not part of this work could not tell from them why a type declared over another type is not a UUID. Each comment now says what its function returns and when the result is nil. The comment on reader.uuidVerdict defines declaration, defined type, alias, and underlying type. That comment then lists the three cases in which a type is a UUID. Parallel cases are lists: the types KindUUID covers, the kinds kindExpr writes, the Go types convert reads, and the indexes indexApplies accepts. The comment on the sessions golden case said that its [16]byte field has an equality index. That field has no index, and the comment now says so. No code changes. Every changed Go file has the same syntax tree as before once its comments are removed.
The stashgen README described UUID fields in one paragraph of eight long sentences, in the middle of the section on wire types. That paragraph is now a section of its own, "UUID fields". The section lists the UUID types, then the types that are not a UUID. The section also says: - why stashgen refuses a type declared over another type - how stashgen reads a declaration - which indexes a UUID takes - what a nil pointer stores The changelog entry is split into the same lists. The entry defines kind, declaration, and sealed null where it first uses them. The encrypt README and the package documentation now state the rule for a type defined over another type. That rule is stricter for a UUID than for the other types. The package documentation also says that a pointer field is optional, and what the field stores for nil. The README's sentence on pointer fields is now a paragraph of its own. Two other README sentences that named a UUID are lists now. One says when null=sealed is the default. The other names the scalar types.
stashgen prints these messages when go generate refuses a sealed field. Three of them were one long sentence with an aside in brackets, and all of them said "seals" where the developer wrote encrypt. The refusal of a type declared over another type now starts with that type, because the developer did not ask for a UUID. The refusal then lists the UUID types, and gives the three ways to fix the field. The old message gave one. Declaring an integer type as [16]byte would store it as a UUID, so the message says which fix is for which case. The refusal of a type whose declaration cannot be read is three sentences: what stashgen could not do, the two causes, and when a package's source cannot be loaded. The list of UUID types is no longer in that message. The list does not help a developer whose problem is missing source. The refusal of a field that is not one scalar now says "must be". A sentence of its own lists the scalar types, and the list is the same. The last sentence says "can be encrypted only inside an opaque struct". The tests that check these messages check the new words. Five failure messages of the UUID test used "single out" and "follow". Those messages now say what the test compares. No behaviour changes. stashgen refuses the same fields.
|
This replies to the findings in the bodies of reviews 6088855333 and 6089215000. The inline threads have their own replies.
|
Summary
stashgennow generates a UUID field. A Go field of type[16]byte, or of a type whose declaration is an array of 16 bytes (such asusrn.261609.xyz/google/uuid.UUID), is sealed as the engine'suuidkind. It can be queried by equality and reads back as the field's own type. A pointer to one is an optional field. This is the Go part of #1821.Closes #1994. Refs #1821.
Changes
Mapping: a field is a UUID when its type, after following aliases, is one of three things:
[16]byteitself (that is,[16]uint8);type ID [16]byte, asusrn.261609.xyz/google/uuid.UUIDis declared;uuid.UUIDorvcvalue.UUID, recognised by name.go/types does not record what a defined type was declared over, so
stashgen/uuid.goreads the declaration from source. Everything else whose underlying type is[16]byteis refused with a message that says why, includingtype Balance encrypt.Int128and the same overUint128. Arrays of another length, and[16]Tfor a typeTdefined overbyte, are refused as before. No existing field changes kind: a sealed[16]bytewas refused until now. Every golden file is byte-identical, andgo generate ./...changes no committed file.Indexes: equality is allowed.
match,oreandopeare refused at generation time by the engine, as for other kinds.enginetest.Staticagrees. A UUID has a fixed width, so a nil pointer is a sealed null by default, withEqNull.null=sqlalso works.Generated code:
EncryptIndex("id", gensupport.UUID, encrypt.Equality).gensupportturns it into the engine's UUID.gensupport.Get[[16]byte]and converted to a named type, or withGetPtrfor a pointer.gensupport.convertreads avcvalue.UUIDinto a*[16]bytedirectly.Docs:
encrypt/doc.go,encrypt/README.md,cmd/stashgen/README.mdand the CHANGELOG. The CHANGELOG's note thatstashgendoes not map a UUID is removed. Two statements that were already out of date are also corrected: the README said a sealed field cannot be a pointer, and the package docs listed bytes among the types that take an order index.Verification
TestGolden/sessions: a named type with equality, plain[16]byte, and two nullable fields, one with a sealed null and one withnull=sql. The test also compiles the generated file.[8]byte,[16]octet, andmatch,oreandopeon a UUID. These are checked with both the fake engine and the real one, which agree on five UUID cases.TestGetReadsAUUIDAsSixteenBytes.TestGeneratedCodeStoresQueriesAndReadsAUUID, with the deterministic offline client. It covers store, equality terms,Eq,EqNull,Encrypt,Decryptback to the named type and to[16]bytewith nil kept, and a one-column update. It fails without theconvertchange.go build,go vet,gofmt -landgo test ./...pass in every module, withSTACK_CONFORMANCE_REQUIRED=1. The only failures areaccounts,contactsanddocumentsinstashgen/testdata/cases, which fail onnexttoo: their generated code exists only as.goldenfiles.go.modandgo.sumare unchanged.github.com/google/uuidis not added; the tests use a local[16]bytetype.Review notes
type MyID uuid.UUID). Accepting it means following the declaration chain, and refusing any chain that reaches the 128-bit integer types. Should it be supported?-trimpathcould hide that file, and such a type would then be refused with "could not be read".uuid.UUIDandvcvalue.UUIDare known by name, so they are not affected. This was not tested under-trimpath.[16]MyByteis refused. The element type must be exactlybyte, because the write path converts only types whose underlying type is[16]byte.value_kinds.jsondoes for other kinds. The tests prove a round trip and correct equality only.gensupportandstashgen, which stage 3 (movingvcvalue) also touches. Whichever merges second needs a small import update.