Skip to content

fix: cache participant attrs for BYE attributes_to_headers (#404) - #775

Open
lixuanqun wants to merge 2 commits into
livekit:mainfrom
lixuanqun:cursor/fix-bye-attrs-headers-33f3
Open

lixuanqun wants to merge 2 commits into
livekit:mainfrom
lixuanqun:cursor/fix-bye-attrs-headers-33f3

Conversation

@lixuanqun

Copy link
Copy Markdown

When an agent hangs up by deleting the room, LocalParticipant is gone before SIP sends BYE, so attributes_to_headers mapping was skipped and custom X-* headers were missing.

Cache the last-seen participant attributes on join/update and reuse them when building BYE/REFER headers if the room is already nil. Applies to inbound and outbound calls.

Fixes #404

@lixuanqun
lixuanqun requested a review from a team as a code owner August 4, 2026 03:32
devin-ai-integration[bot]

This comment was marked as resolved.

@codecov

codecov Bot commented Aug 4, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.65517% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.76%. Comparing base (0460b40) to head (84eab15).
⚠️ Report is 375 commits behind head on main.

Files with missing lines Patch % Lines
pkg/sip/outbound.go 80.64% 2 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #775      +/-   ##
==========================================
+ Coverage   65.25%   68.76%   +3.50%     
==========================================
  Files          51       43       -8     
  Lines        6588     8647    +2059     
==========================================
+ Hits         4299     5946    +1647     
- Misses       1915     2170     +255     
- Partials      374      531     +157     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@genseric-ghiro

Copy link
Copy Markdown
Contributor

Thanks for the fix @lixuanqun. I think it'd be a good idea to implement devin's suggestion for both inbound and outbound calls

When an agent hangs up by deleting the room, LocalParticipant is gone
before SIP sends BYE, so attributes_to_headers mapping was skipped and
custom X-* headers were missing.

Cache the last-seen participant attributes on join/update and reuse them
when building BYE/REFER headers if the room is already nil. Applies to
inbound and outbound calls.

Fixes livekit#404

Co-authored-by: li xuanqun <793005378@qq.com>
@lixuanqun
lixuanqun force-pushed the cursor/fix-bye-attrs-headers-33f3 branch from cc4b49c to 021e361 Compare September 17, 2026 11:33
snapshotParticipantAttrs unconditionally replaced the cache with whatever
the live room reported, so a teardown-time read that comes back empty
erased the values kept for BYE/REFER attributes_to_headers — the exact
destruction case this cache exists to survive. Skip the overwrite when
the read is empty, on both inbound and outbound calls.

Implements the finding from Devin Review on livekit#775.
@lixuanqun

Copy link
Copy Markdown
Author

Thanks @genseric-ghiro. Implemented Devin's finding on both inbound and outbound in 84eab15: snapshotParticipantAttrs now skips the cache overwrite when the live read comes back empty — so a teardown-time empty read (room/participant already gone) no longer erases the values the cache exists to preserve for BYE. Regression tests added in attrs_headers_test.go for both call directions. CI re-running.

@devin-ai-integration devin-ai-integration Bot 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.

Devin Review found 1 new potential issue.

2 flags not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

Comment thread pkg/sip/inbound.go
Comment on lines +2046 to +2050
if len(attrs) == 0 {
// An empty read (room or participant already torn down) must not
// wipe the last known attributes: they back attributes_to_headers
// on BYE/REFER (livekit/sip#404).
return

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Cleared attributes emit stale headers

When a live participant clears every attribute, snapshotParticipantAttrs preserves the old cache. BYE and REFER then emit headers for nonexistent attributes.

Learn more

An empty attribute map is also a valid participant state. These guards cannot distinguish that state from a teardown-time empty SDK read, so both inbound and outbound snapshots retain values that the participant removed. Header generation later treats those retained values as current.

Example: A participant starts with sip.custom=seeded, then removes every attribute while the room remains connected. Its BYE is expected to omit the mapped X-Custom header, but the cache still supplies seeded.

Recommended fix: Track confirmed attribute updates separately from teardown reads. Record confirmed empty states, while preserving the cache only when room lifecycle state proves the participant is unavailable or the read is transient.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@lixuanqun

Copy link
Copy Markdown
Author

Hi @genseric-ghiro, your suggestion from August is implemented in 84eab15 — the snapshot logic now skips the cache overwrite on empty reads for both inbound and outbound, as you proposed. CI is green and the branch is mergeable; could you take a look when you have a moment?

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.

LiveKit attributes are not mapped to SIP X-* headers when sending BYE

3 participants