Skip to content

fix: SIP connect hang - arm timeout before await connect#340

Merged
coygg merged 2 commits into
masterfrom
fix/sip-connect-hang
Apr 3, 2026
Merged

fix: SIP connect hang - arm timeout before await connect#340
coygg merged 2 commits into
masterfrom
fix/sip-connect-hang

Conversation

@coygg
Copy link
Copy Markdown
Collaborator

@coygg coygg commented Apr 3, 2026

Fixes agents stuck on WebRTC connecting forever. Timeout now races against connect(), and ensureRegistered recovers from stuck connecting state.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of connection timeouts to more reliably mark initialization complete and surface an error state when SIP connect fails.
    • Added better detection and logging for “stuck connecting” situations.
    • Triggered automatic recovery attempts when connection attempts exceed the allowed timeout, improving registration resilience.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
policyjar Ready Ready Preview, Comment Apr 3, 2026 10:36pm

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 3, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: eca67ac3-7061-4c4f-ac74-d79f133144fe

📥 Commits

Reviewing files that changed from the base of the PR and between fdb2f68 and 4c0c93b.

📒 Files selected for processing (1)
  • src/hooks/use-telnyx.ts

📝 Walkthrough

Walkthrough

Hook initialization now records connect start time and races client.connect() against a timeout. On timeout the hook marks initialization complete, sets connection status to error, clears registration, and rejects. ensureRegistered() now detects prolonged connecting state and triggers a manual reconnect.

Changes

Cohort / File(s) Summary
Connection initialization & recovery
src/hooks/use-telnyx.ts
Added connectStartTimeRef. Refactored init to set the start time before awaiting client.connect() and race it with a pre-armed timeout promise. Timeout path now logs "SIP connect timeout", calls markInitialized(), sets connectionStatus to 'error', sets isRegistered to false, and rejects with Error('SIP connect timeout'). ensureRegistered() now measures elapsed connect time when connectionStatusRef.current === 'connecting' and, if exceeded, logs a "stuck connecting" warning and calls triggerManualReconnect('connect-timeout').

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I stamped my paw at the ticking line,
A race of promises, snap!—not fine.
When Telnyx lingers past the chime,
I nudge reconnect, reset the time.
Hoppity hop—back in rhyme!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly summarizes the main fix: addressing a SIP connect hang by arming a timeout before awaiting the connect call, which aligns with the core change in the changeset.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/sip-connect-hang

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

coderabbitai[bot]
coderabbitai Bot previously requested changes Apr 3, 2026
Copy link
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/hooks/use-telnyx.ts`:
- Around line 744-753: The stuck-connecting branch in ensureRegistered detects a
connection hang (connectionStatusRef.current === 'connecting' and elapsed >
REGISTRATION_TIMEOUT_MS) but only calls runLifecycleRecovery('connect-timeout')
which merely schedules another ensureRegistered and will be deduped, so it never
forces a reconnect; change this to call
triggerManualReconnect('connect-timeout') (the same recovery used in other
failure paths) instead of or in addition to runLifecycleRecovery so the client
actually disconnects/reinits when the connect timeout is reached; update the
call site in ensureRegistered (and keep runLifecycleRecovery if you want logging
scheduling still) and ensure triggerManualReconnect is invoked with the
'connect-timeout' reason.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2e30ffe9-815a-4754-96e6-7181ec0192d9

📥 Commits

Reviewing files that changed from the base of the PR and between f78147c and fdb2f68.

📒 Files selected for processing (1)
  • src/hooks/use-telnyx.ts

Comment thread src/hooks/use-telnyx.ts
@coygg coygg dismissed coderabbitai[bot]’s stale review April 3, 2026 22:37

Findings addressed.

@coygg coygg merged commit 9a20cb0 into master Apr 3, 2026
4 of 5 checks passed
coygg added a commit that referenced this pull request Jun 1, 2026
* fix: prevent SIP connect hang during telnyx init

* fix: trigger reconnect on stuck connecting detection
@coygg coygg deleted the fix/sip-connect-hang branch June 1, 2026 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant