NetSuite work order lifecycle risk 3 · mediummanual_or_eventreflexion on

workflow_type: work_order_lifecycle · owner: mike · contract v2 · source diagram: ns-work-order-master.html

Mike approves (or low-inventory trigger auto-stages) a work order. Cascade: WO create + reserve BOM + production start + labor capture + component issue + build complete + WO close + variance audit + finished-goods credit. Variance > 5% stages a HITL proposed_action.

0 · Visual flow NetSuite work order lifecycle — 9 fan-out targets, 3 verify checks

idle
NS work order lifecycle — WO intake → component pull → production start → labor capture → component issue → build complete → WO close → variance audit → finished goods 01 / Intake 02 / Pull 03 / Start 04 / Labor 05 / Issue 06 / Build 07 / Close 08 / Variance 09 / FG WO INTAKE — Work order created in NetSuite, either manually by production lead or auto-generated when an assembly's quantityavailable drops below reorder_point. TRIGGER manual: NS UI · production lead enters qty + due date auto: low_inventory event → propose_work_order action_type TARGET ns_record: workorder d1_table: transactions (type=WorkOrd) status: REAL WO intake manual or auto FRONTEND · workorder i COMPONENT PULL — Resolve the assembly's BOM, check inventory_balance for each component, and reserve the required quantity per location. ACTION lookup: assembly_bom WHERE assembly_id = ? check: inventory_balance.quantityavailable per line_key reserve: write reservation row TABLES read: assembly_bom · inventory_balance write: inventory_balance.reserved_qty STATUS d1_mirror: REAL ns_reservation_write: STUB component pull BOM lookup inventory_balance reservation DATABASE · D1 i PRODUCTION START — Work order status transitions to 'In Progress' with start_timestamp recorded. NS workorder record marked released; D1 transactions row updated. ACTION status: 'In Progress' start_ts: now() TABLES write: transactions (WO row) ENDPOINT push: POST /api/ns/workorder/release (via NS_PUSH_QUEUE) STATUS: REAL production start status='In Progress' start_ts captured BACKEND · workorder release i LABOR CAPTURE — Time entries booked against the WO. Hours roll up into actual_labor_cost on completion. Currently STUB — no time-entry surface yet; manual NS entry only. ACTION entry_per_employee_per_phase hours · rate · cost_per_entry TABLES write: transactions (type=TimeBill) · linked to WO STATUS ns_native: REAL (manual) auto_capture: STUB · no scanner/kiosk yet labor capture time entries vs WO hours × rate CAPTURE · STUB autoflow i COMPONENT ISSUE — Components consumed from inventory; inventory_balance decrements per BOM line for the WO. NS posts a workorderissue transaction; D1 mirrors with negative qty rows. ACTION decrement: inventory_balance per BOM line ns_record: workorderissue TABLES write: inventory_balance · transactions (WkOrdIss) STATUS: REAL component issue debit inventory workorderissue posted DATABASE · -qty per line i BUILD COMPLETE — Assembly produced; finished goods qty added to inventory_balance at the production location. NS posts a 'build' transaction; D1 mirrors with +qty for the assembly item. ACTION increment: inventory_balance (assembly_id) ns_record: build (assemblybuild) TABLES write: inventory_balance · transactions (Build) STATUS: REAL build complete credit FG inventory build txn posted BACKEND · +qty assembly i WO CLOSE — Status flips to 'Built'. NS rolls actual cost (components + labor + overhead) and compares to estimated cost on the BOM. Triggers workorderclose record. ACTION status: 'Built' actual_cost_rollup: sum(issues + timebills + overhead_alloc) delta_vs_estimated: computed TABLES write: transactions (WkOrdCls) STATUS: REAL WO close status='Built' actual cost rollup BACKEND · workorderclose i VARIANCE AUDIT — If |actual − estimated| / estimated > threshold (default 5%), proposed_action staged for review. Mike sees the diff and decides whether to update the BOM or flag a production exception. THRESHOLD default: 5% of estimated cost HITL proposed_actions row · action_type='wo_variance_review' TABLES write: proposed_actions · reflexion_log STATUS: REAL · risk 3 variance audit |actual−est| / est > 5% → HITL staged proposal SECURITY · risk 3 i FINISHED GOODS — Assembly is available for sales. inventory_balance.quantityavailable reflects the new build. Sales orders for the SKU can now allocate. TABLES read: inventory_balance · assemblies SURFACES bid-command-center, item entity page, chat get_assembly_inventory STATUS: REAL finished goods available_qty++ SO allocatable DATABASE · D1 · NS sync i if variance approved → update BOM estimated cost LEGEND Frontend Database Backend HITL / risk Capture

1 · Trigger FIRES WHEN…

kind
manual_or_event
event pattern
inventory.low_threshold
description
Manual via NS UI OR auto from low-inventory trigger

2 · Inputs required

namerequiredtype / hint
assembly_idrequiredinteger
qtyrequiredinteger
due_dateoptionalstring

3 · Context loaded D1 queries run before fan-out

name
assembly
tables
assemblies
returns
row
SELECT
  id, itemid, displayname, quantityavailable, reorder_point
  FROM assemblies
  WHERE id = ?
name
assembly_bom
tables
assembly_bom
returns
rows
SELECT
  line_key, item_code, qty, uom, estimated_cost
  FROM assembly_bom
  WHERE assembly_id = ?
name
inventory_balance
tables
inventory_balance · assembly_bom
returns
rows
SELECT
  item_code, location_id, quantityavailable, reserved_qty
  FROM inventory_balance
  WHERE item_code IN (SELECT item_code
  FROM assembly_bom
  WHERE assembly_id = ?)
name
recent_builds
tables
transactions
returns
rows
SELECT
  id, trandate, total_cost, actual_qty, planned_qty
  FROM transactions
  WHERE type='Build'
  AND assembly_id=?
  ORDER BY trandate DESC
  LIMIT 10
name
labor_capacity
tables
labor_schedule
returns
rows
SELECT
  date(start_at) AS day, SUM(duration_min)/60.0 AS hours
  FROM labor_schedule
  WHERE start_at >= date('now')
  GROUP BY day

4 · Preconditions checked before any fan-out

checkruleseverity
assembly_existsassembly_id IN (SELECT id FROM assemblies)block
qty_positiveqty > 0block
components_availableevery BOM line has on_hand >= qty * bom.qtywarn
labor_capacityupcoming_capacity_hours >= estimated_labor_hourswarn

5 · HITL gate

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).

action_type
workflow_work_order_lifecycle (proposal envelope)
entity_ref
workflow:work_order_lifecycle:run_<run_id>
approver
mike (single-admin)

6 · Fan-out targets 9 total · 3 real · 6 stub

#1wo_create stage_proposed_action REAL

action_type
workorder_create
entity_type
workorder

#2bom_reserve kv_invalidate REAL

keys
inventory:assembly:?assembly_id
inventory:bom:?assembly_id

#3component_issue d1_write STUB

table
inventory_balance
operation
update
stub — not yet implemented in src/lib/workflow_runner.ts (kind d1_write hits the placeholder branch). Documented intent only.
UPDATE inventory_balance
  SET quantityavailable = quantityavailable - ?, reserved_qty = reserved_qty - ?
  WHERE item_code = ?
  AND location_id = ?

#4build_complete d1_write STUB

table
transactions
operation
insert
stub — not yet implemented in src/lib/workflow_runner.ts (kind d1_write hits the placeholder branch). Documented intent only.
INSERT INTO transactions (type, assembly_id, trandate, qty, status)
  VALUES ('Build', ?, datetime('now'), ?, 'completed')

#5wo_close stage_proposed_action REAL

action_type
workorder_close
entity_type
workorder

#6variance_audit flag STUB

table
proposed_actions
field
action_type
value
wo_variance_review
condition (if)
abs((actual_cost - estimated_cost)/estimated_cost) > 0.05
stub — not yet implemented in src/lib/workflow_runner.ts (kind flag hits the placeholder branch). Documented intent only.

#7finished_goods_increment d1_write STUB

table
inventory_balance
operation
update
stub — not yet implemented in src/lib/workflow_runner.ts (kind d1_write hits the placeholder branch). Documented intent only.
UPDATE inventory_balance
  SET quantityavailable = quantityavailable + ?
  WHERE item_code = (SELECT itemid
  FROM assemblies
  WHERE id = ?)
  AND location_id = ?

#8notify_warehouse hitl_email_draft STUB

tool
propose_email_to_customer
mailbox
warehouse@globalfoodsolutions.co
template
wo_completion_notice
stub — not yet implemented in src/lib/workflow_runner.ts (kind hitl_email_draft hits the placeholder branch). Documented intent only.

#9reflexion_log_write d1_write STUB

table
reflexion_log
operation
insert
stub — not yet implemented in src/lib/workflow_runner.ts (kind d1_write hits the placeholder branch). Documented intent only.
INSERT INTO reflexion_log (workflow_run_id, entity_type, entity_id, outcome, tags)
  VALUES (?, 'workorder', ?, ?, 'work_order,build,variance')

7 · Post actions declared + runner-automatic

idactionsource
runner_log_runINSERT into workflow_run_log (run_id, workflow_type, status, started_at, completed_at, summary_json)runner automatic
runner_reflexionINSERT into reflexion_log (tags=work_order_lifecycle, run_id, narrative)runner automatic (reflexion_enabled=1)
log_runINSERT workflow_run_logdeclared in contract
reflexionINSERT reflexion_log with tags=work_order,builddeclared in contract
event_completedFIRE event workflow.completed (workflow_type=work_order_lifecycle)declared in contract

8 · Verify checks written to workflow_verify_results

name
WO_status_built
when_to_run
1440 min after run
expected
row
SELECT
  status
  FROM transactions
  WHERE type='WorkOrd'
  AND id=?
  AND status='built'
name
variance_within_threshold
when_to_run
2880 min after run
expected
variance <= 0.05
SELECT
  abs((actual_cost - estimated_cost)/estimated_cost) AS variance
  FROM workorder_summary
  WHERE wo_id=?
name
inventory_correctly_updated
when_to_run
1440 min after run
expected
increased by ?qty
SELECT
  quantityavailable
  FROM inventory_balance
  WHERE item_code = (SELECT itemid
  FROM assemblies
  WHERE id=?)

9 · Retry policy

max_attempts
3
backoff
exponential
base_ms
2000
max_ms
60000
alert_on_final_failure
true

10 · What changes when this workflow runs aggregated side effects

systemtable / resourceactionstatussource
D1proposed_actionsINSERT (action_type=workorder_create)REALfan-out #1 (wo_create)
KV (CACHE)inventory:assembly:?assembly_id, inventory:bom:?assembly_idinvalidateREALfan-out #2 (bom_reserve)
D1proposed_actionsINSERT (action_type=workorder_close)REALfan-out #5 (wo_close)
D1workflow_run_logINSERT (run summary)REALrunner automatic
D1reflexion_logINSERT (tags=work_order_lifecycle)REALrunner automatic
Eventworkflow.completed (or workflow.failed)fireREALrunner automatic
D1workflow_verify_resultsINSERT pending × 3REALrunner verify staging
D1proposed_actionsINSERT (HITL gate envelope)REALrunner HITL gate
D1inventory_balanceupdateSTUBfan-out #3 (component_issue)
D1transactionsinsertSTUBfan-out #4 (build_complete)
D1proposed_actionsset action_type=wo_variance_reviewSTUBfan-out #6 (variance_audit)
D1inventory_balanceupdateSTUBfan-out #7 (finished_goods_increment)
D1proposed_actionsINSERT (email draft via propose_email_to_customer)STUBfan-out #8 (notify_warehouse)
D1reflexion_loginsertSTUBfan-out #9 (reflexion_log_write)