Repository navigation
fix: delivery webhook respects order status transitions - #83
Merged
lordlabakdas merged 1 commit intoOct 4, 2026
Merged
Conversation
apply_webhook_update() wrote order.status = "delivered" directly, bypassing update_order_status()'s ORDER_STATUS_TRANSITIONS check added in #82. A late/stale webhook arriving after a store already cancelled the order (which restocks inventory and reverses loyalty points) could silently flip it back to "delivered" with none of that reversed — leaving stock and loyalty balances desynced from the order's real state. Webhook-driven delivery confirmation now only advances the order when that transition is legal (normally ready -> delivered); otherwise it logs a warning and leaves the order's status alone. The Delivery row itself still records the vendor's "delivered" status either way — only the Order's status write is guarded. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014t1eBFvEm5tiPyqQiQ3DNM
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.
Summary
Follow-up to #82.
DeliveryService.apply_webhook_update()wroteorder.status = "delivered"directly, bypassingupdate_order_status()'sORDER_STATUS_TRANSITIONScheck entirely — it's a different code path (webhook ingestion, not the store-authenticatedPUT /{order_id}/statusendpoint).That meant a late/stale webhook arriving after a store already cancelled the order (which now restocks inventory and reverses loyalty points, per #82) could silently flip the order back to
"delivered"— with none of that cancellation's side effects undone. Stock and loyalty balances would desync from the order's real state.Webhook-driven delivery confirmation now only advances
Order.statuswhen"delivered"is a legal next state perORDER_STATUS_TRANSITIONS(normallyready → delivered); otherwise it logs a warning and leaves the order alone. TheDeliveryrow itself still records the vendor's"delivered"status regardless — only theOrder.statuswrite is guarded.Test plan
deliveredfor acancelledorder does not resurrect it (tests/unit/test_delivery_service.py)test_apply_webhook_update_marks_order_deliveredupdated to start from a legal"ready"statuspytest tests/ -v— 611/611 pass🤖 Generated with Claude Code
https://claude.ai/code/session_014t1eBFvEm5tiPyqQiQ3DNM