When I first deployed ChatSphere, it looked done. Two tabs, two users, messages flying back and forth instantly. I recorded a demo, felt good about it, moved on.

Then I opened a third tab.

The bug

I logged in as the same user in two different tabs — one on my laptop, one on my phone, both signed in as renuka. I closed the laptop tab. The phone tab, still open and still connected, suddenly showed me as offline in the sidebar. I was still there. I just wasn't showing as online anymore.

The root cause was embarrassingly simple once I found it: my online-user tracking was keyed by socket ID, not by username.