Just wanted to close this out. I took off the Sunrace 11-40 and put back the old Shimano 11-30. I was struck by how much I had to reset the limits on the rear mech but it shifted flawlessly. Soooo, my first action was to return the Sunrace for a new one and that’s what I did. But I began to think that there might be some incompatibility between the KMC ebike chain and the Sunrace cassette. So I went with a Alivio 12-36 9 speed, which is ebike rated by the way and that is working well.