Skip to content

Send the track sid with FrameCryptor's setKeyIndex() and setEnabled() - #312

Open
mdepinet wants to merge 2 commits into
livekit:mainfrom
mdepinet:mike/fix-frame-cryptor-track-sid
Open

mdepinet wants to merge 2 commits into
livekit:mainfrom
mdepinet:mike/fix-frame-cryptor-track-sid

Conversation

@mdepinet

@mdepinet mdepinet commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

This PR was written and verified by Claude Opus 5.5 (an AI model by Anthropic), working with @mdepinet.

Fixes #311

What changed

  • E2EEManager::FrameCryptor::setKeyIndex() and setEnabled() now send a track sid. Without one, the FFI panicked converting the empty sid (requests.rs:760), which aborted the process.
  • The FFI addresses a cryptor by participant and track, but FrameCryptor only knows its participant, and adding the track would change its constructor and layout. So, as their docs already describe ("for this participant"), the setters look up the participant's cryptors with manager_get_frame_cryptors and apply to each of its tracks. The public API and ABI are unchanged.
  • A new integration test publishes two encrypted audio tracks, calls both setters on one cryptor, and checks that frameCryptors() reports both tracks switched to key index 1 and disabled.

Testing

Ran on Linux x86_64 against livekit-server --dev:

  • Without the fix, the new test's setKeyIndex() call aborts the test binary with the panic above.
  • With the fix, both E2EE integration tests pass, as do all the unit tests (359).

🤖 Generated with Claude Code

The FFI requires the track sid to find a cryptor, and panics (aborting
the process) when it's missing. FrameCryptor now keeps the sid that
frameCryptors() receives, sends it, and exposes it as trackSid().

Fixes livekit#311

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
devin-ai-integration[bot]

This comment was marked as resolved.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The changes break constructor source and binary compatibility and alter an exported type’s layout, risking invalid memory access for existing consumers.

2 open issues
What changed in this PR

Addresses #311’s FrameCryptor setter crashes by passing the track SID through the LiveKit C++ SDK to the Rust bridge.

Changes:

  • Retains each cryptor’s track SID and sends it with setKeyIndex() and setEnabled().
  • Adds a trackSid() accessor and a required constructor parameter.
  • Extends unit coverage and adds an integration test that verifies setter results.
File Description
src/​tests/​unit/​test_e2ee.cpp Checks the new track SID accessor.
src/​tests/​integration/​test_e2ee.cpp Verifies key-index and enablement changes for a published track.
src/​e2ee.cpp Stores track SIDs from cryptor enumeration and includes them in setter requests.
include/​livekit/​e2ee.h Updates the public constructor, accessor, stored state, and track-specific documentation.

Review effort: Balanced

Comment thread include/livekit/e2ee.h Resolved
Comment thread include/livekit/e2ee.h Resolved
… instead

Adding the track sid to FrameCryptor changed its constructor and its
layout, which existing binaries rely on (its destructor and moves are
inline). Instead, its setters now look up the participant's tracks and
apply to each, as their documentation already describes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the change addressing the FrameCryptor setter crash.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@mdepinet

Copy link
Copy Markdown
Contributor Author

The Tests / Test (ubuntu-24.04-x64) failure is the memory regression check (#275), not a test: every test passed, but the memory tester saw +5 threads (one peer connection factory's set), in audio-track in the first run and video-track in the second. Both times it started at the cycle that logged failed to negotiate the publisher, which looks like the 10 s negotiation hold that livekit/rust-sdks#1538 fixes. This PR doesn't touch that path, and both scenarios pass locally on this branch with zero thread growth. Could someone re-run the job when convenient, please?

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.

FrameCryptor::setKeyIndex() and setEnabled() abort the process: they never send the track sid

2 participants