{
  "id": 14679737,
  "title": "Model Line Changeover as a State Machine So the Next SKU Cannot Start Before Clearance",
  "url": "https://urgent.news/2026/10/15/model-line-changeover-as-a-state-machine-so-the-next-sku-cannot-start",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-10-15T11:15:36.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/yit2022/model-line-changeover-as-a-state-machine-so-the-next-sku-cannot-start-before-clearance-1g66"
  },
  "original_language": "en",
  "account": "In the food manufacturing industry, particularly in small and mid-sized factories in Kenya, product changeovers on production lines can lead to a failure mode where the next product's production order starts while the previous product is still present on the line. This issue arises due to residue, leftover labels, work in progress, and stale machine settings from the previous product. To address this problem, a line clearance checklist and software modification are needed.\n\nCurrently, production orders are often modeled with a status (planned, in_progress, completed) and a line_id. However, this design does not prevent two orders from being in_progress on the same line or starting a new order before the previous one is fully cleared. The solution is to model each line with its own state machine, making orders depend on the line's state.\n\nKey states in the line state machine include RUNNING (for an active order), CLOSED_OUT (when the order is completed with all relevant data recorded), CLEANED (after the cleaning process), and CLEARED (after verification that the line is clear of the previous product). A transition from RUNNING to RUNNING is not allowed, even for administrators, ensuring that no order can start until the previous one has been properly cleared.\n\nThe system enforces several rules through code. Only one active order per line is allowed, and start_order can only be triggered when the line is in SETUP state and first-off QC has passed. Skipping states is not permitted, and there is no transition from RUNNING to RUNNING. Changeover type determines the required cleaning program and verification checks, derived from the products being changed over.\n\nSegregation of duties is crucial, with the verify_clearance.checked_by user differing from the record_cleaning.cleaned_by user, and both requiring a QA/supervisor role. The close_out process is a precondition, ensuring that any packaging or work in progress from the previous order has been returned, consumed, or explicitly scrapped before closing the order.",
  "summary": "By Isaac Muthui, CEO, Tamalaki Business Network Ltd. Originally published at factoraerp.com . If you build production or MES/ERP software for food manufacturers, here is a failure mode worth designing out: the next product's production order can start on a line while the previous product is still, in practice, on it. In small and mid-sized food and agro factories in Kenya, where I work,…",
  "key_points": [
    "Model each production line with a state machine to prevent overlapping orders.",
    "States include RUNNING, CLOSEDOUT, CLEANED, and CLEARED to ensure proper line clearance."
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}