Inventory truth drifts. Cycle counts catch the drift before it bleeds into pick errors and quote inaccuracies. This pipeline schedules a weekly count per zone, captures physical numbers, computes variance vs inventory_balance, auto-adjusts small deltas, stages larger deltas behind HITL, pushes the approved adjustment to NS, updates the D1 mirror, logs the reason, fires an events.inventory.adjusted signal, and surfaces a variance report on the admin dashboard.
0 6 * * MONlocations · cycle_count_schedulecycle_count_variancesinventory_balance · items.avg_costguardrails.inventory_auto_pctproposed_action with action_type='inventory_adjustment'./proposed-actions.htmlproposed_actionsX-Edit-Tokenapproved_by · approved_at · reason_notens_pending_pushes; PushMutexDO drains it to a NetSuite inventoryadjustment record.PushMutexDOinventoryadjustmentsrc/lib/ns.ts · src/durable_objects.tsinventory_balance.quantityonhand reflects the approved value; quantityavailable recomputed.reflexion_log. events.inventory.adjusted fires on the event ledger.reflexion_log · eventscustomer_health_predictor · v_customer_ar_agingadmin-dashboard.html · /inventory/variances| kind | name | purpose |
|---|---|---|
| D1 table | inventory_balance | quantityonhand, quantityavailable, reserved per item × location |
| D1 table | cycle_count_schedule | zone rotation calendar |
| D1 table | cycle_count_variances | per-count variance row (pct, abs, value) |
| D1 table | proposed_actions | inventory_adjustment rows above threshold |
| D1 table | ns_pending_pushes | approved → NS write queue |
| D1 table | reflexion_log | audit row with tag, reason, approved_by |
| D1 table | events | inventory.adjusted event ledger row |
| NS record | inventoryadjustment | NS system-of-record adjustment entry |
| Endpoint | POST /api/inventory/count | ingest physical count rows |
| Endpoint | POST /api/inventory/adjust | confirm an approved adjustment |
| Code path | src/lib/workflow_runner.ts | variance workflow staging |
| Code path | src/durable_objects.ts | PushMutexDO drainer |
| Cron | 0 6 * * MON | weekly zone schedule trigger |