Skip to content

fix(inference): don't leak mock participant sid into request headers#1696

Closed
rosetta-livekit-bot[bot] wants to merge 1 commit into
mainfrom
remodel-passion-bruiser
Closed

fix(inference): don't leak mock participant sid into request headers#1696
rosetta-livekit-bot[bot] wants to merge 1 commit into
mainfrom
remodel-passion-bruiser

Conversation

@rosetta-livekit-bot
Copy link
Copy Markdown
Contributor

@rosetta-livekit-bot rosetta-livekit-bot Bot commented Jun 2, 2026

Problem

Running an agent in console mode crashes on startup as soon as STT connects:

TypeError: Cannot serialize non-str key <MagicMock name='mock.local_participant.sid'>
ERROR  AgentSession is closing due to unrecoverable error

This is a regression from #5937 (agent ID header). That change made get_inference_headers() read ctx.agent.sid — which is room.local_participant.sid. In console mode the room comes from create_mock_room(), where local_participant is an autospec mock and .sid was never assigned, so it stayed a truthy MagicMock. The mock passed the truthy check, got added as the X-LiveKit-Agent-ID header value, and aiohttp then failed to serialize it during the WebSocket handshake — taking down STT and the whole session.

Fix

  • ipc/mock_room.py: pin local_participant.sid = "" and identity = "agent" to real strings, matching how the remote participant already sets .sid.
  • inference/_utils.py: harden get_inference_headers() to only emit non-empty str values for room/job/agent IDs, so no mock or test context can inject a non-serializable header again.

Testing

Verified console mode starts and STT connects. Confirmed the mock room now returns a string sid ("", falsy → header omitted, matching the docstring's "omitted in console mode or tests").

🤖 Generated with Claude Code

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 2, 2026

🦋 Changeset detected

Latest commit: a966084

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 34 packages
Name Type
@livekit/agents Patch
@livekit/agents-plugin-anam Patch
@livekit/agents-plugin-assemblyai Patch
@livekit/agents-plugin-baseten Patch
@livekit/agents-plugin-bey Patch
@livekit/agents-plugin-cartesia Patch
@livekit/agents-plugin-cerebras Patch
@livekit/agents-plugin-deepgram Patch
@livekit/agents-plugin-elevenlabs Patch
@livekit/agents-plugin-fishaudio Patch
@livekit/agents-plugin-google Patch
@livekit/agents-plugin-hedra Patch
@livekit/agents-plugin-hume Patch
@livekit/agents-plugin-inworld Patch
@livekit/agents-plugin-lemonslice Patch
@livekit/agents-plugin-liveavatar Patch
@livekit/agents-plugin-livekit Patch
@livekit/agents-plugin-minimax Patch
@livekit/agents-plugin-mistral Patch
@livekit/agents-plugin-mistralai Patch
@livekit/agents-plugin-neuphonic Patch
@livekit/agents-plugin-openai Patch
@livekit/agents-plugin-perplexity Patch
@livekit/agents-plugin-phonic Patch
@livekit/agents-plugin-resemble Patch
@livekit/agents-plugin-rime Patch
@livekit/agents-plugin-runway Patch
@livekit/agents-plugin-sarvam Patch
@livekit/agents-plugin-silero Patch
@livekit/agents-plugin-soniox Patch
@livekit/agents-plugin-tavus Patch
@livekit/agents-plugins-test Patch
@livekit/agents-plugin-trugen Patch
@livekit/agents-plugin-xai Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

@toubatbrian
Copy link
Copy Markdown
Contributor

also a python-specific one

@toubatbrian toubatbrian closed this Jun 3, 2026
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