Repository navigation
Replace a reconnect attempt the page hid on when it comes back - #528
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit cb77eab. Configure here.
dcruzeneil2
left a comment
There was a problem hiding this comment.
Approving. I built main and this branch locally and ran both against a real Chromium with real media.
Socket held after dial, tab hidden 2s, then shown: main took 14.0s to reconnect (transport timeout plus backoff), this branch took about 0.1s with no failure counted and the video playing. So the fix does what it says in Chromium. I have not tested a real phone lock, Safari or Firefox.
One bug to fix before the next image release. If the aborted attempt already received its track (ws open, signal/provide done, ICE not connected), the reconnect succeeds but the video element ends up paused while the store says playing, so no prompt shows. I hit it 8 of 8 times with UDP blocked during the attempt. On desktop it stayed paused through a 4s wait and another hide and show. I did not try other ways to recover it. With touch emulation the next tap or hide and show restarted it.
My read of the trace: right after the peer is closed, canplaythrough fires on the element still holding the old stream and the autoplay handler sets playing back to true after the store reset. The new stream's srcObject swap then leaves the element paused with no pause event, and the new stream's canplaythrough calls a store play() that is now a no-op. The first step is inferred from timing, I did not isolate it.
This looks older than this PR. On main I saw the same freeze once when an attempt dropped in the media stage and the next one connected. But abort adds a second way in, and in the one run where the tab was hidden during a stalled media stage, main let the old attempt finish and played fine where this branch froze. Resetting playable when a new stream is attached, or clearing srcObject when the store resets, look like the places to start. I have not tested a fix.
Smaller notes:
- In reconnect-abort.test.ts the dropped assertion is vacuous because the fake socket never fires onclose. I replaced abort with a bare close() and the test still passed.
- The dialed = false in dropped() looks redundant since attempt() resets it.
Also not covered: the live view proxy. The test went straight to neko in a local container.

Summary
Fixes a stall in the live view reconnect from #524. If the page hid after a reconnect attempt had already opened its websocket, coming back did nothing:
wake()only acts while waiting, so the page stayed on "Reconnecting..." until the suspended attempt hit its connection or media timeout.hid()). If that happens after the current attempt calledconnect(), the attempt is marked stale.abortdependency: the client'sdisconnect(), which clears the socket and peer handlers first so no drop is reported, followed by the same store reset a drop does, so any tracks the closed attempt received don't linger. A fresh attempt then starts at once, with no backoff and no failure counted. The new attempt only connects after its page check resolves, so two peer connections never overlap.online, orpageshowwhile visible) still leaves a running attempt alone. So does a hide during the page check, which already went back to waiting.Paused video after replacing an attempt
If the aborted attempt had already received its track, the reconnected video could stay paused while the store said it was playing, so no tap prompt showed. Two things in
video.vuecombined:streamundefined, andonStreamChangedreturned early, so the<video>element kept the closed attempt's stream. That stream'scanplaythroughthen setplayableandplayingback to true.srcObjectto the new stream pauses the element without a pause event. The new stream'scanplaythroughcalled the store'splay(), butplayingwas already true, so the watcher never ranvideo.play().Now
onStreamChangedclearssrcObjectwhen the stream goes away, and marks the store unplayable before attaching a new stream. The new stream'scanplaythroughthen movesplayingfrom false to true, which plays the element, or shows the tap prompt if the browser refuses. This also coversmain's existing path, where an attempt drops during the media stage and the next one connects.Testing
bun test tests: 306 pass. New tests:main.connect()ran: no abort, one connect.abortcloses the socket without reporting a drop and resets the video store. The fake socket runs itsoncloseonclose(), so the test fails ifabortis a bareclose(), and also fails without the reset.video.vue: a new stream after an aborted attempt that had its own stream plays, and so does a stream that replaces one already playing. Both fail onc2bffc9.Real Chromium against a production headful browser with this client hot-patched (desktop viewer, page hidden for 2s right after the attempt received its tracks; UDP and the TURN relay blocked so ICE couldn't connect, unblocked before showing):
c2bffc9playing, no promptRuns where no TURN relay was in use connected ICE anyway and never reached the abort; they aren't counted. Not tested: a real phone, Safari, Firefox.
tsc --noEmitand prettier are clean.