First of every month: margin analysis per customer/brand/category. Flag compression vs trailing 3-month avg. Stage propose_price_change for outliers; deliver exec summary.
cron0 7 1 * *| name | required | type / hint |
|---|---|---|
compression_threshold_pp | optional | — |
exclude_customers[] | optional | — |
last_month_marginsv_pricing_with_brandSELECT
customer_id, brand, category, AVG(margin_pct) AS avg_margin
FROM v_pricing_with_brand
WHERE last_invoice_month = strftime('%Y-%m', date('now','-1 month'))
GROUP BY customer_id, brand, categorytrailing_3mov_pricing_with_brandSELECT
customer_id, brand, category, AVG(margin_pct) AS avg_margin
FROM v_pricing_with_brand
WHERE last_invoice_month >= strftime('%Y-%m', date('now','-4 months'))
AND last_invoice_month < strftime('%Y-%m', date('now','-1 month'))
GROUP BY customer_id, brand, category| check | rule | severity |
|---|---|---|
pricing_data_fresh | MAX(pricing_master.updated_at) > now - 7 days | warn |
Risk level 3 ≥ 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_monthly_margin_review (proposal envelope)workflow:monthly_margin_review:run_<run_id>draft_price_proposals stage_proposed_action REALpropose_margin_target_pricingrender_exec_summary http_call STUB/api/digest/email-nowmonthly_margin_summarysrc/lib/workflow_runner.ts (kind http_call hits the placeholder branch at line ~340 and emits step status 'stub'). Documented intent only.deliver hitl_email_draft STUBpropose_email_to_customermikesrc/lib/workflow_runner.ts (kind hitl_email_draft 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=monthly_margin_review, run_id, narrative) | runner automatic (reflexion_enabled=1) |
log_run | INSERT workflow_runs | declared in contract |
reflexion | INSERT reflexion_log with tags=monthly_margin_review | declared in contract |
workflow_verify_results (pending — verify cron not yet wired)proposals_stagedSELECT COUNT(*) FROM proposed_actions WHERE action_type='propose_margin_target_pricing' AND proposed_at > ?
2linear5000true| system | table / resource | action | status | source |
|---|---|---|---|---|
| D1 | proposed_actions | INSERT (action_type=propose_margin_target_pricing, entity_type=workflow_run) | REAL | fan-out #1 (draft_price_proposals) |
| D1 | workflow_run_log | INSERT (run summary) | REAL | runner automatic |
| D1 | reflexion_log | INSERT (tags=monthly_margin_review) | 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 |
| Worker HTTP | POST /api/digest/email-now | invoke | STUB | fan-out #2 (render_exec_summary) |
| D1 | proposed_actions | INSERT (email draft via propose_email_to_customer) | STUB | fan-out #3 (deliver) |