100 Commits
Author SHA1 Message Date
Paul Wells 1ba2cadccd agent: release JobTerminate handler when job ends before registration (#4908)
* agent: release JobTerminate handler when job ends before registration

JobRequest registered the job's JobTerminate handler after AssignJob
returned, so an ended UpdateJobStatus or worker disconnect handled in
between deregistered nothing and the handler leaked. AssignJob also sent
the assignment before recording the job as running, so an immediate
ended update was dropped.

Record the job before sending the assignment, and after registering the
handler recheck under h.mu that the job is still running and its worker
still registered, deregistering otherwise.

Fixes #4901

* replace utils.CloneProto with proto.CloneOf

* agent: wait on worker readiness and poll for released handlers in test
2026-09-25 00:58:22 -07:00
Paul Wells d5c691836f deps: update psrpc to v0.8.0 (#4882)
* deps: update psrpc to v0.8.0

psrpc v0.8.0 splits the brokers into leaf packages so importing psrpc no
longer pulls in nats.go and go-redis, and drops the root constructors:

  - return psrpc.NewRedisMessageBus(rc, opts...)
  + return redisbus.New(rc, opts...)

getMessageBus keeps its NewLocalMessageBus branch -- that shim stays at the
root because localbus costs no dependency. wire_gen.go carries a verbatim
copy of the provider, so it gets the identical edit rather than a wire
rerun, which would churn unrelated output.

redisbus.New takes ...bus.BusOption and psrpc.BusOption is an alias for it,
so PSRPCConfig.BusOptions() spreads in unchanged.

The nats-io requirements drop out of go.mod; this module only ever used the
Redis bus, and nats came in indirectly through psrpc's root package.

* Reorder import statements in ioservice_sip_test.go
2026-09-20 16:45:40 -07:00
Paul Wells c6f3ceba10 update psrpc for subscription close goroutine leak fix (#4859) 2026-09-11 05:41:48 -07:00
Paul Wells e18fbcc0fa wire psrpc bus compression into the message bus constructor (#4844)
getMessageBus built the bus from the redis client alone, so there was no
way to reach the gzip settings psrpc v0.7.6 added at the bus boundary.
Take rpc.PSRPCConfig, which the wire graph already provides, and pass its
bus options to both the redis and the local bus.

Compression is off by default. A peer on an older psrpc cannot decode a
compressed payload and drops it silently, so egress, ingress, SIP and
agent workers all have to be upgraded before quality is raised.
2026-09-05 06:58:59 -07:00
Paul Wells 54496c765d report a reason on room-ended telemetry (#4815)
* report a reason on room-ended telemetry

Room.Close already took a ParticipantCloseReason, but OnClose was func()
with no arguments, so the reason was structurally dropped before it could
reach RoomEnded.

Add types.RoomCloseReason and carry it through Close -> OnClose -> RoomEnded,
where it lands on both the analytics event and the room_finished webhook.

Room.Close now takes the room reason and derives the participant reason from
it, so the two can never disagree. ToParticipantCloseReason maps each reason
to exactly what its call site passed before, so no participant-facing
behaviour changes; a table test pins that mapping.

* fix(test): update webhook test for RoomCloseReason

test/ was outside the packages checked before pushing, so this Close call
site was missed. Also assert the reason reaches the room_finished webhook,
which the unit test cannot cover since it runs with a nil notifier.
2026-08-28 23:41:59 -07:00
Paul Wells b882ccc86d service: cap all metadata at 512 KiB; enforce on join, agent dispatch, and embedded agents (#4602)
* service: enforce metadata size limit in CreateRoom, bump default to 512 KiB

CreateRoom previously accepted any metadata size; only UpdateRoomMetadata
rejected oversized payloads. Mirror the same CheckMetadataSize check at
the CreateRoom API boundary so both entrypoints are bounded.

Default MaxMetadataSize moves from 64000 to 512 * 1024 to match the
practical needs of customers using room metadata for richer state. The
limit remains configurable via the existing limits.max_metadata_size knob.

* service: split room vs. participant metadata limit, enforce on join + agent dispatch

LimitConfig.MaxMetadataSize was shared between room metadata and
participant metadata. Last commit's bump to 512 KiB lifted both ceilings;
this restores the participant ceiling to 64 KB and introduces a separate
MaxRoomMetadataSize (default 512 KiB) for room metadata.

Additional enforcement:

- RoomManager.StartSession rejects joins whose JWT-grants metadata or
  attributes exceed the participant/attributes limits. The check was
  missing entirely from this path.
- AgentDispatchService.CreateDispatch and the embedded
  CreateRoomRequest.Agents path now validate metadata and attributes
  against the common 64 KB ceilings (previously unbounded).

NewAgentDispatchService gains a LimitConfig parameter; the two wire_gen
callsites are updated.

* service: collapse metadata size limit to single 512 KiB knob

Reverts the LimitConfig split introduced in the previous commit:
MaxRoomMetadataSize, CheckRoomMetadataSize, and the max_room_metadata_size
yaml key are removed. MaxMetadataSize moves back to 512 * 1024 and gates
all metadata uniformly — room (CreateRoom, UpdateRoomMetadata), participant
(UpdateParticipant, signal UpdateMetadata, JWT grants on join), and agent
dispatch (CreateDispatch + embedded RoomAgentDispatch).

MaxAttributesSize stays at 64 KB and continues to gate participant and
agent-dispatch attributes separately.

Test cases consolidated under the single knob.

* kb -> kib
2026-06-17 12:35:59 -07:00
Paul Wells 12a023ae45 agent: thread attributes map from dispatch to job (#4598)
* agent: thread simulation flag from dispatch to job

Reads simulation from AgentDispatch / RoomAgentDispatch and copies it
onto Job in agent.LaunchJob and the inline room-agent path so workers
see the flag.

Stacked on top of livekit/protocol#1629.

* agent: replace simulation bool with attributes map

Threads the renamed attributes map (was bool simulation) from dispatch
to job and bumps the protocol pseudo-version.

* deps
2026-06-16 01:53:01 -07:00
Paul Wells cdbbee1f8e deps: bump protocol + psrpc to latest tips (#4565)
* deps: bump psrpc + protocol + cloud-protocol + backend-common to latest

* deps: go get -u sweep + bump counterfeiter

Direct deps bumped via go get -u ./...:
  clipperhouse/displaywidth 0.10.0 -> 0.11.0
  clipperhouse/uax29/v2 2.6.0 -> 2.7.0
  fatih/color 1.18.0 -> 1.19.0
  florianl/go-tc 0.4.7 -> 0.4.8
  hashicorp/go-version 1.8.0 -> 1.9.0
  livekit/protocol -> a7a83da5 (latest)
  ua-parser bumped
  urfave/cli/v3 3.8.0 -> 3.9.0
  otel/sdk 1.43.0 -> 1.44.0
  yaml.in/yaml/v2 2.4.2 -> 2.4.4

Indirect: mdlayher/netlink + socket bumped, mattn/* bumped, olekukonko/*
bumped, counterfeiter v6.11.1 -> v6.12.2.

Newer-major audit: no actionable majors. +incompatible: twitchtv/twirp
v8.1.3 (upstream choice, stays); docker/cli and docker/docker indirect.

Notable stuck patterns worth a separate cleanup:
- pkg/errors v0.9.1 direct dep (unmaintained; stdlib supplants)
- go.uber.org/atomic + multierr direct deps
- ory/dockertest/v3 v3.12.0 (v4 is available — cascade has migrated
  cloud-protocol, backend-common, psrpc to v4).

* deps: pin pion/webrtc/v4 v4.2.11 + pion/sctp v1.9.5

* deps: pin protocol+psrpc+MTU to landed versions
2026-06-05 14:48:51 -07:00
Paul Wells 77ecf920ff rtc: report participant session end time on room move (#4561)
MoveToRoom resets the participant reporter resolver to receive new
(room, participant_session) keys for the destination, but the source
room's participant_session row never gets an end_time — the periodic
duration scrape only emits one once disconnectedAt is set, and a move
doesn't transition the participant to DISCONNECTED. Report end_time
immediately before the reset so the row is closed out cleanly.
2026-06-03 21:35:39 -07:00
Paul Wells 2dd5e63207 telemetry: split webhook-processed hook out of NewTelemetryService (#4548)
* telemetry: split webhook-processed hook registration out of NewTelemetryService

NewTelemetryService used to register a notifier processed-hook on the inner
*telemetryService directly. That made it impossible for downstream wrappers
(e.g. cloud's TelemetryService that overrides Webhook to fan out to a v3
observability pipeline) to intercept webhook events without double-firing
the legacy emission.

Lift the registration into a new exported helper RegisterWebhookHook, and
have the standalone server's wire provider createTelemetryService call it
right after construction so behavior is unchanged for callers that don't
wrap the service.
2026-05-27 09:40:55 -07:00
Paul Wells 222177a9e4 service: prevent nil deref in validate with wrapped join request (#4547)
When a client hits /rtc/v[01]/validate with a base64 WrappedJoinRequest
whose embedded JoinRequest.ClientInfo is unset, validateInternal called
AugmentClientInfo with a nil *ClientInfo and panicked at ci.Address =
GetClientIP(req). The non-wrapped branch already allocates via
ParseClientInfo; do the same here so pi.Client always gets at least the
resolved client Address.
2026-05-26 08:34:15 -07:00
Paul Wells cde8962709 rtc: emit per-data-track bytes via BytesTrackStats (#4540)
Data tracks (the new _data_track datachannel) previously only updated a
private dataTrackStats that logged a single summary at Close. Bytes never
reached the OnTrackStats -> TelemetryService.TrackStats pipeline that
media tracks and signal channels feed.

Wire DataTrack (UPSTREAM, publisher-home) and DataDownTrack (DOWNSTREAM,
per-subscriber) into BytesTrackStats on the same 5s cadence, mirroring
the media-track convention: subscriber's country and ID with publisher's
track ID for DOWNSTREAM. Cross-region proxy DataTracks leave the stats
pointer nil (no publisher reporter on that node, and relayed bytes would
double-count). Legacy dataTrackStats packet-loss/frame counters are
preserved.
2026-05-23 17:42:55 -07:00
Paul Wells 7f08b04c1e Add IsIntentionalDisconnect helper (#4537)
Shared helper for callers that need to distinguish intentional/expected
participant closures (client leave, admin action, room teardown, migration)
from connection failures. Extracted from cloud's IsClosedIntentionally
switch so cloud-side code paths can share a single source of truth.
2026-05-20 11:42:51 -07:00
Paul Wells 019a6640ae rtc: report participant kind code and details (#4534)
* rtc: report participant kind code and details

Plumb ParticipantKind and KindDetails through MediaTrack and
BytesTrackStats so track-level reporting can record the numeric kind
code plus details codes on every participant_session aggregation,
alongside the existing Kind string. Also picks up the new kind fields
on resolved BytesSignalStats participants.

Adds deployment/agentID/version to the agent worker logger.
2026-05-18 23:20:52 -07:00
Paul Wells ab7fdeab7c add AssignmentHook to AssignJob; propagate websocket write errors (#4516)
* add AssignmentHook to AssignJob; propagate websocket write errors

- Replace the `url *string` parameter on `Worker.AssignJob` with a
  middleware-style `AssignmentHook` so callers can intercept the
  `JobAssignment` send (e.g. to set Url, or to gate hedged attempts so
  only one assignment is written).
- Remove the `sendRequest` helper. Inline `WriteServerMessage` and
  propagate the error: `AssignJob` returns immediately on a failed
  availability or assignment write, leaving the job out of
  `runningJobs`; `TerminateJob` still updates local bookkeeping when
  the wire write fails but surfaces the write error to the caller.

* tidy
2026-05-10 21:14:02 -07:00
Paul Wells 12fff29a12 allow setting agent job assignment url (#4512) 2026-05-07 13:13:21 -07:00
Paul Wells 8fbc5adfce update protocol for protojson (#4510) 2026-05-07 00:55:00 -07:00
Paul Wells 803999efad rename agent environment to deployment (#4506)
* rename agent environment to deployment

* deps
2026-05-05 14:19:40 -07:00
Paul Wells bacc21e6c0 add helper to check for agent worker endpoint (#4503) 2026-05-05 13:38:53 -07:00
Paul Wells 253f977d32 add duration seconds reporting (#4500)
* add duration seconds reporting

* deps

* deps
2026-05-02 06:19:23 -07:00
Paul Wells ffab3bd308 add agent environment (#4498)
* add agent environment

* lint

* psrpc error

* deps
2026-05-01 19:30:06 -07:00
Paul Wells d7c2daf1ac report all simulcast layers (#4491) 2026-04-28 10:45:32 -07:00
Paul Wells 2a04bc3ca8 fix publisher frame count reporting for simulcast streams (#4457) 2026-04-16 11:08:33 -07:00
Paul Wells 88c77dc666 compute agent dispatch affinity from target load (#4442)
* compute agent dispatch affinity from target load

* fix test config
2026-04-09 13:49:43 -07:00
Paul Wells 4d8d232a19 ensure participant init is correctly serialized for logging (#4417) 2026-03-31 19:33:57 -07:00
Paul WellsandClaude Opus 4.6 9ab8c1d522 clear track notifier observers on subscription teardown (#4413)
When a subscriber disconnects, observer closures registered on the
publisher's TrackChangedNotifier and TrackRemovedNotifier were never
removed. These closures capture the SubscriptionManager, which holds
the ParticipantImpl, preventing the entire participant object graph
(PCTransport, SDPs, RTP stats, DownTracks) from being garbage collected.

In rooms with many participants that disconnect and reconnect frequently,
this causes unbounded memory growth proportional to the number of
disconnect events. The leaked memory is not recoverable while the room
remains open.

Clear notifiers in both handleSubscribedTrackClose (individual
subscription teardown) and SubscriptionManager.Close (full participant
teardown), matching the existing cleanup in handleSourceTrackRemoved.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 20:48:48 -07:00
Paul Wells 13d02ee9a8 add deadline to dtls connect context (#4395) 2026-03-25 21:13:23 -07:00
Paul WellsandClaude Opus 4.6 c8bb2578be Rename log field "pID" to "participantID" for consistency (#4365)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-15 04:32:02 -07:00
Paul Wells 3cca718072 use separate allocation for signal stats telemetry guard (#4281) 2026-02-03 02:13:49 -08:00
Paul Wells 333f0349d1 clear reference guard when resetting signal stats (#4279) 2026-02-03 01:54:03 -08:00
Paul Wells 700e1788f2 require participant broadcast when metadata/attributes are set in token (#4266) 2026-01-26 14:22:30 -08:00
Paul Wells 0a82438687 add explicit room exists servicestore op (#4175) 2025-12-17 22:14:06 -08:00
Paul Wells 462ec324be prevent uint overflow setting packet not found count (#4169) 2025-12-17 06:54:23 -08:00
Paul Wells 2f2d0a5735 skip lost sequence number ranges in getIntervalStats (#4166) 2025-12-17 00:02:51 -08:00
Paul Wells 898ebe058c clean up manual roomservice log redaction (#4165)
* clean up manual roomservice log redaction

* deps
2025-12-16 23:02:45 -08:00
Paul Wells 3e41725395 move delete to oss service store (#4164) 2025-12-16 22:00:43 -08:00
Paul Wells 0abfb2515c deregister observability function when participant is closed (#4157)
* deregister observability function when participant is closed

* tidy
2025-12-14 04:21:07 -08:00
Paul Wells c6e6c0215f add debug metric for tracking references (#4134) 2025-12-07 11:39:21 -08:00
Paul Wells b23d093c2f update protocol (#4069)
* update protocol

* deps
2025-11-09 19:42:08 -08:00
Paul Wells 060719d17d add config for user data recording (#3966)
* add config for user data recording

* missing file

* wire

* deps
2025-09-29 14:01:39 -07:00
Paul Wells b3ee219ccb fix stats worker closed condition (#3965)
* fix stats worker closed condition

* test

* tidy
2025-09-29 02:51:58 -07:00
Paul Wells 3d73703152 add idempotent reference count to telemetry stats worker (#3964)
* add idempotent reference guard to telemetry stats worker

* tidy

* sync

* tidy
2025-09-29 02:35:16 -07:00
Paul Wells e180be0622 short circuit participant broadcast filter in livestream mode (#3955) 2025-09-25 16:19:35 -07:00
Paul Wells 56ee23282f handle terminated job requests (#3948) 2025-09-23 23:54:01 -07:00
Paul Wells 782a35e801 update protocol for psrpc (#3915) 2025-09-10 21:01:28 -07:00
Paul Wells 17c349210d update protocol for sip api change (#3902) 2025-09-06 12:00:22 -07:00
Paul Wells 2aeadf14dc init ua parser once (#3883) 2025-08-28 05:20:25 -07:00
Paul Wells 8d270e2a0f chunk room updates (#3880)
* chunk room updates

* move to config

* typo

* default
2025-08-26 09:16:00 -07:00
Paul Wells ba702a5323 forward agent id to job state (#3786)
* forward agent id to job state

* deps
2025-07-16 14:17:13 -07:00
Paul Wells 8197438e5f bounds check layer index (#3768)
* bounds check layer index

* tidy
2025-06-29 18:37:26 -07:00
Paul Wells 068b43660b reuse compiled client config scripts (#3743) 2025-06-19 14:31:59 -07:00
Paul Wells 35dda8ea43 swap pub/sub track metrics (#3717) 2025-06-10 11:27:34 -07:00
Paul Wells 630aa7d970 implement observability for room metrics (#3712)
* implement observability for room metrics

* deps

* test

* test

* Raja feedback

* cleanup
2025-06-09 09:32:58 -07:00
Paul Wells e7f0294e3f remove unused ws signal read loop (#3709)
* remove unused ws signal read loop

fixes #3708

* tidy
2025-06-08 20:07:55 -07:00
Paul Wells e4f7d81bdd add client ip to agent worker registration (#3675) 2025-05-20 07:58:28 -07:00
Paul Wells 13b55a80ad move agent token (#3669) 2025-05-15 10:30:14 -07:00
Paul Wells c9385edd1e handle agent worker jwt (#3668)
* handle agent worker jwt

* test

* tidy

* tidy

* deps
2025-05-15 08:23:10 -07:00
Paul Wells aee34ffefa log request for agent dispatch api (#3650) 2025-05-08 08:43:43 -07:00
Paul Wells ee08aede5b skip out of order participant state updates (#3583)
* skip out of order participant state updates

* avoid nil last active pointer

* cleanup

* protect state change callbacks

* gen

* test
2025-04-06 06:44:50 -07:00
Paul Wells ac9e62ef05 add server agent load threshold config (#3520)
* remove agent worker load threshold

* cleanup
2025-03-11 21:07:01 -07:00
Paul Wells 48063df5b8 load mime type before calling writeBlankFrameRTP (#3502) 2025-03-07 23:12:20 -08:00
Paul Wells 43bd251575 simplify vls base access (#3465) 2025-02-26 09:34:59 +05:30
Paul Wells 3167266495 add datapacket stream metrics (#3450)
* add datapacket stream metrics

* normalize mime type
2025-02-19 22:28:10 -08:00
Paul Wells f49103a003 add participant job type (#3443)
* add participant job type

* cleanup

* deps
2025-02-18 00:40:56 -08:00
Paul Wells d8e325d3d4 copy track info when toggling mute (#3406)
* copy track info when toggling mute

* test
2025-02-05 20:12:11 -08:00
Paul Wells 7216c825fb fix internal signal protocol backward compatibility with 1.7.x (#3384)
* fix internal signal protocol backward compatibility with 1.7.x
fixes #3371

* tidy
2025-01-30 16:44:35 -08:00
Paul Wells 3970e965f6 move ConnectedAt to Participant interface (#3383) 2025-01-30 05:45:47 -08:00
Paul Wells ef4b5faba1 close signal session is request messages are undeliverable (#3364) 2025-01-24 00:24:22 -08:00
Paul Wells f435c5cb62 reduce log level for channel closed error when writing signal message (#3361)
* reduce log level for channel closed error when writing signal message

* tidy
2025-01-22 04:33:47 -08:00
Paul Wells 759e5f79e0 allocate node for autocreated room in agent dispatch (#3344) 2025-01-17 00:54:30 -08:00
Paul Wells 29c7906250 skip http request logging when the client aborts the request (#3195)
* skip http request logging when the client aborts the request

* cleanup
2024-11-22 00:42:49 -08:00
Paul Wells 73fbc6b8bb convert psprc error to http code in rtc service failure response (#3187) 2024-11-19 19:45:00 -08:00
Paul Wells 9e4dae7107 add per message deflate to signal ws (#3174) 2024-11-14 00:35:30 -08:00
Paul Wells 09f140afa8 auto create rooms during create agent dispatch api request (#3158) 2024-11-05 16:15:05 -08:00
Paul Wells 24f3c93204 ignore unexported fields in yaml lint (#3145) 2024-10-29 12:16:21 -07:00
Paul Wells b0d3d65f18 update events package (#3126)
* update events package

* deps
2024-10-21 23:44:00 -07:00
Paul Wells 119113a5e9 use proto logger for ice config (#3079) 2024-10-09 09:13:42 -07:00
Paul Wells 00ac004604 use AgentDispatch in internal request (#3074)
* use AgentDispatch in internal request

* deps

* deps

* deps
2024-10-08 01:25:00 -07:00
Paul Wells 4c2b154c41 start jobs with started state (#3070)
* start jobs with started state

* deps
2024-10-07 04:09:10 -07:00
Paul Wells 3261560098 api for agent worker job count (#3068)
* api for agent worker job count

* cleanup

* temp deps

* temp deps

* deps
2024-10-05 05:13:52 -07:00
Paul Wells 99f7be7c1c clean up redundant String calls in logs (#3064) 2024-10-03 08:08:46 -07:00
Paul Wells c9d2552cb3 accept any participant type source to BroadcastMetricsForRoom (#3063) 2024-10-03 05:51:02 -07:00
Paul Wells 119e11e191 check data messages for nil payloads (#3062)
* check data messages for nil payloads

* more checks

* cleanup
2024-10-03 05:19:27 -07:00
Paul Wells bdfb2c4ca9 init agent worker ping handler (#3061)
* init agent worker ping handler

* cleanup
2024-10-03 04:08:07 -07:00
Paul Wells 0b4fd32905 add unlikely logger (#3058) 2024-10-02 22:58:25 -07:00
Paul Wells 8befc8224a use canonical room log field name (#3054) 2024-09-27 16:52:34 -07:00
Paul Wells 10631e2de6 enable room creator service by default (#3043) 2024-09-25 19:08:17 -07:00
Paul Wells 096157e706 clean up worker jobs in handler when job ends (#3042) 2024-09-25 03:04:01 -07:00
Paul Wells d26ade0076 add helpers for partiicpant reconnect and version (#3034) 2024-09-22 23:37:35 -07:00
Paul Wells 5e3b3ee3c1 return copy of job state when starting job (#3035) 2024-09-22 23:37:06 -07:00
Paul Wells 8428d5e62b update protocol (#3031)
* update protocol

* test

* cleanup
2024-09-21 17:05:39 -07:00
Paul Wells 61179d5624 simplify agent registration (#3018)
* simplify agent registration

* testutils

* deps

* fix

* gen

* cleanup

* lower job load
2024-09-19 05:58:30 -07:00
Paul Wells 370f386dd0 add convenience methods to participant (#3016)
* add convenience methods to participant

* tidy
2024-09-19 00:20:22 -07:00
Paul Wells 4deaac2f3f replace proto.Clone calls (#3024)
* replace proto.Clone calls

* deps

* tests
2024-09-18 22:47:33 -07:00
Paul Wells 1436a1f186 driveby cleanup (#3017)
* driveby cleanup

* test
2024-09-18 00:45:55 -07:00
Paul Wells 70b84871fe compute agent service affinity from available capacity (#2995) 2024-09-10 18:12:09 -07:00
Paul Wells b63192a376 add config for signal retry (#2989) 2024-09-08 19:53:19 -07:00
Paul Wells dabbb298c5 mark explicit create paths (#2935) 2024-08-13 22:00:39 -07:00
Paul Wells c371929535 add roommanager service (#2931)
* add roommanager service

* cleanup

* deps

* timeout

* cleanup

* cleanup

* config

* cleanup
2024-08-13 11:00:41 -07:00
Paul Wells 2346c8a6b7 add example agent test (#2914) 2024-08-06 19:51:30 -07:00