Skip to content

fix(ios): capture finishAcceptInvoked by reference in DispatchWorkItem closure#7219

Merged
diegolmello merged 1 commit into
feat.voip-lib-newfrom
fix/c2-ios-finishaccept-voiplib
Apr 23, 2026
Merged

fix(ios): capture finishAcceptInvoked by reference in DispatchWorkItem closure#7219
diegolmello merged 1 commit into
feat.voip-lib-newfrom
fix/c2-ios-finishaccept-voiplib

Conversation

@diegolmello

@diegolmello diegolmello commented Apr 22, 2026

Copy link
Copy Markdown
Member

Summary

  • Wrap finishAcceptInvoked in reference-capturable container so DispatchWorkItem closure sees mutations
  • Prevents 10s timeout from firing finishAccept(false) after user already accepted call

Test plan

  • Swift syntax check passes
  • iOS build succeeds

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue in VoIP call acceptance where the accept action could be triggered multiple times for the same incoming call, improving system reliability and preventing unintended duplicate acceptances.

…m closure

Wrap finishAcceptInvoked in [false] array so DispatchWorkItem closure sees
mutations. Prevents 10s timeout from firing finishAccept(false) after user
already accepted call.

Closes #6918
@coderabbitai

coderabbitai Bot commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

Changed the deduplication flag in handleNativeAccept from a mutable Bool to a one-element array [false] to ensure proper closure capture. This allows the finishAccept closure and a scheduled 10-second timeout to safely share and update the same state, preventing duplicate accept invocations for a given call.

Changes

Cohort / File(s) Summary
VoIP Service Deduplication
ios/Libraries/VoipService.swift
Changed completion-deduplication flag from captured mutable Bool to one-element array [false] to ensure safe shared state between finishAccept closure and timeout work item.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • #7209: Addresses the same closure-capture deduplication issue in handleNativeAccept by sharing mutable finishAcceptInvoked state.

Suggested labels

type: bug

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The PR title clearly describes the specific fix: changing how finishAcceptInvoked is captured in a DispatchWorkItem closure to enable proper reference sharing.
Linked Issues check ✅ Passed The PR fixes a bug in the VoIP incoming call flow by preventing the 10s timeout from invoking finishAccept after user acceptance, directly supporting the voice support feature's call state management objectives [#6918].
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the finishAcceptInvoked reference capture issue in VoipService.swift, which is directly related to the voice calling feature's call state management requirements.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@diegolmello diegolmello temporarily deployed to experimental_ios_build April 22, 2026 22:50 — with GitHub Actions Inactive
@diegolmello diegolmello had a problem deploying to official_android_build April 22, 2026 22:50 — with GitHub Actions Failure
@diegolmello diegolmello had a problem deploying to experimental_android_build April 22, 2026 22:50 — with GitHub Actions Failure

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
ios/Libraries/VoipService.swift (1)

460-501: ⚠️ Potential issue | 🟠 Major

Array capture semantics create invisible state divergence between closures

The finishAcceptInvoked array at line 460 is captured by value in the timeoutWorkItem closure (line 499) via the explicit capture list. When finishAccept mutates finishAcceptInvoked[0] at line 463, that mutation occurs on a different Array instance than the copy held by the timeout closure. Copy-on-write semantics ensure these independent copies diverge—the timeout guard at line 501 will not observe the mutation, defeating the dedupe logic.

Proposed fix (use a reference wrapper for shared mutable state)
-        var finishAcceptInvoked = [false]
+        final class FinishAcceptState {
+            var invoked = false
+        }
+        let finishAcceptState = FinishAcceptState()
         let finishAccept: (Bool) -> Void = { [weak payload] success in
-            guard !finishAcceptInvoked[0] else { return }
-            finishAcceptInvoked[0] = true
+            guard !finishAcceptState.invoked else { return }
+            finishAcceptState.invoked = true
             guard let payload else { return }
             stopDDPClientInternal(callId: payload.callId)
             if success {
@@
-        let timeoutWorkItem = DispatchWorkItem { [weak payload, finishAcceptInvoked] in
+        let timeoutWorkItem = DispatchWorkItem { [weak payload] in
             guard let payload else { return }
-            guard !finishAcceptInvoked[0] else { return }
+            guard !finishAcceptState.invoked else { return }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ios/Libraries/VoipService.swift` around lines 460 - 501, The dedupe flag
currently uses an Array (finishAcceptInvoked) which gets copied into
timeoutWorkItem's capture list causing divergent state; replace that shared
mutable state with a reference type (e.g., a small class wrapper like
FinishAcceptInvokedBox with a Bool property or an Atomic/ThreadSafeBool) and
update references in finishAccept and timeoutWorkItem to read/write that single
shared instance (e.g., finishAcceptInvoked.value) so both closures observe the
same mutation; ensure the same reference is captured (no value-capture in the
closure capture lists) and keep existing guard checks and mutation logic
otherwise unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@ios/Libraries/VoipService.swift`:
- Around line 460-501: The dedupe flag currently uses an Array
(finishAcceptInvoked) which gets copied into timeoutWorkItem's capture list
causing divergent state; replace that shared mutable state with a reference type
(e.g., a small class wrapper like FinishAcceptInvokedBox with a Bool property or
an Atomic/ThreadSafeBool) and update references in finishAccept and
timeoutWorkItem to read/write that single shared instance (e.g.,
finishAcceptInvoked.value) so both closures observe the same mutation; ensure
the same reference is captured (no value-capture in the closure capture lists)
and keep existing guard checks and mutation logic otherwise unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1ca81cb6-d700-4511-a70f-17a2f5a48700

📥 Commits

Reviewing files that changed from the base of the PR and between eb33c97 and f50e9ba.

📒 Files selected for processing (1)
  • ios/Libraries/VoipService.swift
📜 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). (1)
  • GitHub Check: ESLint and Test / run-eslint-and-test
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: OtavioStasiak
Repo: RocketChat/Rocket.Chat.ReactNative PR: 6499
File: app/containers/ServerItem/index.tsx:34-36
Timestamp: 2025-12-17T15:56:22.578Z
Learning: In the Rocket.Chat React Native codebase, for radio button components on iOS, include the selection state ("Selected"/"Unselected") in the accessibilityLabel instead of using accessibilityState={{ checked: hasCheck }}, because iOS VoiceOver has known issues with accessibilityRole="radio" + accessibilityState that prevent correct state announcement.

@github-actions

Copy link
Copy Markdown

iOS Build Available

Rocket.Chat Experimental 4.72.0.108608

@diegolmello diegolmello merged commit ebd6b9b into feat.voip-lib-new Apr 23, 2026
8 of 12 checks passed
@diegolmello diegolmello deleted the fix/c2-ios-finishaccept-voiplib branch April 23, 2026 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant