Skip to content

fix(core): read each ExclusiveStartKey value's descriptors as DynamoDB does - #1444

Open
eliseong wants to merge 3 commits into
mainfrom
eliseong-querykey-invalid-start-key-2026-11-24
Open

eliseong wants to merge 3 commits into
mainfrom
eliseong-querykey-invalid-start-key-2026-11-24

Conversation

@eliseong

@eliseong eliseong commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

What

Query and Scan now count the type descriptors of each ExclusiveStartKey value, and of each value nested in its L or M. A member that is not a descriptor, and a descriptor whose payload is null, are not counted.

  • No descriptor answers The provided starting key is invalid: Supplied AttributeValue is empty, must contain exactly one of the supported datatypes. This covers {}, {"X": "1", "Y": "2"} and {"S": null}, at any level.
  • Two or more descriptors answer The provided starting key is invalid: Supplied AttributeValue has more than one datatypes set, must contain exactly one of the supported datatypes, at any level.

A member that is not a descriptor is ignored beside one that is, so {"S": "a", "X": "1"} reads as the S value a. An empty NS, an SS with duplicates and a NULL of false keep their own text with no prefix. Elements of an L are read in order, so the first bad element decides the answer.

On main, a top-level empty value, a nested empty value and a value with two descriptors answer the text without the prefix, an unknown descriptor answers SerializationException, and {"S": "a", "X": "1"} is refused.

Why

Closes #848

Testing done

  • DynamoDB in us-east-1 on 1 December 2026: 86 raw signed Query and Scan requests on a table keyed on pk (S). Each request was sent twice and got the same answer both times. A local SQLite server built from this branch gives the service's answer for 56 of them; at 5b51a9e it gave it for 16. No request that matched at 5b51a9e differs now. The requests that still differ also differ at 5b51a9e and are listed under Notes.
  • Core unit tests pin each measured value shape and its text. Engine tests run the production from_value plus deserialize_error path for Query and Scan and assert the exact ValidationException.
  • cargo fmt --all -- --check, cargo clippy -p extenddb-core -p extenddb-engine --all-targets -- -D warnings, cargo test -p extenddb-core --lib (1246 passed) and cargo test -p extenddb-engine --lib (983 passed).

Notes

Checklist

  • I have read CONTRIBUTING.md
  • All tests pass (cargo test --workspace)
  • Code is formatted (cargo fmt --check)
  • Clippy is clean (cargo clippy -- -W clippy::pedantic)
  • I have added or updated tests for new functionality
  • I have updated documentation if behavior changed
  • Breaking changes are noted below (if any)
  • If this changes the wire protocol, Storage trait, auth model, on-disk
    format, or public CLI surface, an RFC has been accepted or is linked
    below. Otherwise, an ADR captures the decision (link below).

ADR / RFC: n/a

Breaking changes

None. A start key value with a member that is not a type descriptor beside one that is now reads instead of being refused, as on the service.


By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache License 2.0 and I agree to the Developer Certificate of
Origin (DCO). See CONTRIBUTING.md for details.

A Query or Scan ExclusiveStartKey value that is empty, or carries only an
unknown type descriptor, answered without DynamoDB's starting-key sentence:
the empty value gave the bare AttributeValue message and the unknown
descriptor gave a SerializationException. The service answers both with
ValidationException "The provided starting key is invalid: Supplied
AttributeValue is empty, must contain exactly one of the supported datatypes".

A custom deserializer for ExclusiveStartKey now adds that prefix for the empty
and unknown-descriptor cases and leaves other value errors (an empty number
set, for one) unprefixed, as the service does. Query and Scan.

Closes #848

@LJMart11 LJMart11 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 5b51a9e. 1 finding: 1 Important.

The change adds a shared ExclusiveStartKey deserializer for Query and Scan that answers the starting-key-prefixed message for an empty value or a single unknown descriptor. Confirmed against live DynamoDB (us-east-1) and the SQLite-backed server, same raw request to both: {} and {"X":"1"} as a top-level value answer the prefixed message with status 400 on both; {"NS":[]} answers the unprefixed number-set message on both; a valid key, an absent key and a null key deserialize as before. With the guard at serde_helpers.rs:193 disabled, 2 core and 2 engine tests fail. Engine lib tests passed (890).

  • Important crates/core/src/serde_helpers.rs:193 — The prefix is applied only when the top-level value is {} or has one unknown member, but live DynamoDB also prefixes two-member values, multi-descriptor values and nested empty or unknown values, which this head still answers without the prefix.

Comment thread crates/core/src/serde_helpers.rs Outdated
// contains "descriptor" is not mistaken for an unknown descriptor.
if let Some(obj) = value.as_object() {
let first_key = obj.keys().next().map_or("", String::as_str);
if obj.is_empty() || (obj.len() == 1 && !KNOWN_DESCRIPTORS.contains(&first_key)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important
The guard at serde_helpers.rs:193 applies the starting-key prefix only to a top-level {} or a one-member unknown descriptor, so other shapes the service prefixes still get the old text. The PR body lists these as unmeasured; I measured them with the same raw Scan request against us-east-1 and the SQLite server, and Query behaves the same as Scan on both.

{"pk":{"X":"1","Y":"2"}}: service prefixed ... is empty, must contain exactly one ...; head 400 Supplied AttributeValue has more than one datatypes set, ... (no prefix).
{"pk":{"S":"a","N":"1"}}: service The provided starting key is invalid: Supplied AttributeValue has more than one datatypes set, ...; head the same text without the prefix.
{"pk":{"M":{"a":{}}}} and {"pk":{"L":[{}]}}: service prefixed empty; head unprefixed empty.
{"pk":{"L":[{"X":"1"}]}} and {"pk":{"M":{"a":{"X":"1"}}}}: service prefixed empty (400 ValidationException); head 400 SerializationException unknown AttributeValue type descriptor: X.
{"pk":{"s":"a"}}: both prefixed (match).

Fix: either run the shape check recursively and cover the multi-member case with the same prefix (the multi-member text is ... has more than one datatypes set, must contain exactly one of the supported datatypes), or state in the body and in docs/differences-from-dynamodb.md that nested and multi-member values stay unprefixed. serde_helpers.rs:284-292 and engine/src/query.rs:865-875 pin the nested unknown descriptor as unprefixed and change with a recursive fix. If these are left as is, the title's claim of matching the service is limited to the two top-level shapes.

Evidence: serde_helpers.rs:193 reads if obj.is_empty() || (obj.len() == 1 && !KNOWN_DESCRIPTORS.contains(&first_key)). Raw signed Scan with ExclusiveStartKey set to each value above, one request each to both targets; the quoted texts are the responses. Two further differences I saw and did not chase: the service answers 200 for {"S":"a","X":"1"} where the head answers 400, and for {"NS":[]} plus "sk":{} the service reports the {} member while the head reports the NS error (member order).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in e9c0619. Each value's type descriptors are now counted at the top level and inside L and M. Measured on Query and Scan in us-east-1 on 1 December 2026, each request twice, and this head gives the service's answer for {"X":"1","Y":"2"}, {"S":"a","N":"1"}, {"M":{"a":{}}}, {"L":[{}]}, {"L":[{"X":"1"}]}, {"M":{"a":{"X":"1"}}} and {"L":[{"S":"a","N":"1"}]}. {"S":"a","X":"1"} now reads as the S value a, as on the service. The tests that pinned a nested unknown descriptor as unprefixed now expect the prefix.

{"NS":[]} beside "sk":{} is the order in which the service visits the key attributes. #1013 tracks it, and this PR leaves it as it is.

…B does

The starting-key sentence was added only for a top-level value that
was empty or had one member that is not a type descriptor. DynamoDB
counts the type descriptors of each value, and of each value nested in
its L or M. A member that is not a descriptor, and a descriptor whose
payload is null, are not counted:

- no descriptor answers "Supplied AttributeValue is empty";
- two or more descriptors answer "Supplied AttributeValue has more
  than one datatypes set".

Both carry "The provided starting key is invalid: ". A member that is
not a descriptor is ignored beside one that is, so {"S":"a","X":"1"}
reads as the S value a. An empty NS, an SS with duplicates and a NULL
of false keep their own text with no prefix. Elements of an L are read
in order, so the first bad element decides the answer.

Measured in us-east-1 on 2026-12-01, each request sent twice, on Query
and Scan; the rows with a null payload on Scan only.

Signed-off-by: Elise Ong <eliseong@amazon.com>
@eliseong eliseong changed the title fix(core): prefix the ExclusiveStartKey empty-value refusal fix(core): read each ExclusiveStartKey value's descriptors as DynamoDB does Dec 1, 2026
@eliseong
eliseong requested a review from LJMart11 December 1, 2026 19:21

@LeeroyHannigan LeeroyHannigan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I read the change against main 92155f3. For one bad value, the new answers are the service's. {} and an unknown descriptor answer the empty text with The provided starting key is invalid: , as #848 measured. A null payload, or a member that is no descriptor beside one that is, does not count. On this branch, cargo test -p extenddb-core --lib passed 1246 tests and cargo test -p extenddb-engine --lib query passed 54. A server built from it answers {}, {"X": "1"} and {"S": null} on Query and Scan with the prefixed empty text, where main gives the text without the prefix or SerializationException. CI passed, and the branch merges with main.

I sent three more start keys to DynamoDB in us-east-1 on 2 December, each twice, to a table keyed on pk:

ExclusiveStartKey DynamoDB This PR
{"pk": {"N": "bob", "S": "x"}}, on Query and on Scan ValidationException: "The parameter cannot be converted to a numeric value: bob" the more-than-one text, with the prefix
{"pk": {"L": [{"N": "bob"}, {}]}}, on Query the same numeric text the empty text, with the prefix

So the service reads a payload before it counts the descriptors, and a number fault in an earlier element decides an L. Main did not give these answers either, so they are not regressions. The comments on lines 165 and 169 ask to narrow the stated rule.

This overlaps #1377 (opened 23 November) and #854 (opened 5 November). #1377's type_descriptor and is_type_descriptor in crates/core/src/types/attribute_value.rs apply the same counting rule to every AttributeValue. #854 adds the prefix for the Scan ExclusiveStartKey. The part that only this PR adds is the prefix on Query. The merge with #1377 is clean, so both copies of the rule would stay. Under code-size.md, the second of the two to merge drops its copy. On top of #1377, this change would come down to the prefix on the two errors.

This needs one change before it merges. 1.1.0 refused {"S": "a", "X": "1"}, answered SerializationException for an unknown descriptor, and gave the empty and more-than-one texts without the prefix. docs/versioning.md puts such changes under Behavior Changes by Release in the upgrade manual, so this needs a v1.2.0: entry.

On the description: "No request that matched at 5b51a9e differs now" compares with this PR's own first commit, which already changed these answers. A count against the merge base 5489d29 would show whether an answer that main gave right now differs.

The other inline comments are smaller.

/// Read one `ExclusiveStartKey` value, and each value nested in its `L` or
/// `M`, as DynamoDB does (measured 2026-12-01, us-east-1). Members that are
/// not descriptors, and descriptors whose payload is null, are ignored. A
/// value with no other descriptor is "empty" and one with several is "more

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DynamoDB reads a payload before it counts the descriptors. {"N": "bob", "S": "x"} answers "The parameter cannot be converted to a numeric value: bob" on Query and on Scan. I measured it on 2 December, each request twice. Please narrow the rule here and in the description to valid payloads, and list the faulty-payload case with #720.

/// than one datatypes set". These two
/// refusals carry the starting-key sentence. An empty `NS`, an `SS` with
/// duplicates and a `NULL` of false keep their own text with no prefix.
/// Elements of an `L` are read in order, so the first bad element decides the

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{"L": [{"N": "bob"}, {}]} answers the numeric text for bob on Query (measured 2 December). So a number fault in an earlier element decides, where this code answers the empty text. "the first element that the deserializer refuses (number faults are not checked here, #720)" says what the code does.


/// The sentence DynamoDB puts ahead of a refusal of an `ExclusiveStartKey`
/// value's shape.
const INVALID_START_KEY: &str = "The provided starting key is invalid";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the third copy of the sentence: crates/engine/src/start_key.rs holds it at lines 62 and 397, and prefixed() in the engine test adds a fourth. Core cannot import from the engine, so one constant in crates/core/src/error/messages.rs that start_key.rs also uses would remove the copies. Or the description can say why they stay.

#[serde(rename = "Limit")]
pub limit: Option<i64>,
#[serde(rename = "ExclusiveStartKey")]
#[serde(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#854 takes the Scan ExclusiveStartKey out of the body before it reads ScanInput. Once #854 merges, this attribute and the scan_err half of the engine test are never reached. Please say in the description which PR removes them.

mod gate_tests;

#[cfg(test)]
mod exclusive_start_key_tests {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Four of these five tests are rows of one table of values and texts, and the core table already has those rows. What this module adds is the mapping to ValidationException. One test that loops over three rows (the prefixed empty text, the prefixed more-than-one text and the unprefixed NS text) covers it (code-size.md rule 4).

@navareamol navareamol left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran this head on SQLite next to a build of main. I sent 24 start key shapes and 11 whole key shapes to Scan and Query. They differ from main only where the description says: the empty and more than one texts now carry the starting key sentence, a member that is not a descriptor beside a real one is ignored, and a lowercase descriptor now gets the prefixed empty text instead of SerializationException. A start key of null, an empty map, a list, a string or a number for pk answers the same on both builds. Valid L nested 20, 31 and 33 levels deep still reach the key schema text, and 100 and 200 levels still stop at the JSON parser limit, so the new reader adds no new failure there. Nine existing wire files on start keys, paging and attribute validation pass here (723 tests). I also changed four lines in serde_helpers.rs one at a time (count a null payload, drop the prefix from the empty text, drop it from the more than one text, stop reading L elements). The two new core tests catch each change.

Two things I could not find in the earlier reviews. A descriptor with a false payload next to another descriptor, such as {"S":"a","NULL":false}, is counted and gets the more than one text. Please say that in the description, because "a NULL of false keeps its own text" reads as if it applies there too. A single descriptor with a payload of the wrong JSON type, such as {"S":1} or {"L":{}}, still answers SerializationException on this head and on main. Has anyone checked what the real service answers for those?

I will approve once LeeroyHannigan's points are done: narrow the rule for numeric payload faults, add the v1.2.0 upgrade manual entry, and settle the overlap with the two other PRs.

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.

Query: an empty or unknown-descriptor value in ExclusiveStartKey answers without the service's starting key text

4 participants