oficina / meet Public

Calls: reproduce the 2026-10-21 connection that never came back

TestNativeMacIceRecovery: app A shares, B joins and leaves, C (the same
person) joins with every ICE candidate it sends or receives pointed at
the discard port for a while (ICETestBlock, test-only). Nothing exchanged
during the block is any use after it, so only fresh candidates mend the
pair.

On 0.4.10 code the pair stays down: 2m30s after the block lifted, A still
decoded nothing from C, its tile still said Reconnecting, and ICE never
even reached failed (it sat in checking). With the sharer's screen
watchdog on, its re-add renegotiation happened to carry fresh candidates
in the SDP and mended it after 29-42 s; nothing in the connection layer
did.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev ed9916d8af2017c8b8c1f16a2de52b72381a0c54 parent 882eab8
6 files changed, +271 −7
  • internal/callstest/native_browser_test.go +17 −1
  • internal/callstest/native_ice_test.go +157 −0
  • native/apple/Sources/CallsInterop/Interop.swift +20 −0
  • native/apple/Sources/CallsKit/Call.swift +15 −0
  • native/apple/Sources/CallsKit/ICETestBlock.swift +41 −0
  • native/apple/Sources/CallsKit/Media.swift +21 −6
diff --git a/internal/callstest/native_browser_test.go b/internal/callstest/native_browser_test.go
index e51c3d3..c7dd0e7 100644
--- a/internal/callstest/native_browser_test.go
+++ b/internal/callstest/native_browser_test.go
@@ -266,7 +266,13 @@ type nativeSample struct {
ScreenCaptions []string `json:"screenCaptions"`
SharingScreen *bool `json:"sharingScreen"`
ScreenRecovery string `json:"screenRecovery"`
- Diagnostics string `json:"diagnostics"`
+ Status string `json:"status"`
+ Reconnecting bool `json:"reconnecting"`
+ // Tile notices by peer, and the peers' client strings as the roster
+ // has them (the auto-ice-restart release on; absent before).
+ Notices map[string][]string `json:"notices"`
+ Clients map[string]string `json:"clients"`
+ Diagnostics string `json:"diagnostics"`
}
// nativeApp is one CallsInterop process and the last observation it
@@ -282,10 +288,20 @@ type nativeApp struct {
}
func startNative(ctx context.Context, t *testing.T, binary string, rig *browserRig, room, cookie, label string) *nativeApp {
+ t.Helper()
+ return startNativeEnv(ctx, t, binary, rig, room, cookie, label, nil)
+}
+
+// startNativeEnv is startNative with extra environment for this one app
+// (KEY=value), on top of the test's own.
+func startNativeEnv(ctx context.Context, t *testing.T, binary string, rig *browserRig, room, cookie, label string, env []string) *nativeApp {
t.Helper()
cookies, _ := json.Marshal([]map[string]string{{"name": rig.cookieName, "value": cookie}})
input, _ := json.Marshal(map[string]string{"origin": rig.origin, "room": room, "cookies": string(cookies)})
cmd := exec.CommandContext(ctx, binary)
+ if len(env) > 0 {
+ cmd.Env = append(os.Environ(), env...)
+ }
stdin, err := cmd.StdinPipe()
if err != nil {
t.Fatal(err)
diff --git a/internal/callstest/native_ice_test.go b/internal/callstest/native_ice_test.go
new file mode 100644
index 0000000..ae17047
--- /dev/null
+++ b/internal/callstest/native_ice_test.go
@@ -0,0 +1,157 @@
+//go:build browser && darwin
+
+package callstest
+
+import (
+ "context"
+ "os"
+ "path/filepath"
+ "strconv"
+ "strings"
+ "testing"
+ "time"
+)
+
+// TestNativeMacIceRecovery is the incident of 2026-10-21, about 14:41 UTC:
+// Paul on the Mac app, sharing his screen; Farshad, in the call from a
+// browser, left it and came back from the Mac app; the connection between
+// Paul's app and Farshad's never came up. Paul saw a frozen picture,
+// "Reconnecting to Farshad (Mac)…" and "A participant's media could not
+// connect", and it never recovered on its own. Farshad leaving and joining
+// again mended it.
+//
+// Here: app A shares; app B (the stand-in for Farshad's first client)
+// joins and leaves; app C, the same person, joins with its ICE blocked
+// (ICETestBlock: every candidate either way leads nowhere) for
+// ICE_BLOCK_SECONDS. The block lifts by itself, and nothing that was
+// exchanged while it lasted is any use afterwards — only fresh candidates
+// (an ICE restart) or a fresh connection get the pair talking. Up to
+// 0.4.10 nothing ever made either, and the pair stayed down until someone
+// left. The test then asks that A decodes C's camera and screen again with
+// nobody doing anything.
+//
+// Variants (ICE_RECOVERY_CASE):
+// - "both" (default): C is the same build as A.
+// - "old-peer": C does nothing to recover (CALLS_AUTO_RECOVERY=0) and
+// sends no client version (CALLS_TEST_NO_CLIENT=1), as an app from
+// before this release; A has to mend the pair on its own.
+// - ICE_RECOVERY_PEER=<path to an older CallsInterop>: C is that
+// binary, which has no block of its own, so the block is A's (every
+// candidate A sends or receives) — the old app really is old.
+//
+// The firewall flake TestNativeMacScreenShare describes (two unsigned
+// apps on one Mac connecting only some of the time) is handled the way
+// TestNativeMacScreenPairRecovery handles it: A and B get three tries to
+// connect before anything else happens.
+func TestNativeMacIceRecovery(t *testing.T) {
+ root, err := filepath.Abs("../..")
+ if err != nil {
+ t.Fatal(err)
+ }
+ current := filepath.Join(root, "native/apple/.build/debug/CallsInterop")
+ peerBin := current
+ if v := os.Getenv("ICE_RECOVERY_PEER"); v != "" {
+ peerBin = v
+ }
+ for _, b := range []string{current, peerBin} {
+ if _, err := os.Stat(b); err != nil {
+ t.Fatalf("no interop executable at %s: build with make native-mac first", b)
+ }
+ }
+ block := 25 * time.Second
+ if v, err := time.ParseDuration(os.Getenv("ICE_BLOCK_SECONDS") + "s"); err == nil && v > 0 {
+ block = v
+ }
+ mode := envOr("ICE_RECOVERY_CASE", "both")
+ oldBinary := peerBin != current
+
+ rig := newBrowserRig(t)
+ room, _ := rig.createMeeting(t)
+ ctx, cancel := context.WithTimeout(t.Context(), block+6*time.Minute)
+ defer cancel()
+
+ var a, b *nativeApp
+ for attempt := 1; ; attempt++ {
+ a = startNative(ctx, t, current, rig, room, rig.cookieA, "a")
+ waitNative(t, "the sharing app is in", func() bool { return a.sample().Phase == "admitted" }, a)
+ b = startNative(ctx, t, current, rig, room, rig.cookieB, "b")
+ if pollNative(35*time.Second, func() bool { return a.stat("framesDecoded") > 15 && b.stat("framesDecoded") > 15 }) {
+ break
+ }
+ a.leave(t)
+ b.leave(t)
+ if attempt == 3 {
+ t.Fatal("the two apps never connected")
+ }
+ t.Logf("RETRY the two apps did not connect (attempt %d)", attempt)
+ }
+ defer a.leave(t)
+ a.command(t, "screen-on")
+ waitNative(t, "the first client sees the screen", func() bool {
+ return b.stat("remoteScreens") == 1 && b.stat("screenFramesDecoded") > 15
+ }, a, b)
+ t.Log("A is sharing, and B sees it")
+
+ // Farshad leaves, and comes back from the app.
+ b.leave(t)
+ waitNative(t, "A sees B go", func() bool { return a.stat("rosterPeers") == 1 }, a)
+
+ var env []string
+ switch {
+ case oldBinary:
+ // The old app has no block of its own; A's blocks both ways.
+ a.command(t, "ice-block "+strconv.FormatInt(block.Milliseconds(), 10))
+ case mode == "old-peer":
+ env = []string{"CALLS_TEST_ICE_BLOCK_MS=" + strconv.FormatInt(block.Milliseconds(), 10), "CALLS_AUTO_RECOVERY=0", "CALLS_TEST_NO_CLIENT=1"}
+ default:
+ env = []string{"CALLS_TEST_ICE_BLOCK_MS=" + strconv.FormatInt(block.Milliseconds(), 10)}
+ }
+ blockedAt := time.Now()
+ c := startNativeEnv(ctx, t, peerBin, rig, room, rig.cookieB, "c", env)
+ defer c.leave(t)
+ waitNative(t, "C is in the call", func() bool { return c.sample().Phase == "admitted" && a.stat("rosterPeers") == 2 }, a, c)
+
+ // The connection does not come up while the block lasts.
+ sawFailed := false
+ for time.Since(blockedAt) < block {
+ if a.stat("iceFailedPeers") > 0 {
+ sawFailed = true
+ }
+ if a.stat("iceConnectedPeers") > 0 && a.stat("framesDecoded") > 0 {
+ t.Fatalf("A connected to C through the block: %+v", a.sample())
+ }
+ time.Sleep(250 * time.Millisecond)
+ }
+ t.Logf("block over after %s: A has seen ICE failed: %v; A says %q, notices %v", time.Since(blockedAt).Round(time.Second),
+ sawFailed, a.sample().Status, a.sample().Notices)
+
+ // Nobody does anything. A must decode C's camera and screen again.
+ frames := a.stat("framesDecoded")
+ limit := 90 * time.Second
+ if v, err := time.ParseDuration(os.Getenv("ICE_RECOVERY_WITHIN")); err == nil {
+ limit = v
+ }
+ until := time.Now().Add(limit)
+ recovered := false
+ for time.Now().Before(until) {
+ if a.stat("framesDecoded") > frames+15 && c.stat("screenFramesDecoded") > 15 {
+ recovered = true
+ break
+ }
+ time.Sleep(500 * time.Millisecond)
+ }
+ sa, sc := a.sample(), c.sample()
+ t.Logf("A: status %q, notices %v, clients %v, iceConnected %d, iceFailed %d, autoRestarts %d, autoRebuilds %d, iceRestarts %d",
+ sa.Status, sa.Notices, sa.Clients, sa.Stats["iceConnectedPeers"], sa.Stats["iceFailedPeers"],
+ sa.Stats["autoRestarts"], sa.Stats["autoRebuilds"], sa.Stats["iceRestarts"])
+ t.Logf("C: status %q, iceConnected %d, iceFailed %d, autoRestarts %d, autoRebuilds %d, mangled %d",
+ sc.Status, sc.Stats["iceConnectedPeers"], sc.Stats["iceFailedPeers"], sc.Stats["autoRestarts"],
+ sc.Stats["autoRebuilds"], sc.Stats["iceBlockMangled"])
+ if !recovered {
+ t.Fatalf("STUCK: %s after the block lifted, A still decodes nothing from C (A %+v)", limit, sa)
+ }
+ t.Logf("PASS recovered %s after the block lifted, with nobody acting", time.Since(blockedAt.Add(block)).Round(time.Second))
+ if strings.Contains(a.sample().Status, "could not connect") {
+ t.Fatalf("the failure notice outlived the recovery: %q", a.sample().Status)
+ }
+}
diff --git a/native/apple/Sources/CallsInterop/Interop.swift b/native/apple/Sources/CallsInterop/Interop.swift
index 3a61045..9b7ce8f 100644
--- a/native/apple/Sources/CallsInterop/Interop.swift
+++ b/native/apple/Sources/CallsInterop/Interop.swift
@@ -119,6 +119,11 @@ struct Input: Decodable {
}
// 0.4.1's motion sizing, without the H.264 level cap, for measuring it.
if ProcessInfo.processInfo.environment["CALLS_SCREEN_UNCAPPED"] == "1" { ScreenSendPolicy.levelCapped = false }
+ // The gate's ICE block (ICETestBlock) from the start, before any
+ // connection exists: a peer joining whose connections cannot come up.
+ if let ms = ProcessInfo.processInfo.environment["CALLS_TEST_ICE_BLOCK_MS"].flatMap(Double.init), ms > 0 {
+ call.blockICEForTest(ms: ms)
+ }
let preview = input.chatSnapshot.map { ChatPreview(call: call, path: $0) }
do {
try await call.join(
@@ -279,6 +284,13 @@ struct Input: Decodable {
fflush(stdout)
}
}
+ // Every candidate either way leads nowhere for this long.
+ if command.hasPrefix("ice-block ") {
+ let ms = Double(command.dropFirst("ice-block ".count)) ?? 0
+ await call.blockICEForTest(ms: ms)
+ print("{\"iceBlocked\":true}")
+ fflush(stdout)
+ }
if command == "screen-reshare-test" {
await call.reshareScreenForTest()
print("{\"reshared\":true}")
@@ -323,6 +335,14 @@ struct Input: Decodable {
"screenRecovery": call.screenRecovery,
// §15.23: "Reconnecting…" said for the call, and on how many tiles.
"reconnecting": call.reconnecting,
+ // The call's status line, word for word ("A participant's media
+ // could not connect." among them).
+ "status": call.status,
+ // What each remote tile says above the name, word for word.
+ "notices": Dictionary(
+ uniqueKeysWithValues: (call.state?.peers ?? []).filter { $0.peer != call.state?.peer }.map {
+ ($0.peer, call.levels.peer($0.peer).notices)
+ }),
"reconnectingPeers": call.reconnectingPeers.count,
"syntheticScreenFrames": Interop.screen?.produced ?? 0,
"cameraOpens": Interop.camera.opens,
diff --git a/native/apple/Sources/CallsKit/Call.swift b/native/apple/Sources/CallsKit/Call.swift
index 501feb0..5f51136 100644
--- a/native/apple/Sources/CallsKit/Call.swift
+++ b/native/apple/Sources/CallsKit/Call.swift
@@ -200,6 +200,9 @@ private final class Events: NSObject, BridgeListenerProtocol {
/// peer sampling, five times a second; the microphone warning waits on
/// it (MicSample.sending).
private var sendingAudio = false
+ /// Connections up, and connections in ICE `failed`, at the last look.
+ private var iceConnectedPeers = 0
+ private var iceFailedPeers = 0
/// The loudest remote sound since the gate last asked (sampleStats).
private var remotePeakSinceSample: Float = 0
private var micPeakSinceSample: Float = 0
@@ -708,6 +711,8 @@ private final class Events: NSObject, BridgeListenerProtocol {
let readings = await media.peerAudio(stats: stats, detail: detail, acks: acks)
guard levelWatch != nil, let state else { return }
sendingAudio = readings.values.contains { $0.connected }
+ iceConnectedPeers = readings.values.filter(\.connected).count
+ iceFailedPeers = readings.values.filter(\.failed).count
let me = state.peer
var present = Set<String>()
var people: [String: ReconnectWatch.Peer] = [:]
@@ -1218,6 +1223,11 @@ private final class Events: NSObject, BridgeListenerProtocol {
@_spi(Fixtures) public func freezeScreenWatchForTest(seconds: Double) {
screenWatchFrozenUntil = ProcessInfo.processInfo.systemUptime + seconds
}
+ /// For the gate: every ICE candidate this app sends or receives leads
+ /// nowhere for `ms` (ICETestBlock), so its connections fail.
+ @_spi(Fixtures) public func blockICEForTest(ms: Double) {
+ ICETestBlock.until = ProcessInfo.processInfo.systemUptime + max(0, ms) / 1000
+ }
/// For the gate's encoder stall (see MediaEngine).
@_spi(Fixtures) public func stallScreenEncoderForTest() { media.stallScreenEncoderForTest() }
/// For the gate: the watchdog's share again (spec §15.22), on demand.
@@ -1274,6 +1284,11 @@ private final class Events: NSObject, BridgeListenerProtocol {
values["screenWatchdogFailures"] = UInt64(screenWatchdog.failures)
values["screenReattaches"] = UInt64(screenReattaches)
values["iceRestarts"] = media.iceRestarts
+ // Connections up, and connections ICE has given up on, at the last
+ // look; and the gate's own ICE block (ICETestBlock).
+ values["iceConnectedPeers"] = UInt64(iceConnectedPeers)
+ values["iceFailedPeers"] = UInt64(iceFailedPeers)
+ values["iceBlockMangled"] = ICETestBlock.mangled
values["screenKeyframes"] = screenReport?.keyFramesEncoded ?? 0
if let capture = media.screenCaptureCounts {
values["screenCaptureHeartbeats"] = capture.heartbeats ?? 0
diff --git a/native/apple/Sources/CallsKit/ICETestBlock.swift b/native/apple/Sources/CallsKit/ICETestBlock.swift
new file mode 100644
index 0000000..b1268ce
--- /dev/null
+++ b/native/apple/Sources/CallsKit/ICETestBlock.swift
@@ -0,0 +1,41 @@
+import Foundation
+
+/// For the gate only: a connection's ICE made to fail, as a path that
+/// stops carrying anything does (2026-10-21's incident, a peer whose
+/// connection never came up).
+///
+/// While the block lasts every ICE candidate this app sends or receives —
+/// trickled, or written into a description — has its port replaced by 9,
+/// the discard port, which nothing on the gate's Mac listens on. Both ends
+/// then hold only candidates that lead nowhere, neither receives a check
+/// from the other (so neither can learn a peer-reflexive address), and ICE
+/// runs to `failed`. When the block lifts nothing is undone: the candidates
+/// already exchanged stay wrong, and only an ICE restart (new candidates)
+/// or a new connection gets the pair talking. That is the incident's shape.
+///
+/// Inert unless the interop harness sets `until`; the apps never do.
+enum ICETestBlock {
+ /// Until when (system uptime) candidates are mangled; 0 is never.
+ @MainActor static var until: Double = 0
+ /// Candidates mangled so far, for the gate.
+ @MainActor static var mangled: UInt64 = 0
+
+ @MainActor static var active: Bool { until > 0 && ProcessInfo.processInfo.systemUptime < until }
+
+ /// One candidate line, `candidate:…` or `a=candidate:…`, with its port
+ /// replaced. Anything that is not a candidate line comes back as it was.
+ static func mangle(candidate line: String) -> String {
+ var fields = line.split(separator: " ", omittingEmptySubsequences: false).map(String.init)
+ guard fields.count > 7, fields[0].hasPrefix("candidate:") || fields[0].hasPrefix("a=candidate:"),
+ fields[6] == "typ"
+ else { return line }
+ fields[5] = "9"
+ return fields.joined(separator: " ")
+ }
+
+ /// A description with every candidate line in it mangled.
+ static func mangle(sdp: String) -> String {
+ let lines = sdp.components(separatedBy: "\r\n")
+ return lines.map { $0.hasPrefix("a=candidate:") ? mangle(candidate: $0) : $0 }.joined(separator: "\r\n")
+ }
+}
diff --git a/native/apple/Sources/CallsKit/Media.swift b/native/apple/Sources/CallsKit/Media.swift
index 751f573..0b7f5a6 100644
--- a/native/apple/Sources/CallsKit/Media.swift
+++ b/native/apple/Sources/CallsKit/Media.swift
@@ -412,6 +412,7 @@ import LiveKitWebRTC
peak: peak, buffers: buffers, connected: state == .connected || state == .completed,
connectionBad: state == .disconnected || state == .failed)
reading.gone = state == .failed || state == .closed
+ reading.failed = state == .failed
if deep {
var bytes: UInt64 = 0
var packets: UInt64 = 0
@@ -516,6 +517,8 @@ struct PeerAudioReading: Equatable, Sendable {
var connectionBad = false
/// ICE `failed` or `closed`: whatever was heard on it is gone (§15.24).
var gone = false
+ /// ICE `failed`.
+ var failed = false
var bytes: UInt64?
/// Audio packets received, the receiver there at all, and its track
/// live (§15.24); read with `bytes`.
@@ -861,7 +864,7 @@ struct PeerAudioReading: Equatable, Sendable {
let desc = try await makeDescription(answer: false, restart: restart)
guard !closed else { return }
try await setLocal(desc)
- send("offer", ["description": ["type": "offer", "sdp": desc.sdp]])
+ send("offer", ["description": ["type": "offer", "sdp": Self.testBlocked(sdp: desc.sdp)]])
}
func receive(_ message: Message) {
guard message.gen == generation else { return }
@@ -885,23 +888,35 @@ struct PeerAudioReading: Equatable, Sendable {
self.ignoreOffer = collision && !self.polite
if self.ignoreOffer { return }
if collision { try await self.setLocal(RTCSessionDescription(type: .rollback, sdp: "")) }
- try await self.setRemote(RTCSessionDescription(type: .offer, sdp: desc.sdp))
+ try await self.setRemote(RTCSessionDescription(type: .offer, sdp: Self.testBlocked(sdp: desc.sdp)))
self.ignoreOffer = false
try await self.drain()
let answer = try await self.makeDescription(answer: true)
try await self.setLocal(answer)
- self.send("answer", ["description": ["type": "answer", "sdp": answer.sdp]])
+ self.send("answer", ["description": ["type": "answer", "sdp": Self.testBlocked(sdp: answer.sdp)]])
} else if message.type == "answer", desc.type == "answer", signaling == .haveLocalOffer {
- try await self.setRemote(RTCSessionDescription(type: .answer, sdp: desc.sdp))
+ try await self.setRemote(RTCSessionDescription(type: .answer, sdp: Self.testBlocked(sdp: desc.sdp)))
self.ignoreOffer = false
try await self.drain()
}
}
}
+ /// The gate's ICE block (ICETestBlock), on every candidate either way;
+ /// what it was otherwise.
+ private static func testBlocked(sdp: String) -> String {
+ guard ICETestBlock.active else { return sdp }
+ ICETestBlock.mangled += 1
+ return ICETestBlock.mangle(sdp: sdp)
+ }
+ private static func testBlocked(candidate: String) -> String {
+ guard ICETestBlock.active else { return candidate }
+ ICETestBlock.mangled += 1
+ return ICETestBlock.mangle(candidate: candidate)
+ }
private func add(_ candidate: Candidate) async throws {
guard let pc, !closed, !candidate.candidate.isEmpty else { return }
let ice = RTCIceCandidate(
- sdp: candidate.candidate, sdpMLineIndex: candidate.sdpMLineIndex ?? 0,
+ sdp: Self.testBlocked(candidate: candidate.candidate), sdpMLineIndex: candidate.sdpMLineIndex ?? 0,
sdpMid: candidate.sdpMid)
try await PeerCalls.add(pc, ice)
}
@@ -1020,7 +1035,7 @@ struct PeerAudioReading: Equatable, Sendable {
"candidate",
[
"candidate": [
- "candidate": candidate.sdp, "sdpMid": candidate.sdpMid as Any? ?? NSNull(),
+ "candidate": Self.testBlocked(candidate: candidate.sdp), "sdpMid": candidate.sdpMid as Any? ?? NSNull(),
"sdpMLineIndex": candidate.sdpMLineIndex,
]
])