Every engine that reads the flag (NativeNetworkingImpl for 7-9/12/13,
InstanceV2ReferenceImpl for 11, InstanceV2CompatImpl for 14, CallCoreHost for
18/19) now reads it with getCustomParameterBoolDefaultTrue: an absent key means
on, and only the server's explicit `false` turns it off, the same rollback
switch network_reference_use_addtrack has. Builds before this one keep reading
it as default-off, so the switch reaches only this build and later. The
legacy InstanceImpl (2.7.7, 5.0.0) still hardcodes it off.
Without it, signalled reflector connections are keyed by hostname while every
inbound reflector packet carries the server IP, so no binding response ever
reaches the connection that sent the ping: production logs show 3,469 such
pings with 0 responses on Android 11.0.0 and 8,120 with 0 on iOS 11.0.0, and
a reflector path can only start on a peer-reflexive twin once the peer pings
first.
Checked with the CLI in reflector mode against a local stand-in reflector
(the dev network blocks UDP to Telegram's reflectors; the stand-in routes by
tag and rewrites the tag to the receiver's, never touching the payload), 4-8
calls per arm on 11, 13, 14, 18 and 19, all established: with no key every
signalled reflector connection got its response and was selected first; with
`false` they got none and every call came up on a prflx twin, as before; a
mixed call with the flag on one side connects as before. Not exercised: the
documented key collapse for a peer with several reflector tags on one server
and port (one port per side here). CLAUDE.md records the default, the check
and that open item.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit c1de0882de)
WebRTC's own renegotiation requests (an ICE restart, a track change)
now wait for a quiet stable state like capture changes do, the same
line Android carries in 03d7b86. Measured neutral in the CLI (the four
negotiation scenarios, late cameras on either or both sides, mtproto,
30% signaling loss): the PeerConnection's signaling thread is the media
thread, so a stale event could never replace an in-flight offer; it only
merges a possible redundant offer round, and keeps this file identical
to Android's apart from mtproto and the audio-levels callback.
CLAUDE.md records that android-late-cam fails about one run in five
with or without this change, and why.
On dev/android this reverses 0dd2abe, which had switched this line back to
sendLocalDescription() to match development the same day development moved
to requestRenegotiation(); the two crossed on 2026-10-22.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit ea0f24e32f)
Review follow-ups to 8d5e7e0, which spread the network_sctp_* overrides to
11.0.0 and 18/19:
- fromCustomParameters keeps a value only in 1...60000 ms (RFC 4960's
RTO.Max). A negative value used to pass, and the socket factory then ran
dcsctp's own 1000/1000/3000 ms, neither the 400/400/750 ms defaults nor the
request, while the new log line printed the negative number. A
seconds-for-milliseconds slip (1500000) held the first INIT retransmission
for 25 minutes.
- getCustomParameterInt range-checks json11's double: int_value() is an
unchecked static_cast (undefined past int's range; INT_MAX on arm64,
INT_MIN on x86_64), and json11 parses a 10+ digit, fractional or exponent
number as a double. A number that does not fit an int now reads as absent;
fromCustomParameters is its only caller.
- SignalingSctpConnection's constructor takes Options with no default:
omitting it is how 11.0.0 and 18/19 silently ran the defaults. All four
callers already pass Options::fromCustomParameters.
- The Options field comments said "0 = use default"; a field <= 0 gets
dcsctp's default, not the signaling one.
- SignalingSctpOptionsTest (host cc_test, //submodules/TgVoipWebrtc:
signaling_sctp_options_test) pins absent, valid, per-key, zero, negative,
non-number, fractional, capped and beyond-int values. Before the fix it
failed the negative, over-cap and beyond-int cases.
CLI, 5 s fixed signaling delay, on 11, 13, 14, 18 and 19: overrides of
1500/1500/3000 still give retries 1.50 s then 3.00 s apart; -1 / 1500000 /
3e9 now keep the defaults (0.40 s, then every 0.75 s) and log
"t1_init 400 ms, t1_cookie 400 ms, max backoff 750 ms". The tgcalls host tests
and run-negotiation-tests.sh pass.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit c5ef736663)
network_sctp_t1_init_ms / _t1_cookie_ms / _max_backoff_ms were read only by
InstanceV2Impl. InstanceV2ReferenceImpl (11.0.0), InstanceV2CompatImpl (14.0.0)
and CallCoreHost (18.0.0/19.0.0) built their SignalingSctpConnection with the
defaults whatever the server sent. All four now take their options from
SignalingSctpConnection::Options::fromCustomParameters, which replaces
InstanceV2Impl's copy of the reading code. The defaults (400/400/750 ms) are
unchanged, and the timers are local, so no wire or interop change.
Each connection logs the values it runs with
("SignalingSctpConnection: initiator, t1_init 400 ms, ..."), so a call log
shows whether an override arrived.
On development (8d5e7e0), measured with the CLI, 5 s fixed signaling delay,
both sides asking for 1500/1500/3000 ms: the caller's INIT retries reach the
callee 1.50 s then 3.00 s apart on 11, 13, 14, 18 and 19 (before: 0.41, 0.75,
0.75 s on 11, 18 and 19); without overrides all keep 0.40 s, then every 0.75 s.
On this branch InstanceV2CompatImpl differs from development (it predates
development's c839645, which added the overrides there), so the change to it
is the one extra argument. Checked here by compiling the five changed files
from this branch's tree, with its own headers, against the iOS WebRTC tree;
not run in the CLI on this branch.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 8d5e7e0947)
14.0.0 carried two-way media in no pairing. 14 <-> 14: only the caller sent,
the data channel never opened, the second answer failed (BUNDLE); with video
the first answer failed (ssrc 0 demuxing). 14 -> 13: one sender. 13 -> 14: no
media at all. The CLI's p2p pass check (established + BWE) never noticed.
SignalingTranslator modelled one JSEP offer/answer per call with the caller
always offering. InstanceV2Impl's protocol is different, and CompatImpl now
implements it over the PeerConnection:
- Media is one-way channels; each side offers its own outgoing set (complete),
an answer echoes the offer's exchangeId and lists the offerer's channels it
accepted. Offer vs answer is decided by exchangeId, never by role; glare
follows 13.0.0 (caller ignores, callee rolls back, answers, offers again).
- Outgoing audio/video are kSendOnly transceivers (one video transceiver per
call, kInactive when the camera is off); remote channels get PeerConnection's
kRecvOnly transceivers under mids we choose (r<ssrc>).
- The data channel is never negotiated in 13.0.0 (SCTP 5000, stream 0), so it
is accepted in every synthesised description; data-channel text is parsed as
signaling, which is where 13.0.0 sends MediaState.
- MID/RID header extensions are stripped (mids are local; RtpDemuxer drops RTP
with an unknown MID); receive-only sections carry no ssrc; rejected m-lines
leave BUNDLE; DTLS setup is pinned by role in both directions; candidates use
an empty mid.
- Remote NegotiateChannels are classified on receipt and applied one at a time
while no SetLocal/RemoteDescription is in flight; InitialSetup is applied on
receipt (13.0.0 sends it after the answer that needs it - queueing it
deadlocked 14 -> 13).
- The caller holds its later offers until the callee's first offer (<= 10 s):
at 30% loss a 13.0.0 callee's audio offer crossed the caller's camera offer
and was dropped for good.
- Failed remote answers roll our offer back; failed local answers roll the
remote offer back; automatic re-offers stop after 3 consecutive failures.
Ported from InstanceV2ReferenceImpl's June-September fixes: ICE failed is not
terminal (caller RestartIce, 5 s throttle), 20 s watchdog from start, 2 s
Reconnecting debounce, baseline network record, onTransceiverRemoved by
receiver, network_reflector_resolve_remote_candidate_ip, network_use_mtproto
(DTLS-slot factory; a 14 <-> 13 call under the flag used to pair DTLS with
mtproto and fail). Not ported: network_reference_use_addtrack (wrong here) and
network_reference_allow_hostname_ice_servers (IsComplete() is already true
for hostnames).
tools/cli: --video-late (cameras via setVideoCapture mid-call, callee 3 s,
caller 5 s); p2p prints decoded video frames and remote media-state updates
per side.
Verified with tgcalls_cli, 8 runs per row: --delay 100-300 with --video and
--video-late 8/8 in 14<->14, 14->13, 13->14; 30% signaling loss 8/8 for
audio-only and --video in every pairing and for 14<->14 --video-late;
network_use_mtproto on both ends healthy in all three pairings with zero DTLS
handshakes. 14->13 --video-late at 30% loss is 5/8, each failure one
glare-ignored 13.0.0 offer; 13<->13 scores the same 5/8. Not exercised: the
caller's ICE restart (including a second InitialSetup). A pre-change 14.0.0
build gets no media with a post-change one.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
(cherry picked from commit c0b41396b8)
Already in dev/android (via 45fc400/120e384), left as is:
CLAUDE.md
tools/cli/CLAUDE.md
tools/cli/main.cpp
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A device log (2026-09-22) showed a tile frozen after its endpoint was
requested again: two endpoints received zero RTP for 9 s and 48 s while
every client-side step (transceiver, receive stream, demuxer entries,
sink proxy, constraints resent 3-4 times over a healthy data channel)
matched the earlier requests that worked. The fix for unsignaled
receive streams (a029775) held: none of its log signatures appear.
What differs from CustomImpl is the ReceiverVideoConstraints message.
ReferenceImpl sent minHeight = maxHeight = 90/180/360 from maxQuality
alone and no onStageEndpoints; CustomImpl sends minHeight from
minQuality and maxHeight from maxQuality on the 180/360/720 layer scale,
and puts Full endpoints on stage. The app always requests
minQuality .thumbnail and a .thumbnail max for most grid tiles, so this
engine asked for maxHeight 90, below the lowest simulcast layer. It now
sends CustomImpl's message, and logs the whole JSON instead of a count,
so the next such log shows exactly what was asked. Causation on the
production SFU is inferred: the log carried no requested qualities.
The testbench could not catch it. The Go SFU mapped heights on
ReferenceImpl's own scale (90/180/else) and emitted idealHeight on it,
and the harness always requested Full/Full. Now:
- go_sfu: heights map onto layerHeights {180, 360, 720}, and a positive
maxHeight below 180 forwards nothing (logged). Deliberately strict: a
client sending an off-scale height fails the run. A request that maps
to no layer also stops and removes the pair's LayerSelector; before,
forwarding continued on the surviving selector, because forwardRTP
prefers selectedLayer, so dropping an endpoint never stopped its
video at the SFU.
- cli: --video-quality thumbnail|medium|full requests that max with
minQuality Thumbnail, the app's shape.
Negative control: old engine + new SFU, --participants 0
--reference-participants 2 --video --video-quality thumbnail gives
Video received 0/2 (SFU logs maxHeight 90 refused). With the fix 2/2.
Also green: medium/full, mixed and custom-only thumbnail, mixed
default, early request, 6-participant re-request (0/30 stalled, both
default and thumbnail), sink churn, capture + own video, e2e,
step-down-up, group-churn, late unmute; go test ./...
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
(cherry picked from commit a024eaabf1)
Already in dev/android (via 45fc400/120e384), left as is:
CLAUDE.md
tools/cli/main.cpp
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
External (screencast) audio samples had two consumers that could run at
once. When createAudioDeviceModule() falls back to the FakeAudioDeviceModule
(no host audio device hook produced a module), its ExternalAudioRecorder
pumps _externalAudioSamples straight into the encoder; on iOS the
AudioInjectionPostProcessor added in 2d45feb was attached unconditionally
for Screencast as well, so both drained the same buffer and consecutive
10 ms chunks were summed into one frame.
Attach the post-processor only when a real, host-supplied device module is
the audio device. The decision is made after the module is created and
keyed on what was actually produced (a hook that returns nothing also falls
back to the fake module), not on which hooks are set.
FakeAudioDeviceModuleImpl's destructor now also calls StopRecording(): the
record loop is a detached thread calling Record() on the object, and
teardown previously relied on the owner having called Stop() first.
Part of the fix for bugs.telegram.org/c/22966 (iOS screen-share app audio
never reached other participants); the iOS half stops supplying the audio
device hooks for the screencast context so this fallback is reached.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 6397869a52)
Two production defects with one cause: a packet the network thread has
already handed to the worker when the worker tears down a receive
stream is received as an unknown SSRC, and WebRTC creates a default
("unsignaled") receive stream for it on a channel whose remote content
never changes again. That stream is never reset and keeps the SSRC's
binding in the Call's RtpDemuxer, so the m-line later negotiated for
the SSRC logs "Sink could not be added" and never receives a packet.
Video (device log 2026-09-18): after the app dropped all video
endpoints and requested them again on the same PeerConnection, one tile
stayed frozen while every decoded frame logged
"VideoReceiveStreamInterface not connected to a VideoSink". The factory
now gets its own FieldTrialsView (GRFieldTrials) that enables
WebRTC-Video-DiscardPacketsWithUnknownSsrc and resolves everything else
through tgcalls' shared FieldTrialBasedConfig; before, the engine
inherited the trial only if a CustomImpl call had run earlier in the
process.
Audio (found in the CLI while reproducing the above): the same race at
the first discovery renegotiation recreated an unsignaled stream on the
mid-0 catch-all right after WebRTC reset it. The participant stayed
audible through that stream, but the level sink on the dedicated
receiver never fired, so peers never saw them as speaking (2 of 6 level
sinks dead in a 3-participant run). The outgoing audio transceiver is
now sendonly (answered recvonly), the GRAudioFrameTransformer catch-all
is gone, discovery goes only through the un-demuxable-packet tap, and
the PeerConnection opts into the new vendored-webrtc seam
RTCConfiguration::disable_payload_type_demuxing. The seam is
load-bearing: without it the lone recvonly audio m-line becomes the
payload-type catch-all and a late unmuter is swallowed there
(--unmute-after scored 0/2). First remote audio now arrives ~280 ms
after the first packet (debounce plus one offer/answer), as with
CustomImpl.
CLI: --video-rerequest drops and re-requests every video endpoint five
times under a 150 ms SFU downlink delay and requires every sink to
receive frames past the count taken just before the re-request
(reproduces the frozen tile with --reference-participants 6: 1/30
stalled on the unfixed engine, both runs). Every group run now also
prints "Audio levels heard: X/Y pairs" (every peer must report a real
level for every unmuted sender) and "Unsignaled audio: N stream(s)
(must be 0)" (engine log scanned for the stream WebRTC creates on its
own; 6 for 3 reference participants before). Full sweep green: audio
3 and 6 reference participants, late unmute (reference and mixed),
mixed e2e with video, reference e2e, custom-only, early video request,
capture feeds, 6-participant re-request, group-churn, bandwidth
step-down scenarios.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit a029775032)
Already in dev/android (via 45fc400/120e384), left as is:
CLAUDE.md
tools/cli/CLAUDE.md
tools/cli/main.cpp
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A failed renegotiation CreateOffer or a failed buildRemoteAnswer returned
without completing the renegotiation, so _isRenegotiating stayed set and
every later renegotiation was deferred forever: a participant joining
afterwards never got a receive transceiver and stayed inaudible. Both
paths now post onRenegotiationComplete(), like the SLD/SRD failure paths.
Reviewed GroupInstanceReferenceImpl for the 18/19 start-glare class while
here: not affected (single offerer, locally built answer, serialised
renegotiation, camera swaps the track on a pre-created transceiver).
tools/cli: TGCALLS_CLI_KEEP_LOGS=1 keeps the per-participant group logs
of a passing run (they are written at stop and were always unlinked).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 783d3c03a2)
Already in dev/android (via 45fc400/120e384), left as is:
tools/cli/CLAUDE.md
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Group E2E: once a discovered SSRC has its own m-line, its frames demux to the
per-receiver FrameTransformer and OnUnDemuxableRtpPacket no longer fires for
them, so the per-frame userIdForSsrc lookup now re-asks (via
handleDiscoveredAudioSsrc, de-duped on the in-flight request) while the sender
is still unknown. This restores what the deleted ICE tap did for signaled SSRCs:
a description response that omitted the SSRC no longer leaves that participant
permanently undecryptable.
MtProtoDtlsTransport: SequenceChecker DCHECKs on every entry point; a
framing/encryption failure reports EMSGSIZE from GetError() instead of the ICE
channel's stale error (which RtpTransport reads as ENOTCONN); the never-read
remote fingerprint members are gone; comments say that an undecryptable packet
logs one "Bad incoming data hash" line rather than nothing.
Tests: flags never reach ICE; a failed ICE send propagates its result and
error; an encryption failure reports its own error and a later send clears it;
EncryptedConnection additional messages surface with their own framing; a
sub-4-byte frame surfaces as RTP-class.
CLAUDE.md: the both-ends-must-have-the-flag invariant is back with its new
asymmetric failure shape, and the expected log lines of a healthy mtproto call
(two UnencryptedRtpTransport, one incomplete-TLS-information per transport,
zero Bad incoming data hash) are listed.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 2c94eb6d1d)
Already in dev/android (via 45fc400/120e384), left as is:
CLAUDE.md
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RtpTransport already reports every packet RtpDemuxer drops; the vendored
webrtc now forwards that to PeerConnectionObserver::OnUnDemuxableRtpPacket
(tgcalls seam), parsed and SRTP-unprotected, on the network thread. The
reference group engine reads the SSRC there instead of inspecting every
inbound packet through the pass-through MtProtoIceTransport, which is deleted
along with its factory. The mid=0 catch-all frame transformer is unchanged.
tgcalls_cli --mode group --unmute-after keeps scoring 2/2.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 2f1c7a51a1)
network_use_mtproto now sets Options::external_transport_security and
PeerConnectionDependencies::dtls_transport_factory = MtProtoDtlsTransportFactory,
both from the one decision, instead of disable_encryption plus the ICE-level
decorator. Verified with tgcalls_cli loopback on 11.0.0, 18.0.0 and 19.0.0 with
mtproto on both ends: 4 SetLocalDescription, data channel OPEN_ACK, zero
rejected data sections, zero SCTP parse errors, zero DTLS handshake lines,
UnencryptedRtpTransport on both ends; plain calls unchanged.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 8717d34fb3)
A cricket::DtlsTransportInternal for PeerConnectionDependencies::
dtls_transport_factory (tgcalls seam in the vendored webrtc). It never
handshakes - the shared key exists before the call starts - and reports
kConnected the first time ICE is writable. Framing is byte-identical to
13.0.0's MtProtoPacketTransport with flags as ground truth in both directions
(PF_SRTP_BYPASS = RTP framed bare, 0 = SCTP with the 0xdcdcdcdc prefix), so
DcSctpTransport never parses media. SendPacket returns the caller's length.
The host test stacks a real webrtc::RtpTransport and webrtc::DcSctpTransport
over the transport: state/negotiation surface, framing both ways, wire parity,
stale-ENOTCONN ready-to-send, zero SCTP parse errors for received RTP.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 95340d2397)
WebRTC derives the send codec from the remote answer, and this engine
fabricates that answer itself, so the Opus ptime written in
buildRemoteAnswer is the frame duration we send. Nothing was written, so
the encoder used WebRTC's 20 ms default: ~50 packets/s, three times the
iOS CustomImpl (which requests 120 but is clamped to 60 because the iOS
build no longer defines WEBRTC_OPUS_SUPPORT_120MS_PTIME) and six times
Android and desktop, whose builds keep the define and send 120 ms frames.
In an SFU call every uplink packet is fanned out to all participants, so
the ~60 B of IP/UDP/RTP/SRTP per packet dominates: ~24 kbit/s at 20 ms
against ~8 kbit/s at 60 ms, for a voice stream of a few tens of kbit/s.
The answer now carries ptime=60 and maxptime=120, standard RFC 7587 SDP
that a server-produced answer can take over verbatim. 60 rather than 120
because it is what iOS custom participants have shipped since the 2024
Opus upgrade, needs no build flag, and keeps small conference calls
responsive; the step to 120 would save a further ~4 kbit/s for another
60 ms of delay and a 120 ms hole per lost packet. WebRTC's Audio Network
Adaptor is not a substitute: it adapts frame length to the sender's
uplink estimate, which cannot see the fan-out.
CLI: a reference participant fell from 476 to 170 audio RTP packets in a
10 s run, against 142 for a custom one in the same call; the encoder
config line reads ptime: 60. The mute check, both late-unmute
regressions and the encrypted mixed call still pass.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit ce91d4ff36)
GroupInstanceReferenceImpl muted by disabling the outgoing audio track only.
In WebRTC that reaches ChannelSend::SetInputMute, which zeroes the samples
but keeps encoding and sending, so a muted participant still emitted a full
Opus stream (~50 packets/s at level 0): invisible to every level-based check
and to the peers, but paid for by the SFU and every receiver. What actually
starts and stops the AudioSendStream is the sender's encodings[0].active
(WebRtcAudioSendStream::UpdateSendState); this vendored WebRTC starts the
stream even with no source, so detaching the track would not have helped.
GroupInstanceCustomImpl was never affected: its mute disables the channel.
applyOutgoingAudioMuteState() now toggles that flag through
GetParameters/SetParameters with no renegotiation, keeps the track disabled
so the AGC/level path still sees the mute, and applies the ADM microphone
mute as CustomImpl's onUpdatedIsMuted does - on iOS that is the system mute,
which also drives the muted-speech hint and which the reference engine had
never engaged. It also runs from start(), so the stream is stopped from the
first negotiation via the sender's init parameters. Stopping the only send
stream makes AudioState stop ADM recording, as CustomImpl's muted state
already does; the muted-speech detector lives in the audio unit, not the
recording path, so it is unaffected.
CLI: the Go SFU counts inbound audio RTP per SSRC (GoSfu_QuerySsrcPackets),
read just before teardown, and group validation adds "Muted audio leaks":
every participant that stayed muted must have sent none. A muted reference
participant sent 456 packets in a 10 s run before this change and 0 after;
the late-unmute regressions still score 2/2 with the reference participant
as the late unmuter, so unmute restarts the stream.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 2b700b0452)
Already in dev/android (via 45fc400/120e384), left as is:
CLAUDE.md
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bazel 9 removed the native cc_* rules, so the CLI target needs an
explicit load(). Also point the build docs at the version versions.json
pins (now 9.2.0) rather than a hardcoded 8.4.2, and drop the stale claim
that Bazel 9 is incompatible with this codebase.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit cf22c733cd)
Already in dev/android (via 45fc400/120e384), left as is:
CLAUDE.md
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A failing configureWebRTCSession: reported only an OSStatus, which cannot
distinguish the causes. Seen in a real log: the AVAudioSession route had no
inputs at all, so setPreferredInputNumberOfChannels failed with -50, and because
setConfiguration: treats a failed *preferred* attribute as fatal
(ignoresPreferredAttributeConfigurationErrors is NO) InitPlayOrRecord failed and
the shared device never started — silencing playout too, which needs no input.
Every retry repeated it and leaked an activation count (8 -> 23 in that log).
Dump category, options, mode, activation and WebRTC-session counts, record
permission, input availability, current and maximum channel counts, sample rate
and the full route on the failure path only, so the next occurrence says whether
the input is missing because of permission, because the category has none, or
because the system is not offering one.
Diagnostics only: no behaviour change. In particular the fatal-preference
handling is left alone until a log says why the input was missing.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 6ea1005160)
A participant who unmuted after the call had settled was inaudible to
GroupInstanceReferenceImpl for the rest of the call, and rejoining only
recovered whoever happened to be sending during the ~250 ms before the first
renegotiation — so rejoining a quiet room could give no audio at all.
The engine discovered audio SSRCs from a frame transformer on mid=0, which only
ever sees packets WebRTC was willing to route to the unsignaled catch-all.
SdpOfferAnswerHandler::UpdatePayloadTypeDemuxingState stops being willing as soon
as two *receiving* audio m-lines in a BUNDLE group advertise the same payload
type, and it also calls ResetUnsignaledRecvStream(). Every audio m-line here
advertises Opus 111 (sendrecv mid=0 plus one recvonly per remote SSRC), so the
FIRST discovery renegotiation disabled payload-type demuxing permanently. After
that an unknown SSRC had no MID extension (buildRemoteAnswer strips it), no SSRC
binding and no payload type to fall back on: RtpDemuxer dropped it, no receive
stream was created, and therefore no frame transformer could ever see it.
GroupInstanceCustomImpl was never affected — it receives all remote audio on one
channel, never adds a second m-line, and discovers from raw RTP in
GroupNetworkManager.
Discovery now happens where the packet is still visible: the ICE transport.
MtProtoIceTransport gains an optional IncomingPacketObserver, and its mtproto
encryption becomes optional — with no key it is a pure pass-through (packets and
flags untouched, so DTLS-SRTP above is unaffected) whose only job is the
observer. The group engine injects it that way and reads the SSRC from the
cleartext RTP header; SRTP encrypts the payload, not the header. With a key the
observer runs on the decrypted packet instead, so observation is a byproduct of
the decryption pass either way.
While encryption is on and the sender is still unknown the tap keeps reporting,
mirroring GRAudioFrameTransformer: a description response that omits the SSRC
would otherwise leave that participant permanently undecryptable, and past the
first renegotiation nothing else can ask again. The de-duplication set degrades
to reporting everything when full rather than to reporting nothing — going deaf
to new speakers is the failure this tap exists to remove.
Also register the LogSinkImpl. The constructor built one and the destructor
removed it, but nothing ever called AddLogToStream, so every reference-engine
call wrote a zero-byte log and none of this was diagnosable from a bug report.
An app-side roster (addSsrcs from the participant list) was implemented first and
rejected: this engine adds one recvonly m-line per SSRC and a voice chat's roster
runs to thousands.
CLI: --unmute-after unmutes mid-call while signalling nothing to the peers, and
validation requires every peer to report a real level for the late SSRC. It
scored 1/2 before this change and 2/2 after; the all-custom group and the same
late unmute with no prior renegotiation pass either way, which is what pins the
cause to the renegotiation rather than to the lateness.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 5f1c70c590)
Already in dev/android (via 45fc400/120e384), left as is:
CLAUDE.md
tools/cli/main.cpp
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The iOS wrapper hands the camera over as a VideoCaptureInterface
(descriptor.videoCapture when the camera is on at join, setVideoCapture for
requestVideo:/disableVideo:) and never calls setVideoSource; only the CLI
harness sets descriptor.getVideoSource. GroupInstanceReferenceImpl's
setVideoCapture was an empty stub and its ctor ignored descriptor.videoCapture,
so in a real group call the camera ran, the server marked the participant
video-on, and no frame was ever encoded (no SetVideoSend, the sendonly
transceiver stayed trackless). Route both wrapper paths through the shared
videoCaptureToGetVideoSource (moved out of GroupInstanceCustomImpl into
VideoCaptureInterfaceImpl so the engines cannot drift) and have setVideoSource
store/clear _getVideoSource, so a camera switched off before the join
handshake completes is not re-attached by addRemoteIceCandidates.
The app also hands the engine its full roster, itself included, both in
setRequestedVideoChannels and in addIncomingVideoOutput for the local tile,
and relies on the engine to know which entry is "me". Learn the own endpoint
from the join response's video.endpoint, drop it from everything sent to the
SFU (applyRequestedVideoChannels and the data-channel replay; filtered there
rather than at entry because the app's first request precedes the join
response) and feed own-endpoint sinks from the camera preview, exactly as
CustomImpl does. Before, the engine added a recvonly transceiver whose remote
SSRCs were its own outgoing ones, renegotiated, asked the SFU to loop its
video back, and hung the local tile's sink on a track that could never
receive.
Testbench: the fake platform's makeVideoSource/makeVideoCapturer returned
nullptr, which is why a no-op setVideoCapture went unnoticed; they now build
a FakeVideoCapturer (1280x720 @ 30 fps, tinted by deviceId) so the CLI can
drive engines through the app's VideoCaptureInterface path
(--video-via-capture at join, --video-via-capture-late after the join
response). --request-own-video appends the participant's own endpoint to
every request, the way the app does; validation asks the SFU afterwards
(new GoSfu_QueryRequestedLayer) whether anyone requested itself, and with a
capture feed requires the own-endpoint sink to have received preview frames.
Reference-only capture runs went 0/2 -> 2/2 video pairs, the self-request
count 1 -> 0; CustomImpl passes the same runs, which is what validates the
fake camera and the assertions. Full existing group regression set green.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 1b5aeeddc5)
Already in dev/android (via 45fc400/120e384), left as is:
CLAUDE.md
tools/cli/CLAUDE.md
tools/cli/main.cpp
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Companion to the Telegram-iOS shared-call-audio-device change
(ios_killswitch_disable_call_audio_device_fixes).
- AudioDeviceModuleIOS::StartPlayout/StartRecording unwind the audio device
buffer when the device fails to start and leave Playing() false. They
used to report Playing() == true after a failed AudioOutputUnitStart, so
every later start attempt skipped the device. StopPlayout resets the
flag, Terminate unwinds the module state, and Init() re-applies the last
tone (lastTone_) so a retry through Terminate()+Init() keeps the ringback.
- AudioDeviceIOS::Terminate releases a unit that was initialized but never
started (ShutdownPlayOrRecord). StopPlayout/StopRecording return early in
that state, which left an orphaned Voice-Processing unit and a configured
session behind a failed StartPlayout (seen 2026-09-04: -66637 on a fast
leave/rejoin, incoming audio silent for the whole call).
- RTCAudioSession.updateAudioSessionAfterEvent no longer calls the real
setActive:NO. It was the last real setActive: left in the file
(setActive:error: is already compiled out), is reached from
interruption-ended, media-services and app-became-active-while-interrupted,
and with the app's unbalanced activation count it deactivated the CallKit
session mid-call. Re-activation is kept. +setLegacyDeactivationEnabled:
restores the stock behaviour for the app's killswitch.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit b9e4a46d84)
The PeerConnection-based group engine ignored descriptor.e2eEncryptDecrypt, so a
conference routed to it sent plaintext and could not decrypt anything.
The frame layout is now shared rather than reimplemented: FrameTransformer, the
H264/VP8 plaintext-prefix helpers, ValidateEncryptedFrame and four free functions
move out of GroupInstanceCustomImpl.cpp into group/GroupFrameTransformer.{h,cpp},
and the RNNoise capture post-processor into
group/GroupAudioCapturePostProcessor.{h,cpp}. A conference can mix engines, so the
bytes must match CustomImpl exactly; group_frame_transformer_test pins the layout
(the Opus trailer, the one-byte strip when the extension flag is clear, the VP8 and
H264 prefixes, the 3-to-4 byte NAL start-code widening, the four-attempt retry).
The reference engine encrypts both senders and decrypts the per-receiver audio
transformer, each video endpoint's receiver, and the unsignaled-SSRC discovery tap.
Sender ids resolve per frame through a shared ssrc -> userId registry fed by the
requestMediaChannelDescriptions response the engine used to discard, because the
recvonly transceiver is added on a debounce that can precede that response.
Membership in the registry, not a userId value of 0, decides whether a sender is
known. An unresolved SSRC is re-asked, de-duped on the in-flight request as
CustomImpl does; the engine previously asked exactly once ever.
CustomImpl's capture post-processor is installed here too, so the level/speech
trailer carries a real measurement -- with encryption on that trailer is the only
way a CustomImpl peer learns we are speaking. It also makes the engine report the
ssrc-0 self level it never reported and makes setIsNoiseSuppressionEnabled work.
isConference is deliberately not consumed: it is unrelated to encryption and its
one effect in CustomImpl is to drop outgoing video to a single simulcast layer.
Adds --e2e to the CLI's group mode. Verified against a mixed CustomImpl/
ReferenceImpl testbench run; a wrong-userId negative control drives it to 0/2.
(cherry picked from commit 77b3e61675)
Already in dev/android (via 45fc400/120e384), left as is:
CLAUDE.md
tgcalls/group/GroupAudioCapturePostProcessor.cpp
tgcalls/group/GroupAudioCapturePostProcessor.h
tgcalls/group/GroupFrameTransformer.cpp
tgcalls/group/GroupFrameTransformer.h
tgcalls/group/GroupFrameTransformerTest.cpp
tgcalls/group/GroupInstanceCustomImpl.cpp
tgcalls/group/GroupInstanceReferenceImpl.cpp
tools/cli/main.cpp
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Four independent defects, each sufficient on its own to leave a remote
participant's video black, diagnosed from real-call logs and reproduced in
the CLI testbench before being fixed.
1. Renegotiation before the join answer. The app requests video for the
participants it already knows about right after emitJoinPayload. That
renegotiation ran while no transceiver had a mid yet, so CreateOffer
handed every m-line a fresh mid from PeerConnection's monotonic
generator (offer #1 = 0/1/2, re-offer = 3/4/5/6) and SetLocalDescription
rejected it ("order of m-lines in subsequent offer doesn't match").
Nothing retried: later identical requests hit the "endpoint already
known" early-continue. setRequestedVideoChannels now stores the full set
and defers until the join response is applied (onJoined), un-negotiated
endpoints are re-flagged, and renegotiate() refuses to run before join.
2. Constraints dropped on a connecting data channel.
sendReceiverVideoConstraints returned early while the channel was still
opening and nothing replayed it, so the SFU was never asked to forward
the video. onDataChannelStateChanged now resends the stored request.
3. Receive payload types. Group calls never negotiate payload types per
pair: every client sends with CustomImpl's table (VP8 100, VP9 102,
H264 104, RTX at +1). PeerConnection's receive table comes from the
local description, numbered by walking the platform factory's format
list; on iOS that put H265 on 104, so the remote's H264 was fed to the
H265 depacketizer and never decoded. mungeVideoCodecsInOffer pins the
convention on every video m-line of every local offer.
4. Sink lifetime. addIncomingVideoOutput registered the app's sink on the
receiver track by raw pointer and never removed it, although the app
only holds a weak reference because the tile view owning the sink is
recreated on every quality switch: use-after-free in
rtc::VideoBroadcaster::OnFrame on the next decoded frame. Each endpoint
now owns a GRVideoSinkProxy (weak sinks, per-frame lock and prune, the
shape of CustomImpl's VideoSinkImpl), the only object ever registered on
the track, attached once the track exists and detached on removal and
before Close().
Testbench:
- --early-video-request requests video right after emitJoinPayload, the
app's order; the SFU-driven request arrives ~500 ms after the data
channel opens and never exercised that path.
- FakeInterface advertises video formats in the iOS order by default so
PeerConnection's auto-assigned table matches the device's (the builtin
host order put an H264 profile on 104 by coincidence and masked
defect 3); --builtin-codec-order restores the raw order.
- --video-sink-churn replaces every incoming sink five times after frames
flow; segfaulted before defect 4's fix.
- requestVideoFromEndpoints resends the accumulated full request set,
since both engines drop endpoints missing from the list.
Known, not fixed: a host ReferenceImpl SENDER throttles to ~1-3 fps after
the first seconds (41-65 frames in 30 s vs ~750 from CustomImpl senders);
_minOutgoingVideoBitrateKbit is stored but never applied. Documented in
CLAUDE.md.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 278576fe18)
Already in dev/android (via 45fc400/120e384), left as is:
CLAUDE.md
tgcalls/group/GroupInstanceReferenceImpl.cpp
tgcalls/platform/fake/FakeInterface.cpp
tgcalls/platform/fake/FakeInterface.h
tools/cli/CLAUDE.md
tools/cli/main.cpp
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
03d7b86 routed onRenegotiationNeeded through requestRenegotiation(). With
a6ae18b folding the initial camera into the first offer and deferring
capture renegotiation, development keeps the direct sendLocalDescription()
here; match it to keep the diff against development minimal.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CallCoreHost re-applied descriptor.videoCapture after the core's start had
set _didBeginNegotiation, and the core's video_capture handler offered
unconditionally. In every video call the caller issued a second
CreateOffer while the first was in flight (SetLocalDescription failed)
and the callee sent an unsolicited offer; the caller applied the colliding
offer, rolled its first offer back, and WebRTC's orphaned sctp_mid wedged
the call in an endless offer/answer loop (one round per signaling RTT,
video send stream stopped twice and audio channel flapped per round).
Production: 32 of 39 v19 video calls in the 2026-09-17 not_inited sample,
and the arm's shorter call durations in the A/B.
- host passes config.hasInitialVideoCapture; the core adds video0 in
start, before the initial offer (stock ordering:
InstanceV2ReferenceImpl.cpp:843 precedes beginSignaling at :872), and
the host re-applies the capture only if the core did not add video0.
- core video_capture handler and native setVideoCapture go through
requestRenegotiation(): offer only from a quiet stable state, otherwise
defer to flushPendingRenegotiation() after each SLD/SRD.
- tools/cli: --video now attaches a capture to both p2p descriptors, the
shape that reproduces the loop (19/19: 96 SLD in 8 s -> 4 after).
Needs the webrtc seam "release an unnegotiated sctp_mid on rollback" as
the backstop for any future glare.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit a6ae18bc08)
Conflicts resolved towards development:
- InstanceV2ReferenceImpl.cpp: 03d7b86 already carried this logic; its
copy of requestRenegotiation()/flushPendingRenegotiation() is replaced by
this commit's (development's placement and comments). setVideoCapture()
keeps the _immediateCaptureRenegotiation branch, as in development.
onRenegotiationNeeded() still goes through requestRenegotiation() (03d7b86).
- tools/cli/main.cpp: kept HEAD, already identical to development.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two defects shared by every InstanceV2ReferenceImpl build, found in the
2026-10-11 Android log sample (getlogstgcalls/analysis/FINDINGS-android.md).
- Every call took two offer/answer rounds: both sides pre-create their audio
transceiver with AddTransceiver, which FindAvailableTransceiverToReceive never
associates with the caller's m=0, so the callee answered recvonly and
re-offered its audio as a new m-section. network_reference_use_addtrack is
now default on and covers the camera (addSendTransceiver): 2
SetLocalDescription per call instead of 4, the callee's answer sendrecv, no
glare window on every call. SetCodecPreferences is skipped on a transceiver
AddTrack reused (it already has a mid; the peer negotiated its codec list).
- A rejected answer ("order of m-lines", the offer was replaced in flight) left
the caller without a DTLS role, and it then answered the callee's colliding
offer as a second DTLS client: handshake failure on a connected ICE path,
every later SDP "Failed to set SSL role", no recovery (43 of 200 Android
calls). sendLocalDescription() remembers that the peer answered setup:active
and, when answering an offer in that state, sets passive on the created
answer's transport descriptions and applies it from the CreateAnswer
callback on the signaling thread, so nothing can land in between.
tools/cli: --video-late-caller-ms / --video-late-callee-ms attach one side's
camera N ms after start; network_reference_immediate_capture_renegotiation
(read only under TGCALLS_ALLOW_TEST_KNOBS, a CLI-only define) restores the
pre-2026-09-17 immediate offer so run-negotiation-tests.sh reproduces the
Android chain in-process. All four scenarios failed before and pass after;
mixed old/new pairings, mid-call cameras, mtproto and 30% signaling loss
checked.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Live streams were silent on most third-party Bluetooth A2DP devices while
AirPods and the built-in speaker played fine. The broadcast path mixes the
decoded 48 kHz stream into the audio device's render buffer in
AudioDeviceDataObserverShared::mixAudio, resampling to the hardware rate
with the legacy webrtc::Resampler. That resampler only accepts a fixed
table of integer ratios; 48000 -> 44100 reduces to 160:147, Reset()
returned -1, the code nulled the resampler and silently skipped the mix.
AirPods and the built-in speaker run at 48 kHz (1:1), which is why only
other devices failed. RTC calls never hit this: AudioTransportImpl already
resamples with PushResampler.
Move the resampling into a StreamingAudioRenderer that takes an injected
source, and build it on webrtc::PushResampler<int16_t>, which handles any
ratio and degrades to a copy at 1:1. It refuses anything that is not one
10 ms block, since the sinc stage aborts on a wrong size, and logs instead
of dropping audio quietly. mixAudio now just wraps getAudio in a lambda.
StreamingAudioRendererTest.cpp covers 44.1 kHz stereo, 16 kHz mono, the
48 kHz pass-through, a rate change between calls, and the wrong-size
refusal; the 44.1 kHz and wrong-size cases failed against the legacy code
before the swap. The test is excluded from Package.swift so SwiftPM does
not compile its main().
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QbYZpmQDD1pxbkKYFhB3z8
network_use_mtproto now does real work on InstanceV2ReferenceImpl and
CallCoreHost, producing the same wire bytes as 13.0.0 so an A/B measures the
engine substrate rather than the transport. Default off.
MtProtoIceTransport decorates a real P2PTransportChannel and applies
EncryptedConnection above ICE, injected through the public
ice_transport_factory. Paired with Options::disable_encryption, which makes
JsepTransportController build a plain RtpTransport and stops DTLS entirely, the
stack becomes mtproto -> inactive DtlsTransport passthrough -> RtpTransport:
media is mtproto(RTP) and the data channel mtproto(SCTP), with no DTLS
handshake, matching 13.0.0's MtProtoPacketTransport. STUN stays clear because
the decorator sits above the ICE agent, so reflector and candidate machinery are
untouched.
Requires the "Allow SCTP without DTLS" patch in the vendored webrtc fork:
disable_encryption also makes DtlsEnabled() false, and upstream only creates an
SCTP factory when DTLS is on, which otherwise destroys the data channel and
prevents any call from connecting.
13.0.0 selects its 0xdcdcdcdc SCTP prefix from `flags`, but the inactive
DtlsTransport drops that on send and DCHECKs flags == 0 on receive, so the type
is inferred with InferRtpPacketType and packets always surface with flags 0.
The 11 signal/callback bridges are not compiler-enforced - omitting one fails
silently at runtime - so they live in a single installBridges() method and are
covered by 12 conformance tests, verified to discriminate (13 assertion failures
before the bridges existed, 0 after). The tests are framework-free, since this
repo vendors no googletest.
Verified end to end on p2p calls: 11.0.0 and 18.0.0 both establish with mtproto
on, DTLS handshake log lines drop 45 -> 0, UnencryptedRtpTransport replaces
DtlsSrtpTransport, the data channel reports no failures, 13.0.0 mtproto is
unregressed, both baselines still connect, and an asymmetric flag fails closed.
Design and invariants are in tgcalls/CLAUDE.md.
The fail-fast behaviour was already in place: the core turns a "pc_create"
error event into updateNetworkState(false, true) (ReferenceCallCore.cpp),
so 18/19 does not wait out the 20s watchdog. Two things were still out of
sync with InstanceV2ReferenceImpl::start().
Return immediately. The host fell through to applyAudioProcessingConfig,
which with no _audioProcessing emits a SECOND "pc_create" error event -
harmless, since updateNetworkState(false, true) is idempotent, but it
replaces the first event's diagnostics with a generic "no audio processing"
- and with one would configure audio for a peer connection that does not
exist. Stock returns; now so does this.
Carry the underlying error message. Stock logs
peerConnectionOrError.error().message(); the host emitted a bare
"CreatePeerConnectionOrError failed" with no cause. That matters more here
than in stock, because this string is the only diagnostic that crosses the
ABI into the core's log. Note RTCError::message() returns const char*, so
the concatenation needs an explicit std::string - stock only gets away with
the bare expression because it streams via <<.
Verified with //submodules/TgVoipWebrtc/tgcalls/tools/cli:tgcalls_cli
(exit 0, CallCoreHost.cpp recompiled).
Allow hostname ICE servers in 11.0.0 (gated, default on). SocketAddress is
only "complete" for IP literals, so every TURN/STUN server given as a DNS
name - which is how Cloudflare TURN is configured - was discarded. With
enableP2P false (kRelay) and TCP candidates disabled, a hostname-only server
set gathers zero candidates and the call can never connect. HostAsURIString()
already returns a non-literal host unchanged and brackets IPv6 literals, and
ParseIceServersOrError resolves names itself, so lifting the gate is all that
is needed. Reflectors stay exempt: ReflectorRelayPortFactory matches the
allocator's relay address by SocketAddress equality and cannot match an
unresolved hostname, so it would return no port at all.
Gated on network_reference_allow_hostname_ice_servers, which defaults to ON -
an explicit `false` from the server is the rollback switch. That needed a
default-true custom-parameter helper next to the default-false one; the header
now documents which default suits which kind of flag.
Skip the send when gzip fails in 11.0.0. packetData was left empty, then
encrypted and sent anyway; the peer drops it after decrypt/JSON-parse. If the
dropped message was the offer or answer, the call silently never connects.
18/19 already returns in this case (SignalingFraming), which is what this
mirrors.
Fix the mis-keyed incoming-video-transceiver removal in 11.0.0 AND 18/19.
_incomingVideoTransceivers is keyed by mid, but RtpReceiverInterface exposes
no mid() and the lookup used receiver->track()->id() - the TRACK id - so it
never matched and entries were never erased. Search by receiver instead.
Remove the dead sendCandidate from InstanceV2ReferenceImpl: it has no callers.
InstanceV2Impl's identically-named copy IS called and is untouched.
Verified with //submodules/TgVoipWebrtc/tgcalls/tools/cli:tgcalls_cli
(2074 actions, 2072 local, exit 0).
The reflector keying flag was previously read only by NativeNetworkingImpl
(InstanceV2Impl, call versions 7/8/9/12/13), while InstanceV2ReferenceImpl
(10/11) and CallCoreHost (18/19) passed a literal false - so those engines
carried the keying bug with no way to test the fix. Both now read the
parameter; it stays default-off everywhere.
ReferenceCallCore's pc_renegotiation_needed handler lacked the _isMakingOffer
guard that InstanceV2ReferenceImpl and InstanceV2CompatImpl already have, so
every outgoing 18/19 call issued a duplicate startup offer. Verified: an
18.0.0 p2p call now logs one suppression.
NOT included - network_use_mtproto. MtProtoRtpTransport is a webrtc::RtpTransport
that NativeNetworkingImpl builds directly on the ICE transport. The three
PeerConnection-based engines cannot use it: JsepTransportController creates the
RtpTransport internally (pc/jsep_transport_controller.cc:1083/1087) and exposes
no injection point, so supporting it there requires patching vendored libwebrtc.
NOT included - AddTrack for 18/19. It would need a new pc_add_track ABI command,
and production A/B shows the fix has no measurable effect: every v11_addtrack
delta sits at or below the noise floor set by the v11_mtproto arm, which was
itself a no-op for the reason above.
Records the July 2026 engine audit alongside the 2026-08-19 adversarial
re-analysis that refuted six of its findings, the fixes that landed, the three
default-off experiment flags and their reach, the gate on the reflector flag,
the 12.0.0 release-coordination requirement, and the audit proposals that must
not be implemented.
InstanceV2CompatImpl gets the SDP-observer error handling and the
PeerConnection-creation failure handling its sibling already had - 14.0.0
otherwise retained the same renegotiation deadlock and null dereferences.
network_disable_stun_when_unconfigured (default off, A/B engines only):
PeerConnection forces PORTALLOCATOR_ENABLE_SHARED_SOCKET on every allocator,
which promotes each UDP relay into the STUN server set and sends it Binding
Requests a reflector cannot parse. Pre-setting PORTALLOCATOR_DISABLE_STUN works
because InitializePortAllocator_n ORs onto the allocator's existing flags.
network_reference_use_addtrack (default off, 11.0.0 only): created_by_addtrack()
is set only on the AddTrack path and FindAvailableTransceiverToReceive requires
it, so a callee could not associate its own transceiver with the offerer's m=
section and minted a fresh recvonly one - costing a full extra offer/answer.
Audio only; AddTrack reuse is once-only so it would not cure m-line growth on
the renegotiated video path. The association gate runs on the side applying a
remote offer, so an upgraded callee alone fixes the round trip.
Also completes the wasm state-semantics port with the 2s disconnect debounce
and the _isFailed guard in maybeRestartIce.
CreateConnection resolved the remote candidate's IP only on TCP while the
inbound path always resolves, so on UDP the signalled connection and inbound
packets were permanently distinct keys in Port::connections_ - both operator<
and EqualIPs compare IP first. A binding response from an unmatched address is
dropped, so the signalled connection never saw one and the path could only
bootstrap when the peer pinged first. Measured: 749 signalled relay connections
sent 15,985 pings and received zero responses.
Behind network_reflector_resolve_remote_candidate_ip, default off, read only by
NativeNetworkingImpl. Includes a collision guard: once resolved, the key can
collide with a peer-reflexive connection for the same path, and
AddOrReplaceConnection would destroy that live connection. Upstream's own
pre-check uses the unresolved address, so it does not dedupe our resolved key -
the guard is load-bearing, not redundant.
Readout is relay-remote connections receiving binding responses, NOT prflx
going to zero. See CLAUDE.md for the dual-stack gate before enabling.
_networkStateLogRecords was written only on state transitions and start()
emitted no baseline, so ~77% of failing 11.0.0 calls uploaded "network": [].
The treatment arm's telemetry was systematically poorer than the control's,
which corrupts whatever the A/B reads. InstanceV2Impl::start() already ends
with such an emission.
The wasm cores (18.0.0/19.0.0) mapped a transient ICE 'failed' straight to a
terminal failed state and had no watchdog, no disconnect debounce and no ICE
restart, so the A/B that claims to isolate the substrate alone was also varying
state semantics. Uses the existing set_timer/timer/pc_restart_ice ABI; timers
carry a generation counter because set_timer does not cancel a prior timer of
the same token, and the host now echoes that field back.
Video sinks: _currentStrongSink was registered as a raw pointer with
VideoTrack::AddOrUpdateSink, which stores it unowned in VideoBroadcaster, and
RemoveSink was never called anywhere. Dropping the strong reference left a
dangling pointer that OnFrame dispatches through on the video decode thread.
Removal is tracked to be exactly symmetric with attachment, because
VideoSourceBase::RemoveSink asserts the sink was added and that assertion is
live in -c dbg builds.
CreatePeerConnectionOrError's failure was swallowed - no else, no early return
- after which thirteen sites dereferenced a null _peerConnection and start()
armed two self-rescheduling timers. Also guards stop() and setVideoCapture(),
the latter reachable from the public Instance interface after a failed start.
Every outgoing call issued two startup offers: CreateDataChannelOrError fires
OnRenegotiationNeeded synchronously and the adapter posts it, so it landed
after beginSignaling() had already offered. 15.3% of gzipped outbound
signalling bytes, injected into the SCTP association during setup.
Both SDP observer completions bound webrtc::RTCError and never read it, so the
success path ran on failure. A failed SetRemoteDescription(offer) left
signaling state kStable and the completion still called sendLocalDescription(),
whose implicit overload then picks OFFER - sending an offer where the peer
awaits an answer, deadlocking renegotiation for the rest of the call.
The test CLI could only ever set wasm_core_path in customParameters, so no
engine custom parameter could be exercised. Merges an arbitrary JSON object
from the new flags with the synthesised wasm_core_path entry; with neither
flag passed the value stays empty exactly as before.
The destructor deleted socket_ and then called socket_->UnsubscribeCloseEvent,
which mutates the socket's callback list. SharedSocket() is always false for a
TCP ReflectorPort, so the delete always ran. Adopts the stock TurnPort order:
unsubscribe first, guarded on socket_, then delete.
Close() walked connections() while Connection::Destroy() erased from that same
map. Uses Port::DestroyAllConnections() instead. Close() has no live caller
today; this hardens it for one.
getCustomParameterBool/Int existed as two identical anonymous-namespace
copies. Hoists them into v2/CustomParameters.h and deletes both.
InstanceV2ReferenceImpl, InstanceV2CompatImpl and CallCoreHost all received
Descriptor::config::customParameters and never parsed it, so no custom
parameter was readable in any of them. No behaviour change.
Replaces 10.0.0-pump/11.0.0-pump with two production versions so a
server-side A/B can compare substrates: 18.0.0 runs the call core natively,
19.0.0 runs the same source as a wasm module embedded in the binary. One
class declares both, so they share the Instance shell and CallCoreHost
verbatim and differ only in which backend CallCoreHost constructs — that is
what makes the comparison attributable to the substrate and nothing else.
Substrate is derived from the negotiated version string rather than from
configuration, so neither an app-side nor a server-side mistake can put a
19.0.0 call on the native core and quietly corrupt the A/B.
WamrCoreBackend gains a bytes constructor and now has one load path with two
ways of filling _moduleBytes: the module linked into the binary
(EmbeddedCoreModule.h, generated by the parent repo's genrule), or a file.
The file loader and customParameters.wasm_core_path exist only under
TGCALLS_ALLOW_EXTERNAL_WASM_CORE, set on the CLI target alone: that key
arrives from the server, so shipping it would be a remote-code-execution
surface — WAMR bounds the module's memory, but the module drives negotiation
and signaling through its host imports. With no filesystem-loading code
linked in, the shipped binary can only execute bytes linked into it.
V1 signaling framing is deleted. Both shipped versions are wire 11.0.0, so
the V1 reliability layer (seq flag bits, message packing, acks, resends,
service packets) was unreachable and unexercised; V2 needs none of it
because the transport underneath is reliable, exactly as in stock. Gone with
it: the wireVersion config field, the service-timer wiring and
sendSignalingKeepalive hook, VariantCallCore's keepalive demo, and
tools/parity/p2_framing.py. The C ABI is unchanged — set_timer/timer remain,
used by the stats tick — so no version bump. The reference module shrinks
92741 -> 82162 bytes.
Validated on the CLI: P1 offer/answer MATCH for 18-vs-stock, 19-vs-stock and
18-vs-19; W1-W4, W7-W8 and NR1-NR3 all exit 0 including both 30% drop /
50-200ms delay rows; a corrupt module fails the call (caller Failed, exit 1)
with no fallback to native; the variant module still loads via --wasm-core.
Squashed from 4 commits.
Ports InstanceV2ReferenceImpl's control logic out into a self-contained
"call core" that runs either natively or as a runtime-loaded WASM module
(WAMR), so call behavior can change without shipping a new binary.
- CallCoreABI.h: frozen ABI v1, shaped as a PeerConnection projection —
SDP munge point, transceiver/parameter/ICE-restart commands, observer
events, curated rich stats (pc_get_stats).
- CallCoreHost: fixed host harness executing core commands against the
real PeerConnection. NativeCoreBackend / WamrCoreBackend select the
core at runtime (--wasm-core); per-module createModuleCore factory seam.
- ReferenceCallCore: stock-parity control logic behind the ABI.
VariantCallCore: demo core showing behavior changes (fmtp munge,
adaptive bitrate cap, periodic ICE restart), shipped as wasm only.
- InstanceV2PumpImpl: pump instance registered as 10.0.0-pump/11.0.0-pump.
- Protocol substrate: SignalingFraming ports EncryptedConnection
reliability (V1) and gzip framing (V2) into the core, so the host
boundary is raw signaling packets (seal/open only); N labeled data
channels with binary payloads; audio-processing and PeerConnection
config knobs.
- Compression is a host service (env.host_deflate/env.host_inflate)
rather than vendored miniz, keeping the wasm modules small and making
compressed bytes match stock exactly.
- tools/cli: --log-file. tools/parity: P1/P2 wire-parity scripts.
Squashed from the tgcalls-wasm-core-sketch branch (31 commits).
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>