Skip to content

trystero: the negotiating room counts as advertised, so a page whose first frames Chrome dropped is bound again - #11

Merged
pinhopro merged 1 commit into
mainfrom
fix/lost-first-frames
Dec 5, 2026
Merged

pinhopro merged 1 commit into
mainfrom
fix/lost-first-frames

Conversation

@pinhopro

@pinhopro pinhopro commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

The flake

Main CI run 47519299767 (head 658fe6f) failed the browser interop scenario "One room leaving, either side, leaves the other room and the connection". It failed 1 of the 13 emscripten interop runs on record; the native lane does not run it.

Root cause

The C++ peer, the lower id, offered in both rooms, and the page answered. Chrome drops what a page sends on an answering channel as it opens ("Send failed INVALID_STATE"). Here it dropped the page's presence and its @_hsready for the first room. The C++ first room had been bound by its own negotiation, so it never heard the page was ready: it timed the handshake out after 10 s and kicked the page.

Its rebinding over the live connection binds only a room the remote has advertised, by its presence or by a kept frame. A Trystero JS page advertises a room once per connection and, once kicked from it, sends nothing more of that room. The first room never came back, while the second went on.

Fix

A connection records the token of the room whose negotiation opened it as the remote's advertisement from the start, since the remote answered or offered in that room's signaling. Only the connection the app adopts records it. A held second connection keeps its own token for when it replaces the first. The existing connection returned for another negotiation does not take that negotiation's token, since another remote may have answered in the peer's name.

After the kick, the rebinding (11 s) sends the room's presence, the page binds the room again, and both handshakes pass. No timeout changed.

Proof

  • New interop scenario, "The page losing its first frames on the connection still joins both rooms". js.html's new drop-early-sends drops the page's sends on the first channel it accepts for 300 ms, and the page joins room2 2 s later. This reproduces the CI state exactly: one connection, room second active, room first timed out at 10 s.
    • Before the fix: failed 7 runs of 7.
    • After the fix: passed 20 runs of 20, in about 21 s.
  • Full browser interop: 27 of 27 scenarios pass; "One room leaving" passed 10 runs of 10.
  • Unit tests: 65 of 65 trystero tests pass on clang, 2 of them new: advertised at start, and on adoption, on a held second and on its replacement.
  • Lint: the macOS full lint and the Linux lint (changed mode) are clean.

🤖 Generated with Claude Code

…remote's advertisement, so that a page whose first frames Chrome dropped is bound again after the handshake times out

The interop lane's "one room leaving" scenario failed on main (run 47519299767, 1 of 13 runs):
the C++ peer, the lower id, offered in both rooms, and the page answered. Chrome drops what a page
sends on an answering channel as it opens, and the page's presence and its @_hsready of the first
room were lost. The C++ first room, bound to the connection by its own negotiation, never heard the
page's readiness, timed the handshake out after 10 s and kicked the page from the room. Its
rebinding over the live connection binds only a room the remote advertised, by its presence or by
a kept frame of the room; a Trystero JS page advertises a room once per connection and, kicked from
it, sends nothing more of it, so the first room never came back while the second went on.

A connection now records the token of the room whose negotiation opened it as the remote's
advertisement from the start: the remote answered or offered in that room's signaling. The app
records it only on the connection it adopts, a held second connection keeps it for when it
replaces the first, and the existing connection returned for another negotiation does not take
it, since another remote may have answered that negotiation in the peer's name. After the kick,
the rebinding (11 s) sends the room's presence, the page binds the room again, and both handshakes
pass.

The interop test gains the scenario "The page losing its first frames on the connection still
joins both rooms": js.html's drop-early-sends drops what the page sends on the first channel it
accepts for 300 ms, and the page joins room2 2 s later. It failed 7 runs of 7 before the change
(room first never back in 30 s) and passed 20 runs of 20 after, in 21 s; the full browser interop
passed 27 scenarios of 27, and "one room leaving" 10 runs of 10. Unit tests cover the
advertisement on a started connection and on adoption, a held second, and its replacement.
@pinhopro
pinhopro merged commit 63d63c6 into main Dec 5, 2026
31 checks passed
@pinhopro
pinhopro deleted the fix/lost-first-frames branch December 5, 2026 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant