Skip to content

Conversation

@pierre-lehnen-rc
Copy link
Contributor

@pierre-lehnen-rc pierre-lehnen-rc commented Jan 14, 2026

Proposed changes (including videos or screenshots)

When the callee client accepts a call, we were starting a 10s timeout waiting for the call to become active. This is usually more than enough because the process tends to be much faster than that and this timeout is intended only to cover the time that the client takes to generate the webrtc answer (including ICE Gathering). However, the user may accept the call before the caller client has sent the initial webrtc offer, in which case it needs to wait for the offer before it can start working in the answer. If there are multiple ICE servers delaying the ICE gathering process, this could cause the total amount of time between accepting the call and connecting to it to go over 10s, which would then drop the call.

This PR makes it so that the 10s timeout is reset whenever there's progress in the negotiation.

It also splits the timeout hangup reason into 5 different values in order to specify which specific part of the process timed out.

Issue(s)

VGA-114

Steps to test or reproduce

Further comments

Summary by CodeRabbit

  • Bug Fixes

    • More precisely classifies call failures (unanswered, various SDP timeouts, activation timeout) for clearer diagnostics.
  • New Features

    • Introduces more granular client signaling states during call setup (waiting-for-offer/answer, generating-local-sdp, activating) for improved progress visibility.
  • Refactor

    • Improved call state progression, timeout handling, and negotiation lifecycle to better track SDP exchange and finalization.

✏️ Tip: You can customize this high-level summary in your review settings.

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Jan 14, 2026

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Jan 14, 2026

⚠️ No Changeset found

Latest commit: 0fd4a16

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 14, 2026

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Replaces the coarse 'accepted' client state with granular signaling states, tracks SDP send/receive progress, maps specific client-state timeouts to new hangup reasons (not-answered, timeout-remote-sdp, timeout-local-sdp, timeout-activation), and propagates negotiation finished state to the negotiation manager.

Changes

Cohort / File(s) Summary
Type definitions & schemas
packages/media-signaling/src/definition/call/IClientMediaCall.ts, packages/media-signaling/src/definition/client.ts, packages/media-signaling/src/definition/signals/client/hangup.ts, packages/media-signaling/src/definition/signals/client/local-state.ts
Added new hangup reasons ('not-answered', 'timeout-remote-sdp', 'timeout-local-sdp', 'timeout-activation') and replaced 'accepted' client state with granular states ('waiting-for-offer', 'waiting-for-answer', 'generating-local-sdp', 'activating'), updated JSON schemas/types.
Call signaling & timeouts
packages/media-signaling/src/lib/Call.ts
Added sentLocalSdp/receivedRemoteSdp flags; refactored client-state logic to return new granular states; changed SDP handling flow and timeout scheduling; added mapping from client-state timeouts to specific hangup reasons.
Negotiation lifecycle
packages/media-signaling/src/lib/NegotiationManager.ts, packages/media-signaling/src/lib/services/webrtc/Negotiation.ts
Added negotiation finished tracking (_finished/finished getter), end(finished) semantics, highestFinishedNegotiationId, and hasFinishedAnyNegotiation; adjusted async error handling and lifecycle propagation.
Server call-history mapping
apps/meteor/server/services/media-call/service.ts
Updated getCallHistoryItemState to return 'not-answered' for that reason and return 'failed' for hangup reasons starting with 'timeout'.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Call
    participant Negotiation
    participant Callee

    Caller->>Call: accept() → enter 'accepted' (granular flow)
    Call->>Call: start activation timeout

    Callee->>Call: send offer (remote SDP)
    Call->>Call: receivedRemoteSdp = true
    Call->>Call: update client state -> 'generating-local-sdp' (or 'waiting-for-answer')
    Call-->>Call: clear/adjust timeouts

    Caller->>Negotiation: create local SDP / send answer
    Negotiation->>Call: mark sentLocalSdp = true
    Call->>Call: deliverSdp(), start activation timeout
    Call->>Call: update client state -> 'activating'

    Negotiation->>Negotiation: finish()
    Negotiation->>Call: notify finished
    Call->>Call: clear activation timeout, set state 'active'
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • KevLehman
  • tassoevan

Poem

🐰 A rabbit nibbles SDP and threads,
Waiting, answering, clearing dreads.
Timeouts tuned and states made small—
Hops through signals, avoids the fall. 🥕✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Title accurately describes the main change: improving WebRTC negotiation timeout handling by splitting generic timeout into specific reasons.
Linked Issues check ✅ Passed Code changes fully implement VGA-114 objectives: new timeout reasons added, timeout logic refactored to reset on negotiation progress, separate timeouts for offer-waiting and activation-waiting phases.
Out of Scope Changes check ✅ Passed All changes directly support VGA-114 requirements: new hangup reasons, refined client states, timeout management in Call.ts, and negotiation tracking in NegotiationManager.ts are all necessary.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/media-calls-multi-timeout

🧹 Recent nitpick comments
packages/media-signaling/src/lib/services/webrtc/Negotiation.ts (1)

174-201: Consider consistent throw behavior across wrapper methods.

setPeerRemoteDescription and setPeerLocalDescription call fail() but don't throw, while createEarlyAnswer and getPeerLocalDescription both fail() and throw. This inconsistency means execution continues after some failures but not others.

For example, in setLocalDescription, if setPeerLocalDescription fails (line 112), execution continues to waitForIceGathering() (line 115) before eventually failing at getPeerLocalDescription() (line 118).

The current approach works because downstream methods eventually fail, but a consistent pattern would reduce unnecessary operations after failure.

♻️ Suggested consistent pattern
 protected async setPeerRemoteDescription(this: WebRTCNegotiation, remoteDescription: RTCSessionDescriptionInit): Promise<void> {
   try {
     await this.webrtcProcessor.setRemoteDescription(remoteDescription);
   } catch (err) {
     this.logger?.error(err);
     this.fail('failed-to-set-remote-description');
+    throw err;
   }
 }
 
 protected async setPeerLocalDescription(this: WebRTCNegotiation, localDescription: RTCSessionDescriptionInit): Promise<void> {
   try {
     await this.webrtcProcessor.setLocalDescription(localDescription);
   } catch (err) {
     this.logger?.error(err);
     this.fail('failed-to-set-local-description');
+    throw err;
   }
 }

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between fbc9193 and d01526e.

📒 Files selected for processing (2)
  • packages/media-signaling/src/lib/NegotiationManager.ts
  • packages/media-signaling/src/lib/services/webrtc/Negotiation.ts
🧰 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/lib/NegotiationManager.ts
  • packages/media-signaling/src/lib/services/webrtc/Negotiation.ts
🧠 Learnings (1)
📓 Common learnings
Learnt from: pierre-lehnen-rc
Repo: RocketChat/Rocket.Chat PR: 36718
File: packages/media-signaling/src/lib/Call.ts:633-642
Timestamp: 2025-09-23T00:27:05.438Z
Learning: In PR `#36718`, pierre-lehnen-rc prefers to maintain consistency with the old architecture patterns for DTMF handling rather than implementing immediate validation improvements, deferring enhancements to future work.
⏰ 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). (4)
  • GitHub Check: 📦 Build Packages
  • GitHub Check: cubic · AI code reviewer
  • GitHub Check: CodeQL-Build
  • GitHub Check: CodeQL-Build
🔇 Additional comments (8)
packages/media-signaling/src/lib/services/webrtc/Negotiation.ts (4)

21-24: LGTM! Clean addition of finished state tracking.

The new finished property correctly tracks whether a negotiation completed successfully versus just ending. The initialization and getter are well-structured.

Also applies to: 41-42, 51-51


60-71: LGTM! Good defensive logic for finished state.

The guard finished && this._startedProcessing && !this._failed correctly prevents marking failed negotiations as finished. This ensures the finished flag only reflects successfully completed negotiations.


91-106: LGTM! Type guard and error handling flow are correct.

The isWebRTCNegotiation() guard improves type safety. Even if setPeerRemoteDescription fails and calls fail(), the subsequent end(true) correctly won't set _finished due to the !this._failed check in end().


132-134: LGTM! Clean type guard implementation.

The isWebRTCNegotiation() type guard provides a safe way to check processor availability with proper TypeScript narrowing.

packages/media-signaling/src/lib/NegotiationManager.ts (4)

13-15: LGTM! Clean finished negotiation tracking.

The new hasFinishedAnyNegotiation getter and highestFinishedNegotiationId state correctly enable downstream components to detect when any negotiation has successfully completed. This aligns with the PR objective of tracking negotiation progress for timeout management.

Also applies to: 36-38, 51-51


205-216: LGTM! Proper integration with finished state.

The ended handler correctly captures the finished state before clearing currentNegotiation, ensuring the highestFinishedNegotiationId is tracked for successful completions.


218-225: LGTM! Important cleanup addition.

The explicit currentNegotiation.end() call ensures proper cleanup when errors occur, since fail() in Negotiation.ts doesn't call end() itself.


114-117: LGTM! Error handling is correct here.

Unlike process(), setRemoteAnswer internally uses setPeerRemoteDescription which properly calls fail() on error, ensuring the 'error' event is emitted before the promise rejects.

✏️ Tip: You can disable this entire section by setting review_details to false in your review 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.

@pierre-lehnen-rc pierre-lehnen-rc added this to the 8.1.0 milestone Jan 14, 2026
@pierre-lehnen-rc pierre-lehnen-rc force-pushed the chore/media-calls-multi-timeout branch from bf2d6c7 to cf69554 Compare January 14, 2026 22:53
@codecov
Copy link

codecov bot commented Jan 14, 2026

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.67%. Comparing base (20e4ed3) to head (0fd4a16).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #38191      +/-   ##
===========================================
- Coverage    70.67%   70.67%   -0.01%     
===========================================
  Files         3133     3133              
  Lines       108369   108373       +4     
  Branches     19488    19548      +60     
===========================================
+ Hits         76593    76595       +2     
+ Misses       29775    29772       -3     
- Partials      2001     2006       +5     
Flag Coverage Δ
e2e 60.30% <ø> (ø)
e2e-api 47.33% <0.00%> (-1.01%) ⬇️
unit 71.77% <ø> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 14, 2026

📦 Docker Image Size Report

➡️ Changes

Service Current Baseline Change Percent
sum of all images 0B 0B 0B
account-service 0B 0B 0B
authorization-service 0B 0B 0B
ddp-streamer-service 0B 0B 0B
omnichannel-transcript-service 0B 0B 0B
presence-service 0B 0B 0B
queue-worker-service 0B 0B 0B
rocketchat 0B 0B 0B

📊 Historical Trend

---
config:
  theme: "dark"
  xyChart:
    width: 900
    height: 400
---
xychart
  title "Image Size Evolution by Service (Last 30 Days + This PR)"
  x-axis ["11/18 22:53", "11/19 23:02", "11/21 16:49", "11/24 17:34", "11/27 22:32", "11/28 19:05", "12/01 23:01", "12/02 21:57", "12/03 21:00", "12/04 18:17", "12/05 21:56", "12/08 20:15", "12/09 22:17", "12/10 23:26", "12/11 21:56", "12/12 22:45", "12/13 01:34", "12/15 22:31", "12/16 22:18", "12/17 21:04", "12/18 23:12", "12/19 23:27", "12/20 21:03", "12/22 18:54", "12/23 16:16", "12/24 19:38", "12/25 17:51", "12/26 13:18", "12/29 19:01", "12/30 20:52", "01/16 14:28 (PR)"]
  y-axis "Size (GB)" 0 --> 0.5
  line "account-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.00]
  line "authorization-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.00]
  line "ddp-streamer-service" [0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.12, 0.00]
  line "omnichannel-transcript-service" [0.14, 0.14, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.00]
  line "presence-service" [0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.11, 0.00]
  line "queue-worker-service" [0.14, 0.14, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.13, 0.00]
  line "rocketchat" [0.35, 0.35, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.34, 0.00]
Loading

Statistics (last 30 days):

  • 📊 Average: 1.5GiB
  • ⬇️ Minimum: 1.4GiB
  • ⬆️ Maximum: 1.6GiB
  • 🎯 Current PR: 0B
ℹ️ About this report

This report compares Docker image sizes from this build against the develop baseline.

  • Tag: pr-38191
  • Baseline: develop
  • Timestamp: 2026-01-16 14:28:57 UTC
  • Historical data points: 30

Updated: Fri, 16 Jan 2026 14:28:58 GMT

@pierre-lehnen-rc pierre-lehnen-rc marked this pull request as ready for review January 15, 2026 18:04
@pierre-lehnen-rc pierre-lehnen-rc requested a review from a team as a code owner January 15, 2026 18:04
@pierre-lehnen-rc pierre-lehnen-rc added the stat: QA assured Means it has been tested and approved by a company insider label Jan 15, 2026
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label Jan 15, 2026
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 8 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="packages/media-signaling/src/definition/client.ts">

<violation number="1" location="packages/media-signaling/src/definition/client.ts:8">
P3: Typo in comment: "Thw" should be "The".</violation>
</file>

<file name="packages/media-signaling/src/lib/Call.ts">

<violation number="1" location="packages/media-signaling/src/lib/Call.ts:1043">
P3: The `'accepting'` state is missing from the switch statement. Timeouts are set for this state in `accept()`, but when they fire, this will return the generic `'timeout'` reason instead of a more descriptive one like `'timeout-acceptance'`. Consider adding a case for consistency with other states.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
packages/media-signaling/src/lib/Call.ts (1)

1043-1057: The 'accepting' state is missing from this switch.

Timeouts are set for the 'accepting' state in accept() (line 537), but this method will return the generic 'timeout' reason for that state instead of a specific one like 'timeout-acceptance'.

This was flagged in a previous review. Consider adding a case for consistency with other states.

🧹 Nitpick comments (1)
packages/media-signaling/src/definition/signals/client/hangup.ts (1)

39-43: Minor ordering inconsistency with type definition.

The new hangup reasons are placed after 'timeout' here (line 39), but in IClientMediaCall.ts they appear before 'timeout'. While this doesn't affect validation behavior, maintaining consistent ordering between the type definition and schema enum improves readability and reduces maintenance burden.

♻️ Suggested reordering for consistency
 		reason: {
 			type: 'string',
 			enum: [
 				'normal',
 				'remote',
 				'rejected',
 				'unavailable',
 				'transfer',
-				'timeout',
 				'not-answered',
 				'timeout-remote-sdp',
 				'timeout-local-sdp',
 				'timeout-activation',
+				'timeout',
 				'signaling-error',
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 30a28d6 and fbc9193.

📒 Files selected for processing (8)
  • apps/meteor/server/services/media-call/service.ts
  • packages/media-signaling/src/definition/call/IClientMediaCall.ts
  • packages/media-signaling/src/definition/client.ts
  • packages/media-signaling/src/definition/signals/client/hangup.ts
  • packages/media-signaling/src/definition/signals/client/local-state.ts
  • packages/media-signaling/src/lib/Call.ts
  • packages/media-signaling/src/lib/NegotiationManager.ts
  • packages/media-signaling/src/lib/services/webrtc/Negotiation.ts
🧰 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:

  • apps/meteor/server/services/media-call/service.ts
  • packages/media-signaling/src/lib/NegotiationManager.ts
  • packages/media-signaling/src/definition/call/IClientMediaCall.ts
  • packages/media-signaling/src/lib/services/webrtc/Negotiation.ts
  • packages/media-signaling/src/lib/Call.ts
  • packages/media-signaling/src/definition/client.ts
  • packages/media-signaling/src/definition/signals/client/local-state.ts
  • packages/media-signaling/src/definition/signals/client/hangup.ts
🧠 Learnings (3)
📓 Common learnings
Learnt from: pierre-lehnen-rc
Repo: RocketChat/Rocket.Chat PR: 36718
File: packages/media-signaling/src/lib/Call.ts:633-642
Timestamp: 2025-09-23T00:27:05.438Z
Learning: In PR `#36718`, pierre-lehnen-rc prefers to maintain consistency with the old architecture patterns for DTMF handling rather than implementing immediate validation improvements, deferring enhancements to future work.
📚 Learning: 2025-11-19T18:20:37.116Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 37419
File: apps/meteor/server/services/media-call/service.ts:141-141
Timestamp: 2025-11-19T18:20:37.116Z
Learning: In apps/meteor/server/services/media-call/service.ts, the sendHistoryMessage method should use call.caller.id or call.createdBy?.id as the message author, not call.transferredBy?.id. Even for transferred calls, the message should appear in the DM between the two users who are calling each other, not sent by the person who transferred the call.

Applied to files:

  • apps/meteor/server/services/media-call/service.ts
📚 Learning: 2025-12-18T15:18:31.688Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 37773
File: apps/meteor/client/views/mediaCallHistory/MediaCallHistoryInternal.tsx:24-34
Timestamp: 2025-12-18T15:18:31.688Z
Learning: In apps/meteor/client/views/mediaCallHistory/MediaCallHistoryInternal.tsx, for internal call history items, the item.contactId is guaranteed to always match either the caller.id or callee.id in the call data, so the contact resolution in getContact will never result in undefined.

Applied to files:

  • apps/meteor/server/services/media-call/service.ts
🧬 Code graph analysis (1)
packages/media-signaling/src/lib/Call.ts (2)
packages/media-signaling/src/definition/client.ts (1)
  • ClientState (1-12)
packages/media-signaling/src/definition/call/IClientMediaCall.ts (1)
  • CallHangupReason (30-47)
⏰ 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). (3)
  • GitHub Check: 📦 Build Packages
  • GitHub Check: CodeQL-Build
  • GitHub Check: CodeQL-Build
🔇 Additional comments (12)
packages/media-signaling/src/definition/call/IClientMediaCall.ts (1)

36-40: LGTM! New timeout-specific hangup reasons align well with PR objectives.

The granular hangup reasons (not-answered, timeout-remote-sdp, timeout-local-sdp, timeout-activation) provide better diagnostics for WebRTC negotiation failures. Retaining the generic timeout at line 40 ensures backward compatibility.

packages/media-signaling/src/definition/client.ts (1)

5-8: LGTM! Granular client states enable precise timeout tracking.

The new states (waiting-for-offer, waiting-for-answer, generating-local-sdp, activating) correctly model the WebRTC negotiation lifecycle, enabling the timeout to be reset at each progression step as per the PR objectives.

packages/media-signaling/src/lib/NegotiationManager.ts (3)

13-15: LGTM! Clean getter for checking negotiation completion state.

This getter enables the Call layer to determine if any negotiation has successfully finished, which is essential for distinguishing between timeout-activation (after negotiation) and timeout-remote-sdp/timeout-local-sdp (during negotiation).


36-37: LGTM! Proper initialization and tracking of finished negotiations.

The new highestFinishedNegotiationId property is correctly initialized to null and updated when a negotiation finishes, providing the state needed for the hasFinishedAnyNegotiation getter.

Also applies to: 51-51


213-215: LGTM! Correctly tracks finished negotiation state.

The conditional update ensures highestFinishedNegotiationId is only set when a negotiation completes successfully (negotiation.finished === true), not when it's merely ended or cancelled.

packages/media-signaling/src/definition/signals/client/local-state.ts (1)

44-56: LGTM! Schema enum correctly reflects updated ClientState type.

The expanded clientState enum properly includes the new granular states and removes 'accepted', matching the type definition in client.ts. Note that callState (line 39) still correctly includes 'accepted' since that represents the high-level call lifecycle, distinct from the client-specific negotiation state.

apps/meteor/server/services/media-call/service.ts (1)

231-237: LGTM! New hangup reason guards correctly map to call history states.

The order is correct: checking 'not-answered' explicitly before the startsWith('timeout') ensures proper state mapping. The prefix check elegantly handles all timeout variants (timeout-remote-sdp, timeout-local-sdp, timeout-activation, and generic timeout).

packages/media-signaling/src/lib/services/webrtc/Negotiation.ts (1)

21-23: LGTM! Clean implementation of negotiation completion tracking.

The finished flag correctly distinguishes successful completions from failures/skips:

  • Only set when _startedProcessing && !_failed guards pass
  • end(true) called at the right completion points (remote answer for local negotiations, local description for remote negotiations)
  • Default parameter preserves backward compatibility

Also applies to: 41-41, 51-51, 60-70, 105-105, 128-128

packages/media-signaling/src/lib/Call.ts (4)

192-194: LGTM! SDP exchange tracking flags properly initialized and scoped.

The sentLocalSdp and receivedRemoteSdp flags correctly track the initial SDP exchange progress. They're appropriately scoped to the accepted state in getClientState(), so they won't interfere with renegotiation flows.

Also applies to: 233-234


423-444: LGTM! Granular state mapping aligns with WebRTC offer/answer flow.

The logic correctly reflects the asymmetric nature of caller vs callee:

  • Caller: generates offer first (generating-local-sdp) → waits for answer (waiting-for-answer)
  • Callee: waits for offer first (waiting-for-offer) → generates answer (generating-local-sdp)

The fallback to 'waiting-for-offer' when no negotiation exists handles the edge case where the callee accepts before the caller sends an offer.


779-783: LGTM! Timeout reset on progress achieves the PR objective.

Each client state transition within 'accepted' now starts a fresh TIMEOUT_TO_PROGRESS_SIGNALING timer. Combined with updateStateTimeouts() clearing old timers, this ensures valid calls with slow ICE gathering won't be prematurely dropped.


889-902: LGTM! Refactored SDP processing with proper early return.

The switch statement cleanly handles offer/answer types, and the early return in the default case correctly prevents setting receivedRemoteSdp = true for unsupported SDP types.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

2 issues found across 2 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="packages/media-signaling/src/lib/services/webrtc/Negotiation.ts">

<violation number="1" location="packages/media-signaling/src/lib/services/webrtc/Negotiation.ts:179">
P1: Missing `throw err` after `fail()` call. Unlike `createEarlyAnswer` and `getPeerLocalDescription`, this method swallows the exception, causing callers to continue executing after a failure. This can lead to incorrect state (e.g., `end(true)` being called after failure in `setRemoteAnswer`).</violation>

<violation number="2" location="packages/media-signaling/src/lib/services/webrtc/Negotiation.ts:199">
P1: Missing `throw err` after `fail()` call. Unlike `createEarlyAnswer` and `getPeerLocalDescription`, this method swallows the exception, causing callers to continue executing after a failure. The subsequent `assertNegotiationIsActive()` won't detect this failure since it only checks `_ended`, not `_failed`.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@kodiakhq kodiakhq bot merged commit 68b04f3 into develop Jan 16, 2026
44 checks passed
@kodiakhq kodiakhq bot deleted the chore/media-calls-multi-timeout branch January 16, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants