Skip to content

refactor(stack-encrypt)!: clearer names and modules for the dynamic record path - #2042

Merged
coderdan merged 23 commits into
nextfrom
refactor/dynamic-record-readability
Dec 5, 2026
Merged

coderdan merged 23 commits into
nextfrom
refactor/dynamic-record-readability

Conversation

@coderdan

@coderdan coderdan commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Summary

This pull request renames and moves code in stack-encrypt's dynamic record module, so it is easier to read before the changes planned in #2040. Behaviour does not change. Stored bytes do not change.

Three public paths change, and the stack-encrypt changelog records each one:

  • A plan is now read with Plan::from_frame(frame) in place of record::plan(frame).
  • IntoLabel is now at stack_encrypt::dynamic::IntoLabel.
  • The module dynamic::planned is now dynamic::record::planned. Its types are still re-exported from dynamic.

The dynamic module turns a record from a language binding into encrypted fields. A binding is the layer between the Rust code and another language, such as the Go guest. A plan is the description of a record that the binding sends with it. It says how each field is encrypted.

Changes

Module layout

  • The plan has its own module, dynamic/record/plan.rs. planned.rs and the source reader also move under dynamic/record/.
  • FieldValues and IntoLabel move from the top-level plan module into dynamic. The top-level plan module now has PlanError alone.

Names

  • Plan::from_frame and Plan::from_frame_with replace record::plan and record::plan_with.
  • StoredRow becomes EncryptedRecord, the pair of SourceRecord.
  • split_source becomes into_source_records. It now takes the plan and returns records that fit it.
  • SplitRefusal becomes SourceRecordError, an error type with thiserror.
  • SplitSource and Rows become one type, OneOrMany<T>.
  • TopSink becomes SourceSink, Place becomes Cursor, and the NotARecord sink becomes RecordSeq. The name NotARecord now belongs to an error type.

Callers

  • The callers in stack-encrypt's tests and fuzz target, eql-bindings, the EQL encryption tests and the Go guest use the new names.

Editor

  • .vscode/settings.json turns on stack-encrypt's dynamic feature for rust-analyzer.

Verification

At 3a9d31623, on a Mac, with Rust 1.94.1:

  • fmt and clippy: pass on the root workspace, all features and targets, with -D warnings.
  • Tests: 3,014 run on the root workspace with nextest, all features. 3,008 pass and 2 are skipped.
  • Six stack-auth failures: these tests are outside this change. The branch changes no stack-auth file. The same tests fail on next on this machine, and a different set fails on each run.
  • Doc examples and rustdoc: pass, rustdoc with -D warnings.
  • Fuzz: stack-encrypt's fuzz crate builds.
  • EQL: the eql-bindings and EQL encryption tests pass. The tests that need PostgreSQL were not run.
  • Go: the five wasm modules build and pass the import check. The guest tests pass (85, and 89 with the EQL types), and go test passes for every package.

Related

Review notes

  • Each commit makes one rename or one move, so reading the commits one at a time is easier than reading the whole diff.
  • The last commit updates a compiler-message snapshot in tests/ui, because the message names planned.rs at its new path.

The function returns the records of a source, one per row. The old name
said how it worked and not what it returned.
The type is an error, so it is named as one and implements
std::error::Error through thiserror, as the crate's other errors do.
The function that converted it is now From<SourceRecordError> for the
dynamic Error, so the caller uses the ? operator.
The dynamic module is behind a cargo feature, so rust-analyzer skipped
it and showed no types or errors there.
SplitSource and Rows were the same shape under two names, and
source_rows matched on one to build the other. Both are now
OneOrMany<T>.
The type holds the row and the field the reader is at, which is what a
cursor is. The variables that hold one are renamed with it.
It is the sink the whole source is walked into.
It is the sink for a row of a batch that is a sequence, as RecordMap is
the sink for a row that is a map. The old name is wanted for an error
type.
A SourceRecord was Result<_, Found>, with a description of a value in
the place of an error. Its error is now NotARecord, which holds the
Found and implements std::error::Error.
The file's other sinks use the short form: FieldSeq, SeqSink.
Only dynamic::record reads a source into records, so the reader now
lives at dynamic/record/source.rs and its items are visible to record
alone. The one test that reached it from dynamic::found moves with it.
… the plan

Row is renamed SourceRecord, and source_rows is renamed
into_source_records and takes the plan. They move into record::source
with source_row (now source_record) and check_field, so record sees one
function and one type for reading a source.

The reader that runs before the plan is applied is private to the
module: into_raw_fields, which returns RawFields.
It is the encrypted form of a record, and pairs with SourceRecord. A
caller may not have stored it.
Plan, FieldPlan, Output, NullMode, Verb, the parser and its wire types
move out of dynamic/record.rs into dynamic/plan.rs. record keeps the
entry points and the conversions between a record's forms.

No public path changes: record re-exports the plan's public items, so
dynamic::record::plan and dynamic::record::Plan still resolve. Code
outside the new module reads a plan through its accessors where it
read private fields before.

The tests stay in record.rs for now.
Only the dynamic module uses them, so they move out of the top-level
plan module, which now holds PlanError alone. IntoLabel's public path
is now stack_encrypt::dynamic::IntoLabel.
…ecord

A plan describes a record, and Planned runs one, so both now live under
dynamic/record with the source reader and FieldValues. record's helpers
and the source module's items are visible to record and its submodules
alone.

The query module is the one user outside record. It reads a plan
through record's public re-exports and two methods that stay visible
to dynamic: FieldPlan::indexes and Plan::declared_context.

dynamic::planned is now dynamic::record::planned. Its public types are
still re-exported from dynamic.
The parser was a function named plan in a module that now has a
submodule named plan. It is now an associated function:

  record::plan(frame)                 Plan::from_frame(frame)
  record::plan_with(frame, resolver)  Plan::from_frame_with(frame, resolver)

The _with form follows the crate's other pairs: Plan::new and
Plan::new_with, encrypt and encrypt_with.

Callers are updated in stack-encrypt, its fuzz target, eql-bindings,
the EQL encryption tests, the Go guest and the current docs. The
changelog entry also records the two paths that moved in earlier
commits on this branch: plan::IntoLabel and dynamic::planned.
The module moved under dynamic/record, so the compiler's note points
there.
@changeset-bot

changeset-bot Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 6744662

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 3, 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: 278378a2-8b0e-42d6-b38f-3fe6149a3282

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.

Code review at 3a9d31623eaabbbdf221f40b42cf19284b0fdee6, by /code-review medium in Claude Code (Claude Opus 5.5).

The reviewer compared the moved code with next, using git's moved-code detection. Apart from plain moves, the changes are renames, narrower visibility, .fields becoming the .fields() accessor, and split_refusal becoming From<SourceRecordError> for Error. Each behaves as before. Both sides have 2,652 tests. The one test removed from found.rs is now in record/source.rs.

It found no behaviour defects. It found four doc comments that name the old paths, and I checked each one against the code. Three are inline below. The fourth is in a file this pull request does not change:

  • packages/stack-encrypt/src/target/operations.rs:739: the doc comment names its caller as dynamic::planned::compose. The module is now dynamic::record::planned.

ADR 0007 and docs/plans/2026-10-24-stack-encrypt-api-plan.md also say dynamic::planned. They record the design as it was when they were written, so I will leave them as they are.

The record module's docs, the Absent type and a comment in
target::operations named dynamic::planned, which is now
dynamic::record::planned. The language integration guide pointed at
plan.rs for the grammar, which record.rs still describes, and the
source reader's docs now say a value that is not a record is a
NotARecord error.
@coderdan

coderdan commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

The fourth finding, in target/operations.rs, is fixed in db03a5c too. The comment now names dynamic::record::planned::compose.

@coderdan
coderdan marked this pull request as ready for review December 3, 2026 12:37
@coderdan
coderdan requested a review from a team as a code owner December 3, 2026 12:37

@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 db03a5cf · posted from Claude Code · claude-opus-5-5 · effort medium
Sources: code-review · claude-opus-5-5; code-review agent (manual pass) · claude-opus-5-5; mattpocock-skills:code-review · claude-opus-5-5; rust-security · claude-opus-5-5
Skills: code-review, mattpocock-skills:code-review, company-skills:rust-security, company-skills:review-cross-check

No behaviour defects. All three reviews compared the moved bodies with next and found them the same apart from the renames. The rust-security pass found no change to what is encrypted, what is bound into a context, or what input is accepted.

Findings (11): 11 minor — 7 inline, 4 below.

  • packages/stack-encrypt/src/target/index.rs:97 (outside diff) minor IndexSpec's rustdoc says "dynamic::record::plan documents that shape". That function is now Plan::from_frame, and the name is in backticks, so rustdoc cannot catch it.
  • packages/stack-encrypt/CHANGELOG.md:1201 (outside diff) minor The "To upgrade" table in the same [Unreleased] section still tells users to parse a plan with dynamic::record::plan, which this PR removes. Lines 1310 and 1476 name record::plan and record::plan_with the same way. Write Plan::from_frame and Plan::from_frame_with.
  • docs/plans/2026-11-22-recipher-typescript-sdk.md:454 (outside diff) minor This plan is still in progress and tells implementers to call dynamic::record::plan (lines 454, 477, 1151 and 1366) and cites src/dynamic/planned.rs (line 1302). Both are gone after this PR. Unlike ADR 0007 and the API plan, it is not a record of finished work.
  • general minor The #2040 plan pins its citations to next at 54e647124, but names into_raw_fields (its lines 77 and 478), which this PR adds. After this PR merges, its other citations move too, for example record.rs:177 (EQL_KEY) is now record/plan.rs:25. Re-pin that plan after this merges.

Generated by Claude Code

…paths

The IndexSpec rustdoc, three unreleased changelog entries and the
TypeScript SDK plan named record::plan, which is now Plan::from_frame,
and the plan cited planned.rs at its old path. Output's link to the
stability section resolved against the wrong module after the move.
The source reader's docs say what "the split" is now that split_source
is renamed, and a test's doc comment names the rule it refers to.
@coderdan

coderdan commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

The four findings outside the diff:

  • target/index.rs:97: fixed in d92d4dc. It now names Plan::from_frame.
  • CHANGELOG.md: fixed in d92d4dc, at lines 1201, 1310 and 1476. All three are in [Unreleased]. The entries under 0.3.0 and earlier describe released versions, so they keep the old name.
  • docs/plans/2026-11-22-recipher-typescript-sdk.md: fixed in d92d4dc, at all five lines.
  • The docs(plans): one walk for a record, and host-built stored types #2040 plan's citations: I will re-pin them to next after this pull request merges.

…to raw fields

source.rs wrote Result<RawFields, NotARecord> out sixteen times. The
type had the name SourceRecord before that name went to the record the
plan checks.
…d the type is private

The conversion from SourceRecordError to the dynamic Error moved to
record/source.rs, and its test stayed in record.rs. That kept the struct
and its fields visible to record, with two imports for tests alone. The
test now sits in source.rs's tests, with a helper of its own for the one
error variant it checks, so the struct and its fields are private.
NotARecord and SourceRecordError derive thiserror::Error, and nothing
showed either message, so the text could change with no test failing.
The test pins both. NotARecord names the kind of the value and never
the value; SourceRecordError names no row, field or cause.
…crypted_records and encrypted_record

The encrypt side says record (into_source_records, EncryptedRecord), and
the stack-encrypt glossary lists row as a word to avoid for a
field-by-field record. The decrypt side now matches. Both functions are
private to the record module.
coderdan added a commit that referenced this pull request Dec 4, 2026
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.
@coderdan
coderdan merged commit b939de4 into next Dec 5, 2026
60 of 61 checks passed
@coderdan
coderdan deleted the refactor/dynamic-record-readability branch December 5, 2026 03:41
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.

2 participants