Skip to content

fix(server): write __type first in an error body - #1249

Open
LeeroyHannigan wants to merge 12 commits into
fix/1143-serialization-message-keyfrom
fix/1222-error-member-order
Open

LeeroyHannigan wants to merge 12 commits into
fix/1143-serialization-message-keyfrom
fix/1222-error-member-order

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Changes since the last review

What

In a build without the MongoDB backend, ExtendDB wrote the members of an error body in name order, so CancellationReasons, Item and Message came before __type. A build with the MongoDB backend wrote __type, then the message, then CancellationReasons or Item, because bson enables serde_json's preserve_order there. error_document in crates/core/src/error/mod.rs now writes __type first, then CancellationReasons or Item, then the message, in every build, as DynamoDB does. It writes the members one at a time through a serde_json::Serializer map and returns the bytes.

The server's error_response sends these bytes. Engine::submit and Engine::non_string_argument of the WebAssembly build return them as a string, so the answers of the WebAssembly build change order too. That build has no MongoDB backend, so before this change it wrote the members in name order, for example Message before __type on a SerializationException. error_document does not depend on serde_json's preserve_order, which open #781 enables for every server build.

Each cancellation reason writes Code, Item, Message in every build, as DynamoDB does. CancellationReason declares its fields in that order, and error_document writes the reasons directly. Before this change, the reasons went through a serde_json::Value, which kept the field order Code, Message, Item in a build with the MongoDB backend. SERIALIZATION_FAILURE_BODY, the CRC header and the omission of an empty message do not change. docs/manuals/07-upgrade-manual.md lists the change in a v1.2.0 entry.

The base of this PR is #1220, whose SerializationException arm of message_key these tests expect. Once #1220 merges, this PR is retargeted to main, so that Fixes #1222 closes the issue. When this PR merges, use the What section as the squash message. The message of 36345c8 describes only the order of a build without the MongoDB backend.

Why

DynamoDB's order, measured in us-east-1 on 20 November 2026 from the raw response bytes. Each request was sent twice and got the same order both times.

Request DynamoDB ExtendDB on #1220, SQLite
PutItem with a failing condition __type, message __type, message
PutItem with a failing condition and ReturnValuesOnConditionCheckFailure ALL_OLD __type, Item, message Item, __type, message
UpdateItem with a failing condition and ALL_OLD __type, Item, message Item, __type, message
TransactWriteItems with a client token used again for another Put __type, Message Message, __type
ExecuteTransaction, an UPDATE with a failing condition __type, CancellationReasons, Message CancellationReasons, Message, __type
The same with ALL_OLD __type, CancellationReasons, Message CancellationReasons, Message, __type
TransactWriteItems, an Update of SET k[5].x = :v __type, CancellationReasons, Message CancellationReasons, Message, __type
TransactWriteItems, a failing ConditionCheck with ALL_OLD __type, CancellationReasons, Message CancellationReasons, Message, __type
Query with Limit "0" __type, Message Message, __type
An unknown operation __type __type

In the two transaction rows with ALL_OLD, DynamoDB wrote the members of the cancellation reason as Code, Item, Message. With this change, ExtendDB writes the members of each row in DynamoDB's order, in every build.

Fixes #1222

Testing done

At 2d74400:

  • cargo +1.97.0 test -p extenddb-core --lib: 1258 passed, 1 ignored. cargo +1.97.0 test -p extenddb-server --lib: 521 passed, and 5 backup_store::tests failed. They fail on this host on every branch, because uid 65534 owns /local/home, an ancestor of the directories the tests make.
  • cargo +1.97.0 test -p extenddb-server --features serde_json/preserve_order --lib response: 4 passed. A build with the MongoDB backend has that feature.
  • Clippy with -D warnings on extenddb-core, extenddb-server and extenddb-wasm-adapter, with the test hooks of .github/workflows/clippy.yml, is clean. So are the clippy step of .github/workflows/wasm.yml, cargo +1.94.0 check --all-targets on the three crates, and cargo +1.97.0 fmt --all -- --check.
  • cargo test -p extenddb-storage-postgres --test doc_version_literals passes with the new entry.
  • error_document_writes_the_members_in_the_service_order compares the bytes of 4 bodies. the_members_follow_the_service_per_error holds 8 rows over 5 error types and compares the whole body from error_response with the body DynamoDB sent. In both, an Item holds one attribute, because DynamoDB changed the order of the attributes inside an Item between two sends of one request.
  • cargo test -p extenddb-wasm-adapter passes: 4 unit tests and the parity corpus. an_error_answer_writes_type_first compares the whole answer to a body that is not JSON, to the PutItem with ALL_OLD and to the TransactWriteItems with ALL_OLD.
  • Three controls changed core alone, one at a time, and each made the core test, the server test and the WebAssembly test fail:
    • __type written last in error_body
    • the fields of CancellationReason in the order code, message, item
    • Item written before __type
  • tests/test_error_message_key.py passed 10 tests against ExtendDB on SQLite, in a build with the SQLite backend alone, and 10 on PostgreSQL, in the default build. It reads the members in the order of the bytes. 8 of its tests fail against a server built from fix(server): send Message on a SerializationException #1220's head. Against a server whose CancellationReason fields are in the order code, message, item, the ALL_OLD row of the TransactWriteItems test fails.
  • At 9bfa823, with the production files of fix(server): send Message on a SerializationException #1220's head, 5 of the 8 rows of the_members_follow_the_service_per_error failed. Each DynamoDbError variant went through error_response at 9bfa823 and at fix(server): send Message on a SerializationException #1220's head 5f4f03b, once with a text and once with an empty message: 74 bodies on each. 66 bodies were the same bytes on both. The other 8 differed in the member order alone, and the CRC header matched each body.
  • At 9bfa823, the 29 wire files that read error bodies ran against a server of this PR and a server of fix(server): send Message on a SerializationException #1220. Only 6 tests of tests/test_error_message_key.py had another result on the two servers. On both servers, 9 tests of tests/test_streams_at_timestamp.py failed in the client, which sent no request. This host's botocore 1.43.81 has no Timestamp member in its model of GetShardIterator.
  • python3 -m pytest --collect-only -q collects tests/ and tests/python with no error.

Line counts: production +56 -38, tests +212 -97, and 6 added lines of the upgrade manual.

Not in this PR, each in an open issue:

ExtendDB writes the attributes inside Item in name order. DynamoDB wrote them in an order that changed between two sends of one request, so there is no fixed order to match.

This PR adds a conflict with these open PRs, compared with #1220's head:

#853 conflicts with #1220 in crates/core/src/error/mod.rs and crates/server/src/response_tests.rs. With this PR, its TransactionInProgressException assert becomes a row of the_members_follow_the_service_per_error. The entry in docs/manuals/07-upgrade-manual.md adds no conflict beyond the ones #1220's entry adds.

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

An error body writes its members in a new order: __type first, then CancellationReasons or Item, then the message. A cancellation reason writes Code, Item, Message. Both orders apply in every build and in the answers of the WebAssembly build. A reader that looks up members by name sees no change. A client that compares the raw bytes, or reads the members in order, sees the new order. In the Rust API, extenddb_core::error::error_document returns the bytes in place of a serde_json::Value. extenddb-core is an internal crate of the binary, with no API stability promise.


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.

ExtendDB wrote the members of an error body in name order, so
CancellationReasons, Item and Message came before __type. Amazon
DynamoDB writes __type first, then CancellationReasons or Item, then
the message.

The order was measured in us-east-1 on 20 Nov 2026 from the raw
response bytes, and each request went out twice. A TransactWriteItems
and an ExecuteTransaction cancelled by a failed condition write
__type, CancellationReasons, Message. A PutItem whose condition fails
with ReturnValuesOnConditionCheckFailure ALL_OLD writes __type, Item,
message. An IdempotentParameterMismatchException and a
SerializationException write __type, Message.

error_response now writes the members in that order. Each cancellation
reason keeps its members in name order, which is the order DynamoDB
writes.

Fixes #1222.
…rder

#1009 moved message_key from crates/server/src/response.rs to
crates/core/src/error/mod.rs, where error_document builds the error
body. The merge moves error_body to that file too, beside the private
message_key, and removes this branch's copy of message_key.
error_response calls error_body.

In tests/test_error_message_key.py, _error_code_and_keys keeps the keys
in the order of the bytes and also returns the HTTP status.
error_document in crates/core/src/error/mod.rs now writes the error
body and returns its bytes. It writes the members in the order DynamoDB
writes them: __type, then CancellationReasons or Item, then the
message. It replaces the two writers of the body on this branch. The
server sent the bytes of error_body. The WebAssembly adapter sent the
serde_json::Value that error_document built.

error_response in the server sends the bytes. Engine::submit and
Engine::non_string_argument in the WebAssembly adapter return them as a
String. The WebAssembly answers change order too. That build has no
MongoDB backend, so serde_json wrote the members of the Value in name
order, for example Message before __type on a SerializationException.

The core tests of error_document parse the bytes.
the_members_follow_the_service_per_error now compares the whole body
that error_response sends with the body DynamoDB sent for each row
(us-east-1, 20 Nov 2026, each request twice). The comparison checks
the order of the members at every depth. This commit removes the serde
Visitor that read the top-level member names.

The ValidationException row carries the text DynamoDB sent for a
GetItem with no Key. The Item of the ConditionalCheckFailedException
row holds one attribute, because DynamoDB changed the attribute order
inside an Item between two sends of one request.
CancellationReason now declares its fields as code, item, message. A
reason serializes as Code, Item, Message, the order DynamoDB writes.
The measurements (us-east-1, 20 Nov 2026, each request sent twice) used
a TransactWriteItems ConditionCheck and an ExecuteTransaction UPDATE
whose conditions failed with ReturnValuesOnConditionCheckFailure
ALL_OLD. error_body writes the reasons directly, without the
serde_json::Value round trip.

Before this commit, the reasons went through a Value. A build without
the MongoDB backend wrote the members of the Value in name order, which
is Code, Item, Message. In a build that includes the MongoDB backend,
bson enables serde_json's preserve_order, and the Value kept the field
order Code, Message, Item.

the_members_follow_the_service_per_error gets a row whose reason
carries Item and Message. With the old field order, the row fails when
error_body writes the reasons directly. Through the Value, it fails in
a test build with serde_json's preserve_order enabled.
an_error_answer_writes_type_first sends a ListTables request with a
body that is not JSON through Engine::submit. It compares the answer
with the whole body the server sends for that error: __type, then
Message. When the adapter wrote the serde_json::Value of
error_document, the answer put Message before __type.

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

  1. I think the order of the members is not pinned next to the code that writes it. The three error_document tests in crates/core/src/error/mod.rs parse the bytes back into a serde_json::Value through the new document helper, so they pass in any order. I moved the __type entry to the end of error_body and cargo test -p extenddb-core --lib error_document still passed (3 passed). The server row the_members_follow_the_service_per_error and the wasm test did fail. Could you add one core test that compares the bytes of a TransactionCanceledException whose reason carries Item and Message, and of a ConditionalCheckFailedException with an Item, so a change in core alone is caught there?

  2. an_error_answer_writes_type_first in crates/wasm-adapter/src/runtime.rs checks one answer, a SerializationException. With the reason fields put back to Code, Message, Item, and with Item written before __type, it still passes. Only the server row catches those two. Is the server row meant to be the one place that checks them? If not, one more wasm case with a TransactionCanceledException would cover it.

  3. tests/test_error_message_key.py has no case where the body carries Item, or where a cancellation reason carries Item. On SQLite I sent PutItem, UpdateItem, DeleteItem, ExecuteStatement, a four item TransactWriteItems and an ExecuteTransaction with ALL_OLD against a build of this branch merged with main. Each body started with __type, then Item or CancellationReasons, then the message, and each reason wrote Code, Item, Message. Could you add a PutItem with a failing condition and ALL_OLD, and a TransactWriteItems with a failing ConditionCheck and ALL_OLD, to this file, so the wire run on every backend checks them?

I will approve once item 1 is done. Items 2 and 3 are optional.

error_document_writes_the_members_in_the_service_order compares the
bytes that error_document writes for four errors. Two of the four carry
an Item: a TransactionCanceledException in its cancellation reason,
beside Message, and a ConditionalCheckFailedException at the top of the
body. The order is DynamoDB's (us-east-1, 20 Nov 2026). A change of the
member order in core now fails a core test.

This test replaces the three tests that parsed the bytes back into a
serde_json::Value, and their document helper.
an_error_answer_writes_type_first gets two cases on a table: a PutItem
whose condition fails with ALL_OLD, and a TransactWriteItems whose
ConditionCheck fails with ALL_OLD. The test compares each answer in
full. The cases fail when Item or CancellationReasons come before
__type, and when a cancellation reason writes Message before Item.
tests/test_error_message_key.py gets an ALL_OLD row for a PutItem whose
condition fails and for a TransactWriteItems whose ConditionCheck fails.
The TransactWriteItems rows also check the members of the cancellation
reason. The helper returns the body, and each test reads the members in
the order of the bytes.

DynamoDB wrote these orders on 20 Nov 2026. The two requests need a
table, so they were not measured again for this change.
Behavior Changes by Release gets a v1.2.0 entry for this change, after
the entry for the SerializationException key. An error body writes
__type first, then CancellationReasons or Item, then the message, and a
cancellation reason writes Code, Item, Message, in every build. A client
that compares the raw bytes of an error body sees the new order.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

@navareamol

  1. 3c990b6 adds error_document_writes_the_members_in_the_service_order in crates/core/src/error/mod.rs. It compares the bytes of a TransactionCanceledException whose reason carries Item and Message, and of a ConditionalCheckFailedException with an Item. Two more rows hold the ValidationException and the empty UnknownOperationException of the three tests it replaces. The new test replaces those three tests and their document helper, which parsed the bytes back into a serde_json::Value. I made three changes in core alone, one at a time, and ran the new test after each. With __type moved to the end of error_body, the new test fails. It also fails with the fields of CancellationReason put back to code, message, item, and with the Item entry written before __type.
  2. ee5eecf adds two cases to an_error_answer_writes_type_first, on a table that the test creates: a PutItem whose condition fails with ALL_OLD, and a TransactWriteItems whose ConditionCheck fails with ALL_OLD. The test compares each answer in full. With the reason fields put back to Code, Message, Item, the TransactWriteItems case fails. With Item written before __type, the PutItem case fails.
  3. 2c9ac40 adds these two requests as ALL_OLD rows of test_conditional_check_failed_carries_message_under_lower_case and test_transaction_canceled_carries_message_under_capital_m. The TransactWriteItems rows also check the members of the reason, so the helper now returns the body. Both requests need a table, so I did not send them to DynamoDB again. The rows expect the order you read on SQLite. DynamoDB wrote the same order for both requests on 20 Nov 2026 (both sends), as the module docstring says. Against SQLite at 77cb9b6, the file passes 10 of 10. Against a server whose reason fields are in the order code, message, item, the TransactWriteItems ALL_OLD row fails, with [['Code', 'Message', 'Item']] == [['Code', 'Item', 'Message']].

@navareamol

Copy link
Copy Markdown
Collaborator

All three items are done at 77cb9b6.

  1. The core test now compares raw bytes. I read error_document_writes_the_members_in_the_service_order in crates/core/src/error/mod.rs. It covers a TransactionCanceledException whose reason carries Item and Message, and a ConditionalCheckFailedException with an Item. The three tests that parsed into a Value are gone. Core lib passes on SQLite builds at this head with 1258 passed. I have not rerun your three changes to core alone myself.

  2. The wasm test now covers the ALL_OLD PutItem and the ALL_OLD TransactWriteItems with full answers, on a table the test creates. I read the expected strings and they write __type first, then Item or CancellationReasons, then the message, and Code, Item, Message in the reason. I have not rerun the reason order and Item first changes against it.

  3. The wire file now has ALL_OLD rows. On SQLite, tests/test_error_message_key.py gives 10 passed on a server built from this head. Against a server built from the base branch it gives 8 failed and 2 passed, so the file detects the change. I also sent 58 requests to the head server, including PutItem, UpdateItem, DeleteItem, ExecuteStatement, a 100 member TransactWriteItems with ALL_OLD and an item with attributes named Message and __type. Every error body that has members starts with __type, each reason writes Code, Item, Message, and content-length and x-amz-crc32 match the body.

The DynamoDB orders in the new test and file docstrings are your measurements from 20 Nov 2026. I did not send these requests to DynamoDB, so I take them as stated.

One question on the description: it says production +56 -38 and tests +212 -97. The numstat against the base branch shows 81 added and 58 removed in crates/core/src/error/mod.rs, which holds both production code and its test module. Could you check that the split is right? This does not block.

CI shows 44 passed and 23 still pending, none failed. I will approve once the pending checks finish green.

@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

@navareamol The split is right. At 77cb9b6 the test module of crates/core/src/error/mod.rs starts at line 503 (line 485 on the base). Of the 81 added and 58 removed lines, 37 and 19 are production code above that line. The other 44 and 39 are in the test module.

crates/wasm-adapter/src/runtime.rs is the other file with both kinds: 8 added and 10 removed in production code, and 44 added in its test module. With the other files, that gives production +56 -38 and tests +212 -97, as the description says.

CI finished at 77cb9b6: 70 of 70 checks passed.

…rder

The branch of #1220 is at 57c4d7a, which merges main at 5826e1b.
This branch last had it at 4f3e0f2, with main at c8e66fb.

Git merged docs/manuals/07-upgrade-manual.md with no conflict. #1087
added its v1.2.0 entry after the other v1.2.0 entries of main. The entry
of #1220 and the entry of this branch follow it, in that order. No other
file that this branch changes moved.

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