fix: (Mobile) Voice calls failing when accepted from the lock screen - #40422
Conversation
|
Looks like this PR is ready to merge! 🎉 |
🦋 Changeset detectedLatest commit: 3539af6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 43 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughThis PR fixes a soft lock in call negotiation initialization by introducing a new ChangesCall Negotiation Soft Lock Fix
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Suggested labels
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #40422 +/- ##
===========================================
- Coverage 70.00% 69.93% -0.08%
===========================================
Files 3298 3307 +9
Lines 120067 120581 +514
Branches 21538 21629 +91
===========================================
+ Hits 84049 84323 +274
- Misses 32741 32967 +226
- Partials 3277 3291 +14
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/media-signaling/src/definition/call/IClientMediaCall.ts (1)
25-34:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winAdd
'timeout-local-track'to theclientMediaSignalHangupSchemaenum.The
CallHangupReasontype at IClientMediaCall.ts includes'timeout-local-track', but the corresponding schema at packages/media-signaling/src/definition/signals/client/hangup.ts (line 33-51) does not include this variant in its enum. The inline contract at line 25 of IClientMediaCall.ts explicitly requires this synchronization. Without it, hangup signals carrying'timeout-local-track'will be rejected by schema validation at runtime.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/media-signaling/src/definition/call/IClientMediaCall.ts` around lines 25 - 34, CallHangupReason includes 'timeout-local-track' but the runtime schema enum (clientMediaSignalHangupSchema) is missing that variant; update the enum in clientMediaSignalHangupSchema (the enum definition in the hangup signal schema) to include 'timeout-local-track' so the schema matches the CallHangupReason type and will accept hangup signals with that reason.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@packages/media-signaling/src/definition/call/IClientMediaCall.ts`:
- Around line 25-34: CallHangupReason includes 'timeout-local-track' but the
runtime schema enum (clientMediaSignalHangupSchema) is missing that variant;
update the enum in clientMediaSignalHangupSchema (the enum definition in the
hangup signal schema) to include 'timeout-local-track' so the schema matches the
CallHangupReason type and will accept hangup signals with that reason.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 59daee12-1f5e-47e8-8540-f13f7fb3d855
📒 Files selected for processing (7)
.changeset/fluffy-poets-check.mdpackages/media-signaling/src/definition/call/IClientMediaCall.tspackages/media-signaling/src/definition/client.tspackages/media-signaling/src/definition/services/negotiation.tspackages/media-signaling/src/lib/Call.tspackages/media-signaling/src/lib/NegotiationManager.tspackages/media-signaling/src/lib/Session.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: 📦 Track Image Sizes
- GitHub Check: 🔎 Code Check / Code Lint
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}
📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)
**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation
Files:
packages/media-signaling/src/definition/call/IClientMediaCall.tspackages/media-signaling/src/lib/NegotiationManager.tspackages/media-signaling/src/definition/client.tspackages/media-signaling/src/definition/services/negotiation.tspackages/media-signaling/src/lib/Session.tspackages/media-signaling/src/lib/Call.ts
🧠 Learnings (4)
📚 Learning: 2026-03-16T21:50:37.589Z
Learnt from: amitb0ra
Repo: RocketChat/Rocket.Chat PR: 39676
File: .changeset/migrate-users-register-openapi.md:3-3
Timestamp: 2026-03-16T21:50:37.589Z
Learning: For changes related to OpenAPI migrations in Rocket.Chat/OpenAPI, when removing endpoint types and validators from rocket.chat/rest-typings (e.g., UserRegisterParamsPOST, /v1/users.register) document this as a minor changeset (not breaking) per RocketChat/Rocket.Chat-Open-API#150 Rule 7. Note that the endpoint type is re-exposed via a module augmentation .d.ts in the consuming package (e.g., packages/web-ui-registration/src/users-register.d.ts). In reviews, ensure the changeset clearly states: this is a non-breaking change, the major version should not be bumped, and the changeset reflects a minor version bump. Do not treat this as a breaking change during OpenAPI migrations.
Applied to files:
.changeset/fluffy-poets-check.md
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.
Applied to files:
packages/media-signaling/src/definition/call/IClientMediaCall.tspackages/media-signaling/src/lib/NegotiationManager.tspackages/media-signaling/src/definition/client.tspackages/media-signaling/src/definition/services/negotiation.tspackages/media-signaling/src/lib/Session.tspackages/media-signaling/src/lib/Call.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.
Applied to files:
packages/media-signaling/src/definition/call/IClientMediaCall.tspackages/media-signaling/src/lib/NegotiationManager.tspackages/media-signaling/src/definition/client.tspackages/media-signaling/src/definition/services/negotiation.tspackages/media-signaling/src/lib/Session.tspackages/media-signaling/src/lib/Call.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.
Applied to files:
packages/media-signaling/src/definition/call/IClientMediaCall.tspackages/media-signaling/src/lib/NegotiationManager.tspackages/media-signaling/src/definition/client.tspackages/media-signaling/src/definition/services/negotiation.tspackages/media-signaling/src/lib/Session.tspackages/media-signaling/src/lib/Call.ts
🔇 Additional comments (10)
.changeset/fluffy-poets-check.md (1)
1-6: LGTM!The minor bump is appropriate — the PR adds additive surface area to
@rocket.chat/media-signaling(new public methods, a new event, and new union variants).packages/media-signaling/src/definition/services/negotiation.ts (1)
7-7: LGTM!New
negotiation-startedevent slot added cleanly; producer (NegotiationManager.processNegotiation) and consumer (Call.onNegotiationStarted) are wired consistently.packages/media-signaling/src/definition/client.ts (1)
5-5: LGTM!The
waiting-for-trackstate slots logically betweenacceptingandwaiting-for-offer, matching the new lifecycle introduced inCall.getClientStateand timeout mapping.packages/media-signaling/src/lib/NegotiationManager.ts (1)
232-240: LGTM!
negotiation-startedis emitted right after the fire-and-forgetprocess()call, which is fine since the only consumer (Call.onNegotiationStarted) just refreshes client state. The visibility bump onisConfigured()is the minimum needed to expose it toCall.getClientState, and thethis is WebRTCNegotiationManagertype-guard return is preserved.packages/media-signaling/src/lib/Call.ts (3)
513-516: LGTM — the new branch correctly closes the soft-lock window.When the call is
acceptedbutnegotiationManager.isConfigured()is false (most commonly because no input track is available yet), reportingwaiting-for-trackletsupdateClientStateinstall the dedicatedTIMEOUT_TO_PROGRESS_SIGNALINGtimer with atimeout-local-trackhangup reason. Once the track arrives andsetInputTrackinvokesupdateClientState+processNegotiations, the state advances cleanly towaiting-for-offerand then togenerating-local-sdpvia the newnegotiation-startednotification.
556-559: LGTM — ordering matches the fix intent.Calling
updateClientState()beforeprocessNegotiations()ensures the state moves out ofwaiting-for-trackfirst; otherwise the listener-drivennegotiation-startedcallback would race with stale timeouts still bound towaiting-for-track.
1378-1381: LGTM!
onNegotiationStartedsimply forwards intoupdateClientState, which is the right place to consume the new lifecycle event — the negotiation manager has already setcurrentNegotiationby the time this fires, sogetClientStatewill advance pastwaiting-for-offer.packages/media-signaling/src/lib/Session.ts (3)
438-446: LGTM — this matches the PR's root-cause fix.The previous flow flipped an "updating" flag before the async work completed (even when no work was needed), which caused the lock-screen-accept race. The new shape keeps
requestInputTrackUpdateas a cheap, synchronous early-bail and only enters the guardedswitchInputTrack(withswitchingInputTrack=true) when an actual switch is required. The doubleshouldSwitchInputTrack()check (here and insideswitchInputTrack) correctly handles state changes between scheduling and execution.
489-513: LGTM!
shouldStartInputTrackcorrectly accounts for thecallsToGetUserMediain-flight counter so retries while agetUserMediais pending don't kick off a duplicate request, andshouldSwitchInputTrackcleanly composes the start/stop conditions.
462-487: 💤 Low value
setDeviceIdbypasses theswitchingInputTrackguard without test coverage for concurrent execution.
switchInputTrackcorrectly guards against concurrent invocations by checkingshouldSwitchInputTrack()after acquiring the lock. However,setDeviceIdlogs a warning whenswitchingInputTrackis true then proceeds with its ownsetInputTrack(null) + startInputTrack()sequence, completely bypassing the guard. ThecallsToGetUserMediacounter mitigates overlappinggetUserMediacalls but does not protect the full concurrent sequence. A race condition exists where a device change and a lock-screen-accept switch can execute their track-switching logic simultaneously. No test coverage exists for this concurrent scenario. Recommend adding a test that changes device while a call switch is in-flight, or consider makingsetDeviceIdalso respect theswitchingInputTrackguard.
Proposed changes (including videos or screenshots)
Due to how the mobile app implements voice calls, when a call is accepted from the phone's lock screen it will be registered in the lib and then immediately accepted. This was causing a soft lock where the lib would never request the user's audio for that call, the negotiation would eventually timeout and the call would be dropped.
It happened because when a call is first initialized, it doesn't yet need to request the audio; only after it was accepted. The initialization would trigger the function that updates the state of audio track and it would determine the track is not yet needed, but this function has an
awaitinstruction that causes it to remain in the "updating" state until after the call is flagged as accepted. Once the update function completes, the call would be flagged as already updated and the state change would not be processed.This PR changes the code so that the call will only enter the "updating" state when the track state is actually being changed (as opposed to every time it checks if it needs to change).
In addition I've also made sure that the call's internal state will be refreshed when the first negotiation starts and I also improved the timeout code to explicitly identify when a call fails due to missing the audio track.
Issue(s)
VMUX-113
Steps to test or reproduce
Further comments
Summary by CodeRabbit
Bug Fixes
Improvements