fix(api): reject non-object HTTP payloads instead of erasing them - #8
Merged
Conversation
`#[serde(default)] payload: Value` makes an ABSENT field deserialise to
`Value::Null`, indistinguishable from an explicit one, so the new refusal
answered 422 to `{"op": "publish", "txn": "t1"}` — a push that answered 200
before this branch and queued `{"op": "publish", "_gate": {…}}` with nothing
lost. That case is outside the rationale: there is no caller data being
replaced with an empty object, because there is no caller data.
`Option<Value>` draws the distinction where serde can see it. Absent, and the
explicit `null` serde maps onto it, mean "this item carries only its envelope"
and produce `{}`. A scalar, an array or any other non-object is still refused,
which is the shape that loses something.
No push in the live suite omits `payload`, so nothing caught this.
Claude-Session: https://claude.ai/code/session_012K8u7BEJyd6nDNMCQAgH3z
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Both HTTP push and re-entry replaced any scalar, array, or null payload with
{}before adding_gate. The request still succeeded, so callers could lose their entire application value without an error.Fix
_gatemetadata;Review notes for Alice
Rejecting is intentional. Wrapping a scalar would change the payload shape consumed at egress, while forwarding it without metadata would break path ownership and bounded re-entry attempts. This PR makes the previously destructive case explicit without inventing a new wire envelope.
Direct application-owned queue ingress remains unchanged: the relay still preserves non-object messages exactly as documented.
Verification
cargo fmt --all -- --checkcargo test -p gate-server api::tests::an_http_payload_must_be_an_object_instead_of_being_discardedcargo clippy -p gate-server --all-targets -- -D warnings