Repository navigation
fix(stack-encrypt): say what a record found where it takes an object, and where - #2005
Conversation
…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`.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
|
coderdan
left a comment
There was a problem hiding this comment.
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.
Mutation testing (cargo-mutants,
|
| 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.
|
The two findings outside the diff are fixed too. |
cipherstash-agent
left a comment
There was a problem hiding this comment.
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.rsminor 34 non-test literal builds ofError::{Plan,Source,Record} { …, found: None }(plusrow: NoneonSource/Record) whereError::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-1081minorFound::of_frame/of_entry,object_keys,ProbeandLookup(~190 lines of frame-walkingSinkcode, all called only fromdynamic/) now live in the refusal vocabulary module and compile as dead code withoutdynamic. Consider moving them besidedynamic/source.rs. Judgement call (Divergent Change).languages/golang/encrypt/errors.go:101,languages/golang/internal/guest/diagnostic.go:28minor One comment line each (98 and 107 columns) left from a partial reflow; neighbours are ≤76. gofmt does not rewrap.
Generated by Claude Code
…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.
|
The review's findings outside the diff are fixed in 533f257:
One change from #2006's review is also here, because it belongs to Mutation testing on the diff: 92 mutants, 47 caught, 45 that do not compile, 0 missed. |
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.
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_objectnamed 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
New detail on errors.
dynamic::Foundnames a value's kind, never the value:null,undefined,passthrough,sealed,unknown, or a kind name such asarray,stringoruint32.Error::Plangainsfound.Error::SourceandError::Recordgainrowandfound.row()andfound()accessors.New reasons:
not_a_frameandsource_failed. The new variantError::SourceFailed { field, row, cause }has its own code,stack_encrypt::dynamic_source_failed.Each path:
not_a_frame: "the bytes are not one transport frame"source_failed, naming the field and row. The cause is kept assource()but left out of the message.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.Bindings. The guest maps
SourceFailedto the encoding status. Go'sDiagnosticgainsRow()andFound(). The TypeScript addon passes payload fields through unchanged. stack-profile's payload policy now allows a value's kind and a row's position.Conformance cases changed in place (allowed while every reader is in this repository):
record-declarations-v1:root-null,root-list,field-not-objectandfield-nullgainfound;frame-empty,frame-invalid,frame-truncated,frame-duplicate-keyandframe-trailingnow expectnot_a_frame;frame-typed-null-spec.record-reads-v1:row-not-mapgainsrowandfound: passthrough, the stored structure. The decrypt-side cases are unchanged.Also:
uuidfeature comment instack-encrypt/Cargo.toml(the dynamic path admits a UUID), and "a UUID" added to theSealedNullTyperefusal text.Verification
-D warnings(also--no-default-featuresfor stack-encrypt);cargo test -p stack-encrypt --all-features: 63 binaries and 88 doctests;-D warnings.--in-diff): 109 mutants, 1 missed. That one led to the typed-null bug above, which is now fixed and caught.gofmt,go vetandgo test ./...withSTACK_CONFORMANCE_REQUIRED=1pass in all three modules.next: fmt, stack-encrypt clippy and the guest tests pass again.mise run test:conformancetask. Its Rust and Go runners did run.Review notes
RepeatedKey. A transport frame cannot hold one, so the parser refuses it first, asnot_a_frame.founduses kind names (array,uint64), and messages use words ("an array").