Skip to content

docs(stack-encrypt): the value model, nulls, opaque values and error codes in the language integration guide - #1828

Open
coderdan wants to merge 4 commits into
nextfrom
docs/language-integration-gaps
Open

coderdan wants to merge 4 commits into
nextfrom
docs/language-integration-gaps

Conversation

@coderdan

@coderdan coderdan commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The language integration guide did not cover four things that every new binding runs into. The Go SDK settled each of them, and the TypeScript SDK had to work them out again. This adds them. It also adds the rules that keep a language binding thin.

The guide is packages/stack-encrypt/docs/language-integration.md. It is also the rustdoc of stack_encrypt::dynamic.

Changes

Section 1 gets the rules for a thin language binding, and the guide's names change:

  • A binding is thin. It sends Stack Encrypt's plan as it is, and reads it with dynamic::record::plan. It lets Stack Encrypt check each row and convert each value to its field's kind. It keeps Stack Encrypt's names, such as the outputs c and eq. A gap is fixed in Stack Encrypt, not worked around in the binding.
  • Names. The guide says "Stack Encrypt" for this crate, where it said "the engine". It says "language binding", or "binding" for short. AGENTS.md makes the same change, and its "Designing a language SDK" section points to the new rules.

Section 5, "Control messages and plaintext", gets three parts:

  • The value model. The types Stack Encrypt accepts, including a UUID. An out-of-range date, decimal, timestamp, or UUID is refused when it is sealed. A field with no declared kind stores a logical type that the build does not know as it arrived. A declared kind refuses it. A plan's field types are the same list.
  • Nulls. vitaminc decides whether a null is padded. A fixed-width type's null is a typed null, padded to a value's length. A variable-width type's null is a plain null. A host's frame can carry a typed null. It is padded when it is sealed. A frame writer writes a plain null, so for a record the plan's null mode supplies the type. An SDK does not pad nulls itself.
  • A whole object as one value. An opaque value is a storage blob sealed as bytes. A table separates the three formats (sealed leaf, frame, storage blob). The section lists the four ways the storage profile differs from the frame. It also says what Go and Rust do with a value that has no storage form.

Section 8, "Errors", gets a "Codes" part:

  • pass Stack Encrypt's codes on unchanged;
  • name the binding's own codes after its crate, so they cannot clash with Stack Encrypt's;
  • report a refused value as a typed error, never as text to match;
  • exceptions, Result, or Go's error are the language's choice. The codes are the same in every shape.

Section 11's checklist gets two items. One is for the type mapping, nulls, and opaque values. The other is for a thin binding.

The TypeScript SDK plan (docs/plans/2026-11-22-recipher-typescript-sdk.md) changes step 3 of its build order. The records step includes one field with { record, field }, and waits for #2029 and #2028.

Verification

  • RUSTDOCFLAGS="-D warnings" cargo doc -p stack-encrypt --no-deps --all-features: clean. Every intra-doc link resolves.
  • cargo test -p stack-encrypt --all-features --doc dynamic: 21 passed, after next was merged in.
  • Each claim was checked against the code:
    • the value model and its refusals: Logical::admits and leaf.rs in vitaminc-aead, and the tests uuids_and_unknown_logical_types in dynamic/record.rs;
    • the null rule: vitaminc-aead 0.10.0 leaf.rs, its test a_fixed_width_none_is_a_typed_null_as_long_as_a_some, and NullMode;
    • a host's frame carrying a typed null, and a frame writer writing a plain null: the rustdoc of FrameWriter's typed_null and of OwnedFrame in vitaminc-aead;
    • the storage profile's rules: STORAGE.md in vitaminc-aead-frame 0.10.0;
    • an OpaqueBlob decrypting as its blob's bytes: a probe program against the engine;
    • Go's storage rules: vcffi/storage.go at the version languages/golang/go.mod pins.

Related

Review notes

…codes in the integration guide

A binding author could not learn four things from the guide that every
binding meets: which types the engine accepts, that vitaminc decides
whether a null is padded and the type for it comes from the plan, that
an opaque value is a storage blob in a format separate from the frame,
and how a binding names its own error codes beside the engine's. Each
was worked out once for Go and again for TypeScript.
@changeset-bot

changeset-bot Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 4315942

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

@coderabbitai

coderabbitai Bot commented Nov 25, 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: b3aeb798-2908-4b00-a797-f98bb02268b2

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

@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 36bb7df · posted from Claude Code (scheduled routine) · claude-opus-5-5 · effort medium
Sources: code-review · claude-opus-5-5; mattpocock-skills:code-review standards and spec agents · model unknown; claim-verification agent · model unknown; review-cross-check verification agents · model unknown
Skills: code-review, mattpocock-skills:code-review, company-skills:rust-security, company-skills:review-cross-check, company-skills:review-post, company-skills:run-report

Findings (11): 3 major, 8 minor. All 11 are inline.

The most important one is the first: the new value-model text is written against a ValueFrame that next has already deleted. It merges with no conflicts, but then rustdoc fails and the guide states the old UUID and timestamp rules. Rebase before addressing the rest, because several minor findings (L394-416) will change with that rewrite.

company-skills:rust-security found nothing to add: the change is prose only, and its guidance on errors and nulls does not leak values. One finding was refuted in verification: L702-704 does not duplicate L653-658. One question is left for the author and not raised inline: the Go SDK's own conversion refusals are a sentinel plus text, with no code (for example gensupport/field.go:86). The new rule at L702-704 asks for a code, so should the guide say Go does not meet it yet?

No changeset is needed: stack-encrypt is released by release-plz, and its CHANGELOG already records the guide.


Generated by Claude Code

Comment on lines +388 to +392
A UUID is refused, although vitaminc has a UUID type. So is a logical type
the engine does not know, and a date, decimal or timestamp outside
vitaminc's range. [`crate::dynamic::ValueFrame#the-value-model`] holds the
rule, and [`crate::dynamic::ValueFrame::from_bytes`] refuses a frame that
breaks it.

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.

major This text is stale against the base branch next (612 commits ahead of the merge base ee72307). There ValueFrame is deleted (bfd3136, #1955), UUIDs are accepted as ValueKind::Uuid (#1918), a logical type the engine does not know is carried, and a timestamp keeps the unit the host wrote it in (#1846). The PR merges with no conflicts, but in the merged tree RUSTDOCFLAGS="-D warnings" cargo doc -p stack-encrypt --all-features fails with three unresolved link to crate::dynamic::ValueFrame errors (here and at L412), and line 388 contradicts the guide's own text on next. Rebase onto next and rewrite the value model and nulls sections against dynamic::frame (Frame/OwnedFrame), ValueKind::Uuid and the #1846 unit rule. The docs.rs link at L429 also needs to become recipher-frame.

Source: mattpocock-skills:code-review standards agent · model unknown; orchestrator · claude-opus-5-5


Generated by Claude Code

and the crate's `STORAGE.md`. The blob is sealed as an ordinary bytes
value. A ciphertext of an `OpaqueBlob` decrypts as the bytes of its blob,
and those bytes encrypted as bytes decrypt as the `OpaqueBlob`. So every
language that writes the same blob writes the same ciphertext.

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.

major Sealing is randomised: each leaf gets a fresh data key and nonce (src/cipher.rs:2111-2115), so the same blob seals to a different ciphertext every time. A binding author who writes a cross-language test comparing ciphertexts will find it never passes. Say instead that a ciphertext written by any language opens in any other, and compare blob bytes, not ciphertexts, for determinism.

Source: code-review · claude-opus-5-5; claim-verification agent · model unknown


Generated by Claude Code

Comment on lines +693 to +696
- **Pass the engine's codes on unchanged.** An engine error keeps its own
code (`stack_encrypt::aead`), help, fields and causes. Do not map engine
errors onto codes of your own, or group them into coarser kinds: a
grouping would have to be kept in step with every engine error.

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.

major This contradicts the guest status table earlier in this section: status_for_error (languages/golang/encrypt/guest/src/status.rs:122-150) groups engine errors into coarse numbers such as STATUS_ENCODING, and Go adds sentinels such as encrypt.ErrEncoding on top of Diagnostic.Code. A reader will either drop the status fast path or decide the Go SDK breaks the guide. Scope the rule to the engine's error code: never replace or rename it, but a coarser kind may be added as long as the full code still reaches the caller. Also call the table's numbers "status" rather than "code".

Source: code-review · claude-opus-5-5; mattpocock-skills:code-review spec agent · model unknown; claim-verification agent · model unknown


Generated by Claude Code

Comment on lines +394 to +397
Map your language's types onto this list, and refuse anything else before
it reaches the engine, with an error that names the field and the type. A
plan's field types ([`crate::dynamic::ValueKind`], section 4) are the same
list.

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.

minor ValueKind is not the same list. It has no kind for null, undefined or passthrough (dynamic/kind.rs:355-357; FromStr refuses "null"), and it adds json. A binding that builds its plan vocabulary from this list will emit refused kinds and never offer json. Say the kinds are the value model's types except null, undefined and passthrough, plus json, and point to the list in section 4.

Source: code-review · claude-opus-5-5; mattpocock-skills:code-review spec agent · model unknown; mattpocock-skills:code-review standards agent · model unknown; claim-verification agent · model unknown


Generated by Claude Code

Comment on lines +403 to +406
- **A null of a fixed-width type** (a boolean, a number, a date, a
timestamp or a decimal) is a *typed null*. It is padded to the length of
a value of that type, so once sealed it cannot be told from a value by
its length.

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.

minor A boolean has no typed null. vitaminc-aead's tags.rs:98-100 says a bool's leaf is already as short as a plain null, and ValueKind::Bool maps to None in sealed_null (kind.rs:476-477). Drop the boolean from this list and add: "A boolean's null is the plain null, already as long as a boolean." NullMode::Sealed's rustdoc (record.rs:232-239) has the same wording.

Source: mattpocock-skills:code-review spec agent · model unknown; claim-verification agent · model unknown


Generated by Claude Code

Comment on lines +413 to +414
plan. A field declared with a fixed-width type and `"null": "sealed"`
seals its nulls padded. A field with `"null": "sql"` stores nothing, and

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.

minor "null": "sealed" also requires the field's only index to be equality. An int32 field with an ore index is refused with Reason::SealedNullIndex (record.rs:570-576). Section 4 already states this, so cross-reference it rather than restate part of it.

Source: code-review · claude-opus-5-5; mattpocock-skills:code-review spec agent · model unknown; mattpocock-skills:code-review standards agent · model unknown; claim-verification agent · model unknown


Generated by Claude Code

Comment on lines +449 to +451
- version 1 holds plain scalars only. A date, a timestamp, a decimal, a
UUID, `undefined` and a passthrough have no storage form and are
refused.

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.

minor This lists frame tags as if they were language types, so it reads as contradicting L467-468, where a uuid::Uuid is stored as 16 bytes. Name the refused items as vitaminc's logical-type nodes: date, timestamp, decimal, typed null (missing here), the logical envelopes that carry vitaminc's UUID, undefined and passthrough. Then say a serde type such as uuid::Uuid is not one of them and is written as bytes or text.

Source: mattpocock-skills:code-review spec agent · model unknown; claim-verification agent · model unknown


Generated by Claude Code

Comment on lines +462 to +463
- Go refuses its logical-type values, such as `encrypt.Date` and
`encrypt.Decimal`, and a passthrough, with `vcffi.ErrUnwritable`.

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.

minor For generated Go code these fields are refused at generate time: stashgen rejects an opaque struct field of encrypt.Date, encrypt.Decimal or a vcvalue type other than Object with "has no storage form" (stashgen/read.go:1481-1495). At run time, opaqueBytes returns encrypt.ErrEncoding wrapping vcffi.ErrUnwritable (gensupport/codec.go:388-394). Describe both.

Source: code-review · claude-opus-5-5; claim-verification agent · model unknown


Generated by Claude Code

Comment on lines +470 to +471
Whichever rule you choose, write it down, and make a refusal name the
field.

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.

minor Go's run-time storage refusals do not name the field. For example, an invalid UTF-8 string in an opaque struct fails with a string is not valid UTF-8, and neither vcffi's goStruct nor gensupport/codec.go:394 adds a path. Rust's storage::Error and Go's generate-time refusals do name it. Either add the path in Go or say here that Go's run-time refusals do not name the field yet.

Source: code-review · claude-opus-5-5 (scope corrected by verification)


Generated by Claude Code

Comment on lines +697 to +701
- **Name your own codes after your binding's crate.** An error that only
your SDK raises, such as a value your language cannot convert, gets a
code under its crate's name, never under the engine's: a crate
`example_binding` raises `example_binding::not_a_string`. Then no code
of yours can clash with one the engine adds later.

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.

minor This treats binding and language SDK as one thing, though §1 of this guide and ADR-0008 keep them apart. An SDK layer written in Python, Elixir or Go has no crate to name its codes after. Suggest: "Name your own codes under a namespace you own: the binding crate for the binding's errors, and your SDK's package or module for the SDK's own."

Source: mattpocock-skills:code-review standards agent · model unknown


Generated by Claude Code

…tack Encrypt

The guide and AGENTS.md now name the crate Stack Encrypt, not "the
engine", and the Rust layer of an SDK a language binding.

Section 1 of the guide gains the rules for a thin binding: send Stack
Encrypt's plan as it is, let Stack Encrypt check each row, keep its names,
and fix a gap in Stack Encrypt. The checklist gains the same item, and
AGENTS.md points to the section.

Merging next showed that the value model and null sections were stale:
ValueFrame is gone, a UUID is in the value model, an unknown logical type
is stored as it arrived in an untyped field, and a host's frame can carry
a typed null. Those passages now say so.
The records pull request includes one field with { record, field }, and
starts after Stack Encrypt has a conversion of the encrypted tree and a
call for one field of a plan.

This branch has not been deployed

No deployments
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.

2 participants