Store: 04Decision auditedEvery call recorded, dry run or not
Output: 05Tag appliedThe tag is the processed marker
The same rules judge an order whether it arrives live or on the sweep.
The problem
Orders got tagged by hand for priority, promotions and local delivery, and whoever opened an order picked the shipping service. The rules lived in people's heads, which meant they were applied unevenly and nobody could reconstruct why a given order shipped the way it did.
What I built
Each rule is its own file with its own test. Changing what gets tagged means editing one file and one test, which matters because the rules are the part non-engineers ask about.
Order webhooks drive the live path and a queued cron scan sweeps up whatever the webhook missed. Both run the same pipeline, so the two cannot drift apart.
Every evaluation writes an audit row to Postgres whether or not it acted, dry runs included. Dry run is the default, so you watch a new rule before you trust it.
The local-delivery rule switches qualifying orders to ground, since we ship from in-state and ground arrives next day anyway, then applies its tag as the permanent already-processed marker. It leaves PO Box and military addresses alone, and it will not downgrade an order already on a paid expedited service to something slower than the customer bought.
It resolves the carrier account from the API and caches it, preferring the directly connected account over the reseller one so labels bill to the right place. A missing carrier, service or tag suppresses the switch and fails closed while the other rules carry on.
One-time eligibility gets claimed atomically before the external call, then finalised or released after, which stops a retry applying the same promotion twice.