fix: prevent startup failure when INTERNAL_RAG_TOKEN is unset#387
fix: prevent startup failure when INTERNAL_RAG_TOKEN is unset#387Namraa310806 wants to merge 2 commits into
Conversation
|
@Namraa310806 is attempting to deploy a commit to the firefistisdead's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Caution Review failedFailed to post review comments 📝 WalkthroughWalkthroughStartup no longer raises when INTERNAL_RAG_TOKEN is unset; require_internal_rag_token_configured() returns a boolean and logs a warning. internal_auth_middleware now returns 503 with "INTERNAL_RAG_TOKEN is not configured" (and logs path + client IP) for protected endpoints when the token is missing. ChangesRAG Service Token Configuration and Request-Time Protection
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
rag-service/test_main.py (1)
697-715: ⚡ Quick winConsider expanding test coverage to all protected endpoints.
The parametrized test currently covers 3 endpoints (
/process-pdf,/ask,/summarize), butPROTECTED_RAG_PATHSincludes 7 endpoint paths plus 2 prefix patterns. While the middleware logic is shared, testing all protected endpoints provides defense in depth and catches configuration errors (e.g., if an endpoint is accidentally removed from the protection sets).🧪 Suggested test expansion
-@pytest.mark.parametrize("path", ["/process-pdf", "/ask", "/summarize"]) +@pytest.mark.parametrize("path", [ + "/process-pdf", + "/ask", + "/ask/stream", + "/summarize", + "/knowledge-gaps", + "/validate-session-write", + "/sessions/lookup", +]) def test_protected_endpoints_rejected_when_token_is_cleared_after_startup(path):You may also want to add a test case for prefix-based protection (e.g.,
/ask/v2/future-endpointto verify the/ask/prefix guard).🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@rag-service/test_main.py` around lines 697 - 715, Update the test_protected_endpoints_rejected_when_token_is_cleared_after_startup to iterate over the full set of protected paths instead of the hard-coded three: import PROTECTED_RAG_PATHS from main (or grab main_module.PROTECTED_RAG_PATHS) and parametrize the test over that collection, and add at least one path that exercises prefix-based protection (e.g., "/ask/v2/future-endpoint") to verify prefix guards; keep the same token-clear setup using main_module.INTERNAL_RAG_TOKEN, TestClient(app, ...), and the same assertions for 503 and the "INTERNAL_RAG_TOKEN is not configured" detail.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@rag-service/test_main.py`:
- Around line 697-715: Update the
test_protected_endpoints_rejected_when_token_is_cleared_after_startup to iterate
over the full set of protected paths instead of the hard-coded three: import
PROTECTED_RAG_PATHS from main (or grab main_module.PROTECTED_RAG_PATHS) and
parametrize the test over that collection, and add at least one path that
exercises prefix-based protection (e.g., "/ask/v2/future-endpoint") to verify
prefix guards; keep the same token-clear setup using
main_module.INTERNAL_RAG_TOKEN, TestClient(app, ...), and the same assertions
for 503 and the "INTERNAL_RAG_TOKEN is not configured" detail.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: fb9be230-1ce4-4cf0-ae7d-33acd5bafcff
📒 Files selected for processing (2)
rag-service/main.pyrag-service/test_main.py
Summary
This PR fixes a deployment availability issue where the RAG service could fail to start when
INTERNAL_RAG_TOKENwas not configured.Previously, the service performed token validation during module initialization, causing application startup to fail with a runtime exception if the environment variable was missing. This resulted in a complete service outage rather than a controlled failure for protected endpoints.
Changes Made
require_internal_rag_token_configured()to return configuration status instead of raising an exception.INTERNAL_RAG_TOKENis not configured.Related issue
Fixes: #354
Testing
Verified Scenarios
INTERNAL_RAG_TOKENis configured.INTERNAL_RAG_TOKENis missing.Checklist:
Screenshots / recordings
N/A – Backend-only change.
Notes
This change improves deployment resilience by preventing full application startup failures caused by missing configuration while maintaining secure behavior for protected endpoints.
No database migrations or deployment changes are required.
Security
Summary by CodeRabbit
Bug Fixes
Tests