Skip to content

build_index_sync uses asyncio.run() which fails in async context #11

Description

@DeFiVC

What

The build_index_sync function uses asyncio.run():

def build_index_sync(...) -> VectorStore:
    return asyncio.run(build_index(source_dir, output_path))

asyncio.run() creates a new event loop. If called from within an already-running event loop (e.g., from a FastAPI startup event or an async script), it raises RuntimeError: This event loop is closed.

Why

This limits where the function can be called from.

Scope

  • Document the limitation
  • Or use nest_asyncio / loop.run_until_complete for safer fallback

Acceptance Criteria

  • The function works in both sync and async contexts
  • Or the limitation is documented

Technical Context

  • File: src/knowledge/index_builder.py, line 90

Metadata

Metadata

Assignees

No one assigned

    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