kind-postman-17041
11/26/2025, 12:32 AMtall-airline-16756
11/26/2025, 12:32 AMtall-airline-16756
11/26/2025, 12:32 AMReconnecting, Reconnected, JOIN_FAILURE, ROOM_DELETED, shutdown timeout)
3. Are agents running on dedicated servers or sharing resources with other apps? How many agent servers are active?
4. Do you re-publish tracks or rely on automatic reconnection behavior after the agent reconnects?
5. Do you have SDK logs enabled (e.g., JavaScript setLogExtension())? If so, can you share the recent log lines around a disconnect?
What I’ll check or recommend once you reply:
• Verify graceful shutdown handling and shutdown_process_timeout if disconnects happen during agent shutdown.
• Confirm reconnection flow and whether you need UI state for `Reconnecting`/`Reconnected`.
• Look for connection timeouts (room join >10s) and suggest running multiple agent servers, proper load balancing, or autoscaling.
• Inspect ping/pong and keep-alive stability if disconnects look like signaling timeouts.
Send the answers and any log excerpts and I’ll provide targeted next steps.
Sources: Job lifecycle | LiveKit docs | Connecting to LiveKit | LiveKit docs | Troubleshooting Guide | livekit/livekit_composite | DeepWiki | SIP troubleshooting guide | LiveKit docs | Agent dispatch | LiveKit docskind-postman-17041
11/26/2025, 12:39 AMtall-airline-16756
11/26/2025, 12:39 AMagent_name matching are consistent so agents aren’t delayed by dispatch retries.
• If SIP participants cause bursts, smooth arrival rate or pre-warm idle agents.
5) Keep-alive and timeouts
• Confirm ping/pong connectivity (5s ping / 15s timeout behavior) and watch for signaling stalls.
• If joins regularly hit 10s, move any heavy initialization out of the join path so the connection can complete faster.
6) Reconnection behavior & UX
• Continue to rely on automatic reconnection, but handle Reconnecting UI state so users know there may be a pause while the agent re-publishes tracks.
• If you need faster recovery, implement explicit logic to re-create or re-publish tracks sooner after a reconnect completes.
7) Logging to pinpoint root cause
• Enable detailed SDK logs (use setLogExtension() for JS) and capture timestamps around the CONNECTION_TIMEOUT events.
• Collect server-side logs correlated with the agent’s identity and exact timestamps to see if resource spikes or LB health checks align with the timeouts.
If you want, share:
• One example timestamp (UTC) of a CONNECTION_TIMEOUT and the agent server it hit
• Recent SDK log lines around that event
I’ll identify the most likely cause and recommend the exact next change.kind-postman-17041
11/26/2025, 12:40 AMkind-postman-17041
11/26/2025, 12:41 AMtall-airline-16756
11/26/2025, 12:43 AMkind-postman-17041
11/26/2025, 12:44 AMtall-airline-16756
11/26/2025, 12:44 AMus, eu, asia, aus, uk, etc.).
• Region pinning is available on the Scale plan or higher and must be enabled for your project. Once enabled, a connection routed outside the pinned region is rejected and the client retries within the allowed region. Note: enabling pinning disables automatic failover to other regions during outages.
2) Ping/pong (5s ping / 15s timeout) — what it means and what to check
• The server sends a WebSocket ping every 5 seconds; the client must respond with a pong within 15 seconds. If no pong arrives in 15s, the server treats the signaling connection as stalled and disconnects (this can surface as CONNECTION_TIMEOUT).
• What to verify:
◦ Clients process pings promptly (avoid blocking the event loop or long synchronous work).
◦ Watch for CPU spikes or GC pauses on agent servers that might delay pong responses.
◦ Monitor packet loss and latency between your GCP us-central1 agents and the LiveKit cluster.
◦ Check load balancer behavior and health checks that might affect connection stability.
◦ Correlate CONNECTION_TIMEOUT timestamps with server/client logs and SDK logs (setLogExtension() on JS) to spot patterns.
If you want, I can:
• Confirm the exact regions available for your account and the steps to enable protocol-based region pinning for your project.
• Review one CONNECTION_TIMEOUT event if you share a UTC timestamp and the agent server that handled it.kind-postman-17041
11/26/2025, 12:47 AMtall-airline-16756
11/26/2025, 12:47 AMkind-postman-17041
11/26/2025, 12:53 AMtall-airline-16756
11/26/2025, 12:54 AMReconnected.
• Show Reconnecting UI/state so users expect short pauses during full reconnection flows.
6) Use region pinning (managed LiveKit, Scale+)
• If network variability across PoPs is a factor, enable protocol-based region pinning to force connections into a chosen region (note: this disables automatic failover).
7) Tune graceful shutdown
• Ensure graceful shutdown completes quickly (default 60s). If cleanup is longer, either shorten shutdown tasks or increase shutdown_process_timeout on agent servers.
8) Increase observability and correlation
• Enable SDK logs (setLogExtension() for JS) and server logs; capture ping/pong, onclose/onerror, and system metrics around disconnection times.
• Correlate LiveKit event timestamps (node_id and event time) with agent VM metrics, LB logs, and VPC flow logs to find root cause patterns.
If you want, I can:
• Review one agent-side log snippet (ping/pong and onclose) plus the connection-test output for the VM that hit the timeout and give a prioritized remediation.kind-postman-17041
11/26/2025, 1:01 AMtall-airline-16756
11/26/2025, 1:01 AMkind-postman-17041
11/26/2025, 1:04 AMtall-airline-16756
11/26/2025, 1:05 AMreq.accept() can cause the client to time out or the dispatch to fail).
◦ What to do: ensure on_request handlers accept quickly and defer heavy work to setup_fnc or a background task.
• Room-join / connection latency
◦ LiveKit Cloud enforces a short connection window (commonly seen as ~10s) from dispatch to a joined room. Long initialization or cold-starts can exceed this.
◦ What to do: prewarm models, move heavy initialization out of the join path, use sustained-performance instances.
• Graceful shutdown / drain behavior
◦ If servers are draining or being redeployed often, available capacity drops and dispatch/joins can be delayed.
◦ What to do: verify drain timing, stagger deployments, and keep enough warmed agents.
• Token expiry / reconnect timing
◦ Reconnect attempts must present valid tokens; token expiry or racey refresh logic can prevent quick reconnects.
◦ What to do: ensure tokens are valid during reconnect windows or refresh preemptively.
• Agent load reporting and load_threshold
◦ If the agent reports a high load, it may be skipped for dispatch, producing delays elsewhere.
◦ What to do: verify load_fnc output and adjust load_threshold or capacity.
Diagnostics to run now (high priority)
1. Add ping/pong logs in the agent and capture a recent timeout window (log ping received time and pong sent time).
2. Extract the time from dispatch → req.accept() → room join for a sample timeout event.
3. Run the connection test from the same VM:
npx @livekit/connection-test --url=wss://<your-subdomain>.livekit.cloud --token=<agent-token>
1. Capture agent VM metrics (event-loop delay, GC pause times, CPU steal) and LB/VPC flow logs for the event timestamp.
Quick mitigations
• Prewarm and move heavy tasks off the join/keepalive path.
• Ensure agent code never runs long blocking work on the thread that handles WebSocket events.
• Instrument pings/pongs and alert if pong latency exceeds a few seconds.
• Scale or autoscale to avoid dispatch queuing and cold starts.
• If routing variance is suspected, consider protocol-based region pinning (Scale plan) to constrain which PoP handles the WebSocket.
If you want, share:
• A short agent log snippet showing ping/pong and onclose around one of your recent CONNECTION_TIMEOUTs, and
• The connection-test output from that VM.
I’ll analyze them and point to the most likely agent-side timeout or behavior to fix.
Sources: Agent server options | LiveKit docs | Troubleshooting Latency and Timeout Errors with Turn Detection on AWS | LiveKit Server Platform | livekit/livekit_composite | DeepWiki | Connecting to LiveKit | LiveKit docs | Quotas and limits | LiveKit docskind-postman-17041
11/26/2025, 1:15 AMtall-airline-16756
11/26/2025, 1:16 AMon_request handlers call req.accept() promptly; avoid blocking there.
• If dispatch latency spikes, add more agent capacity or adjust load thresholds.
5) Scale and placement
• Autoscale agents to avoid contention; deploy agents in the same region/PoP as LiveKit when possible.
• Consider protocol-based region pinning (Scale plan) if routing variance is suspected.
6) Reconnect & token handling
• Implement reconnect with backoff and refresh tokens proactively so reconnects succeed.
• On `Reconnecting`/`Reconnected`, re-publish tracks as needed.
7) Observability (must-have)
• Enable SDK logs (setLogExtension() for JS) and server logs; capture ping/pong, onclose, onerror with timestamps.
• Correlate LiveKit event timestamp/node_id with agent VM metrics and LB/VPC logs.
If you want a quick next step, share:
• One agent log snippet around a recent disconnect (ping/pong/onclose) and
• The connection-test output from that VM
I’ll analyze those and give the single highest-impact change to keep that agent connected.