Skip to content

fix(api): keep the base path when a request is retried against the same host - #939

Open
ANDROIDHASSAN wants to merge 1 commit into
livekit:mainfrom
ANDROIDHASSAN:fix/failover-retry-keeps-base-path
Open

ANDROIDHASSAN wants to merge 1 commit into
livekit:mainfrom
ANDROIDHASSAN:fix/failover-retry-keeps-base-path

Conversation

@ANDROIDHASSAN

Copy link
Copy Markdown
Contributor

Problem: #861 made Twirp requests keep the base path of the server URL (e.g. https://host/livekit). #811 added the same-host retry for when no fallback region exists. When that retry runs, the loop sets current_base = next_origin, and next_origin is the bare origin. So the retry drops the base path, posts to https://host/twirp/..., gets a 404, and that 404 is raised as a terminal ServerError.

This can happen on a Cloud API host (cloud-api.livekit.io, which never has fallback regions) or a *.livekit.cloud host whose region list is empty, when the URL has a base path.

Fix: switch current_origin and current_base only when the retry goes to a different origin. A same-host retry keeps the configured base. Retries to fallback regions are unchanged: they still use the region's bare origin.

Tests: test_same_host_retry_keeps_the_base_path in tests/api/test_failover_unit.py. A server serves Twirp only under /livekit, is reached as cloud-api.livekit.io, and drops the first connection. I added a base_path argument to the existing _call_single_host helper for this.

  • on main: ServerError(code=unknown, message=, status=404), after the warning retrying with fallback url http://cloud-api.livekit.io:<port>.
  • with the fix: passes.

tests/api/: 34 passed, 28 skipped. ruff check and ruff format --check are clean on both files. Includes a livekit-api patch changeset.

…me host

With no fallback region, a retryable failure is retried against the same host, but the retry URL was built from the bare origin, so a server URL with a base path got its path dropped and the retry hit a 404. Only switch the base when the retry goes to a different origin.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T14:34:10.330363Z ec02157 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

This branch has not been deployed

No deployments
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