Fix: Handle invalid EMBEDDING_MAX_BATCH_SIZE gracefully
Description
Fixes #244
The application previously crashed with a ValueError if EMBEDDING_MAX_BATCH_SIZE was set to a non-integer value or an invalid string.
Changes
- Added a
try-exceptblock inbackend/config.py. - If parsing fails, it now logs a warning and defaults to
32instead of crashing the backend.
Verification
- Tested locally by setting
EMBEDDING_MAX_BATCH_SIZE="invalid_text". - Verified that the app starts successfully and logs the warning message:
Warning: Invalid EMBEDDING_MAX_BATCH_SIZE 'invalid_text'. Defaulting to 32.
Summary by CodeRabbit
- Bug Fixes
- Improved robustness of batch-size configuration: invalid or non-positive values now emit a warning and a safe default is applied to prevent startup failures.
βοΈ Tip: You can customize this high-level summary in your review settings.
Adds guarded parsing and logging to π― 2 (Simple) | β±οΈ ~8 minutes π° I sniffed the env and gave a twitch, βοΈ Tip: You can configure your own custom pre-merge checks in the settings.π Walkthrough
Walkthrough
backend/config.py for EMBEDDING_MAX_BATCH_SIZE: invalid or non-positive values are caught, a warning is logged, and MAX_BATCH_SIZE falls back to 32 instead of raising.Changes
Cohort / File(s)
Summary
Configuration Error Handling
backend/config.pyAdded
logging import and module logger; replaced direct MAX_BATCH_SIZE init with guarded parsing of EMBEDDING_MAX_BATCH_SIZE (int conversion, positive check). On ValueError or non-positive input logs a warning and defaults MAX_BATCH_SIZE to 32. Preserves existing EMBEDDING_MODEL/EMBEDDING_DEVICE behavior.Estimated code review effort
Poem
I tried to parse but hit a glitch.
I logged a warning, set size to thirty-two,
Now configs hop safeβno crash in view! β¨π₯ Pre-merge checks | β
5
β
Passed checks (5 passed)
Check name
Status
Explanation
Description Check
β
Passed
Check skipped - CodeRabbitβs high-level summary is enabled.
Title check
β
Passed
The title clearly and concisely summarizes the main change: adding graceful error handling for invalid EMBEDDING_MAX_BATCH_SIZE values.
Linked Issues check
β
Passed
The PR implementation meets all coding requirements from issue
#244: prevents crashes, adds error handling with try-except, logs warnings, and defaults to safe value (32).
Out of Scope Changes check
β
Passed
All changes in backend/config.py are directly scoped to the linked issue: adding logging infrastructure and validating EMBEDDING_MAX_BATCH_SIZE with appropriate error handling.
Docstring Coverage
β
Passed
No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
β¨ Finishing touches
π Recent review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
π₯ Commits
Reviewing files that changed from the base of the PR and between 896169aa3a556d434ebdb67d741e446ecbb61117 and 1828cf58282e5df104af70e00f59cf9895b20307.
π Files selected for processing (1)
backend/config.py
π§° Additional context used
πͺ Ruff (0.14.11)
backend/config.py
22-22: Abstract raise to an inner function
(TRY301)
π Additional comments (2)
backend/config.py (2)
1-5: Good logger setup for config warnings.
18-25: Graceful parsing and fallback looks solid.
βοΈ Tip: You can disable this entire section by setting review_details to false in your review settings.
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.
Comment @coderabbitai help to get the list of available commands and usage tips.