Skip to content

LCORE-536 Add error handling for bad llama-stack URLs; no more silent fails#1109

Merged
tisnik merged 2 commits intolightspeed-core:mainfrom
max-svistunov:lcore-536-missing-errors
Feb 5, 2026
Merged

LCORE-536 Add error handling for bad llama-stack URLs; no more silent fails#1109
tisnik merged 2 commits intolightspeed-core:mainfrom
max-svistunov:lcore-536-missing-errors

Conversation

@max-svistunov
Copy link
Contributor

@max-svistunov max-svistunov commented Feb 5, 2026

Description

Adding proper error handling for incorrect llama-stack URL configurations that previously failed silently at startup. Malformed URLs and URLs with wrong scheme are now rejected; unreachable hosts result into error message.

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up service version
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change
  • Unit tests improvement
  • Integration tests improvement
  • End to end tests improvement
  • Benchmarks improvement

Tools used to create PR

Identify any AI code assistants used in this PR (for transparency and review context)

  • Assisted-by: Claude Opus 4.5
  • Generated by: Claude Opus 4.5

Related Tickets & Documents

  • Related Issue # LCORE-536
  • Closes # LCORE-536

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

  1. In lightspeed-stack.yaml, set:

llama_stack:
url: not-a-valid-url

  1. Startup should fail:

llama_stack.url
Input should be a valid URL, relative URL without a base

  1. Same for invalid scheme (e.g. ftp://localhost:8321) and unreachable host (e.g. http://invalid-nonexistent-host:8321).

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Enhanced error handling and logging when Llama Stack service connection fails, providing clearer diagnostics
  • Improvements

    • Stricter URL validation for Llama Stack configuration requiring valid HTTP(S) URLs to prevent misconfiguration

@max-svistunov
Copy link
Contributor Author

@radofuchs Could you PTAL?

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 5, 2026

Warning

Rate limit exceeded

@max-svistunov has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 11 minutes and 19 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Walkthrough

The PR introduces stricter URL validation for Llama Stack configuration by changing the url field type from Optional[str] to Optional[AnyHttpUrl], adds error handling for API connection failures during startup, and updates the client to properly stringify URLs before initialization.

Changes

Cohort / File(s) Summary
Configuration & Type Validation
src/models/config.py
LlamaStackConfiguration.url field type changed from Optional[str] to Optional[AnyHttpUrl], enforcing URL format validation at the model level with updated field description.
Client Initialization
src/client.py
Modified _load_service_client to stringify AnyHttpUrl values via str(config.url) before passing to client initialization, ensuring compatibility with HTTP client libraries.
Startup Error Handling
src/app/main.py
Added APIConnectionError import and wrapped Llama Stack version check in try/except, logging connection failures with service URL and original exception details before re-raising.
Test Updates - Validation
tests/unit/models/config/test_llama_stack_configuration.py
Added comprehensive test suite validating URL acceptance (http/https with trailing slash normalization), rejection of malformed URLs, and rejection of disallowed URL schemes.
Test Updates - Configuration
tests/unit/models/config/test_authentication_configuration.py, tests/unit/test_configuration.py
Updated test data from bare "localhost" to fully-qualified "http://localhost" URLs; adjusted URL assertion to compare string representation with trailing slash normalization.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • radofuchs
  • tisnik
✨ Finishing touches
🧪 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.

@max-svistunov max-svistunov reopened this Feb 5, 2026
@max-svistunov max-svistunov force-pushed the lcore-536-missing-errors branch from 959a6bd to b75a7ac Compare February 5, 2026 14:32
Copy link
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.

LGTM

@tisnik tisnik merged commit e30221b into lightspeed-core:main Feb 5, 2026
21 of 22 checks passed
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