Skip to content

refactor(go)!: move vitaminc's vcffi and vcvalue into the module as encrypt/frame and encrypt/value - #2003

Merged
coderdan merged 6 commits into
nextfrom
refactor/go-frame-codec-in-module
Dec 2, 2026
Merged

coderdan merged 6 commits into
nextfrom
refactor/go-frame-codec-in-module

Conversation

@coderdan

@coderdan coderdan commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The Go SDK no longer imports vitaminc's Go packages vcffi and vcvalue. They have moved into the module, unchanged in shape:

vitaminc package Now What it is
vcffi languages/golang/encrypt/frame the frame codec (the bytes the SDK exchanges with its WebAssembly guest) and the storage profile (the format of an opaque struct)
vcvalue languages/golang/encrypt/value the value types the codec reads and writes: Date, Decimal, Int128, Uint128, UUID, Object and the rest

Both packages stay public, and each type is declared once. encrypt.Date, Decimal, Int128 and Uint128 stay aliases, now of value's types, so code that names only encrypt types needs no change. The go.mod pin on an untagged vitaminc commit is gone, and so is the release-script rule that refused a final version while that pin existed. This is the last stage of moving the AEAD code into this repository, and it unblocks a final Go release.

Closes #1253. Its item 5, the differential fuzzers, is now #2004. Refs #1831 (stage 3 of the move).

Changes

One commit each:

  1. Copy. vcffi and vcvalue copied byte for byte from the Go module cache, at the version the SDK pinned: vitaminc f1fc9ae74, v0.0.0-20261119095843-f1fc9ae74882. Each keeps its MIT licence. Compare the commit with the source file by file.
  2. Make them the module's own.
    • Package clauses frame and value; frame imports encrypt/value. Error text starts "frame: " or "value: ".
    • The tests read this repository's value corpus and storage corpus, and skip outside the repository.
    • Removed, because only vitaminc's own binding (vcencrypt) used them: Sealed, SealedEmptySeq, SealedEmptyMap, TypedNull, FixedType, ErrInvalidFixedType, Plain.Value, Encoder.TypedNull, FixedWidth and VCValueLeaves. The typed null of a nil pointer is built from the tag table, so its bytes are unchanged, and the known-answer tests still pin them.
    • From review: the Encoder's unsigned methods are Uint8 to Uint128, as Go spells them. The zero Encoder no longer panics: it keeps nothing, and Err says so, so a unit test can pass it to EncryptValue. Encryptable is declared once. A storage refusal names the program's type.
  3. Build the module on them (breaking).
    • encrypt gains aliases: UUID and ParseUUID (of value's), and Encryptable and Encoder (of frame's).
    • A nil pointer to an Encryptable is written as a null, which the engine pads to the width of the field's declared type. On a field with no declared type, Cipher.Seal refuses it with ErrEncoding, so the stored length cannot show a null. Generated code always declares a type.
    • stashgen recognises the value types by their names in encrypt or in encrypt/value.
  4. go.mod and the release rule. The root module, encrypt/encrypttest, encrypt/example and examples/s3 drop the vitaminc requirements; go mod tidy changes nothing else. scripts/go-release-version.mjs drops the rule that refused a final version while go.mod pinned a vitaminc pseudo-version, with its tests. A new test checks that a final version from main is accepted.
  5. CI. The nightly go-fuzz-campaign in fuzz.yml fuzzes the codec's three decoders (FuzzUnmarshal, FuzzUnmarshalCipherText, FuzzUnmarshalStorage), building no guest for them. tests-golang.yml starts when the value corpus changes.
  6. Docs. CHANGELOG.md has a Breaking entry saying what changes for code that imported vcvalue or vcffi. Also updated: AGENTS.md, docs/fuzzing.md, the plan's stage 3 "Done" list, the READMEs, STORAGE.md, the conformance docs, and the Rust comments that named the Go codec.

What changes for a program

  • Names only encrypt types: nothing.
  • Imports vcvalue or vcffi: import encrypt/value or encrypt/frame instead, or use the encrypt aliases. Rename UInt8…UInt128 calls to Uint8…Uint128. The removed names above are gone.
  • The stored format is unchanged: every value has the same ciphertext and the same terms as before.

Verification

On the final tree, rebased on next at 54e6471, with all five guests rebuilt:

  • go build, go vet, GOOS=linux GOARCH=386 go vet and gofmt -l (empty) pass in all four modules.
  • STACK_CONFORMANCE_REQUIRED=1 go test ./... passes in all four modules.
  • go generate ./... leaves no drift.
  • mise run go:lint reports 0 issues in each module.
  • go mod tidy -diff is clean in each module.
  • The Go release and workflow script tests pass (15 files, 240 tests).
  • Commits 1 to 5 each build and vet on their own; commit 6 changes only docs and comments.

Not run: the Windows and macOS jobs, live tests, the guest import-surface checks, and fuzzing. No Rust code changes; only Rust and Cargo comments.

Review notes

Decided:

  • Nil pointers. A nil Encryptable on a field with no declared type is refused, rather than written as a null whose length would show it is a null.

Moved to #2040:

Also:

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI; Enforced overrides: Organization
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 96fc162d-0c3d-4fc0-8473-2b1c135335fb

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

@github-actions

Copy link
Copy Markdown
Contributor

Mutation testing (cargo-mutants, --in-diff, stack-auth, stack-encrypt, stack-encrypt-jsonpath, vitaminc-aead, recipher-frame, vitaminc-aead-derive)

No mutants were generated for the changed lines.

@coderdan coderdan left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review (/code-review medium) of 5b860a6. Four findings, all checked against the code: one important, below because its file is outside the diff, and three nits inline.

Important: .github/workflows/tests-golang.yml (outside the diff). A change to the value corpus does not run the Go tests that now read it. internal/frame/conformance_test.go and fuzz_test.go read conformance/vitaminc-aead/value-conformance.json, but neither the pull_request nor the push path filter lists conformance/vitaminc-aead/**. The filter lists packages/recipher-frame/** for the storage corpus, and conformance/stack-encrypt/**. Failure scenario: a pull request adds a value vector that the Go codec decodes differently. Only tests-crates.yml runs, it passes on the Rust side, and the Go drift reaches main with no red check.

I will fix all four in this pull request and reply here and on each thread.

Comment thread languages/golang/encrypt/errors.go Resolved
@changeset-bot

changeset-bot Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 5aa6552

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderdan

Copy link
Copy Markdown
Contributor Author

Review follow-up on the path filter, the finding outside the diff: fixed in 1ad6005. conformance/vitaminc-aead/** is now in both the pull_request and push path lists of .github/workflows/tests-golang.yml. No script test lists these paths. The workflow script tests pass: workflow-paths-filter-parity, tests-workflow-gate, stack-conformance-ci, crates-ci, go-nested-modules and go-release-version. The three inline findings are answered on their threads.

@coderdan
coderdan marked this pull request as ready for review November 27, 2026 14:43
@coderdan
coderdan requested a review from a team as a code owner November 27, 2026 14:43

@cipherstash-agent cipherstash-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review attestation

Reviewed b3981ee5 · 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 axes · model not confirmed. Every finding was verified at b3981ee5 and cross-checked against the existing threads.
Skills: code-review, company-skills:rust-security, mattpocock-skills:code-review, company-skills:review-cross-check, company-skills:review-post

Findings (8): 8 minor — 6 inline, 1 below, 1 in reply.

  • general minor The PR body says "Closes #1253", but #1253 item 5 (port the differential fuzzers to languages/golang/encrypt/guest) is not done, and the plan's "Still to do" says so; no other issue tracks it. The base is next, so GitHub will not auto-close it, but closing it by hand on this PR's word leaves item 5 untracked. Use "Refs #1253" or move item 5 to its own issue.
    Source: mattpocock-skills:code-review spec axis · model not confirmed

company-skills:rust-security: the Rust changes are comments only; nothing in scope.

Checked and not posted (refuted at head): JSONOpen/NewJSONRead taking frame.Object (unreachable outside the module, since both also need an internal *record.Plan), the corpus skip inside the repository, the FixedWidth test name, the widen.go switches.

Open questions for the author, not defects:

  • A nil pointer to an Encryptable is now a 1-byte plain null where its value is 9 bytes, and the engine pads nothing on an Untyped field. Generated code cannot reach this, but a program that calls gensupport.Declare(...).Encrypt("v", gensupport.Untyped) itself can. Refuse a nil Encryptable where no type is declared?
  • The CHANGELOG says ParseInt128, ParseUint128, ParseDecimal and ErrNonFiniteDecimal are "unchanged", but their error text now starts frame: , naming an internal package. errors.Is still matches.
  • encrypt/query.go:122 tells callers to pass a frame.Object, a type outside the module cannot name.
  • The reflect-keyed registry in internal/frame/public.go versus Go principle #4 ("do not use reflection"), and the removal of Date.DaysFromCE/Decimal.Normalized: both already in the PR's own open questions.

Generated by Claude Code

Comment thread languages/golang/encrypt/encoder.go Resolved
Comment thread mise.toml Resolved
@coderdan

Copy link
Copy Markdown
Contributor Author

On the review's general finding: the description now says "Refs #1253" rather than "Closes #1253". Item 5, porting the differential fuzzers to the Go guest, is tracked in #2004. The inline findings and the review's open questions are being fixed; I will reply on each thread.

@coderdan

Copy link
Copy Markdown
Contributor Author

On the review's open questions:

  • A nil Encryptable on a field with no declared type: refused now (311320f). Cipher.Seal refuses a nil pointer to an Encryptable, at any depth, on a field with no declared type. It returns ErrEncoding before anything is sent, so the stored length cannot show a null. The old padded null is not brought back: getting its width would mean calling a user's EncryptValue on a zero value, which can panic, and a type's output need not have a fixed width. On a typed field with sealed nulls, a nil Encryptable still seals to a value's length. The test fails without the check.
  • Error text naming frame: fixed (316207d). ParseInt128, ParseUint128, ParseDecimal, ParseUUID, Date.Validate and Decimal.Validate return errors starting "encrypt: ", and errors.Is still matches. ErrNonFiniteDecimal is now encrypt's own value. The CHANGELOG says what changed instead of "unchanged". Codec errors from encoding a value, such as invalid UTF-8, still read "frame: …" inside the wrapped ErrEncoding text.
  • encrypt/query.go:122: the doc now describes the input as generated code builds it, without naming frame.Object (061da75).

One thing beyond the doc: several exported encrypt.Cipher methods take types a program cannot import. These are QueryTerm, Verify, TargetLimit, Contexts, Seal, Open and JSONOpen, which take a *record.Plan, and JSONOpen, which also takes a frame.Object. They are documented as being for generated code, and the *record.Plan part was already true before this branch. The API is unchanged. This is added to the description's open questions.

coderdan added a commit that referenced this pull request Dec 1, 2026
Phase 2 depends on step 1.6, because the resolver's query form goes there.
Step 1.4 checks the single seal first and can keep today's merge of
pendings. Step 1.3 says how the new term method relates to the typed term
methods. Step 1.1 defines Go's match options as well as sending them. Two
citations and two size figures are corrected, and names that arrive with
#2003 say so.
@coderdan
coderdan force-pushed the refactor/go-frame-codec-in-module branch from 70c6a58 to f97f467 Compare December 2, 2026 04:47
@coderdan

coderdan commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto next (54e6471) and force-pushed. The branch is now 24 signed commits with no merge commits.

What changed beyond the commit hashes:

  • The merges are gone. The three Merge next commits resolved conflicts and also made changes of their own. Those changes are now in ordinary commits:
    • frame.Native, the guest.KindOf change that uses it, and TestAnErrorNamesEachValueTypeByItsKind (from e09a08a) are in "feat(go)!: give encrypt's value types, Encryptable and Encoder types of their own". That commit is where the published types first exist.
    • Moving each guest answer read to frame (also from e09a08a) is in "refactor(go): build the module against internal/frame, not vitaminc".
    • The value_bytes.rs doc comment (from a4d45c4) is in the plain-language Rust comments commit.
  • New commit: "build(go): drop the vitaminc requirements from the S3 example". examples/s3 (docs(golang): add an example that encrypts S3 objects #2034) came to next still listing vcffi and vcvalue as indirect requirements. go mod tidy removes them.
  • The tree is the same as before, plus next's changes. Comparing it with the old head (70c6a58): every file differs only by what next gained since that merge, plus the S3 go.mod and go.sum. AGENTS.md keeps this branch's text and adds next's examples/s3 sentence.

Each commit builds and passes go vet on its own. The Verification section of the description lists what ran at the new head.

…module

The Go SDK encodes every value that it sends to the guest with vitaminc's
Go packages vcffi and vcvalue. go.mod pins them at an untagged commit, so
the Go half of the frame codec moves separately from the Rust half
(recipher-frame, already in this repository). A final release of the
module is refused while that pin stands.

This commit copies both packages in unchanged, so the move can be
compared with the source file by file:

  vcffi   -> languages/golang/encrypt/frame
  vcvalue -> languages/golang/encrypt/value

Both stay public, as they were in vitaminc, and stay two packages: value
holds the value types and imports nothing outside the standard library;
frame is the codec and the storage profile.

Source: github.com/cipherstash/vitaminc bindings/go/vcffi and
bindings/go/vcvalue at commit f1fc9ae74882 (pseudo-version
v0.0.0-20261119095843-f1fc9ae74882), the version that go.mod pins, taken
from the Go module cache. Each package's go.mod is left out, so the two
directories are packages of this module. Each package's MIT LICENSE file
comes with it.

Nothing imports the copies yet. Their package clauses, their import of
vcvalue and the corpus paths of their tests are still vitaminc's; the
next commit makes them the module's own.
The copies are still vitaminc's packages under new paths. This commit
makes them packages of this module, and changes what the review of the
move asked for. Nothing else in the module imports them yet.

- Package clauses become frame and value, and frame imports
  encrypt/value in place of vitaminc's vcvalue. Error text starts with
  "frame: " or "value: ".
- The tests read the value corpus (conformance/vitaminc-aead) and the
  storage corpus (packages/recipher-frame/testdata) from this
  repository, and skip, rather than fail, outside it.
- What only vitaminc's own binding (vcencrypt) used is removed: the
  sealed leaves (Sealed, SealedEmptySeq, SealedEmptyMap), TypedNull,
  FixedType and ErrInvalidFixedType, Plain.Value, Encoder.TypedNull,
  FixedWidth and VCValueLeaves. The typed null for a nil pointer is
  built from the tag table, so the codec keeps no list of types.
- The Encoder's unsigned methods are Uint8 to Uint128, as Go spells
  them, not UInt8 to UInt128.
- The zero Encoder no longer panics. It keeps nothing, and Err reports
  that, so a unit test of a type can pass it to EncryptValue. Usable
  tells the two apart.
- Encryptable is declared once, in frame, and the codec uses it
  directly.
- A storage refusal names the program's own type.

golangci-lint already allows gosec's G115 (integer width conversions)
in the codec, which converts on purpose after checking each limit; the
rule now names encrypt/frame and encrypt/value.
The module now encodes with its own copies of the frame codec and the
value types, and imports nothing from vitaminc.

Each value type is declared once, in encrypt/value. encrypt.Date,
Decimal, Int128 and Uint128 stay aliases, as they were of vcvalue's
types, so code that names only encrypt types needs no change. New
aliases name the rest of what a program writes: encrypt.UUID (with
ParseUUID), and encrypt.Encryptable and encrypt.Encoder, which are
frame's. One type under two names means the codec encodes and decodes
it with no conversion and no registry.

Behaviour that changes with the move:

- Without FixedWidth, a nil pointer to an Encryptable is written as a
  null, which the engine pads to the width of the field's declared type.
  A field that declares no type has no width to pad to, so the stored
  null's length would show that it is a null: Cipher.Seal refuses a nil
  Encryptable there, with ErrEncoding. Generated code always declares a
  type.
- stashgen recognises the value types by their names in encrypt or in
  encrypt/value, so a field may be declared with either.

BREAKING CHANGE: code that imports vitaminc's vcvalue or vcffi imports
encrypt/value or encrypt/frame instead, or uses the encrypt aliases. The
Encoder's unsigned methods are Uint8 to Uint128; what only vitaminc's
own binding used (Sealed, TypedNull, FixedType, FixedWidth,
VCValueLeaves and the rest) is gone.
…guarded them

Nothing in the module imports vitaminc's vcffi or vcvalue any more, so
go.mod no longer requires them, and neither do the nested modules
(encrypt/encrypttest, encrypt/example, examples/s3), which carried them
as indirect requirements through the SDK they replace with a path. go mod
tidy in each removes them and their go.sum lines, and changes nothing
else. The TEMPORARY comment that explained the pin goes with it.

scripts/go-release-version.mjs refused a final version while go.mod
pinned a vitaminc module at a pseudo-version, because vitaminc's Go
bindings had no tags. The module now has no dependency that could carry
such a pin: the codec is in this repository. The rule and its tests go,
and release-golang.yml no longer mentions it. A test now checks that the
script reads the module path from the tree's go.mod and accepts a final
version from main.

Refs #1253
… value corpus changes

The frame codec came with three fuzz targets in encrypt/frame:
FuzzUnmarshal, FuzzUnmarshalCipherText and FuzzUnmarshalStorage. The
nightly go-fuzz-campaign job in fuzz.yml now fuzzes them, one matrix row
each. They decode bytes in pure Go and run no guest, so their rows build
no guest. `mise run go:fuzz` says that it fuzzes the codec as well as
the guests' ABI.

encrypt/frame's tests read conformance/vitaminc-aead, so tests-golang.yml
now starts when that corpus changes. The storage corpus, under
packages/recipher-frame, already starts it.

scripts/go-binding-test.sh names the codec's new path in a comment.
… record the breaking change

vitaminc's vcffi and vcvalue are now encrypt/frame and encrypt/value, so
the documents that named vitaminc's Go packages, or the module's own
copy under internal/, name these instead:

- AGENTS.md lists the two packages with the module's others, and says
  that encrypt's value types, Encryptable and Encoder are aliases of
  theirs.
- languages/golang/CHANGELOG.md records the move under Breaking, with
  what changes for code that imported vcvalue or vcffi, and the new
  aliases and packages under Added.
- docs/fuzzing.md lists the codec's three fuzz targets, and the plan
  for moving vitaminc's code here records stage 3 as done, two
  packages and all.
- The SDK's README, stashgen's README, the conformance READMEs,
  recipher-frame's STORAGE.md, and comments in the Rust crates whose
  formats the Go codec matches, point at encrypt/frame.

These documents are also rewritten in plain language where the review
asked, including comments in Cargo.toml files about the guests' shared
ABI. No code changes.
@coderdan
coderdan force-pushed the refactor/go-frame-codec-in-module branch from f97f467 to 5aa6552 Compare December 2, 2026 06:16
@coderdan coderdan changed the title refactor(go)!: move vitaminc's Go frame codec and value types into the module refactor(go)!: move vitaminc's vcffi and vcvalue into the module as encrypt/frame and encrypt/value Dec 2, 2026
@coderdan

coderdan commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Change of direction: the packages are moved, not merged.

The earlier version of this PR merged vcffi and vcvalue into one internal package, internal/frame, and gave encrypt value types of its own, registered with the codec at init. That was not the intent. The branch is rewritten (force-pushed) to a straight move:

  • vcffi → languages/golang/encrypt/frame (public)
  • vcvalue → languages/golang/encrypt/value (public)
  • encrypt.Date, Decimal, Int128 and Uint128 stay aliases, now of value's types; encrypt.UUID, Encryptable and Encoder are new aliases of value's and frame's.

Each type is declared once, so there is no registry and no second copy of a type. Date.DaysFromCE and Decimal.Normalized, which the earlier version removed, are kept. The review fixes are kept: the zero Encoder does not panic, Uint* spelling, the nil-Encryptable refusal on an untyped field, and the plain-language docs.

The history is now six signed commits from next: a byte-for-byte copy, then the adaptation, the module switch, go.mod and the release rule, CI, and docs. The description is updated, including verification and the open questions; the earlier questions about where the types live, Encoder's scope, and the removed methods no longer apply.

@coderdan
coderdan merged commit 97c9146 into next Dec 2, 2026
84 of 87 checks passed
@coderdan
coderdan deleted the refactor/go-frame-codec-in-module branch December 2, 2026 07:00
coderdan added a commit that referenced this pull request Dec 5, 2026
The plan's file:line citations now point at next at b939de4, the merge
of #2042. They were read at 54e6471.

#2042 moved the dynamic record code. The match options' object form and
EQL_KEY are now in dynamic/record/plan.rs, and bytes_node and the record
decrypt doc are further up dynamic/record.rs. #2003 shifted lines in the
Go SDK's query.go and records.go, and the EQL guest builds in
tests-golang.yml.

Every citation was updated. None could not be.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Go SDK: bring the frame codec and value types in from vitaminc, so the Go host and Rust guest codecs are pinned together

2 participants