Skip to content

fix(engine): refuse a batch table value of another type before counts - #1285

Open
LeeroyHannigan wants to merge 6 commits into
fix/1233-batch-count-and-tablesfrom
fix/1266-batch-type-fault-first
Open

LeeroyHannigan wants to merge 6 commits into
fix/1233-batch-count-and-tablesfrom
fix/1266-batch-type-fault-first

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Changes since the last review

What

A BatchWriteItem over 25 tables, or a BatchGetItem over 100, can hold a value of another JSON type. It now gets a SerializationException, wherever the value sits in the request, as DynamoDB answers. Before this change, such a request got the table count clause.

When the counts of a batch fail, check_request_item_counts in crates/engine/src/request_limits.rs calls type_fault. It walks the parsed body against the members of the request (BATCH_GET, BATCH_WRITE, and ATTRIBUTE_VALUE for the items and keys). It stops at the first value whose JSON type the member does not take. Examples are a number where a list goes, and an array where an object goes. The walk reads these as DynamoDB does:

The SerializationException holds serde's text for that value, after the handler's prefix Start of structure or map found where not expected:. The walk runs only for a batch whose counts fail, and it makes no copy of the body.

The PartiQL checks walk attribute values too (check_parameter_types in crates/core/src/partiql/params.rs). That walk builds only with the partiql feature, and it refuses {"BOOL": "true"}, which DynamoDB reads as a boolean in a batch item. So this PR does not call it.

#1114 adds boolean_text beside BOOLEAN_TEXTS in crates/engine/src/query_key_values.rs. boolean_text(text).is_some() gives the same answer as reads_as_boolean(text). Whichever of the two PRs merges second drops its copy.

The doc of cross_account::refuse now says that a batch outside its counts gets the answer of check_request_item_counts first.

The base of this PR is #1268.

Refs #1266

Why

These are DynamoDB's answers in us-east-1 on table names that do not exist, each request sent twice with the same answer both times. Each other table holds one put request or one key. SE is SerializationException. COUNT is the ValidationException with the table count clause. The dates are 20 and 21 November and 2 December 2026, and 25 November for "TRUE" and "1".

Request DynamoDB ExtendDB on #1268 ExtendDB with this PR
BatchWriteItem, 26 tables, one table value 1, {} or [1], or a PutRequest, Item, DeleteRequest or Key of another JSON type SE COUNT SE
BatchGetItem, 101 tables, one table value 1 or {"Keys": 1}, or a key, ProjectionExpression, ConsistentRead, ExpressionAttributeNames or AttributesToGet of another JSON type SE COUNT SE
An attribute value of another type, such as {"S": 1} SE COUNT SE
An array where an object goes: a BatchGetItem table value [], or a BatchWriteItem request [] or PutRequest [] SE COUNT SE
One table {"Keys": 1, "ConsistentRead": "true"} SE COUNT SE
A boolean string, a missing or null member, or an attribute value fault in one table, and a table value 1 in another, in either order SE COUNT SE
BatchWriteItem, 26 tables, an attribute {"S": null}, {"BOOL": null}, {"L": null}, {"X": "a"}, {"BOOL": "true"} or {} COUNT COUNT COUNT
BatchGetItem, 101 tables, a key {"pk": {"S": null}} or {"pk": {"X": "a"}}, or ConsistentRead "true", "TRUE", "1" or "false" COUNT COUNT COUNT
BatchGetItem, 101 tables, ConsistentRead "x" SE COUNT SE
BatchWriteItem, 26 tables, one value [{}] COUNT COUNT COUNT

In the COUNT rows, DynamoDB's clause quotes the whole request map, for BatchGetItem too. ExtendDB gives BatchGetItem's clause at 'RequestItems' with no map.

The review of this PR sent 72 requests to DynamoDB on 20 and 21 November. With this change, 68 of them get DynamoDB's exception type from a SQLite server of this head, against 15 on #1268's head. No request that had DynamoDB's type on #1268 loses it. All 82 answers, 10 controls among them, were HTTP 400. Three of the other four are BatchGetItem tables with no Keys within the counts, which #1301 changes. The fourth is an attribute {"B": "!"} that is not base64, as "Not in this PR" says.

Testing done

At ef7b83c, whose tree is the tree of 1cc4130:

  • cargo test -p extenddb-engine --lib: 979 passed. cargo test -p extenddb-wasm-adapter: 4 passed, the parity corpus test among them.
  • cargo +1.97.0 fmt --all -- --check, the two clippy commands of .github/workflows/clippy.yml with -D warnings on extenddb-core, extenddb-engine and extenddb-server, cargo +1.97.0 clippy -p extenddb-engine --lib --no-default-features -- -D warnings and cargo +1.94.0 check --all-targets on the same crates are clean.
  • python3 -m pytest --collect-only -q collects 7212 tests in tests and 731 in tests/python, with no error.
  • The unit table malformed_entries_in_order has 38 rows. The production code of 57f165e reads the first error of a typed parse. With it, rows 21, 22, 24, 26, 28, 30 and 32 to 36 fail. The rows with the fault in the other order pass there, because there the typed parse meets the type fault first.
  • Against SQLite and PostgreSQL servers built from this head: tests/python/test_batch.py, tests/test_batch_operations.py and tests/test_batch_write_validation_order.py passed 111 tests on SQLite and 111 on PostgreSQL, 66 of them in test_batch.py. On SQLite, tests/test_authz_cross_account.py passed 19.
  • This head's test_batch.py against a server built from fix(engine): list batch table faults after the table count clause #1268's head: 23 failed and 43 passed. The 23 failures are the rows of the type fault table that expect a SerializationException.
  • On a fresh SQLite server, the first 15.4 MB BatchWriteItem body over the count raised the peak memory (VmHWM) to 691112 kB at this head. At fix(engine): list batch table faults after the table count clause #1268's head it rose to 700452 kB. Each figure is one run, at a host load of about 9 on 16 cores.

Line counts against #1268: production +131 -8, tests +287 -33.

This PR adds no conflict with an open PR. No other open PR changes request_limits.rs or tests/python/test_batch.py. This head merges with each open PR that changes another of its files with no conflict that the PR does not have with main already.

Not in this PR:

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

A batch outside its counts can hold a value of another JSON type. It gets a SerializationException in place of the count clause, as the What section says. Requests within the counts get the same answers as before.


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 BatchWriteItem over 25 tables, or a BatchGetItem over 100, got the
table count clause when one table's value had another JSON type.
DynamoDB answers a SerializationException for such a request.

When the counts of a batch fail, the count check before authorization
now parses the body as the handler does. A value whose JSON type is not
the member's gets the handler's SerializationException. A missing or
null member keeps the count clause, as does the string "true" or
"false" where a boolean goes. DynamoDB answers those with the count
clause. The parse reads the body without a copy, and runs only for a
batch whose counts fail.

An attribute value of another type, such as {"S": 1}, keeps the count
clause too, where DynamoDB answers a SerializationException. The
AttributeValue reader gives a null, or a string DynamoDB accepts, the
same text as a value of another type. The check cannot tell them apart.

Measured in us-east-1 on 20 and 21 November 2026, each request sent
twice, with names of tables that do not exist.

Refs #1266. This commit leaves the BatchGetItem row, since its count
clause quotes DynamoDB's own text form of the whole request.
…first

The two branches added a helper at the same place in test_batch.py. The
merge keeps OTHER_ACCOUNT from the base branch, then _raw_batch from
this branch.
type_fault kept the table count clause only for the strings "true" and
"false" where a boolean goes. Over the table count, DynamoDB answered
the count clause for a ConsistentRead of "TRUE", "True", "1", "yes",
"FALSE" or "0" too. Its echo of each request read the string as a
boolean (measured 2026-11-25). Before this change, those requests got a
SerializationException, where #1268 gave the count clause.

type_fault now keeps the count clause for each string that
reads_as_boolean accepts. That function reads BOOLEAN_TEXTS, the list
of strings that the Query shape check already uses, and
shape_fault_first calls it too. Another string, such as "x", keeps the
SerializationException, as DynamoDB answered on 2026-11-21.

The unit table and the wire table get rows for "TRUE", "1", "false" and
"x". Against DynamoDB, the wire table now accepts a table count clause
that quotes the request map, as DynamoDB gave on 2026-11-21 and
2026-11-25. Against ExtendDB it still compares the full text.

Refs #1266.
@demohan demohan self-assigned this Nov 29, 2026

@demohan demohan 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.

A batch table value of another JSON type is now refused before the counts in most shapes at 79fbe54: of 83 shapes sent twice to us-east-1 and to this head and its base on SQLite and PostgreSQL, the base matched the service's exception class on 17 and this head on 60, with no shape answered worse than on the base. The new SerializationException comes where the count clause did, after authentication and before the IAM decision (a user with no policy gets it over the counts and AccessDenied within them, as on the base), and before the foreign-account check, as on the service. Every boolean text the service reads keeps the count clause here too, on all 8 sent. All five mutations fail malformed_entries_in_order, the 7 new SerializationException wire rows fail on the base and all 11 pass against the service, fmt, clippy, 934 engine tests, the 48 cases of test_batch.py on both backends and the 1.91.1 check are clean. Every CI run at this head was cancelled. The branch conflicts with main at 222d80a in partiql/request_checks.rs, from #1215, and a resolution builds and passes 979 engine tests.

I will approve once a value of another JSON type is found wherever it sits, not only at the typed parse's first error (below).

Comment thread crates/engine/src/request_limits.rs Outdated
/// faults, so the check reads serde's fixed `invalid type: <unexpected>,
/// expected <expected>` text.
fn type_fault(operation: &str, body: &Value) -> Option<DynamoDbError> {
let e = if operation == "BatchGetItem" {

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.

The typed parse stops at its first error, so a later value of another type is not seen when the first error is a boolean string, a missing member, a null or an AttributeValue fault, and since preserve_order is off, "later" means later in key order, so the answer turns on table names. On 11 such shapes the service answered SerializationException twice and this head the count clause twice: one table {"Keys":1,"ConsistentRead":"true"}; ConsistentRead "true" in t000 with 1 in t005; [{"PutRequest":{}}] before 1; {"Keys":null} or {} before 1; {"BOOL":"true"}, {"S":null} or {} before 1. An array where an object goes is reported by serde as invalid length, not invalid type, so it keeps the count clause too: 101 BatchGetItem tables with one value [], 26 BatchWriteItem tables with [[]] or [{"PutRequest":[]}], and filled arrays for structs, where the service answers SerializationException. An AttributeValue of another type ({"S":1}, which the body leaves out) gets NUMBER_VALUE cannot be converted to String there. Walking the parsed JSON for the first value of another type, rather than reading the typed parse's first error, would cover all of these and avoid the second parse: a 15.0 MB over-count BatchWriteItem peaked at 767 and 756 MB here against 632 and 631 MB on the base.

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.

1cc4130 replaces the typed parse with a walk of the parsed body against the members of the request. It stops at the first value of another JSON type in any table. It skips a null, a string where a boolean goes that reads_as_boolean accepts, and a member that the request does not name. An array where an object goes is a type fault there, and so is {"S": 1}.

On 2 December each of the 11 shapes in your list, and each array shape, got SerializationException from DynamoDB, both sends. I also sent each shape with the two tables swapped, and those got the same. malformed_entries_in_order has 17 new rows for them, and the wire table 19. With the production code of 57f165e, 11 of the new unit rows fail. On a fresh SQLite server, the first 15.4 MB BatchWriteItem body over the count raised the peak memory to 691112 kB at this head. At #1268's head it rose to 700452 kB, one run each.

Comment thread crates/engine/src/request_limits.rs Outdated
);
fn malformed_entries_in_order() {
// Measured 2026-11-20 and 2026-11-21, and 2026-11-25 for rows 17 and
// 18. Rows 0 to 4, 6, 7 and 20 have the service's error type, and row 4

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.

Optional. Row 4's clause quotes the whole request map on the service today, the #1215 form, not this text. The body describes the state before 79fbe54: every boolean text keeps the count clause now, not only "true" and "false", the table has 21 rows, test_batch.py 48 tests and the wire table 11 rows, and "makes no copy of the body" no longer holds.

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.

Row 4 expects the quoted map form since 57f165e. Its comment in 1cc4130 says that the row has DynamoDB's text outside the quoted map, as measured on 2 December. The body now describes this head: every text of BOOLEAN_TEXTS, 38 unit rows and 66 tests in test_batch.py. It also gives the 30 rows of the wire table, and the walk, which makes no copy of the body.

…first

The base now refuses a BatchWriteItem outside its counts in the quoted
request map form, as DynamoDB answered on 25 Nov and 2 Dec 2026. In
test_batch.py the merge keeps both imports and _raw_batch. It drops
OTHER_ACCOUNT, which no test uses now.

The rows of malformed_entries_in_order that expect the BatchWriteItem
table count clause now expect the quoted form. In
test_batch_type_fault_over_the_table_count, a BatchWriteItem count
refusal goes through _assert_write_refusal. A BatchGetItem one gets
ExtendDB's text by equality, and DynamoDB's quoted map goes through the
new _assert_quoted, which _assert_write_refusal calls too. DynamoDB
quoted the request map in these BatchGetItem refusals on 25 Nov and
2 Dec. The QUOTED escape is gone, as in the base.
type_fault read only the first error of a typed parse of the body. That
error could be a string read as a boolean, a missing or null member, or
an attribute value fault. Then a later value of another JSON type stayed
hidden, and the request kept the count clause. DynamoDB answered each of
these requests with a SerializationException on 2 Dec 2026, in either
order of the two tables.

Now type_fault walks the parsed body against the members of the request.
It stops at the first value of another JSON type. A null is an absent
member. A string that reads_as_boolean accepts is a boolean. The walk
also finds an array where an object goes, and an attribute value of
another type, such as {"S": 1}. It makes no typed copy of the body.

The unit table has 17 new rows and the wire table 19, from the
measurements of 2 Dec.
…first

#1215 now writes per_table_count_error with validation_refusal, and
the base merged it. No branch above #1215 has per_table_count_error,
so no file changes.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

@demohan A value of another JSON type is now found wherever it sits, in 1cc4130. The reply in the thread on request_limits.rs line 224 has the details. 57f165e merges #1268's new head, and the head merges main at b3510a9 with no conflict.

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.

2 participants