Skip to content

fix(livekit): stop a late ingress_ended restarting the wrong scene, and close the room when the last player leaves - #57

Merged
leggetter merged 1 commit into
mainfrom
fix/livekit-soundtrack-room-close
Nov 25, 2026
Merged

leggetter merged 1 commit into
mainfrom
fix/livekit-soundtrack-room-close

Conversation

@leggetter

Copy link
Copy Markdown
Collaborator

Two bugs found while recording the voice-adventure demo on 24 Nov:

  • Wrong-scene soundtrack restart. On a scene change, ensure() deleted the old scene's ingress and only recorded the new scene once the new ingress existed. The ingress_ended webhook for the deleted ingress could arrive in between, see the old scene as still wanted, and restart it, which deleted the new scene's ingress 2 seconds after it started. ensure(), stop() and onEnded() now run one at a time per room.
  • The room never finished. The story agent stays in the room after players leave (closeOnDisconnect: false) and the app keeps the soundtrack playing, so LiveKit never sent room_finished. When the last human leaves and nobody rejoins within 10 seconds, the agent marks the story ended, asks the app to stop the soundtrack, and leaves 10 seconds later.

Tests: app npm test 66 pass and agent npm test 60 pass, both typecheck clean, with new tests for both fixes. Live check: room_finished arrived 51 seconds after the last player left, with no manual room close, and a tavern to forest scene change produced no wrong-scene restart.

🤖 Generated with Claude Code

Posted by an AI agent with human oversight.

…nd close the room when the last player leaves

Soundtrack race: ensure() deleted the old scene's ingress and then spent a few
hundred ms creating the new one, and only set the wanted scene at the end. The
ingress_ended webhook for the deleted ingress could arrive in that window, see
the old scene as still wanted, and restart it, which deleted the new scene's
ingress seconds after it started. ensure(), stop() and onEnded() now run one at
a time per room, so a late webhook is judged against the scene the story is in.

Room never finished: the story agent stays in the room after a player leaves
(closeOnDisconnect is false) and the app keeps the soundtrack playing, so the
room was never empty and LiveKit never sent room_finished. When the last human
leaves, and nobody comes back within 10 s, the agent marks the story ended,
asks the app to delete the soundtrack ingress, and leaves 10 s later (so a bot
player sees the ended state and leaves too).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@leggetter
leggetter merged commit 87de5b8 into main Nov 25, 2026
11 checks passed
@leggetter
leggetter deleted the fix/livekit-soundtrack-room-close branch November 25, 2026 13:40
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.

1 participant