4. RPW Domain Logic Bug Fixes and Input Validation
Date: 2026-11-22
Status
Accepted
Context
An audit of the legacy RPW calculation in Home.dart uncovered five correctness and availability issues:
rangeOut.contains(nodeId)compared integer IDs againstListrows (alwaysfalse) while shadowing loop indexi, causing an infinite freeze whenever a downstream node depended on an oversized task (Tek > cycleTime) or when graphs contained cycles.getArrowChainexited early on hittingfinalNodeId, skipping subsequent outgoing branches from the same source node.- RPW values were matched to sorted node rows by list position instead of node ID, scrambling results whenever
finalNodeIdwas not numerically largest. maxRPWignoredrangeOutstations, allowing division by zero or negative balance delay; Production Rate was also printed to console instead of shown in the UI.clearAll()omitted several internal lists and fields, leaking stale edges into subsequent runs.
Decision
Keep the Helgeson and Birnie RPW workflow and output steps intact while fixing all five defects inside HelgesonBirnieRpwSolver, RpwInputValidator, and CalculatorViewModel:
- Validate inputs against OWASP allowlists and safe size caps (
maxEdges = 500,maxUniqueNodes = 200), rejecting self-loops, duplicates, conflictingTekvalues, cycles, and disconnected graphs before solving. - Traverse forward arrow chains using a visited set without premature
breakstatements. - Store
tekByNodeandrpwByNodekeyed strictly by integer node ID. - Track
rangeOutIdsanddependsOnBigIdsexplicitly with a forward-progress guard so workstation packing always terminates. - Compute
maxStationLoadacross all workstations, guard zero denominators, and display Production Rate in the UI alongside Balance Delay and Line Efficiency.
Consequences
- Every valid and invalid input terminates deterministically in bounded time and memory.
- Users receive clear validation errors rather than silent miscalculations or app freezes.
- Regression tests in
test/domain/services/rpw_solver_test.dartlock in each fix.