Skip to content

fix(prompt_client): gracefully handle invalid CRE_LLM_* env vars (#1169) - #1170

Closed
muntasir-396 wants to merge 1 commit into
OWASP:mainfrom
muntasir-396:fix/litellm-retry-env-fallback-1169
Closed

muntasir-396 wants to merge 1 commit into
OWASP:mainfrom
muntasir-396:fix/litellm-retry-env-fallback-1169

Conversation

@muntasir-396

Copy link
Copy Markdown

Closes #1169

Summary of Changes

  • Wrapped CRE_LLM_MAX_RETRIES and CRE_LLM_RETRY_SLEEP_SECONDS parsing in retry_policy() (application/prompt_client/litellm_router.py) with defensive try/except (ValueError, AttributeError) handling.
  • Falls back to default values (DEFAULT_MAX_RETRIES = 2, DEFAULT_RETRY_SLEEP_SECONDS = 15) and logs a warning with the offending value if non-numeric/invalid strings are provided.
  • Clamps negative values to 0 to prevent negative sleep intervals and invalid retry counts.
  • Added comprehensive unit tests in application/tests/litellm_router_test.py covering:
    • Default behavior when env vars are unset
    • Valid string integer overrides
    • Non-numeric strings (ensuring fallback + warning logged)
    • Negative integers (ensuring clamped to 0)

Testing

Ran all tests with:

PYTHONPATH=. python -m unittest application/tests/litellm_router_test.py

- Fall back to defaults and log a warning if CRE_LLM_MAX_RETRIES or CRE_LLM_RETRY_SLEEP_SECONDS contain non-integer values
- Clamp negative retry and sleep values to 0
- Add unit tests verifying defaults, valid overrides, invalid strings, and negative values
@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: OWASP/OpenCRE
  • Branch: main
  • File: .coderabbit.yml
  • Commit: 06f2c56
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0a3056be-1746-4a8b-a3ac-3bd2cc3ea6ce
📥 Commits

Reviewing files that changed from the base of the PR and between 06f2c56 and 1d5393a.

📒 Files selected for processing: 2
  • application/prompt_client/litellm_router.py
  • application/tests/litellm_router_test.py

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.

Summary by CodeRabbit

  • Bug Fixes
    • LLM retry settings now default to 2 retries with a 15-second delay when not configured. Valid settings are applied as non-negative values; invalid settings fall back to the defaults and generate a warning instead of causing an error.

Walkthrough

The retry policy now defaults to 2 retries and 15 seconds between retries. It parses environment values defensively, clamps negative values to zero, and logs warnings when values are invalid. Tests cover these cases.

Changes

Retry policy configuration

Layer / File(s) Summary
Parse retry settings and validate behavior
application/prompt_client/litellm_router.py, application/tests/litellm_router_test.py
retry_policy uses defaults of 2 retries and 15 seconds, parses valid environment values, clamps negative values to zero, and logs warnings before using defaults for invalid values. Tests cover these behaviors.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 1d539

No actionable issue is identified that would prevent merging after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely identifies the main change: graceful handling of invalid CRE_LLM_* environment variables.
Description check Passed The description directly explains the defensive parsing, fallback behavior, clamping, warnings, and tests in the changeset.
Linked Issues check Passed Issue #1169 requires graceful handling of non-integer CRE_LLM_MAX_RETRIES and CRE_LLM_RETRY_SLEEP_SECONDS values. retry_policy() catches ValueError and falls back to defaults of 2 and 15. It l…
Out of Scope Changes check Passed The changes stay within issue #1169. The negative-value clamp adds validation for the same retry settings and prevents invalid retry counts and sleep intervals. The added tests directly cover the pars…
Full details: Linked Issues check

Explanation

Issue #1169 requires graceful handling of non-integer CRE_LLM_MAX_RETRIES and CRE_LLM_RETRY_SLEEP_SECONDS values. retry_policy() catches ValueError and falls back to defaults of 2 and 15. It logs a warning that includes the invalid value. Tests cover unset variables, valid values, invalid strings, and negative values.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #1169. The negative-value clamp adds validation for the same retry settings and prevents invalid retry counts and sleep intervals. The added tests directly cover the parsing behavior. No unrelated change is shown in the supplied evidence.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@muntasir-396 muntasir-396 closed this by deleting the head repository Oct 25, 2026
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.

Gracefully handle non-integer values in CRE_LLM_* retry environment variables

1 participant