Repository navigation
Add a built-in LiveKit token service with delegated leaves for MatrixRTC (1.1.3) - #598
James-Chapman wants to merge 19 commits into
Conversation
|
Important Review skippedToo many files! This PR contains 168 files, which is 68 over the limit of 100. To get a review, reduce the PR to 100 files or fewer by splitting it into smaller PRs or changing its base branch. Upgrade to a paid plan to raise the limit. This review couldn't start because sufficient usage credits or metered capacity aren't available. Add credits or update usage-based reviews in the billing tab, then retry.
|
2345e42 to
fd571b6
Compare
9b38886 to
a1ef2ef
Compare
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a1ef2ef01f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
a1ef2ef to
196a9f8
Compare
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…anges A state_after delta was measured from the state recorded for the newest event at since. On a room forked at since, that is one branch's state, not the resolved state the client was told, so a key that resolution later moved back was never sent (review of PR 595). A backfilled event ordered at or below since did the same, and the left-room delta had the same baseline. Every change to a room's current state in the main process now goes into PersistentStore::state_change_log. A change is filed at the causing event's stream ordering, raised above every position a sync has answered, so the state told as of a served position never changes. resolved_state_at and resolved_state_changes rebuild the state told and the exact delta from that one record. A window of messages costs no state row. A since from before start-up gets the room's whole state once. No migration (ADR-0827, superseding part of ADR-0819). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rypto boundary Add crypto/LiveKitToken: a participant-token signer whose grant type cannot express roomCreate, roomAdmin or hidden, a room-creation signer with roomCreate alone, and an HS256 verifier that never reads the header's alg. libsodium's HMAC-SHA256 stays internal. Pinned vectors from Python's hmac and RFC 7515 A.1 (ADR-0828). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sign_livekit_room_admin_token signs {"room":<name>,"roomAdmin":true} for one
MSC4195 room name and nothing else, with a vector computed apart from this
code. ADR-0828 and the crypto boundary doc now list four operations.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds server.rtc.livekit.{url,api_url,api_key,api_secret_file,token_lifetime}
(exclusive with the external service_url) and serves get_token on the
unstable io.element.msc4195 and stable v1 client paths: a token only for a
caller this server finds joined, with MSC4195's room name and identity, no
create, admin or hidden rights, after CreateRoom at the configured API
address under an outbound slot with the lock released (ADR-0829, ADR-0830).
A request for another server's SFU is relayed over signed federation when
that server has a joined member here; its 403 M_FORBIDDEN and 400
M_INVALID_PARAM are passed on in this server's words, so the outbound call
now carries those two errcodes as well as M_INVITE_BLOCKED. A federated
request is judged from this server's state and answered subscribe-only
(ADR-0831). /versions and the transports list match what is served.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The relay of get_token to another server is a perform_outbound_call caller, so ADR-0349's table and test_outbound_answer_trust.py name it: unverified, over main's own client. Also wrap a changelog bullet line that ran to 121 characters. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…elay (ADR-0831, ADR-0595) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…and hydration (ADR-0832) Migration 004 creates livekit_delegations on SQLite and PostgreSQL, with LiveKitDelegationTable holding the rows in memory and LiveKitDelegationStore.hpp writing them in one transaction each. A new delegation replaces the row holding its key and the row holding its delay ID; account deactivation deletes a user's rows beside the delayed events. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… LiveKit webhook MSC4195 delegate_delayed_leave: a joined caller hands the server one delay ID per (room, slot, member). The livekit-delegations job asks LiveKit's GetParticipant (a one-room roomAdmin token, the configured address only, the lock released) and restarts the delayed leave while the participant is connected, or sends it once LiveKit no longer shows them (ADR-0832). Delegations live in migration 004 and go with a cancel, a send, a leave or a deactivation. POST /_merovingian/livekit/webhook is served on the client listener: an HS256 token from the configured key, a body SHA-256 match, a bounded body, staleness and replay checks. It only brings a matching delegation's next check forward; it never changes state itself (ADR-0833). The MSC4195 request readers move to LiveKitRequestFields and the LiveKit test fixture to tests/support/LiveKitTestSupport.hpp, shared by the token and delegation flows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… its delegation The federated get_token names its room in the body, so the route-level server ACL check never saw it, and an ACL leaves a denied server's users joined: a denied server could get a subscribe-only token for the call. Main now refuses a denied origin with the same 403, and a client's token request is not relayed to a server the room denies (ADR-0831). A GetParticipant answer is applied only to the delegation it was asked for (slot, member, creation time, LiveKit names), so a delegation stored again while the lock was free is not taken as seen. One run drops at most 64 delegations, keeping one lock hold bounded (ADR-0832). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The documentation site build (mkdocs --strict) refused the link to a 0079 file name that does not exist. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hared_ptrs
scripts/reject-unsafe.sh read "free (" in a comment as a call to free(),
and the LiveKit test helpers' shared_ptr lines had no review marker. Each
one shares a call log or mock with the std::function hook installed on the
runtime, which must be copyable.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ex webhooks, bound DNS Four findings from review of PR 598: - The federation worker's Landlock secret-path guard now lists server.rtc.livekit.api_secret_file, so a worker-readable placement of the LiveKit API secret (beneath /etc/ssl/certs, say) refuses to start the worker, as for every other secret (ADR-0062). - run_livekit_delegations asks the due delegations most overdue first, stamps each GetParticipant token when its call is made, and schedules the next check from when the calls ended, so a slow LiveKit cannot make the job ask the same 16 again while others wait (ADR-0832). - The webhook finds matching delegations through an index by LiveKit room name and identity (livekit_delegation_participants, kept in step with the progress map), and checks each match against its progress, instead of scanning every delegation (ADR-0833). - perform_livekit_request charges the host lookup and the exchange to one OutboundDeadline: the exchange gets what the lookup left, and none is started once it is spent (ADR-0830). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rker relay success path Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Scenarios for the paths CI's coverage report showed unexecuted in LiveKitDelegations.cpp: a malformed or over-long webhook token and claims that are not an object (401); authentic events with no object body, no participant, an unreadable createdAt, or a time before the delegation (ignored); createdAt as a bare integer; the bounded memory of event IDs; the API secret missing (no call, webhook 500); the token service switched off (delegations dropped, webhook 404); a stored delegation whose names cannot be derived (dropped); and an unreadable GetParticipant answer (nothing changes). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The deadline stops a slow lookup from adding a whole exchange, and stops an exchange from starting once it is spent. The lookup is a blocking getaddrinfo the deadline cannot interrupt, so the comment, ADR-0830 and the CHANGELOG no longer claim the call never outlasts its budget. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CodeQL's poorly-documented-function rule failed on five Catch2 scenarios of 106 to 125 lines. Each is split where its cases already divide, so every scenario is under 95 lines and no case is lost or changed: - the worker relay: the admitted relay and the spent permit, apart from the refusals for another origin, no permit and another body's permit; - the webhook: replayed, stale, other-kind and unknown signed webhooks apart from the signature, prompt and size cases, both on CheckedDelegation, now declared before its first user; - the federated request: the 400s and the no-service 404 apart from the 403s; - the relay: the other server's refusals and errors apart from the success and the ACL; - the refusals before any call: no outbound client apart from the budget, the signing key and the API secret. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1b02594 to
955350c
Compare
… when the owner asks (#599) * Give SQLite writes one pooled connection so a write never waits in SQLite's busy handler for another (1.1.4) The DB-7 scenario lost three of 64 writes under load: three pooled SQLite connections being opened polled SQLite's busy handler for the first one's lock, lost to its back-to-back commits (every journal and database sync runs under EXCLUSIVE) and were refused after 5 s with SQLITE_BUSY. SQLite runs one write at a time, so the SQLite write pool now holds one connection whatever database.pool_size says, and writers wait in the pool instead (ADR-0834). database.pool_size applies to PostgreSQL only. A new scenario holds SQLite's write lock on a leased pool slot for 7 s while a second write runs; on the old code that write was refused at BEGIN IMMEDIATE after the busy timeout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Name the one SQLite write connection in the review skill's database invariants Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Change the version only when the owner asks, and keep this branch at 1.1.3 The owner's rule from 2026-11-18: no branch increments the version on its own; it changes only when the owner asks, and every change adds its CHANGELOG bullets to the newest version's entry (ADR-0835, superseding ADR-0464 and the per-branch increment of ADR-0647). docs/versioning.md, the root AGENTS.md, docs/coding-rules.md, docs/AGENTS.md and the review skill now say so. Under the new rule this branch drops its 1.1.4 bump: every version location is back to its base's 1.1.3, and the SQLite fix's bullet and release-notes sentence move into the 1.1.3 entry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>



Summary
Version 1.1.3. This adds MatrixRTC slice 4, a LiveKit token service built into the server (MSC4195), so a deployment needs no
lk-jwt-service. It also adds MSC4195's delegated delayed leave, a LiveKit webhook that brings a delegation's check forward, and an exactstate_afteron/sync, measured from an in-memory log of resolved state changes. It adds migration 004 (livekit_delegations). This PR is stacked on #597.What changed
roomAdminforGetParticipant.verify_hs256_tokenchecks webhooks and never readsalg.POST /_matrix/client/{v1,unstable/io.element.msc4195}/rtc/livekit/get_tokenissues a token only to an authenticated caller that this server's own current room state shows as joined.roomCreate, admin or hidden-participant rights, and its lifetime is bounded to 60 to 3600 seconds.SecretBuffer./versionsandrtc/transportsadvertise the service (m.livekiton stable only).server.rtc.livekit.service_url) stays available, and the two cannot both be configured.jwtis passed on.WorkerRelayKind::livekit_token, bound to the verified request by origin and a body-digest permit (ADR-0595).POST .../rtc/livekit/delegate_delayed_leavestores one delegation per room, slot and member, with at most 20 per user.livekit-delegationsjob asksGetParticipantwith the lock released. While the participant is connected it restarts the delayed leave; once LiveKit no longer shows the participant it sends the leave. It acts only throughmanage_delayed_event.POST /_merovingian/livekit/webhookis served on the client listener.LiveKitDelegationTablein-memory table, store functions, strict hydration (a bad row is skipped and counted), deletion on deactivation, and the worker's load profile excludes the table.AGENTS.mdfiles, ADRs 0827 to 0833, and the CHANGELOG.Why it changed
lk-jwt-servicemeans an extra service with its own trust boundary. Building it in lets the server judge membership from its own state and keep the LiveKit secret behind the crypto boundary.CI tests
Modified tests
tests/integration/test_livekit_token_flow.cpp,tests/integration/test_livekit_delegation_flow.cpp,tests/integration/test_federation_worker_flow.cpp: five scenarios over CodeQL's 100-line limit are each split in two where their cases already divide, keeping every case (the worker relay, the webhook, the federated refusals, the relay errors and the refusals before any call).tests/conformance/test_route_query_conformance.cpp: the get_token and delegate rows.tests/conformance/test_sync_state_after_conformance.cpptests/integration/test_database_upgrade_flow.cpp: version 4, and the new table takes a row.tests/integration/test_federation_worker_flow.cpp: the LiveKit relay is bound by origin and permit.tests/integration/test_persistent_homeserver_flow.cpptests/integration/test_postgresql_store_behaviour_flow.cpp: delegation round trip.tests/integration/test_sync_handler_flow.cpp,tests/integration/test_sync_state_after_flow.cpptests/unit/test_config_rtc.cpp: token-service config is refused, never repaired.tests/unit/test_database_persistence.cpp: version 4 steps and plans.tests/unit/test_worker_landlock.cpp: a LiveKit secret the worker could read is detected.tests/unit/test_crypto_livekit_token.cpp: a correctly signed token with an undecodable header or payload, and the room-admin signer's refusals.tests/integration/test_livekit_token_flow.cpp: the federation provider main wires; refusals with no outbound client, no slot, no usable signing key, no readable secret.tests/integration/test_livekit_delegation_flow.cpp: fair scheduling under a slow LiveKit; the webhook index across replacement and drop; malformed tokens and claims; ignored events; the bounded event-ID memory; no secret; the service switched off; an unnameable stored delegation; an unreadable answer.tests/integration/test_federation_worker_flow.cpp: main issues a token for a verified worker relay.tests/unit/test_federation_inbound_request.cpp,tests/unit/test_federation_transactions.cpptests/unit/test_worker_relay_binding.cpp,tests/unit/test_worker_relay_frame.cpp,tests/unit/test_worker_table_load_profile.cpptests/tooling/test_outbound_answer_trust.py:livekit.relayis classified as unverified.tests/smoke/meson.build: db-migrate plans to version 4.tests/complement/merovingian.conf.template,tests/support/EduRelayContext.hppNew tests
tests/unit/test_crypto_livekit_token.cpp: HS256 vectors, grant shapes, verification.tests/unit/test_livekit_names.cpp: MSC4195 name vectors.tests/unit/test_livekit_delegation_table.cpp,tests/unit/test_livekit_delegation_store.cpptests/unit/test_resolved_state.cpp,tests/unit/test_state_change_log.cpptests/conformance/test_livekit_token_conformance.cpptests/integration/test_livekit_token_flow.cpp: issuance, refusals, the server ACL, the relay, the log.tests/integration/test_livekit_delegation_flow.cpp: validation, the per-user cap, restart, send, drops, a race with the lock released, the drop bound, webhook authentication, replay, staleness and 413.tests/unit/test_livekit_room_service.cpp: the lookup draws from the call's deadline; the request builders' and the perform refusals.tests/support/LiveKitTestSupport.hpp,tests/support/StatePduSupport.hppVerified:
python build.py vmon the Linux VM at this head (1b02594), committed tree: Ok 92, Fail 0, no Timeout, read fromtestlog.txt(1656 test cases, 1655 passed, 1 skipped). Integration 1012.5 s, unit 137.2 s, conformance 128.9 s.DB-7 concurrent writes to SQLite reuse at most database.pool_size connections(tests/integration/test_security_audit_write_pool_flow.cpp, lines 171 and 175,61 == 64), after three write connections were refused withSQLITE_BUSYwhile opening. That run took 1392 s for integration, under load. The scenario then passed 20 times out of 20 run alone, and in the full run above. This PR does not touch the SQLite connection-open path; the failure is followed up in Give SQLite writes one pooled connection, and change the version only when the owner asks #599.scripts/reject-unsafe.shon the VM at 196a9f8 (the commit since changes only three test files): exit 0.Integration suite time. Measured on the same VM, back to back:
The 38 s difference in the integration binary is mostly not the new tests. All 42
[livekit],[delegation],[webhook]and[rtc]integration test cases together take 4.13 s (--durations yes). The costliest are:Earlier runs of the same binary ranged from 1012 s to 1719 s, so the time margin against the 1800 s limit depends on load on the VM. The limit is unchanged here; whether to trim, split or raise it is the owner's call.
Not verified:
🤖 Generated with Claude Code