Repository navigation
fix(server): write __type first in an error body - #1249
LeeroyHannigan wants to merge 12 commits into
Conversation
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
left a comment
There was a problem hiding this comment.
-
I think the order of the members is not pinned next to the code that writes it. The three
error_documenttests incrates/core/src/error/mod.rsparse the bytes back into aserde_json::Valuethrough the new document helper, so they pass in any order. I moved the__typeentry to the end oferror_bodyandcargo test -p extenddb-core --lib error_documentstill passed (3 passed). The server rowthe_members_follow_the_service_per_errorand the wasm test did fail. Could you add one core test that compares the bytes of aTransactionCanceledExceptionwhose reason carries Item and Message, and of aConditionalCheckFailedExceptionwith an Item, so a change in core alone is caught there? -
an_error_answer_writes_type_firstincrates/wasm-adapter/src/runtime.rschecks one answer, aSerializationException. With the reason fields put back toCode, 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 aTransactionCanceledExceptionwould cover it. -
tests/test_error_message_key.pyhas no case where the body carries Item, or where a cancellation reason carries Item. On SQLite I sentPutItem,UpdateItem,DeleteItem,ExecuteStatement, a four itemTransactWriteItemsand anExecuteTransactionwithALL_OLDagainst a build of this branch merged with main. Each body started with__type, then Item orCancellationReasons, then the message, and each reason wroteCode, Item, Message. Could you add aPutItemwith a failing condition andALL_OLD, and aTransactWriteItemswith a failingConditionCheckandALL_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.
|
|
All three items are done at 77cb9b6.
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. |
|
@navareamol The split is right. At 77cb9b6 the test module of
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.
Changes since the last review
docs/manuals/07-upgrade-manual.mdwith no conflict. The v1.2.0 entries of main come first, fix(storage-sqlite): keep each partition key in one parallel Scan segment #1087's among them, then the entry of fix(server): send Message on a SerializationException #1220, then the entry of this PR. The diff of this PR against fix(server): send Message on a SerializationException #1220's branch does not change.What
In a build without the MongoDB backend, ExtendDB wrote the members of an error body in name order, so
CancellationReasons,ItemandMessagecame before__type. A build with the MongoDB backend wrote__type, then the message, thenCancellationReasonsorItem, because bson enables serde_json'spreserve_orderthere.error_documentincrates/core/src/error/mod.rsnow writes__typefirst, thenCancellationReasonsorItem, then the message, in every build, as DynamoDB does. It writes the members one at a time through aserde_json::Serializermap and returns the bytes.The server's
error_responsesends these bytes.Engine::submitandEngine::non_string_argumentof 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 exampleMessagebefore__typeon aSerializationException.error_documentdoes not depend on serde_json'spreserve_order, which open #781 enables for every server build.Each cancellation reason writes
Code,Item,Messagein every build, as DynamoDB does.CancellationReasondeclares its fields in that order, anderror_documentwrites the reasons directly. Before this change, the reasons went through aserde_json::Value, which kept the field orderCode,Message,Itemin 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.mdlists the change in a v1.2.0 entry.The base of this PR is #1220, whose
SerializationExceptionarm ofmessage_keythese tests expect. Once #1220 merges, this PR is retargeted to main, so thatFixes #1222closes 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.
__type,message__type,messageReturnValuesOnConditionCheckFailureALL_OLD__type,Item,messageItem,__type,messageALL_OLD__type,Item,messageItem,__type,message__type,MessageMessage,__type__type,CancellationReasons,MessageCancellationReasons,Message,__typeALL_OLD__type,CancellationReasons,MessageCancellationReasons,Message,__typeSET k[5].x = :v__type,CancellationReasons,MessageCancellationReasons,Message,__typeALL_OLD__type,CancellationReasons,MessageCancellationReasons,Message,__typeLimit"0"__type,MessageMessage,__type__type__typeIn the two transaction rows with
ALL_OLD, DynamoDB wrote the members of the cancellation reason asCode,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 5backup_store::testsfailed. 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.-D warningsonextenddb-core,extenddb-serverandextenddb-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-targetson the three crates, andcargo +1.97.0 fmt --all -- --check.cargo test -p extenddb-storage-postgres --test doc_version_literalspasses with the new entry.error_document_writes_the_members_in_the_service_ordercompares the bytes of 4 bodies.the_members_follow_the_service_per_errorholds 8 rows over 5 error types and compares the whole body fromerror_responsewith the body DynamoDB sent. In both, anItemholds one attribute, because DynamoDB changed the order of the attributes inside anItembetween two sends of one request.cargo test -p extenddb-wasm-adapterpasses: 4 unit tests and the parity corpus.an_error_answer_writes_type_firstcompares the whole answer to a body that is not JSON, to thePutItemwithALL_OLDand to theTransactWriteItemswithALL_OLD.__typewritten last inerror_bodyCancellationReasonin the ordercode,message,itemItemwritten before__typetests/test_error_message_key.pypassed 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 whoseCancellationReasonfields are in the ordercode,message,item, theALL_OLDrow of theTransactWriteItemstest fails.the_members_follow_the_service_per_errorfailed. EachDynamoDbErrorvariant went througherror_responseat 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.tests/test_error_message_key.pyhad another result on the two servers. On both servers, 9 tests oftests/test_streams_at_timestamp.pyfailed in the client, which sent no request. This host's botocore 1.43.81 has noTimestampmember in its model of GetShardIterator.python3 -m pytest --collect-only -qcollectstests/andtests/pythonwith 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:
message; DynamoDB sendsMessage, and the token mismatch text differs #760).ALL_OLD: DynamoDB writesMessage, and ExtendDB writesmessage(TransactionCanceledException and IdempotentParameterMismatchException carrymessage; DynamoDB sendsMessage, and the token mismatch text differs #760).SET k[5].x = :v(A SET path that goes through a list index past the end answers the absent attribute text, where DynamoDB answers the document path text #1216).ExtendDB writes the attributes inside
Itemin 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:
crates/server/src/response.rs. fix(server): answer by media type, method and path as DynamoDB does #1079 sends the body throughwire_response, which writes the CRC header, and this PR changes the line that gets the bytes. On a rebase, keeplet body_bytes = error_document(error);and fix(server): answer by media type, method and path as DynamoDB does #1079's call ofwire_response.crates/server/src/response.rs. fix(dev-mode): refuse browser and admin requests for a foreign host #635 moves the body oferror_responseintoerror_response_with_status, and this PR changes the lines that build the bytes there. On a rebase, keep fix(dev-mode): refuse browser and admin requests for a foreign host #635's function andlet body_bytes = error_document(error);in it.crates/server/src/response.rs. Each conflicts with main in other files already. feat(core): throttle errors carry the service's ThrottlingReasons #532 adds aThrottlingReasonsmember to the error body. On a rebase, that member goes intoerror_bodyincrates/core/src/error/mod.rs. Its position is not measured.#853 conflicts with #1220 in
crates/core/src/error/mod.rsandcrates/server/src/response_tests.rs. With this PR, itsTransactionInProgressExceptionassert becomes a row ofthe_members_follow_the_service_per_error. The entry indocs/manuals/07-upgrade-manual.mdadds no conflict beyond the ones #1220's entry adds.Checklist
cargo test --workspace)cargo fmt --check)cargo clippy -- -W clippy::pedantic)Storagetrait, auth model, on-diskformat, 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:
__typefirst, thenCancellationReasonsorItem, then the message. A cancellation reason writesCode,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_documentreturns the bytes in place of aserde_json::Value.extenddb-coreis 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.