Why would I get `Twirp 408 timeout` running the ag...
# ask-ai
p
Why would I get
Twirp 408 timeout
running the agent locally, but not when running in production?
t
Thanks for reaching out, Mario. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — this is a great question. I’m responding to your issue about seeing a "Twirp 408 timeout" when running the agent locally but not in production. Short answer: this usually points to environmental differences (network, routing, or resource limits) between your local machine and your production environment that cause the request to exceed the Twirp client deadline. What to check (quick checklist) • Network latency / routing: ◦ Verify network path and latency from your local machine to the LiveKit endpoint (ping, traceroute). Higher latency or additional hops can push requests past Twirp deadlines. ◦ Check for VPNs, corporate proxies, or firewalls that could be delaying or re-writing HTTP/2 traffic. • Local resource constraints: ◦ Ensure CPU and memory on your local machine aren’t saturated when the agent runs. CPU contention can delay request handling. • Differences in DNS / endpoint used: ◦ Confirm you’re hitting the same service endpoint/region as production. A different region can mean higher RTTs. • Intermediate network devices: ◦ Load balancers, proxies, or NAT devices in your local path may impose timeouts or rate limits that don’t affect production instances inside the cloud network. • Request-specific server processing: ◦ Some calls trigger long upstream work (webhooks, AI models, third-party APIs). If those paths are slower for requests originating from local tooling (different headers, auth, or payload), the client deadline can be reached. • Config/auth/config drift: ◦ Confirm your local config (timeouts, API keys, environment variables, dependency versions) matches production. A shorter client deadline locally or mismatched configs can explain the difference. Immediate troubleshooting steps 1. Identify the exact Twirp RPC that times out (RoomService, SIPService, etc.) and check logs on the service for corresponding requests and timings. 2. From your local machine, measure latency to the LiveKit host: ◦ Run ping/traceroute and an HTTP/2-aware test (or use curl with
--http2
) to see RTT and any TLS/HTTP/2 negotiation delays. 1. Reproduce with an extended deadline: ◦ If possible, temporarily increase the client deadline for that RPC locally to see whether the request eventually succeeds. If it does, the problem is purely timing. 1. Test from a different network: ◦ Try from a cloud VM in the same region as production or a different local network (home vs corporate) to isolate whether your local network is the cause. 1. Inspect local CPU/memory during the request: ◦ Use top/Activity Monitor to see if the agent or system is CPU-bound when the request is sent. 1. Check for intermediate blocking: ◦ Disable VPNs/proxies or try bypassing corporate network rules to see if that removes the timeout. What I can help with next • If you share which RPC is timing out and a short snippet of the client timeout/deadline value you’re using, I can suggest the exact place to increase the deadline or where to look in logs. • If you can paste traceroute/ping results (obscure any sensitive hostnames), I can help interpret them and point to likely causes. • I can also walk you through temporarily increasing the Twirp deadline locally and safe ways to test whether upstream services are taking longer. If you prefer, tell me: • Which RPC is timing out (e.g., RoomService.CreateRoom, SIPService.Whatever). • The client deadline you’re using locally (if set), and whether production uses a different deadline. • Whether you’re on a VPN or behind a corporate network. We’ll narrow this down together and get your local agent behaving like production. Sources: Troubleshooting Latency and Timeout Errors with Turn Detection on AWS | Tool definition and use | LiveKit Documentation | Still Have Questions | Diagnosing Connection Errors with the Connection Test Utility | LiveKit
a
When does the on_enter function gets called ?
t
Thanks — I’m answering your question about when the
on_enter
function is called. Short answer:
on_enter
runs when an agent becomes the active agent for an AgentSession. When exactly that happens • Initial activation: When an AgentSession starts and the session is created with that agent as the active agent. • Agent handoff: When control is transferred from one agent to another during a session (a handoff). • Explicit update: When
session.update_agent()
is called to change the session’s active agent. Notes and common uses • Only one agent is active at a time and
on_enter
is called only when that agent takes control — it is not executed on every user interaction. • Use
on_enter
for initialization tasks (welcome messages, setting up state, kicking off background setup, etc.). If you want, tell me: • Which agent class or code path you’re using (a short snippet helps), and I’ll point to the exact place
on_enter
is invoked or show a small example of initializing greetings or state in
on_enter
. Sources: Pipeline nodes and hooks | LiveKit Documentation | Agents and handoffs | LiveKit Documentation