Hello friends, I have been trying to debug this i...
# server-api
a
Hello friends, I have been trying to debug this issue for around 15 hours and could not find a way. I have this code working on local very well. The architecture is like this: I am running the frontend on Vercel. There is a button that asks a name and a button to join. When I click join, agent also joins. The backend is running on Google Cloud Run. The STT-LLM-STT part is handling by Livekit Cloud. This service is working very well on my local machine. The agent joins the room and we have a realtime conversation. But when I try to do it on cloud (UI on Vercel) the agent never joins. I can see the sessions on Livekit Dashboard. What should I do? LLMs took me into a deep hole that I barely survived. You are kind of the last resort. Appreciate any kind of ideas.
βœ… What Works Locally Your local logs show perfect functionality: β€’
🚨 ENTRYPOINT FUNCTION CALLED! 🚨
β€’
πŸŽ‰ AGENT SESSION STARTED SUCCESSFULLY! πŸŽ‰
β€’
received user transcript
β€’ Successful OpenAI API calls β€’ Real conversation happening (
"Hello?"
,
"I don't want talk about the start up"
) β€’ Agent responding appropriately ❌ What Fails on Cloud Run Cloud Run logs show the worker registering but the agent never joining rooms that clients create.
r
It sounds like you're experiencing an issue where your agent is not joining the room when deployed on Google Cloud Run, despite working perfectly on your local machine. Here are some steps and considerations that might help you debug the issue: 1. Check Environment Variables Ensure that all necessary environment variables are correctly set in your Cloud Run environment. This includes any API keys or configuration settings that your agent relies on. Sometimes, differences in environment variables between local and cloud deployments can lead to unexpected behavior. 2. Network Permissions Verify that your Cloud Run service has the necessary permissions to connect to LiveKit. This includes checking if the service account associated with your Cloud Run instance has the right permissions to access LiveKit services. 3. Logging Add more detailed logging in your Cloud Run application to capture the flow of execution. This can help you identify where the process is failing. For example, log when the agent attempts to join the room and any errors that occur during that process.
Copy code
console.log('Attempting to join room:', ctx.room);
4. Check for Errors Look at the Cloud Run logs for any error messages or warnings that might indicate what is going wrong. Pay particular attention to any network-related errors or issues with the LiveKit API. 5. Timeouts and Latency Cloud Run may have different latency characteristics compared to your local environment. Ensure that your agent has enough time to join the room before any timeouts occur. You might want to implement retries or increase timeout settings if applicable. 6. Firewall and Networking If your Cloud Run service is running in a VPC, ensure that it can reach the LiveKit service. Check any firewall rules that might be blocking outbound connections. 7. Debugging Locally with Cloud Emulator Consider using the Google Cloud Emulator to simulate the Cloud Run environment locally. This can help you identify issues that only occur in the cloud environment. 8. Review LiveKit Configuration Double-check your LiveKit configuration settings in the cloud environment. Ensure that the room and participant settings are correctly configured and that the agent is set up to join the correct room. Example Code Snippet Here’s a snippet to ensure that your agent is attempting to join the room and logging the result:
Copy code
entry: async (ctx: JobContext) => {
    await ctx.connect();
    console.log('waiting for participant');
    const participant = await ctx.waitForParticipant();
    console.log(`Participant joined: ${participant.identity}`);

    try {
        await session.start({
            agent: StoryAgent.create(participant.identity, participant.location),
            room: ctx.room,
        });
        console.log('Agent joined the room successfully');
    } catch (error) {
        console.error('Error joining the room:', error);
    }
}
By following these steps, you should be able to identify the root cause of the issue and resolve it. If you continue to have problems, consider isolating components to see if the issue lies with the agent, the connection to LiveKit, or the Cloud Run environment itself.
Do you have a room id where agent did not join? It should start with
RM_
a
Thanks @refined-appointment-81829 1. Environment Variables βœ… 2. Network Permissions ⚠️ (need to check this again) 3. Logging Enhancement βœ… 4. Check for Errors βœ… 5. Timeouts and Latency βœ… 6. Firewall and Networking ⚠️ 7. Debugging Locally with Cloud Emulator ⚠️ 8. Review LiveKit Configuration βœ… The basic problem with the debugging log is as follows: Key Evidence from Logs Local (Working): β€’ βœ…
🚨 ENTRYPOINT FUNCTION CALLED! 🚨
β€’ βœ…
πŸŽ‰ AGENT SESSION STARTED SUCCESSFULLY! πŸŽ‰
β€’ βœ… Successful conversation flow Cloud Run (Failing): β€’ βœ… Worker registration successful β€’ βœ…
received job request
β€’ ❌ Entrypoint never called I'll check the networking and firewalls but I am not sure that is the problem because during setup, I have done everything correctly. I don't think something will change after deployment but I will double check. Some people say that Google Cloud Run is not suitable for Livekit Agents and they recommend Google Cloud Compute. What do you think?
r
Do you have a session ID where an agent did not join the room?
It will start with
RM_
a
Yes, I have a session ID start with RM_ even if the agent do not join the room
πŸ˜• 1
I think I have solved the issue by moving the service from Google Cloud Run to Google Cloude Compute. There are no agent joining problem right now but I am having performance issues. Deepgram is not responding fast enough and I think I need to change the server from 2vCPU 8GB version to a better one. I'll play around and see if I can fix the performance issues.
Now I get these: -
2025-08-21 16:03:20,815 - livekit.plugins.silero - WARNING - inference is slower than realtime
Copy code
ClientConnectionResetError: Cannot write to closing transport
deepgram connection closed unexpectedly
and "AgentSession is closing due to unrecoverable error"
I'll start another thread on agents channel about this issue. Thank you @refined-appointment-81829
r
I was going to suggest trying Cloud Agent and see if it helps: https://livekit-users.slack.com/archives/C01KZ61HZRR/p1755703664834609