Repository navigation
Approve no longer hangs when a review is open in two tabs - #4302
Merged
Merged
Conversation
…goes through (#4218) Each plan, annotate and code review tab held its own EventSource streams (three in annotate: external annotations, the file watch, the client lease), one HTTP/1.1 connection each. Two tabs of one review used all six connections Chromium allows per host, so the Approve POST waited in the browser's queue forever with the buttons disabled. SharedEventSource (packages/ui/utils) is a drop-in for new EventSource(url): tabs that open the same URL elect a leader with a Web Lock, the leader holds the one connection and passes frames and errors on over a BroadcastChannel. A tab that starts listening later asks the leader to reconnect so it gets the stream's first frames. Without Web Locks each tab opens its own, as before. Decision POSTs also carry a 30 s signal: one that is never answered ends as unreachable and shows the existing not-sent toast with Retry.
…fused; stand in for a frozen leader - A rejected lock request (or a throwing request or BroadcastChannel) left the tab with no stream and no error, so no polling fallback and no client lease (an annotate --gate session whose only tab closed never expired). The tab now opens its own stream. - A frozen leader stalled every follower. Followers ping over the channel every 5 s; after 15 s unanswered one follower (an ifAvailable second lock, never steal) relays its own stream until the leader answers, then steps down with a join. At most one connection per URL per tab. - e2e: the second tab gets an agent's note posted before it opened, while both are open, and after the first tab closed. - HANDOFF: the default streams share one connection per URL across tabs.
…over when the stand-in sleeps too - Each relayed connection has an id, announced before its frames; followers take frames of the connection they last heard announced only, so a frozen leader's queued frames (already relayed by the stand-in) are dropped. - A stand-in role granted after a relayer was heard is let go at once. - With no answer for 30 s and the stand-in role refused (the stand-in is suspended too), a tab opens its own stream and relays it to no one until a relayer is heard again. - e2e counts each note once in the second tab.
backnotprop
marked this pull request as ready for review
November 30, 2026 20:39
… from a server that is gone
…o-tabs # Conflicts: # packages/ui/HANDOFF.md
…o-tabs # Conflicts: # packages/ui/HANDOFF.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4218
Before: with a plan, annotate or code review open in two tabs of one browser, pressing Approve (or Send Feedback) in one of them spun forever: buttons disabled, no error, nothing written, the agent waiting. Each tab held its own event streams (annotate: external annotations, the file watch, the client lease), one HTTP/1.1 connection each, and two tabs used all six connections Chromium allows per host, so the POST sat in the browser's queue. Closing the other tab let it through.
After: tabs share one connection per stream.
SharedEventSource(packages/ui/utils/sharedEventSource.ts) replacesnew EventSource(url)for every review stream: the tabs that open the same URL elect a leader with a Web Lock; the leader holds the connection and passes frames and errors on over a BroadcastChannel. A tab that starts listening later asks the leader to reconnect, so it gets the stream's first frames (snapshot, ready). When the leader closes, the next tab takes the stream. No server change: the servers still see a connection while any tab is open, which is all the client lease and the agent-gone check ask.Fallback: each tab opens its own stream, as before, where Web Locks or BroadcastChannel is missing (a remote session over plain http), where the browser refuses the lock request (for example a site that may not store data), or where the channel cannot be made. Without this, a refused lock left the tab with no stream and no error: no polling fallback, and an annotate
--gatesession whose only tab closed never expired.A suspended leader (the stand-in): a leader tab the browser freezes (background tabs on iPad or Android, for example) keeps its lock and sends nothing. Followers ping it over the channel every 5 s; a running leader answers, even hidden. After 15 s without an answer, one follower takes a second lock (
ifAvailable, neversteal), opens its own stream and relays it; when the leader is heard again it steps down and asks for fresh first frames. A role granted after the leader was heard is let go at once. If the stand-in is suspended too (30 s of silence with the role refused), a tab opens its own stream and relays it to no one until a relayer is heard. Each relayed connection has an id announced before its frames, and tabs take frames of the connection they follow only, so the frames a woken leader had queued are not applied twice (no doubled agent logs, no deleted note coming back). A tab holds at most one connection per URL. While a stand-in relays beside a frozen leader whose connections stay open, the connection count is the leader's plus one set, so a decision can again wait for the 30 s deadline below.Decision POSTs also get a 30 s deadline, so a send that never gets through ends with the existing "not sent" toast and Retry instead of spinning. No new words.
Measured (annotate
--gatewith the client lease, built from source, sandboxed, headless Chromium, two pages in one context): on main, tab 1 opens 3 streams, tab 2 three more; Approve in tab 2 was still pending after 11.5 s and went through only when tab 1 closed. With this branch tab 2 opens no stream and Approve answers 200 in about 100 ms. Tab 2 shows an external note posted before it opened, one posted while both are open, and one posted after tab 1 closed, each exactly once; after tab 1 closes, tab 2 opens the three streams itself.Tests:
Not proven: Safari and Firefox; a real frozen tab (the stand-in is covered by unit tests with fake timers and a fake frozen tab).