Skip to content

fix(stack-encrypt): say what a record found where it takes an object, and where - #2005

Merged
coderdan merged 15 commits into
nextfrom
fix/engine-not-an-object-errors
Nov 28, 2026
Merged

coderdan merged 15 commits into
nextfrom
fix/engine-not-an-object-errors

Conversation

@coderdan

@coderdan coderdan commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The engine's "not an object" errors now say what was found, where, and in which operation. Before, five of the six paths that raised not_an_object named no field and no row, and none said what was found. A value that failed while it was read was reported as "not an object", and the value's own error was lost. No error contains a value. An error names a value's kind, such as "an array" or "null", only where the kind is visible without decrypting: input the caller sent, and the stored record's own structure. A decrypt error never says what a decrypted value opened as.

Closes #1985.

Changes

  1. New detail on errors.

    • dynamic::Found names a value's kind, never the value: null, undefined, passthrough, sealed, unknown, or a kind name such as array, string or uint32.
    • Error::Plan gains found. Error::Source and Error::Record gain row and found.
    • Each reaches the payload, the message, and the new row() and found() accessors.
  2. New reasons: not_a_frame and source_failed. The new variant Error::SourceFailed { field, row, cause } has its own code, stack_encrypt::dynamic_source_failed.

  3. Each path:

    Path Now
    Plan bytes that are not a frame (E1) not_a_frame: "the bytes are not one transport frame"
    A plan frame that is not an object (E1) "the plan is an array, not an object of field specs"
    A field spec that is not an object (E2) "the field's spec is a string, not an object (field "value")"
    A record to encrypt that is not an object (E3) "row 2 of the records to encrypt is null, not an object of fields", or "the record to encrypt is …"
    A value that fails while it is read (E4) source_failed, naming the field and row. The cause is kept as source() but left out of the message.
    A stored record that is not an object (E5, E6) "row 1 of the records to decrypt is a passthrough value, …"
  4. A real bug found by the mutation gate. A plan whose spec was a typed null was refused naming no field, because the frame reader refuses typed nulls and the key was lost. Keys are now read with the probe sink. New conformance case: frame-typed-null-spec.

  5. Bindings. The guest maps SourceFailed to the encoding status. Go's Diagnostic gains Row() and Found(). The TypeScript addon passes payload fields through unchanged. stack-profile's payload policy now allows a value's kind and a row's position.

  6. Conformance cases changed in place (allowed while every reader is in this repository):

    • record-declarations-v1:
      • root-null, root-list, field-not-object and field-null gain found;
      • frame-empty, frame-invalid, frame-truncated, frame-duplicate-key and frame-trailing now expect not_a_frame;
      • new case: frame-typed-null-spec.
    • record-reads-v1: row-not-map gains row and found: passthrough, the stored structure. The decrypt-side cases are unchanged.
  7. Also:

    • Two wording fixes found in other reviews: the uuid feature comment in stack-encrypt/Cargo.toml (the dynamic path admits a UUID), and "a UUID" added to the SealedNullType refusal text.
    • CHANGELOG entries: stack-encrypt (Breaking, since variant fields changed) and Go (Added).

Verification

  • Rust:
    • fmt, workspace clippy with -D warnings (also --no-default-features for stack-encrypt);
    • cargo test -p stack-encrypt --all-features: 63 binaries and 88 doctests;
    • rustdoc public and private with -D warnings.
  • Mutation testing (--in-diff): 109 mutants, 1 missed. That one led to the typed-null bug above, which is now fixed and caught.
  • Go guest: fmt, clippy and tests under all four feature sets.
  • Go: with all five guests built, gofmt, go vet and go test ./... with STACK_CONFORMANCE_REQUIRED=1 pass in all three modules.
  • recipher-js: clippy and tests.
  • Corpus: Biome formatting, and the conformance script tests (55).
  • After merging next: fmt, stack-encrypt clippy and the guest tests pass again.
  • Not run: the full mise run test:conformance task. Its Rust and Go runners did run.

Review notes

  • Repeated key inside a field spec. stack-encrypt: "not an object" errors do not say what was found, or which field, row or operation #1985 asked for it to be reported as RepeatedKey. A transport frame cannot hold one, so the parser refuses it first, as not_a_frame.
  • Rows are named for: a row that is not an object, a source failure, and any refusal while a record is split (repeated key, invalid value, too deep or too long, unwritten). A field misfit (missing, unknown or wrong type) names a field but no row. Go always sends a batch, so adding a row there would change every Go refusal.
  • found uses kind names (array, uint64), and messages use words ("an array").

…feature

The comment on the `uuid` feature said the dynamic path refuses a uuid.
It does not: the dynamic path admits `ValueKind::Uuid`, and seals and
indexes a UUID with the feature off. The feature adds only the typed
`value::Uuid`. Say that, so nobody turns the feature on for the dynamic
path, or off believing it removes UUIDs from it.
The `SealedNullType` refusal and the record plan's docs listed the types
of fixed width that take `"null": "sealed"` as a bool, a number, a date,
a timestamp or a decimal. A UUID is fixed width too: `ValueKind::Uuid`
has a sealed null (a typed null of sixteen bytes), the dynamic plan
admits one, and the declaration corpus accepts `sealed-null-uuid`. Name
it, so a caller refused for a sealed null of text is not steered away
from a UUID.
… and where

A plan, a field's spec, a record to encrypt or a stored record that was not
an object was refused as `not_an_object` with nothing more: five of the six
places named no field, none named the row of a batch or what was there,
and a value that failed while it was read, or bytes that were not a frame,
were reported the same way. A caller could not tell which input was wrong,
or why.

Each of those refusals now says what it found, where, and in which
operation, and never the value:

- `dynamic::Found` names a value's kind (null, a passthrough, a sealed
  value, or a schema kind such as array, string or uint32). `Error::Plan`
  gains `found`; `Error::Source` and `Error::Record` gain `row` and
  `found`. Both reach the payload (`found`, `row`) and the message, as in
  "row 2 of the records to decrypt is a passthrough value, not an object
  of stored fields".
- Bytes given as a plan that are not one transport frame get their own
  reason, `not_a_frame`. A frame whose root, or a field's spec, is not an
  object keeps `not_an_object` and says what it is. The spec's keys are
  now read through a sink, so a passthrough elsewhere in the plan no
  longer turns an unknown key into the wrong reason.
- A source that fails as it is read is `Error::SourceFailed`
  (`stack_encrypt::dynamic_source_failed`, reason `source_failed`). It
  names the field and the row being read and keeps the value's own error
  as its cause, outside the message, since a host's error can quote the
  value. The split now keeps the field for such a failure, and forgets it
  once a record's values are written.
- A typed field that opens as another type says what it opened as:
  `PlanError::FieldType` gains `found`, as in
  `field "doc" opened as an array, not an object`.

The guest maps `SourceFailed` to the encoding status like the other input
refusals. Go's `Diagnostic` gains `Row` and `Found`. The TypeScript addon
passes the payload through unchanged. stack-profile's payload policy now
lists a value's kind and a row's position as allowed detail.

Conformance cases changed in place (every reader is in this repository):
- record-declarations-v1: root-null, root-list, field-not-object,
  field-null gain `found`; frame-empty, frame-invalid, frame-truncated,
  frame-duplicate-key, frame-trailing expect `not_a_frame`.
- record-reads-v1: row-not-map gains `row` and `found`;
  authenticated-int32-as-int64, authenticated-int32-as-string,
  authenticated-int32-as-uint64, authenticated-null-as-required gain
  `found`.
- record-raw-frames-v1: authenticated-int64, authenticated-string gain
  `found`.

Closes #1985
The mutation gate found the probe's typed-null arm unobserved, and the
test that observes it found a defect: a plan whose spec was a typed null
was refused as "the plan is an object, not an object of field specs",
naming no field. The frame reader refuses a typed null wherever it is,
and the plan parser read the refused entry's key with that reader, so
the key was lost and the refusal fell back to the root.

The keys are now read with the probe, which reads past a typed null, so
the spec is refused for its field as `not_an_object` with `found` null.

Conformance case added to record-declarations-v1: frame-typed-null-spec,
a frame whose spec is a typed null, refused by both readers with
`not_an_object`, field `value`, found `null`.
@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: 4d70db04-9675-4344-adbb-0b83a43c7ef6

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

@changeset-bot

changeset-bot Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 8f823d9

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 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 c5a3775. Seven findings, checked against the code: two important and three nits inline, and two nits outside the diff, below.

.cargo/mutants.toml:165 (outside the diff, nit). The exclusion entry_key::<impl Deserialize<'de> for Keys>::deserialize::<impl Visitor<'de> for V>::expecting names a visitor this PR deleted. entry_key now uses refusal::object_keys. Its comment still says the plan's root is refused with one fixed NotAnObject, but the root can now be NotAFrame, or NotAnObject with found. Remove the dead exclusion and fix the comment.

conformance/stack-encrypt/raw-frames-contract.md:45 (outside the diff, nit). It says stack_encrypt::plan_field_type names "the field and the expected kind", but the changed record-raw-frames-v1 and record-reads-v1 cases now also require found. A binding author following the prose would fail the corpus, because both runners compare the payload exactly. This interacts with the first important finding: if found comes off the decrypt path, these cases change back.

I will fix these before marking the pull request ready, and reply on each thread.

@github-actions

github-actions Bot commented Nov 27, 2026 •

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)

caught missed unviable timeout
82 0 75 0

Every mutant in the changed lines was caught by a test.

The plan parser no longer reads a refused plan's keys with a serde
visitor, so the exclusion for that visitor's `expecting` matches nothing.
The comment on the remaining visitors said a plan's root is refused with
one fixed reason; it is refused as `not_a_frame`, or as `not_an_object`
with the kind the frame reports.
…name only the field and row still open

Review of the "not an object" errors found a privacy leak and four places
where an error could name the wrong field or row, or none.

- A decrypt that opened a field as another type than the plan declares
  reported what it opened as (`found`, and "field "doc" opened as an
  array"). The type tag is inside the AEAD envelope, so that is the
  plaintext's own metadata, such as which rows hold a null. The refusal
  is back to naming the field and the declared type alone, with no
  `found`. A kind is now named only for what the caller sent (a plan, a
  source, a query input) or for the stored record's own structure (a row
  that is a passthrough or a sealed leaf rather than a map, which the
  stored form shows without decrypting). stack-profile's payload policy,
  the raw-frame contract and the CHANGELOGs say so, and a test asserts a
  decrypt-side refusal has no `found` and names no kind.
- A source failure named a field from when its entry began until the
  record ended, so a failure between two fields blamed the first. Each
  field's value is now written through a writer that marks the field
  finished when the value completes, so a failure between fields, or after
  a field's container ends, names no field.
- The row was set when a batch element began and never cleared, so a
  failure after the last element, or between elements, named the last
  row; and an element the source began and dropped unwritten left no
  record and shifted the rows after it. Rows begun are counted, the row is
  cleared when its record is put, and a dropped element is refused as
  `unframeable` naming its row.
- A frame-writer refusal that named no field became `Error::Internal`,
  which Go reports as an internal failure. It is the caller's input: a
  `Source` refusal, `unframeable`, with the row.
- The row a refusal is in is now passed through for every refusal made
  while the source is split (a repeated key, a value its logical type does
  not admit, a value too deep or too long). A field's own misfit (missing,
  unknown, of another type) still names no row: adding one would change
  every Go refusal, since Go always sends a batch. The CHANGELOG, the
  rustdoc and the Go doc now say exactly which refusals name a row.

Conformance cases changed back in place: record-reads-v1
authenticated-int32-as-int64, authenticated-int32-as-string,
authenticated-int32-as-uint64 and authenticated-null-as-required, and
record-raw-frames-v1 authenticated-int64 and authenticated-string, lose
`found` and expect their payload from before this branch. row-not-map
keeps `row` and `found`: the row is a passthrough in the stored form.
@coderdan

Copy link
Copy Markdown
Contributor Author

The two findings outside the diff are fixed too. .cargo/mutants.toml no longer has the dead entry_key exclusion, and its comment is fixed (990ea28). conformance/stack-encrypt/raw-frames-contract.md now says the field-type refusal never names the kind a leaf opened as (706fc9f). Checks: fmt, clippy, rustdoc (public and private), stack-encrypt tests, the guest under all four feature sets, Go in all three modules with STACK_CONFORMANCE_REQUIRED=1, Biome and the conformance script tests all pass. Mutation testing on the fix lines: 27 mutants, 13 caught, 14 that do not compile, 0 missed.

@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 706fc9fb · posted from Claude Code · claude-opus-5-5 · effort medium
Sources: code-review (medium) · claude-opus-5-5; rust-security · claude-opus-5-5; Standards and Spec agents (mattpocock-skills:code-review) · model unknown
Skills: code-review, company-skills:rust-security, mattpocock-skills:code-review, company-skills:review-cross-check

Findings (7): 1 major, 6 minor — 3 inline, 3 below, 1 in reply.

  • packages/stack-encrypt/src/dynamic/record.rs, dynamic/query.rs minor 34 non-test literal builds of Error::{Plan,Source,Record} { …, found: None } (plus row: None on Source/Record) where Error::bad_plan(r).in_field(..) / Error::bad_source(r).in_field(..) give the same value; every new field on these variants touched each site. Judgement call (Duplicated Code).
  • packages/stack-encrypt/src/refusal.rs:864-1081 minor Found::of_frame/of_entry, object_keys, Probe and Lookup (~190 lines of frame-walking Sink code, all called only from dynamic/) now live in the refusal vocabulary module and compile as dead code without dynamic. Consider moving them beside dynamic/source.rs. Judgement call (Divergent Change).
  • languages/golang/encrypt/errors.go:101, languages/golang/internal/guest/diagnostic.go:28 minor One comment line each (98 and 107 columns) left from a partial reflow; neighbours are ≤76. gofmt does not rewrap.

Generated by Claude Code

Comment thread packages/stack-encrypt/src/refusal.rs Resolved
Comment thread packages/stack-encrypt/src/refusal.rs Resolved
…fusal paths

Review of the "not an object" errors found a new leak and some loose
ends:

- `SourceFailed` kept the host's `SourceError` as its cause, and the
  derived `Debug` printed it, so `{:?}`, `tracing::error!(?err)` or a
  panic from `.unwrap()` showed text that can quote the value. `Error`
  now has a hand-written `Debug`: every other variant prints as the
  derive did, and the cause prints as `SourceError(..)`. `source()` still
  reaches it. The test asserts the marker text is absent from `{:?}`,
  `{:#?}`, the message and the payload.
- A known logical type over a value it does not admit (a date over a
  null) was named "a value of a type this build does not know". Only a
  logical type this build does not know is `unknown` now; any other is
  named by the value's physical kind.
- A writer's refusal with no field to name kept a field's reason
  (`repeated_key`, `field_type`) it could not attribute. With no field it
  is `unframeable`, with the row.
- The frame-walking sinks behind `Found` (`of_frame`, `of_entry`,
  `object_keys`, the probe and the lookup) are used only by the dynamic
  interface, and compiled as dead code without it. They now live in
  `dynamic::found`.
- `split_source` names its shared place `place`, without an alias.
- Thirty-two literal `Error::{Plan, Source}` builds that set no row and
  no kind use `bad_plan`/`bad_source` with `in_field`.
- A source refusal only a query's input meets (an operator, a range, a
  term, statistics, a null query, a JSON operator's input) said "record
  source does not fit the plan", though no record or plan was involved.
  It says "query input does not fit the field".
- Two Go doc comments left long by a partial reflow are rewrapped.
@coderdan

Copy link
Copy Markdown
Contributor Author

The review's findings outside the diff are fixed in 533f257:

  • Constructors: 32 literal builds now use bad_plan or bad_source with .in_field(..). Seven are left as they are, because they carry found, row or an Option field.
  • Frame-walking code: of_frame, of_entry, object_keys, the probe and the lookup now live in a new dynamic/found.rs. refusal.rs keeps Found and its Display. A --no-default-features build has no dead-code warnings, and its tests, clippy and rustdoc pass.
  • Go comments: the two long comment lines are rewrapped.

One change from #2006's review is also here, because it belongs to Error::Source. A refusal only a query's input can meet now starts "query input does not fit the field" rather than "record source does not fit the plan". field_type keeps the record wording, because records hit it too.

Mutation testing on the diff: 92 mutants, 47 caught, 45 that do not compile, 0 missed.

Comment thread packages/stack-encrypt/src/refusal.rs Resolved
The doc comments on `Error`, `Reason` and `Found`, and on the helpers that
find the kind of a value, packed several ideas into each sentence and used
terms they did not explain. A reader who was not part of the work could not
follow them.

The comments now use short sentences and lists. They explain a term where
it first appears, such as "record source", "transport frame" and
"passthrough". They state the rule for when an error names a kind of value:
only when the engine can read the kind without decrypting anything.

Only comments change. No code, message text or reason code changes.
…uage

The comments on the code that splits a record source into fields, and on
the code that turns a split error into the caller's error, were hard to
follow. They used long sentences, and words such as "refusal", "place" and
"the open field" with no explanation.

The comments now say what each item does, when it returns an error, and
what that error names. Parallel cases are lists. The same applies to the
test comments, the `uuid` feature comment in Cargo.toml and one comment in
the cargo-mutants configuration.

Only comments change.
The Go doc comments for `Diagnostic.Row` and `Diagnostic.Found`, the list
of details a Diagnostic can contain, and the CHANGELOG entry each packed
several rules into one sentence.

They are now short sentences and lists. `Found` lists its kinds and says
what "passthrough", "sealed", "undefined" and "unknown" mean. The guest's
status comment says why each input error is named one by one.

Only comments and Markdown change.
The CHANGELOG entry for errors about input that is not an object was hard
to follow. It now starts with what a caller must change to upgrade, then
lists each change in short sentences, and explains "field spec",
"transport frame" and "typed null" where they first appear.

The payload policy in stack-profile and the raw-frames contract say the
same rule in the same words: an error names a kind only when the kind can
be read without decrypting anything.

Only comments and Markdown change.
The doc on Error::Plan named four keys. The plan reader also accepts
"null", as the doc on Reason::UnknownKey already says.
…sages

The messages of the dynamic input errors used the names in the code, such
as "record source", "sealed value", and "transport frame". The developer
who gets one of these errors did not write those names. The messages now
name what the developer passed: the record to encrypt, the record to
decrypt, or the query input.

Only the text of the messages changes. The codes, the reason names, the
payload fields, and the variants stay the same.

- An error with a `found` kind has a message of one sentence. An example
  is "row 2 of the records to encrypt is null, not an object of fields".
  That message no longer starts with "record source does not fit the
  plan". The start repeated what the sentence says.
- The other messages of `Error::Source` start with the input that the
  reason is about. A record and a query can both cause a value of another
  type, or an `undefined` value. For those two reasons, the message names
  both inputs when the error has no row.
- The message of `Error::Record` starts with "the record to decrypt does
  not match the plan".
- The message of `Error::SourceFailed` says that a value in the record to
  encrypt returned an error. The help text says why the message leaves
  the cause out.
- The message for plan bytes that are not a frame says what a transport
  frame is.
- A message says "an encrypted value" for the kind `sealed`, and "a type
  this build does not define" for an unknown logical type.

No message includes a value, the text of a cause, or the kind that a
value decrypted to. The tests that pin the cause text and the `Debug`
output still pass unchanged.
…Debug

The text of a SourceError comes from the caller's own code, and it can
include the value that failed. So `dynamic::Error` had a hand-written
Debug that matched on every variant, only to print the cause of
SourceFailed as `SourceError(..)`.

The placeholder now comes from SourceError itself, in vitaminc-aead.
SourceError has a small Debug that prints `SourceError(..)` and nothing
of the error it wraps. A type that contains a SourceError can derive
Debug again. `dynamic::Error` derives Debug, and the hand-written impl
is gone.

The Debug output of each variant of `dynamic::Error` is the same as
before, in the plain form and the pretty form. A test that formatted one
value of each variant gave the same bytes before and after the change.

Three errors in vitaminc-aead contain a SourceError, and they print the
placeholder now too: `EncryptError::Source`, `DecodeError::Source`, and
`FrameWriteError::Source`. Before, their derived Debug printed the
caller's text.

`Display`, `inner()`, and `source()` are unchanged. A caller that needs
the text reads it through one of them on purpose.
@coderdan
coderdan merged commit db58fe3 into next Nov 28, 2026
63 checks passed
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.

stack-encrypt: "not an object" errors do not say what was found, or which field, row or operation

2 participants