Skip to content

fix: pass root_path to FastAPI constructor instead of uvicorn#1187

Merged
tisnik merged 1 commit intolightspeed-core:mainfrom
major:fix/rspeed-2467-root-path-doubled-prefix
Feb 19, 2026
Merged

fix: pass root_path to FastAPI constructor instead of uvicorn#1187
tisnik merged 1 commit intolightspeed-core:mainfrom
major:fix/rspeed-2467-root-path-doubled-prefix

Conversation

@major
Copy link
Copy Markdown
Contributor

@major major commented Feb 19, 2026

Description

When lightspeed-stack runs behind 3scale with ROOT_PATH=/api/lightspeed, requests arrive with a doubled path prefix (/api/lightspeed/api/lightspeed/v1/infer) because uvicorn.run(root_path=...) injects the value into scope['root_path'], and Starlette concatenates it with the already-prefixed scope['path'] from 3scale.

Move root_path from uvicorn.run() to the FastAPI() constructor, matching how rlsapi handles it. This way Starlette knows the mount prefix without uvicorn double-prepending it.

Type of change

  • Bug fix

Tools used to create PR

  • Assisted-by: Claude
  • Generated by: N/A

Related Tickets & Documents

Checklist before requesting a review

  • I have performed a self-review of my code.
  • PR has passed all pre-merge test jobs.
  • If it is a core feature, I have added thorough tests.

Testing

  • Existing uvicorn runner unit tests updated to verify root_path is no longer passed to uvicorn.run().
  • All 5 tests in tests/unit/runners/test_uvicorn_runner.py pass.
  • Full verification requires deploying behind 3scale with ROOT_PATH=/api/lightspeed and confirming requests to /v1/infer route correctly without path doubling.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed root path configuration to be applied during FastAPI initialization, ensuring correct base URL resolution.
  • Tests

    • Updated tests to reflect changes in root path configuration handling.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 19, 2026

Walkthrough

The changes relocate root_path configuration from being passed to uvicorn.run to being passed to the FastAPI constructor. The uvicorn runner no longer forwards root_path, while the FastAPI app startup now includes root_path from service configuration. Corresponding test updates reflect this parameter relocation.

Changes

Cohort / File(s) Summary
Root path configuration relocation
src/app/main.py, src/runners/uvicorn.py
Added root_path parameter to FastAPI constructor instantiation; removed root_path from uvicorn.run call and its docstring description.
Test updates
tests/unit/runners/test_uvicorn_runner.py
Removed root_path argument from all uvicorn.run mock calls and updated docstring to clarify root_path belongs on FastAPI constructor, not uvicorn.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • tisnik
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: moving root_path parameter from uvicorn.run() to FastAPI constructor, which is the core fix for the doubled path prefix bug.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

When lightspeed-stack runs behind 3scale with ROOT_PATH=/api/lightspeed,
requests arrive with a doubled path prefix because uvicorn injects
root_path into scope['root_path'] and Starlette concatenates it with
the already-prefixed scope['path'] from 3scale.

Move root_path from uvicorn.run() to the FastAPI() constructor, matching
how rlsapi handles it.

Signed-off-by: Major Hayden <major@redhat.com>
@major major force-pushed the fix/rspeed-2467-root-path-doubled-prefix branch from 5785876 to 50adeaf Compare February 19, 2026 17:26
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/unit/runners/test_uvicorn_runner.py (1)

109-129: Negative case verified; missing positive-side test for the FastAPI constructor.

test_start_uvicorn_with_root_path correctly guards against root_path reappearing in uvicorn.run(). However, the other half of this fix — FastAPI(root_path=...) in src/app/main.py — is untested. If line 87 of src/app/main.py is accidentally removed or zeroed out, no existing test would catch the regression.

Consider adding a test in tests/unit/app/ (e.g., test_main.py) that patches fastapi.FastAPI and asserts root_path is forwarded from configuration.service_configuration.root_path to the constructor.

Would you like me to draft that complementary test or open a tracking issue?

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/runners/test_uvicorn_runner.py` around lines 109 - 129, Add a
positive test that patches fastapi.FastAPI and asserts the FastAPI constructor
receives root_path from the configuration; create (for example) a test function
test_fastapi_receives_root_path that builds a ServiceConfiguration with
root_path set, imports/instantiates whatever creates the app (the code that
calls FastAPI in src/app/main.py), patches fastapi.FastAPI to capture
constructor kwargs, then asserts that FastAPI was called with root_path equal to
configuration.service_configuration.root_path (and still allows other default
constructor args to be passed through). Ensure the test imports the app-creation
function used in main.py and uses the same configuration source so removal of
the FastAPI(root_path=...) call would fail this test.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/unit/runners/test_uvicorn_runner.py`:
- Around line 109-129: Add a positive test that patches fastapi.FastAPI and
asserts the FastAPI constructor receives root_path from the configuration;
create (for example) a test function test_fastapi_receives_root_path that builds
a ServiceConfiguration with root_path set, imports/instantiates whatever creates
the app (the code that calls FastAPI in src/app/main.py), patches
fastapi.FastAPI to capture constructor kwargs, then asserts that FastAPI was
called with root_path equal to configuration.service_configuration.root_path
(and still allows other default constructor args to be passed through). Ensure
the test imports the app-creation function used in main.py and uses the same
configuration source so removal of the FastAPI(root_path=...) call would fail
this test.

Copy link
Copy Markdown
Contributor

@tisnik tisnik left a comment

Choose a reason for hiding this comment

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

ok

@tisnik tisnik merged commit 2b44c5e into lightspeed-core:main Feb 19, 2026
20 of 21 checks passed
@major major deleted the fix/rspeed-2467-root-path-doubled-prefix branch February 19, 2026 19:03
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