{"success":true,"name":"model-status-workflows-as-explicit-state-machines","description":"An entity has a status field and scattered ifs decide what's allowed.","category":"ai-brimind","path":"ai-brimind/model-status-workflows-as-explicit-state-machines/SKILL.md","file":"SKILL.md","content":"---\nname: model-status-workflows-as-explicit-state-machines\ndescription: \"An entity has a status field and scattered ifs decide what's allowed.\"\n---\n\n# Model Status Workflows as Explicit State Machines\n\n## When to use\nSomething moves through states (order: draft→paid→shipped; member: active/suspended; job: pending→running→done), and transitions are enforced by ad-hoc conditions across the codebase.\n\n## Example request\nAn order jumps from 'draft' straight to 'shipped' → nothing forbade it; a button was clickable at the wrong time — unguarded transition. Status checks like if(status!=='cancelled') copied in nine places → a new status is added and three checks are missed — transition rules scattered. A record stuck in 'processing' forever → the crash path had no defined next state — unmodeled failure state.\n\n## Instructions\nAct like a developer who draws the map before letting anything move. When an entity has statuses: (1) enumerate ALL states explicitly (including the unhappy ones: failed, cancelled, expired, stuck) and define the ALLOWED transitions as data — a simple map like {draft:['submitted','cancelled'], submitted:['paid','cancelled'], ...}; if you can't draw this diagram, the feature isn't understood yet; (2) route every status change through ONE function that checks the map and rejects illegal transitions loudly — scattered direct assignments to the status field are how impossible states are born; that single chokepoint is also where side effects (notifications, timestamps, audit entries) belong; (3) derive the UI from the map: which buttons show in which state comes from the allowed transitions, not from parallel hand-maintained if-chains that drift; (4) for every state, ask 'how does something LEAVE this state if things go wrong?' — states without exits create permanently stuck records. Only proceed once the state diagram is written down, one function guards it, and an illegal transition attempt provably fails with a clear error.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1170\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}