Skip to content

API Reference parrot.integrations.liveavatar.broadcast.redis_registry

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.integrations.liveavatar.broadcast.redis_registry

View source

Cross-worker broadcast registry backed by Redis (FEAT-537 — Module 2).

Production implementation of :class:~.registry.BroadcastRegistry. Spec §2: "persist scoped metadata, moderation and admission state in Redis so another worker can serve participants or request shutdown … Admission is atomic across workers: pending plus active reservations must never exceed ten."

Every compound operation is one Lua script. Admission, ownership claim, the floor barrier, departure-with-succession, election, transition and socket binding all read and write inside a single atomic server-side call, so two workers racing on the same broadcast cannot interleave a read with the other's write. Nothing here does read-modify-write from Python.

Key layout, namespaced by tenant and broadcast id::

{prefix}:{tenant}:{bid}:descriptor      JSON BroadcastDescriptor
{prefix}:{tenant}:{bid}:leases          hash lease_id -> JSON lease envelope
{prefix}:{tenant}:{bid}:tombstones      zset livekit_identity -> expiry
{prefix}:{tenant}:{bid}:hands           zset lease_id -> sequence
{prefix}:{tenant}:{bid}:owner           string "<worker_id>:<epoch>"
{prefix}:{tenant}:{bid}:stop            string, moderator lease that stopped it
{prefix}:{tenant}:{bid}:meta            hash of registry-internal scalars
{prefix}:{tenant}:index                 set of live broadcast ids

Nothing secret is ever written: the descriptor carries no token by construction, owner_worker_id is an opaque worker id (never a network address — address resolution belongs to the service layer), and no PCM, AWS credential or LiveAvatar access token touches these keys.

Attribute DEFAULT_KEY_PREFIX

Type: str

Class RedisBroadcastRegistry

Redis-backed, cross-worker :class:BroadcastRegistry.

Parameter Type Default Description
redis_client Any An redis.asyncio.Redis with decode_responses=True.
key_prefix str DEFAULT_KEY_PREFIX Namespace for every key this registry owns.
clock Optional[Callable[[], float]] None Optional client-side clock. Production leaves this None so every script stamps time from Redis TIME — the single clock all workers share. Tests inject a fake clock so TTL behaviour is deterministic without sleeping.
owns_client bool False Whether :meth:aclose should close redis_client.

Method RedisBroadcastRegistry.from_url

Build a registry from a Redis URL (lazy redis.asyncio import).

from_url(redis_url: str, *, key_prefix: str = DEFAULT_KEY_PREFIX, clock: Optional[Callable[[], float]] = None) -> 'RedisBroadcastRegistry'

Parameter Type Default Description
redis_url str Standard redis:// URL.
key_prefix str DEFAULT_KEY_PREFIX Namespace for every key this registry owns.
clock Optional[Callable[[], float]] None Optional client-side clock override (tests only).

Returns: 'RedisBroadcastRegistry' — A ready registry owning its own connection pool.

Method RedisBroadcastRegistry.ping

Verify the Redis connection. Raises the driver's error when down.

ping() -> bool

Returns: bool

Method RedisBroadcastRegistry.aclose

Close the underlying client when this registry owns it.

aclose() -> None

Method RedisBroadcastRegistry.purge_all_for_tests

Delete every key under this registry's prefix. Test helper only.

purge_all_for_tests() -> int

Returns: int — Number of keys removed.

Method RedisBroadcastRegistry.create

create(descriptor: BroadcastDescriptor) -> BroadcastDescriptor

Parameter Type Default Description
descriptor BroadcastDescriptor

Returns: BroadcastDescriptor

Method RedisBroadcastRegistry.get

get(tenant_id: str, broadcast_id: str) -> Optional[BroadcastDescriptor]

Parameter Type Default Description
tenant_id str
broadcast_id str

Returns: Optional[BroadcastDescriptor]

Method RedisBroadcastRegistry.transition

transition(tenant_id: str, broadcast_id: str, new_state: BroadcastState, *, output_epoch: Optional[int] = None, reason: Optional[BroadcastReason] = None, expected_owner_epoch: int) -> BroadcastDescriptor

Parameter Type Default Description
tenant_id str
broadcast_id str
new_state BroadcastState
output_epoch Optional[int] None
reason Optional[BroadcastReason] None
expected_owner_epoch int

Returns: BroadcastDescriptor

Method RedisBroadcastRegistry.claim_owner

claim_owner(tenant_id: str, broadcast_id: str, worker_id: str, *, now: Optional[float] = None) -> Tuple[bool, int]

Parameter Type Default Description
tenant_id str
broadcast_id str
worker_id str
now Optional[float] None

Returns: Tuple[bool, int]

Method RedisBroadcastRegistry.renew_owner

renew_owner(tenant_id: str, broadcast_id: str, worker_id: str, owner_epoch: int, *, now: Optional[float] = None) -> bool

Parameter Type Default Description
tenant_id str
broadcast_id str
worker_id str
owner_epoch int
now Optional[float] None

Returns: bool

Method RedisBroadcastRegistry.reserve_viewer

reserve_viewer(tenant_id: str, broadcast_id: str, principal: ParticipantPrincipal, livekit_identity: str, *, now: Optional[float] = None) -> Admission

Parameter Type Default Description
tenant_id str
broadcast_id str
principal ParticipantPrincipal
livekit_identity str
now Optional[float] None

Returns: Admission

Method RedisBroadcastRegistry.confirm_viewer

confirm_viewer(tenant_id: str, broadcast_id: str, lease_id: str) -> ViewerLease

Parameter Type Default Description
tenant_id str
broadcast_id str
lease_id str

Returns: ViewerLease

Method RedisBroadcastRegistry.heartbeat_control

heartbeat_control(tenant_id: str, broadcast_id: str, lease_id: str, *, now: Optional[float] = None) -> None

Parameter Type Default Description
tenant_id str
broadcast_id str
lease_id str
now Optional[float] None

Method RedisBroadcastRegistry.release_viewer

release_viewer(tenant_id: str, broadcast_id: str, lease_id: str, *, now: Optional[float] = None) -> ReleaseOutcome

Parameter Type Default Description
tenant_id str
broadcast_id str
lease_id str
now Optional[float] None

Returns: ReleaseOutcome

Method RedisBroadcastRegistry.list_leases

list_leases(tenant_id: str, broadcast_id: str) -> List[ViewerLease]

Parameter Type Default Description
tenant_id str
broadcast_id str

Returns: List[ViewerLease]

Method RedisBroadcastRegistry.raise_hand

raise_hand(tenant_id: str, broadcast_id: str, lease_id: str, *, now: Optional[float] = None) -> BroadcastDescriptor

Parameter Type Default Description
tenant_id str
broadcast_id str
lease_id str
now Optional[float] None

Returns: BroadcastDescriptor

Method RedisBroadcastRegistry.cancel_hand

cancel_hand(tenant_id: str, broadcast_id: str, lease_id: str) -> BroadcastDescriptor

Parameter Type Default Description
tenant_id str
broadcast_id str
lease_id str

Returns: BroadcastDescriptor

Method RedisBroadcastRegistry.dismiss_hand

dismiss_hand(tenant_id: str, broadcast_id: str, moderator_lease_id: str, target_lease_id: str) -> BroadcastDescriptor

Parameter Type Default Description
tenant_id str
broadcast_id str
moderator_lease_id str
target_lease_id str

Returns: BroadcastDescriptor

Method RedisBroadcastRegistry.grant_floor

grant_floor(tenant_id: str, broadcast_id: str, moderator_lease_id: str, target_lease_id: Optional[str], expected_version: int) -> BroadcastDescriptor

Parameter Type Default Description
tenant_id str
broadcast_id str
moderator_lease_id str
target_lease_id Optional[str]
expected_version int

Returns: BroadcastDescriptor

Method RedisBroadcastRegistry.commit_floor

commit_floor(tenant_id: str, broadcast_id: str, target_lease_id: str, floor_epoch: int) -> BroadcastDescriptor

Parameter Type Default Description
tenant_id str
broadcast_id str
target_lease_id str
floor_epoch int

Returns: BroadcastDescriptor

Method RedisBroadcastRegistry.abort_floor

abort_floor(tenant_id: str, broadcast_id: str, floor_epoch: int) -> BroadcastDescriptor

Parameter Type Default Description
tenant_id str
broadcast_id str
floor_epoch int

Returns: BroadcastDescriptor

Method RedisBroadcastRegistry.release_floor

release_floor(tenant_id: str, broadcast_id: str, speaker_lease_id: str) -> BroadcastDescriptor

Parameter Type Default Description
tenant_id str
broadcast_id str
speaker_lease_id str

Returns: BroadcastDescriptor

Method RedisBroadcastRegistry.revoke_floor

revoke_floor(tenant_id: str, broadcast_id: str, moderator_lease_id: str, expected_version: int) -> BroadcastDescriptor

Parameter Type Default Description
tenant_id str
broadcast_id str
moderator_lease_id str
expected_version int

Returns: BroadcastDescriptor

Method RedisBroadcastRegistry.elect_moderator

elect_moderator(tenant_id: str, broadcast_id: str, *, now: Optional[float] = None) -> Optional[str]

Parameter Type Default Description
tenant_id str
broadcast_id str
now Optional[float] None

Returns: Optional[str]

Method RedisBroadcastRegistry.bind_speaker_socket

bind_speaker_socket(tenant_id: str, broadcast_id: str, lease_id: str, socket_id: str, floor_epoch: int) -> bool

Parameter Type Default Description
tenant_id str
broadcast_id str
lease_id str
socket_id str
floor_epoch int

Returns: bool

Method RedisBroadcastRegistry.unbind_speaker_socket

unbind_speaker_socket(tenant_id: str, broadcast_id: str, lease_id: str, socket_id: str) -> bool

Parameter Type Default Description
tenant_id str
broadcast_id str
lease_id str
socket_id str

Returns: bool

Method RedisBroadcastRegistry.request_stop

request_stop(tenant_id: str, broadcast_id: str, by_lease_id: str) -> BroadcastDescriptor

Parameter Type Default Description
tenant_id str
broadcast_id str
by_lease_id str

Returns: BroadcastDescriptor

Method RedisBroadcastRegistry.stop_requested

stop_requested(tenant_id: str, broadcast_id: str) -> bool

Parameter Type Default Description
tenant_id str
broadcast_id str

Returns: bool

Method RedisBroadcastRegistry.set_media_state

set_media_state(tenant_id: str, broadcast_id: str, *, room_name: Optional[str] = None, avatar_identity: Optional[str] = None, direct_identity: Optional[str] = None, liveavatar_session_id: Optional[str] = None) -> Optional[BroadcastDescriptor]

Parameter Type Default Description
tenant_id str
broadcast_id str
room_name Optional[str] None
avatar_identity Optional[str] None
direct_identity Optional[str] None
liveavatar_session_id Optional[str] None

Returns: Optional[BroadcastDescriptor]

Method RedisBroadcastRegistry.list_broadcasts

Every live broadcast across every tenant this registry has seen.

Reads the tenant roll-call and each tenant's index set rather than scanning the keyspace, so the cost is proportional to live broadcasts instead of to total Redis keys.

list_broadcasts() -> List[Tuple[str, str]]

Returns: List[Tuple[str, str]] — (tenant_id, broadcast_id) pairs.

Method RedisBroadcastRegistry.expire

expire(tenant_id: str, broadcast_id: str, *, now: Optional[float] = None) -> List[ExpiryEvent]

Parameter Type Default Description
tenant_id str
broadcast_id str
now Optional[float] None

Returns: List[ExpiryEvent]

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally