Assembly build + BOM review
Assembly build review is the assembly-side counterpart to item_record_review. Where the item review keeps the items catalog clean, this one keeps assemblies — the BOM-bearing parents — honest. Mike (or the weekly cost-drift cron) opens an assembly, sees its full state, and proposes targeted BOM line changes or header field updates.
The cascade is deliberately wide: BOM changes ripple to assembly_cost_rollup, then to pricing_master for any active customer pricing, then to bid_lines for any open bid, then to the spec sheet PDF, then to KV caches that key off the assembly_id.
Risk level 3 (medium). Contract stored as workflow_definitions WHERE workflow_type='assembly_build_review'.
Trigger conditions
- Cost drift cron fires when an assembly's
drift_pct_vs_priorexceeds the R533 threshold. - Mike opens
/assembly/<code>and notices a BOM line that doesn't match reality. - Vendor failover means a BOM line's sourcing changed and rates need to follow.
- USDA substitution swaps a commodity component — triggers a follow-on drawdown check.
- Spec audit flags a yield mismatch between assembly header and BOM math.
If any BOM line references a USDA commodity item, step 9 also kicks off usda_drawdown_commit automatically — that ensures the commodity allocation stays in sync without Mike chasing it.
The 9 beats
-
01
Stage assembly header update (if header_changes)
Header field changes (
description,custitem_brand,custitem_pack_size,custitem_case_count,custitem_yield) stage as oneproposed_actionsrow withaction_type=assembly_header_update. -
02
Stage BOM line updates (if line_changes)
Each BOM line add/update/remove stages as one (or batched)
proposed_actionsrow withaction_type=assembly_bom_update. Cascade policy determines bundling. -
03
Invalidate assembly cache
Keys
assembly:{assembly_code},assembly_full:{assembly_id}, andbom:{assembly_id}are deleted so the next /assembly/<code> render is fresh. -
04
Recompute cost rollup
If BOM lines changed,
assembly_cost_rolluprecomputes raw + packaging + labor + overhead + freight from the new BOM. Persistsdrift_pct_vs_priorfor next cron. -
05
Invalidate pricing cache for affected rows
Each
(customer, school_year)pricing cache that touched this assembly gets busted. Keys derive fromcontext.active_pricing_rows. -
06
Regenerate spec sheet (conditional)
If
header_changestouched pack_size or case_count, or ifline_changesaffected yield, the spec sheet PDF regenerates via the existingregenerate_spec_sheettool. -
07
Flag dependent bids
For any open bid_line whose item_code equals the assembly's item_code (status in active or submitted), a flag marks the bid for re-pricing review.
-
08
Notify program owners (conditional)
If
customer_programs_usingis non-empty, one email per customer with this assembly drafts inoutbound_email_logwithstatus=pending_review. -
09
Trigger USDA drawdown check (conditional)
If a BOM line references a USDA commodity item, the runner invokes
usda_drawdown_commitso allocation stays aligned with the new BOM.
What's different after the workflow runs
- NS assembly record + BOM rows are updated within the NS push drain window.
assembly_cost_rollupreflects the new costs with a freshlast_computed.- Open pricing_master rows touching this assembly are flagged for review.
- Spec sheet PDF is regenerated if user-facing fields moved.
- Customer program owners have a draft email waiting if they're affected.
- A USDA drawdown is triggered if commodity allocation moved.
What can go wrong and how to recover
Retry policy is 2 attempts with backoff. Final failure raises an anomaly; manual recovery is POST /admin/assembly/recompute?assembly_id=<id>.
Retry policy applies. Drainer cron re-attempts within 15 min. D1 holds the proposed state.
Precondition catches this before stage; the runner refuses with a block-severity error. Mike fixes the line_key in the proposed payload and re-stages.
Browser Rendering can stretch on large BOMs. Old PDF remains in R2; next manual regen catches it.
Adjacent workflows + diagrams
Code paths + invariants
| Concern | Where |
|---|---|
| Workflow contract | workflow_definitions WHERE workflow_type='assembly_build_review' |
| Drift detector | R533 weekly assembly rollup cron |
| Cost rollup table | assembly_cost_rollup |
| Spec regen tool | regenerate_spec_sheet (executeChatTool branch) |
| USDA trigger | any BOM line where line_key matches usda_commodity_items |
| Reflexion tag | assembly_review,bom_change,data_cleanup |
| Risk level | 3 |
| Expected duration | ~variable (data-driven) |
| Trigger | manual_or_event · event_type_glob=assembly.cost_drift_detected |