Skip to content

fix(server): read request members in the client's order on every build - #781

Open
LeeroyHannigan wants to merge 6 commits into
mainfrom
fix/723-sort-request-keys
Open

LeeroyHannigan wants to merge 6 commits into
mainfrom
fix/723-sort-request-keys

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Changes since the last review

demohan approved 4774b89 on 24 November. Since then the branch has two new commits:

CI at 4ef91ea passed all 64 checks, and code scanning reports no open alert.

What

The server crate enables serde_json's preserve_order feature. Every build of the extenddb binary now parses a request with its members in the order the client wrote them. That covers the four Dockerfiles and the npm binaries. Before, only a build that compiled the MongoDB backend kept that order, because bson 2.15.0 enables the feature. The other builds read every object in name order.

Inside one map the service uses another order. It checks the members of one ExpressionAttributeValues map or one PartiQL parameter map in the order that a Java HashMap of the map yields them. This change walks those maps and ExpressionAttributeNames in that order on every build.

The changes:

  • crates/server/Cargo.toml enables the feature, with a comment that gives the reason.
  • compute_fingerprint hashes a copy of TransactItems with the members of every object sorted by name. It calls Value::sort_all_objects, which serde_json added in 1.0.129. The workspace requirement moves from "1" to "1.0.129". Cargo.lock does not change, because it holds 1.0.150.
  • crates/engine/Cargo.toml enables the feature for the engine's tests.
  • crates/core/src/map_order.rs holds the bucket model that print_order in the PartiQL echo held, and its tests. The echo, the PartiQL parameter checks and the two placeholder maps use it.
  • deserialize_placeholder_map in serde_helpers.rs runs its checks in the service's order. A value of the wrong JSON type comes first, the first one written. A JSON null is not such a value. Then ExpressionAttributeValues checks its keys and then its values, and ExpressionAttributeNames checks its empty names and then its keys. Each fault keeps its text.
  • check_parameter_types and its check of one value move from partiql/params.rs to serde_helpers.rs, because a build without the partiql feature has no PartiQL module. params.rs re-exports it. fix(core): answer JSON null members as DynamoDB does #1103 makes the same move, so the two branches conflict in five hunks of the two files. A merge that keeps one copy passes the core tests.
  • Comments in six files said that only a build with the MongoDB backend keeps the request's order. They now say that every build with the server keeps it. The files are table_name_gate.rs, partiql/mod.rs, partiql/common.rs, core/src/partiql/params.rs, backup_format/data_file.rs and data_file_nested_decode_memory.rs.
  • The admin guide and the backup manual show /health with status first, the order that every build now writes.
  • Tests: crates/server/src/handler_member_order_tests.rs, the dual-target file tests/test_request_member_order.py, a table of two-fault maps in serde_helpers.rs and the map rows of params.rs. tests/raw_signed_request.py gets answer, which reads the status, error type and message of a response. tests/test_partiql_numbers.py drops the xfail that depended on the build.

Measured on Amazon DynamoDB

us-east-1, raw signed bodies with the members in the order written. Two type faults in two members of the body get the fault of the member written first. Every answer is HTTP 400 SerializationException.

Operation Members A and B A written first B written first
Query "Limit": "0", "ConsistentRead": "x" STRING_VALUE cannot be converted to Integer Unexpected token received from parser
Query "Select": 7, "Limit": "0" NUMBER_VALUE cannot be converted to String STRING_VALUE cannot be converted to Integer
TransactWriteItems, a Put "TableName": 5, "Item": "x" NUMBER_VALUE cannot be converted to String Unexpected field type
GetItem "ConsistentRead": "x", "ProjectionExpression": 5 Unexpected token received from parser NUMBER_VALUE cannot be converted to String
PutItem "ReturnValues": 5, "Expected": "x" NUMBER_VALUE cannot be converted to String Unexpected field type
UpdateItem "ReturnValues": 5, "ExpressionAttributeNames": "x" NUMBER_VALUE cannot be converted to String Unexpected field type

A type fault beside a validation fault answers the type fault in both orders. A Limit of 0.0 beside an empty value answers the Limit fault in both orders.

Two faults in one map. In a table of 4 buckets, :b is in bucket 0, :c in 1, and :a and :e in 3. bad and x are in bucket 0, and a and e in 1. A map of four members takes 8 buckets, where a is in bucket 1 and bad in 4.

Map Members Service answer in both orders
UpdateItem ExpressionAttributeValues :c and :b both {} the empty :b
the same :a and :c both {} the empty :c
the same :a and :e both {}, with and without a valid :p the member written first
the same :c = {"S": 5} and :b = {"BOOL": "x"} the member written first
the same :b = {} and :a = {"S": 5} SerializationException for :a
the same key b with a valid value, and :c = {} the invalid key b
Scan ExpressionAttributeValues, with a valid :p :b = {} and :a = {"X": "1"} the empty :b
UpdateItem ExpressionAttributeNames #c = "" and #b = 5 SerializationException for #b
the same #c = "" and #b = null the empty #c
ExecuteStatement parameter map e 40 maps deep and bad = {"N": "abc"} The parameter cannot be converted to a numeric value: abc
the same bad and a 40 maps deep, with and without a valid x the same
the same bad and a 40 maps deep, with a valid x and y Nesting Levels have exceeded supported limits

The 44 rows of tests/test_request_member_order.py pin these answers. On 19 November a script posted each row body twice, as the test posts it. All 88 answers equal the pinned status, error type and message. The :a and :c rows, the :c and :b rows, the e row and the Scan row date from 12 November (#1013). The other one-map rows date from 19 November, with 2 sends per order and the same answer each time.

For two malformed keys in ExpressionAttributeValues and for two empty names, the service named either member from one send to the next. No fixed order matches it every time. For a malformed key beside an empty name it named the empty name in both orders. Its text there has a 1 validation error detected: prefix that ExtendDB does not send (#1160), so the Rust table pins that row and the Python file does not.

Other effects on the PostgreSQL, SQLite and Cassandra builds

The MongoDB build already behaved this way, except in the three maps above, which change on every build.

Typed items and M values are BTreeMaps. So stream records, backup data files, exports and the duplicate item checks keep name order.

compute_fingerprint makes one more copy of the TransactItems tree while it hashes. It runs only for a TransactWriteItems with a ClientRequestToken. A standalone benchmark of three 4 MB request shapes measured 1.4 to 38 ms and 6 to 109 MB for the copy and the sort.

Not in this change

Why

The builds answered a body with two type faults differently. The typed input deserializers visit the members in the map's order and stop at the first one that fails. The MongoDB build visited the written order and answered as the service does. The other builds visited name order. They answered the other fault when the member first by name was not the one written first.

Inside one map, main's name order gives another member than the service for some maps, and the written order for others. Walking those maps in the service's order gives the service's member on every build.

Closes #723

Testing done

At 4774b89, on main c2e9a32.

A SQLite server, cargo build --locked -p extenddb --no-default-features --features sqlite, on 127.0.0.1:

  • tests/test_request_member_order.py and tests/test_partiql_numbers.py: 147 passed, 3 xfailed.
  • The same two files on a server built from main at c2e9a32: 23 failed, 124 passed, 3 xfailed. The 23 are 7 rows with their two faults in two members of the body, 15 one-map rows and test_the_first_problem_in_map_member_order_is_reported.
  • 63 of the 154 test files, the PartiQL, transaction, validation, expression and authorization files and test_query_scan.py: 3876 passed, 3 skipped, 10 xfailed. CI runs the whole suite on the SQLite integration server.

Mutants:

  • A sort after the parse in handle_request, which gives the order of a build without the feature: 11 rows fail.
  • preserve_order removed from crates/server/Cargo.toml: the Rust test fails under cargo test -p extenddb-server, and passes at the head.
  • The three map walks in the parsed order: 7 rows fail, and 2 core tests fail in each feature mode.
  • The type check of the placeholder maps in bucket order: 1 row fails, from the pair with two type faults in one map.
  • Each of three mutants of the placeholder maps fails the table test in serde_helpers.rs, in both feature modes. They drop the type check, check the values of ExpressionAttributeValues ahead of its keys, or check the keys of ExpressionAttributeNames ahead of its empty names.
  • The sort removed from compute_fingerprint: cargo test --locked -p extenddb-engine --lib fingerprint fails.

In a build of the whole workspace, bson and the engine's dev-dependency also turn the feature on. There the Rust test handler_member_order_tests.rs checks dispatch alone. It checks the feature under cargo test -p extenddb-server, as the second mutant shows. In CI the Python rows check it on the SQLite server, which has neither.

Builds and checks:

  • cargo +1.97.0 fmt --all -- --check: pass.
  • Both clippy commands in clippy.yml, on 1.97.0 with --locked and -D warnings: pass.
  • cargo +1.91.1 check --locked --workspace --all-targets: pass.
  • cargo +1.97.0 test --locked --lib, with -p for each crate: extenddb-engine 867 passed, extenddb-core 1151 passed and 1 ignored, and the same for extenddb-core with --features serde_json/preserve_order. extenddb-server gives 514 passed and 5 failed. The 5 are backup_store tests that need a temporary directory whose ancestors belong to root or to the test user. This host has no such directory.
  • cargo +1.97.0 check --locked -p extenddb-core --no-default-features --all-targets: pass.
  • cargo tree -i serde_json -e features shows preserve_order for the feature sets postgres, mongodb, cassandra, sqlite,dev-mode and sqlite.
  • The four licence notice checks of licenses.yml: pass. Cargo.lock is the same as on main.

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

On the PostgreSQL, SQLite and Cassandra builds, a body with two type faults can get another answer than before. It is the fault of the member written first, as the service answers. On every build, two faults in one ExpressionAttributeValues, ExpressionAttributeNames or PartiQL parameter map can get another answer than before, in the service's order above. On the PostgreSQL, SQLite and Cassandra builds, the JSON that the server writes lists its keys in another order.

A build with preserve_order hashed a transaction request in the client's order: the MongoDB build, and a build of the whole workspace. After the upgrade, a retry with the same ClientRequestToken gets IdempotentParameterMismatchException when the first request's members were not in name order. That holds while the store keeps the first request's token, at most 10 minutes on the MongoDB store. Builds without the feature hashed name order before, so their stored tokens still match.


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.

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

On the MongoDB build, and on the workspace-root builds that CI runs pytest against (PostgreSQL, Cassandra and MongoDB), the merge-base read request members in the order the client wrote them. DynamoDB uses that order to choose among serialization faults, so those builds gave DynamoDB's answer on the bodies in the inline comments. With the sort they give the name-order answer. I measured each body in us-east-1 on 10 November 2026, two sends each, with the same answer both times.

Merged onto main, the sort also changes PartiQL answers that main gets right. That one comes from main moving under the branch, not from this change, but the merged result answers it wrongly. Keeping the client's order fixes both.

The description also needs four corrections:

  • The new file also runs in the Cassandra pytest job, which has preserve_order, and in the SQLite job, which does not and so cannot fail it.
  • The published PostgreSQL image is built with -p extenddb and has no preserve_order, unlike CI's PostgreSQL server.
  • The "695 tests" selection collects 700 with the run-tests ignore list. The result it reports holds.
  • If the sort stays, serde_json = "1" in Cargo.toml needs to be at least 1.0.129, the first release with sort_all_objects.

Comment thread crates/server/src/handler.rs Outdated
// order. DynamoDB answered each two-fault Query and Scan body measured on
// 2026-11-03 alike in both orders. Sorting gives every build the sorted
// order; without `preserve_order` the call does nothing.
input.sort_all_objects();

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.

On the MongoDB build this changes answers the merge-base gave correctly. Query {..., "Limit": "0", "ConsistentRead": "x"}: DynamoDB answers SerializationException: STRING_VALUE cannot be converted to Integer (Limit). The merge-base MongoDB build names Limit; this change names ConsistentRead. With ConsistentRead written first DynamoDB answers Unexpected token received from parser.

PutItem "Item": {"pk": {"S": "k"}, "b": {}, "a": {"X": "1"}}: DynamoDB answers ValidationException: Supplied AttributeValue is empty, must contain exactly one of the supported datatypes. The merge-base MongoDB build gives the same. This change gives SerializationException: ... unknown AttributeValue type descriptor: X.

The same holds for UpdateItem with ":b": {} before ":a": {"X": "1"}, for TransactItems[].Put with TableName: 5 before Item: "x", and for this file's own Scan body with :b first. Keeping the client's member order on every build gives DynamoDB's member on all of these. The fingerprint in transact_write_helpers.rs can hash a sorted copy, because DynamoDB accepts a retry with reordered members as a replay.

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.

The sort is gone. The server crate now enables preserve_order, so every build reads the members in the order the client wrote them. compute_fingerprint hashes a copy with the members sorted by name. On the service, a retry whose Put lists its members in another order replays (16 November, two runs). A different item under the same token answers IdempotentParameterMismatchException.

Your Query and TransactWriteItems pairs and this file's Scan body are rows of the new test, in both orders. On ExtendDB a type-fault row checks serde_json's text, which names the member written first (#1012).

With b or :b written first, the PutItem and UpdateItem bodies now get the service's empty-value answer on every build. With {"X": "1"} written first, ExtendDB still answers the descriptor fault, where the service answers the empty-value text in both orders (#629).

Comment thread crates/server/src/handler.rs Outdated
// order. DynamoDB answered each two-fault Query and Scan body measured on
// 2026-11-03 alike in both orders. Sorting gives every build the sorted
// order; without `preserve_order` the call does nothing.
input.sort_all_objects();

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.

Merged onto main, this also changes PartiQL answers on the MongoDB build. ExecuteStatement with the parameter {"M": {"d": <40 nested M levels>, "bad": {"N": "abc"}}}: DynamoDB and main answer Nesting Levels have exceeded supported limits: Attributes in the item have nested levels beyond supported limit. Main with this change answers The parameter cannot be converted to a numeric value: abc.

The BatchExecuteStatement echo of a parameter map {"BB": ..., "Aa": ...} prints BB first on DynamoDB and on main, and Aa first with this change. test_the_first_problem_in_map_member_order_is_reported moves from XPASS to XFAIL, and the comments in params.rs, partiql/mod.rs, echo.rs and table_name_gate.rs that say these builds keep request order stop being true.

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.

With the sort gone, every build keeps the written order. The ExecuteStatement parameter with d first answers the nesting fault again. On a SQLite server built from this branch, the BatchExecuteStatement echo prints BB first, as the service does.

test_the_first_problem_in_map_member_order_is_reported passes on every build now, so this branch removes its xfail. The comments in params.rs, partiql/mod.rs, echo.rs and table_name_gate.rs say that every build with the server keeps the request's order.

Comment thread crates/server/src/handler.rs Outdated
// client wrote its members in; other builds sort them by name. The typed
// input deserializers stop at the first member that fails, so on such a
// build a body with two faults got an error chosen by the client's member
// order. DynamoDB answered each two-fault Query and Scan body measured on

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 does not answer every two-fault body alike in both orders. Query with Select: 7 and Limit: "0" answers NUMBER_VALUE cannot be converted to String with Select first and STRING_VALUE cannot be converted to Integer with Limit first. The bodies measured on 3 November pair a type fault with a validation fault, and those do answer alike.

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.

The measurements agree. Two type faults answer the member written first in Query and TransactWriteItems (12 November) and in GetItem, PutItem and UpdateItem (16 November). A sort cannot give that in both orders, so this revision keeps the client's order instead. The test has one row per order for each of those pairs.

Comment thread tests/test_request_member_order.py Outdated
# Copyright 2026 ExtendDB contributors
# SPDX-License-Identifier: Apache-2.0

"""The order of a request body's members does not change the error it gets.

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 does not hold for two type faults (see the comment on handler.rs). It holds for the pairs this file sends.

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.

The docstring now gives three cases. Two type faults answer the member written first. A type fault beside a validation fault answers the type fault in both orders. Two validation faults get one answer in both orders.

Comment thread tests/test_request_member_order.py Outdated
{**head, "ExpressionAttributeValues": values, "Limit": limit},
)
assert limit_first[0] == 400, limit_first
assert values_first == limit_first

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 passes while the change answers DynamoDB's SerializationException: STRING_VALUE cannot be converted to Integer body with ValidationException: ExpressionAttributeValues contains invalid value: ... for key :a. It also passes when the sort runs only for Query and Scan, and when it sorts in descending order. Pinning each body's status, type and message from DynamoDB (xfail on #778 where ExtendDB differs), adding PutItem, UpdateItem and GetItem bodies, and adding a Rust unit test that runs under cargo test --workspace would catch these.

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.

Each row now pins the service's status, error type and message for one body in one member order. The rows cover Query, Scan, TransactWriteItems, GetItem, PutItem and UpdateItem. On ExtendDB a type-fault row checks serde_json's text instead, which names the member written first (#1012). A row that ExtendDB answers otherwise is a strict xfail on #720, #778 or #629.

The two rows of each pair with two type faults expect different members. A server that reads the members in any fixed order fails one row of each such pair. That covers a descending sort, and a sort for Query and Scan only. With the sort restored after the parse in handle_request, 8 rows fail.

two_type_faults_answer_the_member_written_first, in crates/server/src/handler_member_order_tests.rs, runs under cargo test --workspace. It fails when the server crate loses preserve_order.

Comment thread tests/test_request_member_order.py Outdated
resp = requests.post(
url, data=payload, headers=dict(request.headers), verify=endpoint_url is None, timeout=30
)
doc = resp.json()

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 non-JSON answer raises JSONDecodeError here and the status is lost. tests/raw_signed_request.py has signed_post for raw signed bodies, which would also avoid reading client._request_signer._credentials on line 51.

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.

The rows now post through signed_post, with the credentials of the boto3 session, so the test no longer reads the client's signer. answer in tests/raw_signed_request.py reads the status, the error type and the message. For an answer that is not JSON it keeps the status and returns the text.

@LeeroyHannigan
LeeroyHannigan force-pushed the fix/723-sort-request-keys branch from 1ddf02d to f685853 Compare November 16, 2026 22:57
@LeeroyHannigan LeeroyHannigan changed the title fix(server): read request members in sorted order on every build fix(server): read request members in the client's order on every build Nov 16, 2026
@demohan demohan self-assigned this Nov 19, 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.

The sort is gone, every build keeps the written order, and the fingerprint hashes a sorted copy. Each body from the earlier review now gets DynamoDB's member on all four backends, the PartiQL answers on main match DynamoDB again, and the rows pin DynamoDB's status, type and message. I measured each body in us-east-1 on 19 November 2026, two sends per order.

Three items remain.

  1. On the SQLite, PostgreSQL and Cassandra builds this changes two answers that main gives correctly. Both come from a walk over one map. The earlier review asked for the written order without these maps in view. UpdateItem with "ExpressionAttributeValues": {":c": {}, ":b": {}}: DynamoDB and main name :b, and this branch names :c. ExecuteStatement with the parameter {"M": {"e": <40 nested M levels>, "bad": {"N": "abc"}}}: DynamoDB and main answer The parameter cannot be converted to a numeric value: abc, and this branch answers Nesting Levels have exceeded supported limits: Attributes in the item have nested levels beyond supported limit. The same holds with n for e. These are rows of #1013. The empty-value check in deserialize_expression_values and the parameter walk in params.rs can visit the members in the bucket order that print_order in echo.rs models, or keep name order as main does.
  2. tests/test_request_member_order.py:9 and the message of f685853 say that two validation faults get one answer in both orders. Inside one map that does not hold: UpdateItem and Scan with :a and :e both {} answer the key written first. This branch gives the same answers. The PR body words it correctly.
  3. two_type_faults_answer_the_member_written_first passes under cargo test --locked --workspace --exclude extenddb-backup-store with preserve_order removed from crates/server/Cargo.toml. bson turns the feature on in any workspace build. It fails under cargo test -p extenddb-server. The pytest rows catch the same loss on the SQLite build.

Comment thread crates/server/Cargo.toml
# faults with the fault of the member written first. Without this feature a
# parsed object is sorted by name, except in a build that also compiles
# `bson`, which turns the feature on.
serde_json = { workspace = true, features = ["preserve_order"] }

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.

With this line the empty-value check in deserialize_expression_values walks ExpressionAttributeValues in the written order on every build. UpdateItem with {":c": {}, ":b": {}} written in that order: DynamoDB answers ExpressionAttributeValues contains invalid value: Supplied AttributeValue is empty, must contain exactly one of the supported datatypes for key :b in both orders, and main on SQLite gives the same. This branch on SQLite answers for key :c. The PartiQL parameter walk changes the same way: {"e": <40 nested M levels>, "bad": {"N": "abc"}} answers The parameter cannot be converted to a numeric value: abc on DynamoDB and on main, and the nesting fault on this branch. Measured 19 November 2026, two sends per 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 7c3d5d6. The checks of one ExpressionAttributeValues, ExpressionAttributeNames or PartiQL parameter map now visit the members in the order that print_order modelled, on every build. The model moved to extenddb_core::map_order, and the echo uses it there. Both of your bodies get the service's answer, and the n body is a row of the parameter test in params.rs.

I measured more bodies on 19 November, two sends per order. The service checks one placeholder map in steps. A value of the wrong JSON type comes first, the first one written. Then ExpressionAttributeValues checks its keys ahead of its values, and ExpressionAttributeNames its empty names ahead of its keys. The bucket order alone would answer the empty :b for {":b": {}, ":a": {"S": 5}} in both orders, where the service and main answer the type fault. So the two placeholder maps now check the JSON types first, with the check that check_parameter_types runs. The bodies are rows of tests/test_request_member_order.py. Each of its 44 rows got the pinned answer from the service twice, and a server built from main fails 22 of them.

Comment thread tests/test_request_member_order.py Outdated
Amazon DynamoDB answers a body with two type faults (members it cannot
convert to their type) with the fault of the member written first, and a
type fault beside a validation fault with the type fault in either order.
Two validation faults get one answer in both orders.

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.

Inside one map this does not hold. UpdateItem with "ExpressionAttributeValues": {":a": {}, ":e": {}} answers for key :a, and with :e written first answers for key :e. Scan gives the same. This branch matches both, so only the sentence needs to change. The f685853 commit message has the same sentence.

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 4774b89. The docstring now says that inside one map the order written decides only between two members in one bucket, such as :a and :e. The :a and :e bodies are rows of the file in both orders, with and without a third member. The commit message says the same.

/// parses the body itself and so checks the feature, not `handle_request`:
/// `tests/test_request_member_order.py` sends the bodies through the handler.
#[tokio::test]
async fn two_type_faults_answer_the_member_written_first() {

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.

With preserve_order removed from crates/server/Cargo.toml, this test passes under cargo test --locked --workspace --exclude extenddb-backup-store, the command in test.yml. bson from extenddb-storage-mongodb turns the feature on in any workspace build. Under cargo test -p extenddb-server it fails at line 67. A CI step that runs it with -p extenddb-server would let it fail.

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.

In the workspace run it cannot fail. Besides bson, the engine's dev-dependency on serde_json turns the feature on there too. I left CI as it is. CI's Python job tests a SQLite server built with -p extenddb --no-default-features --features sqlite, which has neither. Without the feature, that server parses in name order. A name sort after the parse gives that order, and it fails 11 tests there (the first mutant in the description). They are 10 rows of tests/test_request_member_order.py and the map order test of tests/test_partiql_numbers.py. A step with -p extenddb-server would compile the server crate's tree a second time in each test run, for a second check of the same feature. The test's comment and the description now say what it checks in each build. I can add the step if you want it.

compute_fingerprint hashed the TransactItems JSON in the order the
parsed request held it. A build with serde_json's preserve_order
feature, such as the MongoDB build, holds the client's order. There, a
retry that wrote the same members in another order got
IdempotentParameterMismatchException.

The service replays such a retry. Measured in us-east-1: on 2026-11-10
for an item's attributes, and on 2026-11-16 for a Put's members. A
different item under the same token is still a mismatch.

The hash now covers a copy with the members of every object sorted by
name. A build without preserve_order hashed those bytes before, so its
stored tokens still match. A token that a preserve_order build stored
for members out of name order answers a mismatch to a retry after the
upgrade.

compute_fingerprint sorts the copy with Value::sort_all_objects.
serde_json added it in 1.0.129, so the workspace now requires that
version. The engine's tests turn on preserve_order. Their rows can then
hold members out of name order, and the fingerprint test fails without
the sort.
The server crate now turns on serde_json's preserve_order feature, so a
parsed request keeps the order the client wrote its members in. Before,
only a build that compiled the MongoDB backend did, through bson. Other
builds read every object in name order. The typed input deserializers
stop at the first member that fails, so the builds answered a body with
two type faults differently.

The service answers such a body with the fault of the member written
first. Measured in us-east-1 in both member orders: Query and
TransactWriteItems on 2026-11-12, GetItem, PutItem and UpdateItem on
2026-11-16. A sort in every build would make the builds agree, but it
cannot match the service in both orders of one body. A unit test sends
two type faults in both orders through dispatch.

The comments about member order now say that every build with the
server keeps the request's order. Inside one map the service walks Java
HashMap order (#1013), so for two faults in different buckets ExtendDB
can still answer the other member. The PartiQL parameter map test no
longer needs its build-dependent xfail.

Every build now writes /health with "status" first. The admin guide and
the backup manual showed its keys in name order, or said that the order
depends on the build. Their examples now show "status" first.

Fixes #723
The service checks the members of one ExpressionAttributeValues map in
the order that a Java HashMap of the map yields them. It checks one
PartiQL parameter map the same way. Two members in one bucket come in
the order written. The previous commit made every build walk these maps
in the order written. Main walks them in name order on the builds
without the MongoDB backend. Neither order is the service's, so the
previous commit changed answers that main gave correctly. For :c and :b
both {}, the service and main name :b, and the order written names :c.

The bucket model of the PartiQL echo moves from the engine to
extenddb_core::map_order. The echo, the PartiQL parameter checks and the
checks of ExpressionAttributeValues and ExpressionAttributeNames use it.
For two empty names, the service named either member in each order, so
any fixed order gives one of its answers.

The two placeholder maps also take the service's steps in its order.
The service refuses a value of the wrong JSON type first, the first one
written. It finds such a value while it reads the request. A JSON null
is not such a value. Then ExpressionAttributeValues checks its keys, and
then its values. ExpressionAttributeNames checks its empty names ahead
of its keys. The refusal of each fault keeps its text.

ExpressionAttributeValues uses check_types, the check that
check_parameter_types runs on each PartiQL parameter. A build without the
partiql feature has no PartiQL module, so both functions move from that
module to serde_helpers. PR #1103 makes the same move.

Measured in us-east-1 on 2026-11-12 and 2026-11-19, in both member
orders, on maps of two, three and four members (#1013).
…ders

Each row of test_request_member_order.py sends one body with its members
in the order written. It pins the status, error type and message the
service gave in us-east-1. Two type faults in a Query, a
TransactWriteItems Put, GetItem, PutItem or UpdateItem answer the member
written first. A type fault beside a validation fault answers the type
fault in both orders. A Limit of 0.0 beside an empty value answers the
Limit fault in both orders.

Other rows hold two faults in one ExpressionAttributeValues,
ExpressionAttributeNames or PartiQL parameter map. The service answers a
value of the wrong JSON type first, and of two such values the one
written first. A malformed key of ExpressionAttributeValues comes ahead
of an empty value. Among the other faults, the service names the member
that a Java HashMap of the map yields first. The order written decides
only between two members in one bucket, such as :a and :e. A server that
walks such a map in name order or in the order written fails a row. The
service named either member from one send to the next for two malformed
keys in ExpressionAttributeValues, and for two empty names. No row pins
those.

ExtendDB words a type fault with serde_json's text or with its own
(#1012), and on ExtendDB a type-fault row checks that text. For two type
faults it names the member written first, so a server that reads the
members in another order fails the row. A row that ExtendDB answers
otherwise is a strict xfail:

- a fractional Limit (#720)
- a Limit fault after a value fault (#778)

The rows post through signed_post, and a new helper beside it in
raw_signed_request.py, answer, reads the status, error type and message
of a response. An answer that is not JSON keeps its status.
demohan
demohan previously approved these changes Nov 24, 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.

The items from the earlier reviews are resolved at 4774b89. Each body was sent twice to the service and to this head on SQLite, PostgreSQL, MongoDB and Cassandra.

  • UpdateItem with {":c": {}, ":b": {}} answers the empty value error for key :b in both written orders, as the service does. Scan, Query, DeleteItem and TransactWriteItems answer the same.
  • ExecuteStatement with a 40-level parameter e or n beside "bad": {"N": "abc"} answers The parameter cannot be converted to a numeric value: abc in both orders. PartiQL pairs m/r and k/u, and placeholder maps of 7 and 13 members, also match the service in both orders.
  • Of 104 bodies, 24 that answered differently at f685853 now match the service, and none that matched answers differently here. 200 placeholder pairs and a 100-member PartiQL map keep each value with its key.
  • With preserve_order removed, 2 core unit tests and 7 wire rows fail, and the SQLite pytest build CI uses fails 11 tests. CI is green on 64 of 64 checks.

crates/server/tests/handler_member_order_tests.rs

Optional. Under CI's cargo test --workspace, preserve_order is on, so this test cannot fail there. It fails under cargo test -p extenddb-server. A CI step running that crate alone would let it fail where it is meant to.

crates/core/src/params.rs:41 and serde_helpers.rs:458

Optional. These comments say the crate's own tests run in name order. Under cargo test --workspace they run in written order, because preserve_order is on.

@LeeroyHannigan
LeeroyHannigan added this pull request to the merge queue Nov 24, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 24, 2026
…mber order test

Main's #526 added two parameters to compute_fingerprint: the request's
ReturnConsumedCapacity and ReturnItemCollectionMetrics. The merge of main
into this branch (9dbeb7d) left this branch's test
fingerprint_hashes_the_members_sorted_by_name with a call of two
arguments. So the engine's lib tests did not compile. The test now calls
the module's fp helper, which passes NONE for both. With NONE, the hash
covers the same bytes as before #526, so each expected fingerprint is
unchanged.

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

The items from the earlier review are resolved at 4ef91ea. Each body was sent twice to the service in us-east-1 and to SQLite, PostgreSQL, MongoDB and Cassandra servers built from this head.

  • UpdateItem with {":b":{},":c":{}} answers ... for key :b in both written orders, and so do the Query, DeleteItem, TransactWriteItems and Scan forms. ExecuteStatement with a 40-level e or n beside "bad":{"N":"abc"} answers The parameter cannot be converted to a numeric value: abc in both orders, as do the m/r and k/u pairs and the 7- and 13-member maps.
  • The 104 bodies from the earlier round answer at this head as at 4774b89, the four backends answer alike on 113 of 113, and this head matches the service on 100 of 113 against 72 on main, with none regressed; the other 13 differ on main and at 4774b89 too (#1160, #1104, #778, #720). 200 placeholder pairs and a 100-member PartiQL map store every value under its own key.
  • 4ef91ea makes the engine tests compile after the merge of main without changing the four expected fingerprints, and removing the sort in compute_fingerprint fails transact_write_helpers.rs:407. With main's #526, a reordered retry with the same token replays with 200 on the service and on all four backends, and adding ReturnConsumedCapacity or ReturnItemCollectionMetrics, or changing the item, answers IdempotentParameterMismatchException.
  • With preserve_order removed, the Rust test fails under -p extenddb-server and 11 SQLite wire tests fail; with both map walks in parsed order, 2 core tests and 7 wire rows fail. fmt, both clippy commands, the 1.91.1 check and core with and without the feature are clean, and CI is green on 64 of 64 checks.

crates/core/src/params.rs:41

Optional. Under cargo test --workspace this crate's tests do not run in name order, so this comment and serde_helpers.rs:458 describe the -p extenddb-server run only.

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.

MongoDB build: bson turns on serde_json preserve_order, so a request body with two faults reports a different first error than on the other backends

2 participants