Skip to content

fix(livekit): gracefully handle empty request body and strip whitespace#89

Merged
Benji918 merged 2 commits into
devfrom
fix/livekit-endpoint-robustness
May 30, 2026
Merged

fix(livekit): gracefully handle empty request body and strip whitespace#89
Benji918 merged 2 commits into
devfrom
fix/livekit-endpoint-robustness

Conversation

@Bnabdulwasiu
Copy link
Copy Markdown
Collaborator

Description

This PR implements critical robustness enhancements to the LiveKit endpoint controllers (app/api/v1/routes/livekit.py). It ensures that the backend gracefully handles trailing/leading whitespaces in room path parameters (such as test-room%20) and processes empty request bodies (-d '') cleanly without raising unhandled json.JSONDecodeError exceptions (preventing unexpected 500 Internal Server Errors).

Type of Change

  • feat — New feature
  • fix — Bug fix
  • refactor — Code refactoring (no functional change)
  • docs — Documentation update
  • test — Adding or updating tests
  • chore — Maintenance (dependencies, CI, tooling)

Related Issue

Closes # (LiveKit controller route robustness follow-up)

Changes Made

  • Whitespace Trimming (_parse_uuid & routes): Added automatic string trimming to interview_id in path parameters. This prevents spaces in URL parameters from triggering uuid formatting validation exceptions or matching failures.
  • Safe request.json() Decoding (generate_token & post_result): Wrapped raw JSON body parsing in a try-except block falling back to {} on exceptions. This prevents empty request payloads (-d '') from raising unhandled backend exceptions.
  • Ruff Compliance: Verified and cleaned up code formatting (uv run ruff check - All checks passed!).

Proof of Work

API Response / Screenshots

POST /api/v1/livekit/test-room%20/token (With empty body -d '')

Status: 200 OK

{
  "serverUrl": "wss://meetmind-5fv6f5wu.livekit.cloud",
  "roomName": "test-room",
  "participantName": "Test User",
  "participantToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiVGV..."
}

Test Cases

  • test_token_returns_correct_shape — Verifies token shape and LiveKit VideoGrants generation.
  • test_token_test_room_bypass_works — Verifies test room bypass and manual participant naming.
  • test_token_returns_404_for_unknown_interview — Verifies correct 404 response on unknown UUIDs.
Test output
uv run pytest tests/test_livekit.py
======================= 19 passed, 2 warnings in 15.90s =======================

Checklist

  • My branch follows the naming convention (<type>/<short-description>)
  • My commits follow Conventional Commits
  • I have added meaningful tests that cover success and failure paths
  • All new and existing tests pass locally (uv run pytest)
  • I have included proof of work (JSON responses or screenshots)
  • I have updated documentation if needed
  • My code follows the project's style guidelines

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 30, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: ad319b16-5145-4877-84ae-d2e1e48ac56b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/livekit-endpoint-robustness

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Benji918 Benji918 merged commit 4a816cc into dev May 30, 2026
7 checks passed
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.

2 participants