What is the difference between ctx.job.room.metada...
# ask-ai
c
What is the difference between ctx.job.room.metadata and ctx.room.metadata? How are these fields populated?
t
Thanks for reaching out, Yousri. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking about the difference between
ctx.job.room.metadata
and
ctx.room.metadata
, and how those values get set. • Difference: ◦
ctx.job.room.metadata
is the room metadata as captured on the job object at dispatch time (available before you connect). ◦
ctx.room.metadata
is the room metadata on the live
Room
instance after the agent connects and reflects the current room state. ◦ They refer to the same underlying room metadata value; they can differ only if the room metadata was changed between job dispatch and when the agent connected. • How they're populated: ◦ Room metadata is set server-side when a room is created or updated (e.g., via server APIs like create/update room metadata or via
RoomConfiguration
in access tokens). ◦ That server-set metadata is synchronized to participants and agents;
ctx.job.room.metadata
captures the value at dispatch,
ctx.room.metadata
shows the live value after connection. Would you like me to show where to read/update room metadata or an example call to update it? Sources: Job lifecycle | LiveKit docs | Room metadata | LiveKit docs | Authentication | LiveKit docs
c
I'm facing some cases where my metadata cannot be found inside the entrypoint athough I created the room with metadata and create room API. WHat's the safest field to access
t
You're seeing missing metadata sometimes — I can help. A few quick recommendations and one question to narrow it down. • Safest field to access in the entrypoint: use
ctx.job.room.metadata
. It exists on the job object at dispatch and is available before you call
ctx.connect()
, so it won't depend on the live room connection timing. • Why:
ctx.job.room.metadata
reflects the room state captured at job dispatch.
ctx.room.metadata
is only populated after the agent connects and may be empty if you try to read it before or if the room state changed between dispatch and connect. • Best practices to avoid missing values: ◦ Read
ctx.job.room.metadata
in the entrypoint before calling
ctx.connect()
. ◦ If you must use
ctx.room.metadata
, call it only after a successful
ctx.connect()
and consider waiting for room state sync events. ◦ Validate metadata at room creation (server-side) and confirm the create/update API returned the expected value. ◦ Add defensive checks: if
ctx.job.room.metadata
is empty, retry a short delay and then check
ctx.room.metadata
after connect. Quick question to help diagnose: when you say "cannot be found inside the entrypoint," are you reading metadata before or after
ctx.connect()
? Also, can you share a minimal code snippet showing where you read the metadata?