USDA commodity lot exhausted. Recompute weighted-average cost from next lot. Affected open quotes flagged. Engage USDA reconciliation. Update PUB6000 + other commodity items.
event["inventory_threshold_cron","manual_lot_close"]| name | required | type / hint |
|---|---|---|
commodity_sku | required | — |
exhausted_lot_id | required | — |
next_lot_unit_cost | required | — |
effective_from | required | — |
current_lotsusda_commodity_lotsSELECT lot_id, remaining_qty, unit_cost FROM usda_commodity_lots WHERE commodity_sku=? AND status='active'
affected_quotesquotes · quote_linesSELECT
id
FROM quotes q
JOIN quote_lines ql ON ql.quote_id=q.id
WHERE ql.item_code=?
AND q.lifecycle_status IN ('draft','proposed','sent')| check | rule | severity |
|---|---|---|
next_lot_exists | current_lots.length > 0 | block |
cost_diff_reasonable | abs(next_lot_unit_cost - exhausted_lot.unit_cost) / exhausted_lot.unit_cost < 0.3 | warn |
Risk level 4 ≥ 3 — runner stages a proposed_actions row before fan-out runs. Mike must approve in proposed-actions.html before any side-effect step executes (real or stub).
workflow_usda_drawdown_commit (proposal envelope)workflow:usda_drawdown_commit:run_<run_id>update_vendor_costs d1_write STUB["INSERT vendor_costs row with new weighted avg"]src/lib/workflow_runner.ts (kind d1_write hits the placeholder branch at line ~340 and emits step status 'stub'). Documented intent only.recompute_assemblies chat_tool STUBrecompute_assembly_cost_rollupsrc/lib/workflow_runner.ts (kind chat_tool hits the placeholder branch at line ~340 and emits step status 'stub'). Documented intent only.flag_affected_quotes stage_proposed_action REALflag_stale_quoteusda_reconcile d1_write STUB["UPDATE usda_commodity_programs SET reconciliation_status='pending' WHERE program_id IN (?)"]src/lib/workflow_runner.ts (kind d1_write hits the placeholder branch at line ~340 and emits step status 'stub'). Documented intent only.| id | action | source |
|---|---|---|
runner_log_run | INSERT into workflow_run_log (run_id, workflow_type, status, started_at, completed_at, summary_json) | runner automatic |
runner_reflexion | INSERT into reflexion_log (tags=usda_drawdown_commit, run_id, narrative) | runner automatic (reflexion_enabled=1) |
log_run | INSERT workflow_runs | declared in contract |
reflexion | INSERT reflexion_log with tags=usda_drawdown,sku:? | declared in contract |
workflow_verify_results (pending — verify cron not yet wired)new_cost_appliedSELECT unit_cost FROM vendor_costs WHERE effective_from=? ORDER BY id DESC LIMIT 1
2linear2000true| system | table / resource | action | status | source |
|---|---|---|---|---|
| D1 | proposed_actions | INSERT (action_type=flag_stale_quote, entity_type=workflow_run) | REAL | fan-out #3 (flag_affected_quotes) |
| D1 | workflow_run_log | INSERT (run summary) | REAL | runner automatic |
| D1 | reflexion_log | INSERT (tags=usda_drawdown_commit) | REAL | runner automatic |
| Event | workflow.completed (or workflow.failed) | fire | REAL | runner automatic |
| D1 | workflow_verify_results | INSERT pending × 1 | REAL | runner verify staging |
| D1 | proposed_actions | INSERT (HITL gate envelope) | REAL | runner HITL gate |
| D1 | unknown | write | STUB | fan-out #1 (update_vendor_costs) |
| Chat tool | recompute_assembly_cost_rollup | invoke (side_effects=unknown) | STUB | fan-out #2 (recompute_assemblies) |
| D1 | unknown | write | STUB | fan-out #4 (usda_reconcile) |