the rectangle is placed on it’s center to all the grid’s points. This means your final size of the instanced geometry is gridSize + rectangleSize. Hence when calculating the scale for the rectangle, you have to subtract one from the number of rows:
op('grid1').par.sizex/(op('grid1').par.rows-1)
You can test this by rendering the grid ontop of the instances: