agents icon indicating copy to clipboard operation
agents copied to clipboard

Participant spoken attribution always set to agent

Open Uldiniad opened this issue 8 months ago • 7 comments

Bug Description

Spoken input from participants is attributed to the agent in chat. Text input is correctly attributed to the participant

Expected Behavior

Spoken input from participants is attributed to the correct participant.

Reproduction Steps

1. Configure an agent that transcribes user speech and publishes transcriptions 
2. On the frontend, receive transcriptions
3. Observe participant identity is always the agent's identity

Operating System

Windows 11 (WSL 2)

Models Used

AWS

Package Versions

livekit==1.0.25
livekit-agents[aws]==1.5.0
livekit-plugins-noise-cancellation==0.2.5
livekit-plugins-openai==1.5.0
livekit-plugins-silero==1.5.0
livekit-plugins-turn-detector==1.5.0

livekit-client==2.17.3
@livekit/components-core==0.12.13
@livekit/components-react==2.9.20
@livekit/components-styles==1.2.0

Session/Room/Call IDs

LiveKit Cloud

Proposed Solution


Additional Context

No response

Screenshots and Recordings

No response

Uldiniad avatar Mar 20 '26 20:03 Uldiniad

@cosmastech, any updates on this? know who to ping to have them take a look?

Uldiniad avatar Apr 09 '26 18:04 Uldiniad

@Uldiniad could you share a minimal example that can reproduce the issue?

longcw avatar Apr 10 '26 03:04 longcw

it's only happening when e2ee is enabled

Uldiniad avatar Apr 10 '26 18:04 Uldiniad

Hi, I'm Himanshu, a new contributor looking for a scoped reproduction task. I read the clarification that this occurs with E2EE enabled and saw #5190 is closed. Would a minimal example comparing spoken vs typed transcription attribution with E2EE on/off help move this forward? Is the issue still reproducible on a current release, and is there a preferred starter example to use?

himanshumehta10 avatar Oct 24 '26 03:10 himanshumehta10

I have not tried since the last time I posted about it. I can try again on the latest setup but I am nearly certain that it is the case still. I'll try sending what I get

Uldiniad avatar Oct 25 '26 00:10 Uldiniad

@longcw @himanshumehta10 here's the minimal example. It still reproduces on the latest releases.

# /// script
# dependencies = ["livekit", "livekit-api"]
# ///
import asyncio
import os

from livekit import api, rtc

URL = os.environ["LIVEKIT_URL"]
API_KEY = os.environ["LIVEKIT_API_KEY"]
API_SECRET = os.environ["LIVEKIT_API_SECRET"]


def token(room: str, identity: str, kind: api.AccessToken.ParticipantKind) -> str:
    return (
        api.AccessToken(API_KEY, API_SECRET)
        .with_identity(identity)
        .with_kind(kind)
        .with_grants(api.VideoGrants(room_join=True, room=room))
        .to_jwt()
    )


async def run(e2ee: bool) -> None:
    room = f"attribution-e2ee-{str(e2ee).lower()}"
    encryption = rtc.E2EEOptions(
        key_provider_options=rtc.KeyProviderOptions(shared_key=b"repro")
    )
    options = rtc.RoomOptions(encryption=encryption if e2ee else None)
    user, agent = rtc.Room(), rtc.Room()
    sender = asyncio.get_running_loop().create_future()
    user.register_text_stream_handler(
        "lk.transcription", lambda reader, identity: sender.set_result(identity)
    )
    await user.connect(URL, token(room, "user", "standard"), options)
    await agent.connect(URL, token(room, "agent", "agent"), options)

    # Publish the user's transcript the way livekit-agents does
    writer = await agent.local_participant.stream_text(
        topic="lk.transcription", sender_identity="user"
    )
    await writer.write("hello")
    await writer.aclose()

    print(f"e2ee={e2ee}: user's transcript arrived from {await sender!r}")
    await agent.disconnect()
    await user.disconnect()


async def main() -> None:
    await run(e2ee=False)
    await run(e2ee=True)


asyncio.run(main())
$ LIVEKIT_URL=... LIVEKIT_API_KEY=... LIVEKIT_API_SECRET=... uv run repro.py
e2ee=False: user's transcript arrived from 'user'
e2ee=True: user's transcript arrived from 'agent'

Uldiniad avatar Oct 25 '26 00:10 Uldiniad

@Uldiniad thanks for the minimal example. I ported it into a test against a local livekit-server --dev (1.13.11) and it reproduces exactly:

Data-channel encryption Identity the user's handler sees
off user
on, shared key agent
on, per-participant keys agent

Reproduction run

The cause isn't in agents. room_io passes sender_identity correctly to stream_text. The server exempts an agent's on-behalf text-stream header from identity override only when it can read it in plaintext. With encryption on, the header is inside an EncryptedPacket the server can't inspect, so it stamps the agent's identity on it.

I opened livekit/livekit#5132 with the server code references and three ways to fix it:

  • Exempt encrypted packets from agents. Simple, but it would trust an agent's claimed sender for every encrypted type, RPC included.
  • Carry the on-behalf identity inside the encrypted payload. The cleanest, but it needs protocol and SDK changes.
  • Frontend fallback using lk.transcribed_track_id. A workaround, and the one you can apply today.

Test used: test_transcription_e2ee_attribution.py. Run it with --runxfail to see the two encrypted cases fail.

himanshumehta avatar Nov 03 '26 17:11 himanshumehta