Skip to content

LCORE-1858: degraded mode support#1781

Merged
tisnik merged 2 commits into
lightspeed-core:mainfrom
tisnik:lcore-1858-degraded-mode
May 24, 2026
Merged

LCORE-1858: degraded mode support#1781
tisnik merged 2 commits into
lightspeed-core:mainfrom
tisnik:lcore-1858-degraded-mode

Conversation

@tisnik
Copy link
Copy Markdown
Contributor

@tisnik tisnik commented May 24, 2026

Description

LCORE-1858: degraded mode support

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

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

Related Tickets & Documents

  • Related Issue #LCORE-1858

Summary by CodeRabbit

  • New Features

    • Configurable retry mechanism for improved Llama Stack version checks during application initialization.
    • Enhanced graceful degradation support allowing the application to continue operation when Llama Stack connection fails during startup.
  • Bug Fixes

    • Improved version detection to accurately report detected Llama Stack version information.
    • Corrected logging message formatting in version validation output messages.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 24, 2026

Warning

Review limit reached

@tisnik, we couldn't start this review because you've used your available PR reviews for now.

Your plan currently allows 1 review/hour. Refill in 49 minutes and 52 seconds.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more review capacity refills, 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 trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: fae270ec-0fc3-4e38-ae8a-453822f26a30

📥 Commits

Reviewing files that changed from the base of the PR and between 519fd44 and 58e50c3.

📒 Files selected for processing (1)
  • src/app/main.py

Walkthrough

This PR refactors Llama Stack version checking to accept configurable retry parameters and return the detected version, then integrates the updated logic into FastAPI startup with conditional degraded-mode fallback on connection failure.

Changes

Llama Stack Connectivity on Startup

Layer / File(s) Summary
Version check function contract and signature
src/utils/llama_stack_version.py
check_llama_stack_version now imports DEFAULT_MAX_RETRIES and DEFAULT_RETRY_DELAY from constants, accepts these as parameters, and returns Optional[str] (the detected version) instead of None. On successful version retrieval it returns the version string; after retries are exhausted it returns None. Log message formatting in compare_versions is also corrected.
Startup lifespan integration and error handling
src/app/main.py
Adds AsyncLlamaStackClient import, obtains the typed async client during lifespan initialization, calls the refactored check_llama_stack_version with configured retry parameters, and logs the returned version when available. On APIConnectionError, startup logs degraded-mode entry when allow_degraded_mode is enabled; otherwise the exception is re-raised.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • lightspeed-core/lightspeed-stack#1777: Introduces the allow_degraded_mode configuration field that is now used in this PR's startup error handling to conditionally enter degraded mode on Llama Stack connection failure.
🚥 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 'LCORE-1858: degraded mode support' directly matches the main objective of the PR, which is to add degraded mode support as indicated in both the description and commit messages.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

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.

@tisnik tisnik force-pushed the lcore-1858-degraded-mode branch from 519fd44 to 58e50c3 Compare May 24, 2026 16:54
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.

Actionable comments posted: 2

🤖 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.

Inline comments:
In `@src/utils/llama_stack_version.py`:
- Around line 25-29: The docstring for check_llama_stack_version is missing a
Returns section; update the function's docstring (for check_llama_stack_version)
to include a Returns entry that states it returns an Optional[str] — the
detected Llama Stack version string on success or None if the version could not
be determined after retries — and briefly mention any error behavior if
applicable (e.g., that it does not raise on failure but returns None).
- Line 5: The retry helper get_llama_stack_version currently re-raises
APIConnectionError on final failure which makes the later "return None" branch
unreachable and conflicts with callers expecting Optional[str] (e.g.,
src/app/main.py); update get_llama_stack_version to honor the Optional[str]
contract by catching APIConnectionError on the last retry and returning None
instead of re-raising (or alternatively change the function signature to return
str and propagate the exception consistently); ensure you adjust the function's
return type annotation (Optional[str]) and remove unreachable code paths so the
caller's "version is None" branch can run.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 62055541-bba3-41ff-9b1b-e5382bba2291

📥 Commits

Reviewing files that changed from the base of the PR and between 496eff7 and 519fd44.

📒 Files selected for processing (2)
  • src/app/main.py
  • src/utils/llama_stack_version.py
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (16)
  • GitHub Check: pydocstyle
  • GitHub Check: bandit
  • GitHub Check: spectral
  • GitHub Check: unit_tests (3.13)
  • GitHub Check: unit_tests (3.12)
  • GitHub Check: build-pr
  • GitHub Check: integration_tests (3.13)
  • GitHub Check: Pylinter
  • GitHub Check: Konflux kflux-prd-rh02 / lightspeed-stack-on-pull-request
  • GitHub Check: E2E: server mode / ci / group 3
  • GitHub Check: E2E: library mode / ci / group 3
  • GitHub Check: E2E Tests for Lightspeed Evaluation job
  • GitHub Check: E2E: server mode / ci / group 1
  • GitHub Check: E2E: library mode / ci / group 1
  • GitHub Check: E2E: server mode / ci / group 2
  • GitHub Check: E2E: library mode / ci / group 2
🧰 Additional context used
📓 Path-based instructions (2)
src/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

src/**/*.py: Use absolute imports for internal modules: from authentication import get_auth_dependency
Llama Stack imports: Use from llama_stack_client import AsyncLlamaStackClient
Check constants.py for shared constants before defining new ones
All modules must start with descriptive docstrings explaining purpose
Use logger = get_logger(__name__) from log.py for module logging
All functions must have complete type annotations for parameters and return types, use modern syntax (str | int), and include descriptive docstrings
Use snake_case with descriptive, action-oriented names for functions (get_, validate_, check_)
Avoid in-place parameter modification anti-patterns; return new data structures instead of modifying function parameters
Use async def for I/O operations and external API calls
Use standard log levels with clear purposes: debug() for diagnostic info, info() for program execution, warning() for unexpected events, error() for serious problems
All classes must have descriptive docstrings explaining purpose and use PascalCase with standard suffixes: Configuration, Error/Exception, Resolver, Interface
Abstract classes must use ABC with @abstractmethod decorators
Follow Google Python docstring conventions with required sections: Parameters, Returns, Raises, and Attributes for classes

Files:

  • src/utils/llama_stack_version.py
  • src/app/main.py
src/app/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

src/app/**/*.py: FastAPI dependencies: Import from fastapi module for APIRouter, HTTPException, Request, status, Depends
Use FastAPI HTTPException with appropriate status codes for API endpoints and handle APIConnectionError from Llama Stack

Files:

  • src/app/main.py
🔇 Additional comments (1)
src/app/main.py (1)

102-116: LGTM!

Comment thread src/utils/llama_stack_version.py
Comment on lines 25 to +29
async def check_llama_stack_version(
client: AsyncLlamaStackClient,
max_retries: int = _DEFAULT_MAX_RETRIES,
retry_delay: int = _DEFAULT_RETRY_DELAY,
) -> None:
max_retries: int = DEFAULT_MAX_RETRIES,
retry_delay: int = DEFAULT_RETRY_DELAY,
) -> Optional[str]:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win

Document the new return value in the docstring.

This function now returns the detected version, but the docstring still has no Returns section, so the in-file contract is incomplete.

As per coding guidelines, "Follow Google Python docstring conventions with required sections: Parameters, Returns, Raises, and Attributes for classes".

🤖 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 `@src/utils/llama_stack_version.py` around lines 25 - 29, The docstring for
check_llama_stack_version is missing a Returns section; update the function's
docstring (for check_llama_stack_version) to include a Returns entry that states
it returns an Optional[str] — the detected Llama Stack version string on success
or None if the version could not be determined after retries — and briefly
mention any error behavior if applicable (e.g., that it does not raise on
failure but returns None).

@tisnik tisnik merged commit 3b044c3 into lightspeed-core:main May 24, 2026
30 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.

1 participant