Skip to content

docs(plans): one walk for a record, and host-built stored types - #2040

Open
coderdan wants to merge 51 commits into
nextfrom
docs/one-walk-record-plan
Open

coderdan wants to merge 51 commits into
nextfrom
docs/one-walk-record-plan

Conversation

@coderdan

@coderdan coderdan commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This adds a draft plan. It changes no code.

Stack Encrypt is the Rust library that encrypts values and derives search terms. Today it encrypts a record one field at a time. EQL is the SQL library that stores and queries encrypted values in PostgreSQL. Today the EQL form of a stored value is built in Rust for every language, by a piece of code called a resolver.

The plan changes both, in two phases:

  1. A record is encrypted in one walk. The encrypted tree has a node for a search term. Go and TypeScript read the tree themselves and build the stored value, so the resolver can be removed.
  2. A query comes back as the same kind of tree.

The plan also says how the one walk is built. A field is described once, by a declaration. That one declaration encrypts the field, decrypts it, and gives its query terms. The design follows the iterator adapters of the Rust standard library. A spike of it is in #2043.

Three more parts came from the review:

  • The Go SDK needs no code generator. A Go program calls cipher.Encrypt(ctx, users, &rows), and the SDK reads the struct's fields while the program runs, as encoding/json does. That is step 1.8.
  • One stored format changes. The prefix on an EQL value's c becomes rc:1:. A reader accepts the old prefix too, so every stored value still opens. Nothing else that is stored changes.
  • A new layout for stack-encrypt and vitaminc-aead. With it, a reader can follow one encrypt call from the first file.

Changes

  • docs/plans/2026-12-01-one-walk-records-and-host-built-types.md: the plan.

The plan has these parts:

Part What it holds
Decisions Dan Draper's decisions, each with its date
The design The declaration, with an example of a field, a record of a Rust struct, and a plan
What was checked The three experiments, what each covered, and what each did not
Groundwork Nine pull requests, G1 to G9, that can start before phase 1
Phase 1 Steps 1.1 to 1.8: the record path
Phase 2 Steps 2.1 to 2.4: queries
Open questions 47 questions. 42 have answers, and 43 to 47 are open

Verification

  • Citations. The plan cites code as it stands on next at b939de404. Each cited line was read there. The answers of 5 and 6 December cite next at bf69526db, and were read there. Lines cited from the spike say so, and name spike: one walk for records and values (not for merging) #2043.

  • Reviews. Two automated reviews checked the first version against the code. Dan Draper then reviewed the plan and left 17 comments. Every finding and comment has an answer on this pull request.

  • Open questions. Each one was gone through with Dan Draper on 5 and 6 December 2026. Each answer is written under its question in the plan.

  • The spike. spike: one walk for records and values (not for merging) #2043 tried the declaration design for encrypt, decrypt, and query.

  • Prototypes. Six small programs were compiled and run to check claims in the plan. Three are Rust, on 1.94.1:

    • zip leaves a term out of what decrypt takes;
    • the query lookup needs no position marker;
    • a record of a struct is built from closures, with no field names.

    Three are Go, on 1.26.10. They show the shape of a call with no generated code, and which mistakes the compiler finds. None of the six encrypts, and none is in this pull request.

  • Plain language. The checker reports 0 items that must be fixed.

  • No test was run for this pull request, because it changes no code.

Related

Review notes

  • Who decided what. The decisions in the plan are Dan Draper's. The steps are a proposal.
  • Still open. Questions 43 to 46 are about the Go SDK with no generator. They cover what happens to stashgen, where a struct declares its context, and how a query names a column. They also cover which other Go principles change. Question 47 is about a record of a Rust struct. Questions 43 to 46 wait for the trial in step 1.8.
  • The design principles change too. The plan drops the Go principle "Generate code with a Go tool", and the rule that no call takes a context. docs/sdk-design-principles.md and its decision record change in a pull request of their own.
  • Proposed names. plaintext_from, and the Go and TypeScript names in step 1.5, are proposals.
  • Releases. The next EQL release waits until this plan is done. The new prefix takes two releases, so that every reader is upgraded before any writer changes.
  • No changeset: the pull request changes one file under docs/plans/.

A draft plan in two phases. Phase 1 encrypts a record in one walk, adds a
term node to the ciphertext tree, and moves the building of a stored type
into Go and TypeScript, so the resolver can be removed. Phase 2 returns a
query as a tree of terms.
@changeset-bot

changeset-bot Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 7f72a35

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 Dec 1, 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: 3272e0a6-6782-47a1-a6fc-50544c552bd1

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

@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.

Automated review at medium effort. It reported seven findings. I checked each one against next at 54e647124, and all seven are correct, two of them in part. The inline comments give each finding and what I found when I checked it.

Three findings change the plan's order of work. Four are corrections to citations and figures.

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 marked this pull request as ready for review December 1, 2026 13:09
@coderdan
coderdan requested a review from a team as a code owner December 1, 2026 13:09

@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 76cb8efe · posted from Claude Code · claude-opus-5-5 · effort medium
Sources: code-review · claude-opus-5-5; rust-security · claude-opus-5-5; mattpocock-skills:code-review (standards and spec) · claude-opus-5-5
Skills: code-review, company-skills:rust-security, mattpocock-skills:code-review, company-skills:review-cross-check

Findings (14): 5 major, 9 minor. All 14 are inline.

Every finding was checked against the code at 76cb8efe. None repeats the seven threads already on this PR. Three findings were refuted and are not posted: the TypeScript {t, v} form (no shipped addon produces it), the count of 26 frame tags (correct: 0xF4 is refused on read), and skills drift (no skill documents this surface).

Four further points need a decision by the author and were not verified as defects:

  • A term node would count as a sealed leaf in check_shape (vitaminc-aead/src/seal.rs:293) and sealed_any (walk.rs:146), because both test !matches!(n, Passthrough). Then a map or sequence that holds only terms passes the rule that refuses a container with no sealed leaf. Step 1.3 should say that a term is not sealed.
  • After step 1.6, the dynamic path refuses a JSON index on a plain field (JsonIndexPending, kind.rs:111-118). Its JSON operators also run only through a target (query.rs:833-838). So the JSON check needs more than the host building the stored value.
  • Step 1.6 removes eql_bindings::encryption::{query, targets}. These are public modules of a crate published in lockstep with @cipherstash/eql, so that is a major release of all five EQL artefacts. The section "What this changes elsewhere" does not say so.
  • value-napi/src/ciphertext.rs:23-31 says applications may have persisted {t, v}. That is out of date, but it is not part of this plan.

Generated by Claude Code

A second review found that the plan could not finish if the JSON check
failed, because one step both built the stored types and removed the
resolver. Step 1.6 now builds the types one by one, and step 1.7 removes
the resolver when every type is done.

The plan also says what the JSON check has to change first, where the type
catalog comes from once no resolver answers, which mentions of EQL stay in
stack-encrypt, and that TypeScript needs a call that returns a record's
tree. Step 1.4 has two refusal tests. Refs #2033.
@coderdan

coderdan commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Replies to the four points in the review body that asked for a decision. I checked each against the code.

  1. A term counted as a sealed leaf. Correct (seal.rs:293, walk.rs:146). Step 1.3 now says that a term is not a sealed leaf, and names both rules.
  2. The JSON index on a plain field. Correct (refusal.rs:923, query.rs:833). "Checks to make first" now says the JSON check has to change Stack Encrypt first. It has to admit the index on a plain field and return the document in the tree.
  3. The public modules of eql-bindings. Correct. query and targets are public. targets is public on main too. The plan lists this under what changes elsewhere. Open question 13 asks whether it is a major release.
  4. The comment in value-napi. Not part of this plan, so nothing changed.

All 14 inline findings were correct. The fixes are in 0c4766a. Each thread has a reply.

…SON check

The plan said the filter of TextSearch differs from the filter of
TextMatch. The two are built the same way, under the same match options.
They differ only for text that cuts no token: TextMatch refuses it, and
TextSearch stores an empty filter. The plan now says so, with the lines
that do it, and names the one rule the two host types differ by.

The JSON check gave two facts and no reason. It now says why a JSON
document has no route through the tree today: a plan cannot list the
JSON index as an output, the target builds the stored value in Rust from
the index's document, and a JSON operator reads its options from the
target.
A stored type implements the visitor, so a type outside the Go module has
to be able to import it. A package under internal cannot be imported from
another module, and gensupport is for generated code alone. The open
question on the package now asks for its name, and whether a type must
embed the default.
…im to consider

The reader and the visitor had different names in Rust, in the experiment
and in the Go codec. The plan now proposes one name for each part, written
in each language's style. Step 2.3 records the option of a deprecated
QueryTerm in Go, with the facts that decide how much it helps.
@coderdan

coderdan commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

#2003 is updated, and this plan's Go steps name a package it no longer adds.

#2003 no longer merges vitaminc's Go packages into internal/frame. It moves them as they are, and both are public:

  • vcffi → languages/golang/encrypt/frame: the codec, including MarshalCipherText and UnmarshalCipherText, and the storage profile.
  • vcvalue → languages/golang/encrypt/value: the value types. It imports only the standard library.

encrypt.Date, Decimal, Int128, Uint128 and UUID are aliases of value's types, and encrypt.Encryptable and Encoder are aliases of frame's.

So the plan's references to internal/frame (lines 274, 371, 393 and 574) need to become encrypt/frame. That also bears on open question 8. Step 1.5 proposes a new public package, encrypt/transcode, beside the codec, partly because the codec was internal. Now that encrypt/frame is public, the reader and visitor could live there, next to UnmarshalCipherText, which step 1.5 already says becomes a visitor on the public reader. Is a separate package still wanted?

An open question moved here from #2003. encrypt.Cipher's QueryTerm, Verify, TargetLimit, Contexts, Seal, Open and JSONOpen all take a *record.Plan, from internal/record. A program outside the module can't import that type, so it can't call these methods; only generated code can. Step 2.3 removes QueryTerm. The plan doesn't say what happens to the other six. Step 1.4, where a record is encrypted in one walk, rewrites the path behind Seal and Open. Should that step also give these methods signatures that use no internal type, by the rule the plan sets for the visitor ("No internal type in an exported name")? Or should they stay as they are, for generated code only?

…oes there

The frame-codec pull request now moves vitaminc's Go packages as two public
packages, encrypt/frame and encrypt/value, and adds no internal/frame. The
plan's Go steps name the new path. With the codec public, the reader and
the visitor go beside it, so the plan no longer proposes a package of its
own. A new open question asks what happens to the Cipher methods that take
an internal plan type.
@coderdan

coderdan commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Checked against #2003 at 5aa6552, and fixed in 132a2a3.

The package path. #2003 now adds languages/golang/encrypt/frame and languages/golang/encrypt/value, and no internal/frame. The plan's Go steps name encrypt/frame in every place.

The reader's package. The plan no longer proposes encrypt/transcode. Step 1.5 now puts the reader and the visitor in encrypt/frame, beside the codec. The reasons:

  • The codec was internal, and that was the main reason for a second package. It is public now.
  • With the reader beside the codec, one package reads the tree. Step 1.5 has a rule that each language has one parser.
  • encrypt/frame imports the standard library and encrypt/value alone, so no exported name uses an internal type.

Open question 8 still asks whether a package of its own is wanted. That choice is not mine to make.

The six Cipher methods. Added as open question 16. The facts in the plan:

  • Verify, TargetLimit, Contexts, Seal, Open, and JSONOpen take a *record.Plan (languages/golang/encrypt/query.go:292, languages/golang/encrypt/records.go:47).
  • Step 1.4 rewrites the path behind Seal and Open.
  • The Go SDK's principle 7 says that no method that a user touches is called a plan or returns one (docs/sdk-design-principles.md:160).

The plan does not choose. Principle 7 rules out a public signature that takes a plan. So the choice is between a move behind gensupport and no change.

The spike in #2043 walks a record with one sink built from the plan and
seals it in one pass, with no adapter sink in the caller. The plan now
records the decisions from the spike, what it checked, the order of the
pull requests for step 1.4 and the rules each one follows. Questions 1,
9 and 11 have answers, and question 17 asks whether the plan still
implements EncryptTarget.
The spike in #2043 showed that a target can be declared once, as a sink
for one walk of the value and a finishing step, and that the one
declaration encrypts the target, decrypts it and gives its query terms.
The combinators become adapters over that trait, as the standard
library's iterator adapters are. This is how the plan's third decision
is built, so the question of whether it still stands is answered.

The plan now has:
- the decisions made during the spike;
- the declaration design, and what the compiler checks;
- what the spike checked for encrypt, decrypt and query, what it did not
  cover, and the four ways it differs from today's code;
- the layout of stack-encrypt and vitaminc-aead: the three calls as
  top-level modules, one place for each index, the order of the
  modules, and the crate root's 29 names;
- the groundwork that can start now: #2042, the AES cipher in #2044,
  vitaminc-normalize and the layout moves;
- step 1.4 as eight pull requests;
- twelve new open questions, and answers to questions 1, 6 and 17.

It replaces the record-sink design of the last commit, which the
declaration design superseded.
The plan said the move was an unchanged copy of the published crate,
followed by the crate's changes. The move in #2052 follows the
vitaminc-aead move: the crate comes with its git history, at the code of
its 0.10.0 release. The crate's own changes follow from the vitaminc-aead
changes in step 1.4, so they go there. The supply-chain store does not
cover the crate yet, and the plan now says what that needs.
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.
Open question 2 is answered. Every language can then skip a
passthrough node without reading its frame.
Open question 3 is answered by the rule for decrypt: a term opens
nothing. A term at the root or in a sequence is refused as malformed.
On decrypt, a type that stores its context opens under the stored one,
as typed Rust does today. A renamed column then does not stop old rows
from opening. The Go SDK refuses a stored i that differs from the
plan, so step 1.6 changes that. Open question 4 is answered.
The last commit recorded the opposite of the decision. Today's rule
stays: on decrypt, the stored i of an EQL value has to match the
plan's label. The label comes from the declaration and is independent
of the name of a database column, so a renamed column does not stop
old rows from opening.
Open question 5 is answered. eql-codegen reads the catalog, so the
generated Go and TypeScript types and eql-bindings share one source.
An EQL value is written with the prefix rc:1: in place of
stack-encrypt:1:. A reader accepts both, so every stored value still
opens. It is groundwork item G9. Open question 41 asks whether the
change is rolled out in one release or two.
The first release accepts both prefixes and still writes the old one.
The second writes rc:1:. Open question 41 is answered.
Open question 7 is answered for selectors and tokens. The host type
writes the base64 and decides how the value binds. The two operands
that are whole EQL objects wait for the JSON check.
…e default

Open question 8 is answered. The interface has one unexported method
that only the default has, so a new kind of node breaks no type.
Open question 10 is answered. Issue 2029 stays open until step 1.5
lands.
Open question 12 is answered: an SDK reads no list of types. The EQL
package has each concrete type with its visitor.

Step 1.6 had three stale sentences. After G8 no rule about empty match
text moves to the host type. The host type checks the stored i. The
prefix on c comes from the catalog, and a reader accepts both.
…tashgen

Open question 13 is answered: no release has the two eql-bindings
modules, and the next EQL release waits until this plan is done, so
they are deleted.

Open question 42 asks whether the Go SDK keeps its code generator once
the stored types are built in Go.
The Go SDK reads the fields of a struct while the program runs, as
encoding/json does. The call is cipher.Encrypt(ctx, users, &rows). A
stored struct can also have a method that says how it is sealed, and
the compiler then checks each field. It is step 1.8.

The Go principle that asks for a generator is dropped, and so is the
rule that no call takes a context. An SDK mirrors the Rust API as
closely as is idiomatic in its language.

PR 1716 is a second generator for a program that uses sqlc, because
stashgen has no struct to tag there.
Open question 14 is answered. Step 1.5 builds TypeScript records on the
tree from the start. Issues 1813 and 1803 stay open until then.
…e unexported

Open questions 15 and 16 are answered by step 1.8: with no generated
code, Go needs no deprecated QueryTerm, and the cipher methods that
take a plan have no caller outside the module.
Open questions 18 and 19 are answered. DecryptSource<P> keeps the
compile-time check that a stored type opens to a plaintext type, and
returns the decrypt half of the declaration.
Open question 21 is answered. Step 1.4 keeps the order of next.
Open questions 22 and 23 are answered. Both are on next, and the spike
left both out. Step 1.4 keeps them, and its done-when list says so.
Open question 24 is answered. Each index says whether it has an index
for each operator, written out with no macro, and zip reads that from
its two sides. A prototype compiled.
Open question 25 is answered. A closure reads each field and gives its
type, so a hand-written declaration cannot check one field and seal
another. A plan still reads fields by name. A prototype compiled.

The closure that builds the plaintext takes the fields by position, as
next does, so two fields of one type can still be exchanged there.
…me for it

Open questions 26 and 28 are answered. A typed JsonPlaintext is handed
to the JSON tree directly, as on next. Its walk gives JSON text, which
is the opaque form. For a struct or a record from a binding, a sink is
the aim, and the JSON check decides.

The plan says JSON tree where it said JSON index, and the terms
section defines JSON tree and opaque JSON.
Open questions 29 and 30 are answered. The stored layout of a leaf is
in sealed/. The EQL test for opaque JSON and the test crate of the
recipher-js value bridge both go through Stack Encrypt, with the test
key source of the test-support feature.
The groundwork table says which pull requests exist. Step 1.3 no
longer waits for open question 3, which is answered.
coderdan added a commit that referenced this pull request Dec 5, 2026
The CRAP (Change Risk Anti-Patterns) gate scores every function under the
crate's source folder and fails on a complex function with no coverage.
The gate skipped test code in two ways: a `tests/` directory by an exclude,
and an inline test module because the tool does not score one. A test
module in a file of its own is neither. So the gate scored 346 test
functions as production code and failed on seven of them.

The task now excludes `tests.rs` and `*_tests.rs`, as the stack-auth task
already does for `tests.rs`. With the excludes, the tool scores the same
1,779 functions as it does on the base branch.

Refs #2040

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