Enforce stock, totals, status-transition and audit invariants purely with SQLite triggers
Exact prompt
# Task: enforce shop invariants with SQLite triggers `schema.sql` defines products, orders, order_items and audit_log. Write **only** `triggers.sql` (it is executed right after `schema.sql` on an empty database with SQLite 3.46 via Python's `sqlite3`; do not change `schema.sql`). Application code will do plain INSERT/UPDATE/DELETE statements; the database itself must keep these rules: 1. Inserting an order item: if `unit_price_cents` is NULL it is set to the product's current `price_cents`; the product's `stock` decreases by `qty`. If stock is insufficient the statement fails with an error whose message contains `insufficient stock` and nothing changes. 2. Updating an item's `qty` adjusts stock by the difference (same insufficient-stock error). Changing an item's `product_id` is forbidden (error containing `immutable`). 3. Deleting an order item restores its stock. 4. `orders.total_cents` always equals the sum of `qty * unit_price_cents` over its items (0 when none). An item keeps the `unit_price_cents` it got at insert time; later product price changes do not affect existing items or totals. 5. Items can only be inserted, updated or deleted while their order's status is `pending`; otherwise error containing `order locked`. 6. Order status may only change pending->paid, pending->cancelled, paid->shipped, paid->cancelled (same status = no-op allowed). Any other change fails with error containing `bad transition`. Cancelling an order returns the stock of all its items (items stay, total stays). 7. Every change of a product's `price_cents` (old != new) writes one audit_log row: entity 'product', entity_id, field 'price_cents', old and new values as text. Every order status change writes a row with entity 'order', field 'status', old and new status. Updates that leave the value unchanged write no audit row; changes to other columns (e.g. `stock`) are not audited. 8. A product that appears in any order item cannot be deleted (error containing `in use`). Use `RAISE(ABORT, '...')` for errors. No network.
Needs BEFORE vs AFTER trigger choice, RAISE(ABORT) atomicity, NULL-safe comparisons (IS NOT), recomputing totals on insert/update/delete, transition tables and cancel-time stock restoration across duplicate lines. Original benchmark task written for usecaserank.com (not based on a specific public post). Headless, offline run on a reproducible fixture. Each run's notes say how its cost was measured (estimates are marked).
Success criteria: 1. All 13 hidden unittest cases pass (schema.sql + agent triggers.sql in an in-memory SQLite 3.46 DB): price defaulting, stock decrement/insufficient-stock abort, qty delta updates, immutable product_id, delete restores stock, per-order totals, locked non-pending orders, allowed/forbidden status transitions, cancel restores stock, audit rows only on real changes, item price unaffected by later product price change, in-use product delete blocked, schema.sql unchanged.
Best model for this task so far: Claude Haiku 5.5 (effort default (no --effort flag) · thinking on) (success, $0.02, 1m).
All runs (4)
100% pass rate across 4 eligible runs: 4 pass, 0 partial, 0 fail. Partial and failed runs are listed below with everything else.ⓘ
| Model | Cost | Time | Step-insⓘ | Autonomy | Outcome | Trustⓘ | Date | Compare |
|---|---|---|---|---|---|---|---|---|
| OGPT-6.1 Soldefault · thinking on | $0.06 | 1m | 0 | Fully autonomous | pass | Trust 80% | 2026-10-22 | |
| AClaude Haiku 5.5default · thinking on | $0.02 | 1m | 0 | Fully autonomous | pass | Trust 80% | 2026-10-17 | |
| AClaude Opus 5.5default · thinking on | $0.27 | 1m | 0 | Fully autonomous | pass | Trust 80% | 2026-10-17 | |
| AClaude Sonnet 5.5default · thinking on | $0.11 | 39s | 0 | Fully autonomous | pass | Trust 80% | 2026-10-17 |
Embed this result
A live badge for this use case. It links back here and updates as new runs are published.
Get new runs and ranking changes weekly
Which models got better or cheaper on real tasks like this one.