Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/plans/2026-10-24-stack-encrypt-api-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -2312,7 +2312,7 @@ review. The rules are the query artifact's.
`.via`. The `MatchConfig` documentation says a field and its query agree "by
construction". That is true only for one-value plans today. Both
are amended, not contradicted in silence.
- **Tracked in.** Steps 1 and 2 are done: #1279, #1318, #1317 and #1233 are closed. They brought `prepare`, the `sem::query` rules and `Op`, and dropped `Matches`'s case parameter. The analyzer of "Match configuration: one analyzer" is its own work (#1673). Step 3 is done apart from its clean-up: the field references and `Planned` (#1486, closed), and the removal of `DefaultIndex` and `.via` (#1666). Issue #1671 is open to remove `PlanError::IndexOptions` and the other variants nothing raises, and to amend ADR-0009 and the `MatchConfig` documentation. Step 4 is issue #1672, open.
- **Tracked in.** Steps 1 and 2 are done: #1279, #1318, #1317 and #1233 are closed. They brought `prepare`, the `sem::query` rules and `Op`, and dropped `Matches`'s case parameter. The analyzer of "Match configuration: one analyzer" is its own work (#1673). Step 3 is done apart from its clean-up: the field references and `Planned` (#1486, closed), and the removal of `DefaultIndex` and `.via` (#1666). #1671 removes `PlanError::IndexOptions` and the six other variants nothing raised, and amends ADR-0009 and the `MatchConfig` documentation. Step 4 is issue #1672, open.
- **Finished when** these are all true:
- every index's operators appear in one declaration, and a test shows
the typed and dynamic lookups agree on every index;
Expand Down Expand Up @@ -2465,4 +2465,4 @@ renames.
| `scope(..)`, `bind(..)`, `bind(claim = ..)`, `keyset(name(field = ..))` | The declaration attributes. Confirmed |
| `stack-kms` to `stack-zerokms` | Not decided. The crate rename is part of the crate layout question, which stays open |
| `scope = ".."`, Go `scope=` | The record's name is its first scope, so the attribute and the Go tag both say `scope`. Today they say `context = ".."` and `context=`. The builder's `Plan::scope(..)` was part of this decision and goes with the builder. Decided by Dan on 8 November 2026 |
| `plan.query(field, op)`, `plan.field(name)`, `IndexNotDeclared`, `FieldIndexes`, `StageSpec`, `Match<Dynamic>`, `NotPortable` | The dynamic interface names. Confirmed |
| `plan.query(field, op)`, `plan.field(name)`, `FieldIndexes`, `StageSpec`, `Match<Dynamic>`, `NotPortable` | The dynamic interface names. Confirmed. `IndexNotDeclared` was on this list and is removed (#1671): no query takes an index from the caller |
2 changes: 1 addition & 1 deletion languages/golang/encrypt/guest/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ mod tests {
fn a_plan_refusal_is_the_callers_input() {
assert_eq!(
status_for_error(&stack_encrypt::Error::Plan(
stack_encrypt::PlanError::NoContext
stack_encrypt::PlanError::BindInQuery
)),
STATUS_ENCODING
);
Expand Down
23 changes: 23 additions & 0 deletions packages/stack-encrypt/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Breaking

- **Seven `PlanError` variants that nothing raised are removed** (#1671).
Only the plan builder and `plan::all` raised them, and both are gone,
so no call returned them: `IdentityWithoutField`, `IndexNotDeclared`,
`IndexOptions`, `MixedCiphers`, `NoContext`, `PassthroughIndexed` and
`TargetWithVerbs`. `plan::all` raised `MixedCiphers`; the builder raised
the other six.
Their error codes go with them (`stack_encrypt::plan_identity_without_field`,
`plan_index_not_declared`, `plan_index_options`, `plan_mixed_ciphers`,
`plan_no_context`, `plan_passthrough_indexed` and
`plan_target_with_verbs`). The other variants keep their codes. No
`dynamic::Reason` is removed: a data plan with a passthrough beside
another output, or with both outputs and a target, is still refused as
`passthrough_with_outputs` or `outputs_with_target`. To upgrade, delete
match arms that name a removed variant; `PlanError` is
`#[non_exhaustive]`, so a wildcard arm already covers the rest. No
stored byte changes.

- **A cipher no longer reads credentials you did not name** (#1722).
`StackCipher::new()` and `init()` on the bare builder read
`CS_CLIENT_ID`, `CS_CLIENT_KEY`, `CS_CLIENT_ACCESS_KEY`,
Expand Down Expand Up @@ -1297,6 +1314,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
still comes back before the pending exists, as a `dynamic::Error`.
`decrypt_with`'s `expected` context is checked inside the `Planned`
lowering. No stored byte changes.
- **The `MatchConfig` and `Match` documentation says how a field and its
query agree** (#1671), where it said they agree "by construction". A
query made from the field's reference answers through the field's own
`Match<O>`, and a data plan's query reads the field's one match index. A
filter derived directly with `match_terms` matches a stored one only
under the field's configuration.
- **The context parameter of the cipher-directed methods is named
`context`, not `aad`** (#1568): `KeysetCipher::encrypt_tree`,
`KeysetCipher::decrypt_tree`, `StackCipher::decrypt`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
status: proposed
date: 2026-10-13
amended: 2026-11-10
amended: 2026-11-23
supersedes: ADR-0004 (decision 5)
extends: ADR-0003, ADR-0007
---
Expand Down Expand Up @@ -249,6 +249,10 @@ pub trait DefaultIndex<S>: Operator {
}
```

*Amended 2026-11-23:* `DefaultIndex` and `.via` are removed. A field's
target type answers through `Answers`, and a plan that is data through
`dynamic::Op::answered_by`. See [Amended 2026-11-23](#amended-2026-11-23-1671).

### 4. A query term is one of three things, and the trait it implements is its fidelity

```rust
Expand Down Expand Up @@ -1282,3 +1286,42 @@ vitaminc-ore's `Orderable`, which `stack_encrypt::Orderable` re-exports.
That trait covers the integers of 16 bits and wider, the floats, text,
dates, timestamps, and decimals. It does not cover bytes or an 8-bit
integer. Where this ADR names `op::Ordered`, read `Orderable`.

## Amended 2026-11-23 (#1671)

`DefaultIndex` and `.via(index)` are removed (#1666, with the plan builder
they belonged to). Nothing replaced them with a new choice: each field
declares at most one index per operator (amended 2026-11-10), so a query
has nothing to choose.

- **A typed field answers through its target type.** A query starts from
the field's reference, which carries the field's target type. That type
implements `Answers<Op, In>`, whose `Via` is the index that answers `Op`:
`EqualityTerm` answers `Eq` through `Equality`, `MatchTerms<O>` answers
`Matches` through `Match<O>`, and a tuple of terms answers through the
one term that answers the operator. So a field declared with a match
index under configuration `O` is queried under `O`: the query cannot
name another index or other options. A field whose type has no
`Answers` impl for an operator has no method for it, and the query does
not compile.
- **A plan that is data answers through `dynamic::Op::answered_by`.** A
field of a data plan lists its indexes as `IndexSpec` values.
`dynamic::Op::answered_by(kind, indexes)` returns the one that answers
the operator for the field's kind, from each index's own declaration of
its operators (`IndexSpec::answers`). The query derives its term under
that index's options, which are the options the stored term was derived
under. `Plan::query` refuses an operator no index answers before any key
is requested.

Neither path takes an index from the caller, so the refusals that guarded a
caller's choice are removed with it: `PlanError::IndexNotDeclared` (an index
the field does not declare) and `PlanError::IndexOptions` (a match index
under other options). Five more variants that only removed code raised go
with them: `IdentityWithoutField`, `NoContext`, `PassthroughIndexed` and
`TargetWithVerbs`, which the plan builder raised, and `MixedCiphers`, which
`plan::all` raised. A data plan that declares a passthrough field with
outputs, or a field with both outputs and a target, is still refused, by
the parser, as `passthrough_with_outputs` and `outputs_with_target`.

Where decision 1 and decision 7 write `.via(Ore)` and `.via(Ope)`, read: the
index the field declares for the operator.
53 changes: 5 additions & 48 deletions packages/stack-encrypt/src/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ mod tests {
use uuid::Uuid;

use crate::diagnostic::is_code_of;
use crate::sem::{MatchOptions, TermBytesError, TermError};
use crate::target::IndexSpec;
use crate::sem::{TermBytesError, TermError};
use crate::{BlobError, Descriptor, Error, LabelError, LeafBytesError, PlanError};

/// One row per variant of an enum, written `pattern => value`. The
Expand Down Expand Up @@ -89,7 +88,7 @@ mod tests {
},
Error::NoKeyset => Error::NoKeyset,
Error::NotOpened => Error::NotOpened,
Error::Plan(_) => Error::Plan(PlanError::NoContext),
Error::Plan(_) => Error::Plan(PlanError::BindInQuery),
Error::Blob(_) => Error::Blob(BlobError::NotABlob),
]));
errors.extend(boxed(variants![
Expand Down Expand Up @@ -165,16 +164,12 @@ mod tests {
field: field(),
source: LabelError::Empty,
},
PlanError::IdentityWithoutField => PlanError::IdentityWithoutField,
PlanError::DuplicateField { .. } => PlanError::DuplicateField { field: field() },
PlanError::SharedIdentity { .. } => PlanError::SharedIdentity {
identity: "age".into(),
first: "age".into(),
second: "years".into(),
},
PlanError::PassthroughIndexed { .. } => {
PlanError::PassthroughIndexed { field: field() }
},
PlanError::DuplicateIndex { .. } => PlanError::DuplicateIndex {
at: field(),
index: "eq",
Expand All @@ -191,19 +186,6 @@ mod tests {
expected: "int64",
},
PlanError::NoSuchField { .. } => PlanError::NoSuchField { field: field() },
PlanError::MixedCiphers => PlanError::MixedCiphers,
PlanError::IndexNotDeclared { .. } => PlanError::IndexNotDeclared {
field: field(),
index: "ore",
},
PlanError::IndexOptions { .. } => PlanError::IndexOptions {
field: field(),
declared: IndexSpec::Match(MatchOptions::default()),
asked: IndexSpec::Match(MatchOptions {
downcase: false,
..MatchOptions::default()
}),
},
PlanError::IndexOverlap { .. } => PlanError::IndexOverlap {
at: field(),
first: "ore",
Expand All @@ -214,9 +196,7 @@ mod tests {
first: "the plan",
second: "the call",
},
PlanError::NoContext => PlanError::NoContext,
PlanError::BindInQuery => PlanError::BindInQuery,
PlanError::TargetWithVerbs { .. } => PlanError::TargetWithVerbs { field: field() },
]));
#[cfg(feature = "dynamic")]
errors.extend(dynamic_variants());
Expand All @@ -226,6 +206,7 @@ mod tests {
#[cfg(feature = "dynamic")]
fn dynamic_variants() -> Vec<Row> {
use crate::dynamic::{Error, Reason, TargetError, ValueKind};
use crate::target::IndexSpec;
let name = || "email".to_string();
let target = || "TextEq".to_string();
let mut errors = Vec::new();
Expand Down Expand Up @@ -384,11 +365,6 @@ mod tests {
fn every_payload() -> Vec<(Box<dyn crate::ErrorPayload>, serde_json::Value)> {
use serde_json::json;
let (a, b) = (Uuid::from_u128(1), Uuid::from_u128(2));
let declared = IndexSpec::Match(MatchOptions::default());
let asked = IndexSpec::Match(MatchOptions {
downcase: false,
..MatchOptions::default()
});
let payloads: Vec<(Box<dyn crate::ErrorPayload>, serde_json::Value)> = vec![
(
Box::new(Error::Kms(crate::kms::Error::GenerateKey(
Expand Down Expand Up @@ -548,34 +524,14 @@ mod tests {
}),
json!({ "field": "age", "expected": "int64" }),
),
(
Box::new(PlanError::IndexNotDeclared {
field: "age".into(),
index: "ore",
}),
json!({ "field": "age", "index": "ore" }),
),
(
Box::new(PlanError::IndexOptions {
field: "age".into(),
declared: declared.clone(),
asked: asked.clone(),
}),
json!({
"field": "age",
"index": "match",
"declared": { "match": { "tokenizer": { "ngram": 3 }, "downcase": true, "k": 3, "m": 256 } },
"asked": { "match": { "tokenizer": { "ngram": 3 }, "downcase": false, "k": 3, "m": 256 } },
}),
),
(
Box::new(PlanError::TwoContextSources {
first: "the plan",
second: "the call",
}),
json!({ "first": "the plan", "second": "the call" }),
),
(Box::new(PlanError::NoContext), json!({})),
(Box::new(PlanError::BindInQuery), json!({})),
];
// The builder error's fields come through the box.
#[cfg(feature = "http")]
Expand All @@ -600,6 +556,7 @@ mod tests {
#[cfg(feature = "dynamic")]
fn dynamic_payloads() -> Vec<(Box<dyn crate::ErrorPayload>, serde_json::Value)> {
use crate::dynamic::{Error, Reason, TargetError, ValueKind};
use crate::target::IndexSpec;
use serde_json::json;
let name = || "email".to_string();
let target = || "TextEq".to_string();
Expand Down
43 changes: 1 addition & 42 deletions packages/stack-encrypt/src/dynamic/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,25 +662,16 @@ fn refusal(error: crate::Error) -> (Option<String>, Reason) {
P::FieldLabel { field, .. } => (Some(field), Reason::ContextNotLabel),
P::DuplicateField { field } => (Some(field), Reason::DuplicateField),
P::SharedIdentity { second, .. } => (Some(second), Reason::SharedIdentity),
P::PassthroughIndexed { field } => (Some(field), Reason::PassthroughWithOutputs),
P::DuplicateIndex { at, .. } => (Some(at), Reason::DuplicateOutput),
P::IndexOverlap { at, .. } => (Some(at), Reason::OverlappingOutputs),
P::EmptyIndexes => (None, Reason::NoOutputs),
P::NotInPlan { field } => (Some(field), Reason::UnknownField),
P::NotInValue { field } => (Some(field), Reason::FieldMissing),
P::FieldType { field, .. } => (Some(field), Reason::FieldType),
P::NoSuchField { field } => (Some(field), Reason::NoSuchField),
P::TargetWithVerbs { field } => (Some(field), Reason::OutputsWithTarget),
P::IndexNotDeclared { field, .. } | P::IndexOptions { field, .. } => {
(Some(field), Reason::Refused)
}
P::BindInQuery => (None, Reason::BindInQuery),
P::EmptyPart => (None, Reason::EmptyBinding),
P::IdentityWithoutField
| P::MixedCiphers
| P::TwoContextSources { .. }
| P::NoContext
| P::ContextNotStorable { .. } => (None, Reason::Refused),
P::TwoContextSources { .. } | P::ContextNotStorable { .. } => (None, Reason::Refused),
}
}

Expand Down Expand Up @@ -8388,11 +8379,6 @@ mod tests {
some("years"),
SharedIdentity,
),
(
P::PassthroughIndexed { field: field() }.into(),
some("age"),
PassthroughWithOutputs,
),
(
P::DuplicateIndex {
at: field(),
Expand Down Expand Up @@ -8427,32 +8413,6 @@ mod tests {
some("age"),
NoSuchField,
),
(
P::TargetWithVerbs { field: field() }.into(),
some("age"),
OutputsWithTarget,
),
(
P::IndexNotDeclared {
field: field(),
index: "ore",
}
.into(),
some("age"),
Refused,
),
(
P::IndexOptions {
field: field(),
declared: IndexSpec::Equality,
asked: IndexSpec::Equality,
}
.into(),
some("age"),
Refused,
),
(P::IdentityWithoutField.into(), None, Refused),
(P::MixedCiphers.into(), None, Refused),
(
P::TwoContextSources {
first: "the plan",
Expand All @@ -8462,7 +8422,6 @@ mod tests {
None,
Refused,
),
(P::NoContext.into(), None, Refused),
(P::BindInQuery.into(), None, BindInQuery),
(
P::IndexOverlap {
Expand Down
Loading
Loading