Skip to content

[BUG] LSC:dev-latest fails to start when used as library #291

@manstis

Description

@manstis

Bug Description

lightspeed-stack fails to start when running as a library.

Describe the bug

[07/25/25 12:26:31] INFO     Initializing app                                                                                                                                                            main.py:19
                    INFO     Including routers                                                                                                                                                           main.py:68
Traceback (most recent call last):
  File "/app-root/src/lightspeed_stack.py", line 91, in <module>
    main()
  File "/app-root/src/lightspeed_stack.py", line 86, in main
    start_uvicorn(configuration.service_configuration)
  File "/app-root/src/runners/uvicorn.py", line 20, in start_uvicorn
    uvicorn.run(
  File "/app-root/.venv/lib64/python3.12/site-packages/uvicorn/main.py", line 580, in run
    server.run()
  File "/app-root/.venv/lib64/python3.12/site-packages/uvicorn/server.py", line 67, in run
    return asyncio.run(self.serve(sockets=sockets))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/asyncio/runners.py", line 195, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/asyncio/base_events.py", line 691, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/app-root/.venv/lib64/python3.12/site-packages/uvicorn/server.py", line 71, in serve
    await self._serve(sockets)
  File "/app-root/.venv/lib64/python3.12/site-packages/uvicorn/server.py", line 78, in _serve
    config.load()
  File "/app-root/.venv/lib64/python3.12/site-packages/uvicorn/config.py", line 436, in load
    self.loaded_app = import_from_string(self.app)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app-root/.venv/lib64/python3.12/site-packages/uvicorn/importer.py", line 19, in import_from_string
    module = importlib.import_module(module_str)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 999, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/app-root/src/app/main.py", line 77, in <module>
    setup_model_metrics()
  File "/app-root/src/metrics/utils.py", line 16, in setup_model_metrics
    for model in client.models.list()
                 ^^^^^^^^^^^^^^^^^^^^
  File "/app-root/.venv/lib64/python3.12/site-packages/llama_stack_client/resources/models.py", line 93, in list
    return self._get(
           ^^^^^^^^^^
  File "/app-root/.venv/lib64/python3.12/site-packages/llama_stack_client/_base_client.py", line 1178, in get
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app-root/.venv/lib64/python3.12/site-packages/llama_stack/distribution/library_client.py", line 177, in request
    result = loop.run_until_complete(self.async_client.request(*args, **kwargs))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/asyncio/base_events.py", line 667, in run_until_complete
    self._check_running()
  File "/usr/lib64/python3.12/asyncio/base_events.py", line 628, in _check_running
    raise RuntimeError(
RuntimeError: Cannot run the event loop while another loop is running
sys:1: RuntimeWarning: coroutine 'AsyncLlamaStackAsLibraryClient.request' was never awaited
make: *** [Makefile:123: run-lsc] Error 1

To Reproduce

lightspeed-stack.yaml

name: Lightspeed Stack
service:
  host: 0.0.0.0
  port: 8080
  auth_enabled: false
  workers: 1
  color_log: true
  access_log: true
llama_stack:
  use_as_library_client: true
  library_client_config_path: /app-root/lightspeed-stack-run.yaml
user_data_collection:
  feedback_disabled: true
  transcripts_disabled: true

lightspeed-stack-run.yaml

version: '2'
image_name: lightspeed-stack
container_image: lightspeed-stack
apis:
- inference
- agents
providers:
  inference: []
  safety: []
  agents: []
metadata_store: null
models: []
shields: []
vector_dbs: []
datasets: []
scoring_fns: []
benchmarks: []
tool_groups: []
logging: null
server:
  port: 8321
  tls_certfile: null
  tls_keyfile: null
  tls_cafile: null
  auth: null
  disable_ipv6: false

Launch

docker run -it -p 8080:8080 \
  -v ./lightspeed-stack.yaml:/app-root/lightspeed-stack.yaml \
  -v ./lightspeed-stack-run.yaml:/app-root/lightspeed-stack-run.yaml \
  quay.io/lightspeed-core/lightspeed-stack:dev-latest

Steps to reproduce the behavior:

As above.

Expected behavior

lightspeed-stack should start-up when ran as library.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions