Skip to content

Conversation

Akrog
Copy link

@Akrog Akrog commented Jul 8, 2025

Description

Log levels on the llama_stack_client are currently broken and setting
LLAMA_STACK_LOG=debug doesn't work as it should. Log levels are
automatically changed to WARNING.

This is caused by us blindly loading the llama_stack library, which
initializes logging to WARNING except a subset of modules that can be
modified using the LLAMA_STACK_LOGGING env var.

With this patch we only import llama_stack when we are actually going
to use it, so that when we use the normal llama-stack client we can set
its logging level.

Type of change

  • Bug fix

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

Just run lightspeed-stack with a remote llama-stack and set the LLAMA_STACK_LOGGING to debug and see that you don't get debug logs, but you do once you apply this patch.

Summary by CodeRabbit

  • Refactor
    • Improved how certain components are loaded internally to optimize resource usage. No changes to visible features or functionality.

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.

it looks ok, thank you. Just please rebase your PR

Log levels on the llama_stack_client are currently broken and setting
`LLAMA_STACK_LOG=debug` doesn't work as it should.  Log levels are
automatically changed to WARNING.

This is caused by us blindly loading the `llama_stack` library, which
initializes logging to WARNING except a subset of modules that can be
modified using the `LLAMA_STACK_LOGGING` env var.

With this patch we only import `llama_stack` when we are actually going
to use it, so that when we use the normal llama-stack client we can set
its logging level.
Copy link
Contributor

coderabbitai bot commented Jul 9, 2025

Walkthrough

The import statements for LlamaStackAsLibraryClient and AsyncLlamaStackAsLibraryClient were moved from the top-level module imports to within the load methods of their respective holder classes. This localizes the imports to when the clients are actually loaded, rather than at module initialization.

Changes

File(s) Change Summary
src/client.py Moved imports of LlamaStackAsLibraryClient and AsyncLlamaStackAsLibraryClient inside the load methods of their respective holder classes. No changes to public API or declarations.

Poem

In burrows deep, imports now hide,
Only hopping out when clients are applied.
No more waiting at the door—
They’re fetched just when you ask for more!
A tidy warren, swift and neat,
Where code and rabbits rarely meet. 🐇

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
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: 1

🔭 Outside diff range comments (1)
src/client.py (1)

57-72: Apply the same clean-ups to the async path

Mirror the boolean simplification and folded import for consistency and to satisfy linters.

-        if llama_stack_config.use_as_library_client is True:
+        if llama_stack_config.use_as_library_client:
...
-                from llama_stack.distribution.library_client import AsyncLlamaStackAsLibraryClient  # type: ignore
+# pylint: disable=import-outside-toplevel
+                from llama_stack.distribution.library_client import (
+                    AsyncLlamaStackAsLibraryClient,
+                )  # type: ignore
🧹 Nitpick comments (1)
src/client.py (1)

20-34: Avoid verbose boolean comparison

is True is unnecessary and triggers pylint’s singleton-comparison. Rely on the value’s truthiness instead.

-        if llama_stack_config.use_as_library_client is True:
+        if llama_stack_config.use_as_library_client:
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2cc5e93 and 244b537.

📒 Files selected for processing (1)
  • src/client.py (2 hunks)
🧰 Additional context used
🪛 GitHub Actions: Black
src/client.py

[error] 1-1: Black formatting check failed. Run 'black --write' to fix code style issues.

🪛 GitHub Actions: Python linter
src/client.py

[warning] 25-25: pylint: Line too long (109/100) (line-too-long)


[warning] 62-62: pylint: Line too long (114/100) (line-too-long)


[warning] 25-25: pylint: Import outside toplevel (llama_stack.distribution.library_client.LlamaStackAsLibraryClient) (import-outside-toplevel)


[warning] 62-62: pylint: Import outside toplevel (llama_stack.distribution.library_client.AsyncLlamaStackAsLibraryClient) (import-outside-toplevel)

⏰ 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). (1)
  • GitHub Check: build-pr
🔇 Additional comments (1)
src/client.py (1)

1-85: CI is red – run Black

GitHub Actions reports a Black failure. Execute black src/client.py (or black .) and repush to unblock the pipeline.

Comment on lines 24 to 28
logger.info("Using Llama stack as library client")
from llama_stack.distribution.library_client import LlamaStackAsLibraryClient # type: ignore
client = LlamaStackAsLibraryClient(
llama_stack_config.library_client_config_path
)
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Fold long import and document the deliberate late import

The inner import fixes the logging bug, but the line exceeds 100 chars and still raises import-outside-toplevel. Break it and add an explicit pragma.

-                from llama_stack.distribution.library_client import LlamaStackAsLibraryClient  # type: ignore
+# pylint: disable=import-outside-toplevel
+                from llama_stack.distribution.library_client import (
+                    LlamaStackAsLibraryClient,
+                )  # type: ignore
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
logger.info("Using Llama stack as library client")
from llama_stack.distribution.library_client import LlamaStackAsLibraryClient # type: ignore
client = LlamaStackAsLibraryClient(
llama_stack_config.library_client_config_path
)
logger.info("Using Llama stack as library client")
# pylint: disable=import-outside-toplevel
from llama_stack.distribution.library_client import (
LlamaStackAsLibraryClient,
) # type: ignore
client = LlamaStackAsLibraryClient(
llama_stack_config.library_client_config_path
)
🧰 Tools
🪛 GitHub Actions: Python linter

[warning] 25-25: pylint: Line too long (109/100) (line-too-long)


[warning] 25-25: pylint: Import outside toplevel (llama_stack.distribution.library_client.LlamaStackAsLibraryClient) (import-outside-toplevel)

🤖 Prompt for AI Agents
In src/client.py around lines 24 to 28, the import statement inside the function
is too long and triggers an import-outside-toplevel warning. Break the import
into multiple lines to keep it under 100 characters and add a comment with a
pragma to explicitly ignore the import-outside-toplevel warning, documenting
that the late import is deliberate to fix the logging bug.

Copy link
Contributor

@umago umago left a comment

Choose a reason for hiding this comment

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

Code-wise it looks fine, just need to fix the current issues with CI

@lpiwowar
Copy link

LGTM! 👍 As already stated above, linters are complaining.

@umago
Copy link
Contributor

umago commented Jul 23, 2025

@Akrog r u going to take a look at this ? I think we can merge it once the linters issues are fixed.

@tisnik
Copy link
Contributor

tisnik commented Aug 5, 2025

@Akrog Hello, is this one still relevant?

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.

4 participants