From 792dbceab5accb938c08e874abe22fd253edc64a Mon Sep 17 00:00:00 2001 From: slothitude Date: Sat, 30 May 2026 12:12:09 +1000 Subject: [PATCH] Fix serve command: handle outside asyncio.run() to avoid nested loop error uvicorn manages its own event loop, so cmd_serve must not be called inside asyncio.run(). Also deduplicate redundant VectorIndex branching. Co-Authored-By: Claude Opus 4.6 --- aucourt_ingest/main.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/aucourt_ingest/main.py b/aucourt_ingest/main.py index 0accdf6..15e3ce9 100644 --- a/aucourt_ingest/main.py +++ b/aucourt_ingest/main.py @@ -319,14 +319,8 @@ def cmd_serve(args): database=config.storage.neo4j_database, ) - # VectorIndex requires ChromaDB directory — skip for memory backend in tests - vector_index = None - if backend != "memory": - from aucourt_ingest.storage.vector_index import VectorIndex - vector_index = VectorIndex(str(config.storage.chromadb_dir)) - else: - from aucourt_ingest.storage.vector_index import VectorIndex - vector_index = VectorIndex(str(config.storage.chromadb_dir)) + from aucourt_ingest.storage.vector_index import VectorIndex + vector_index = VectorIndex(str(config.storage.chromadb_dir)) from aucourt_ingest.api.app import create_app app = create_app(graph_db, vector_index, max_tokens) @@ -336,10 +330,7 @@ def cmd_serve(args): uvicorn.run(app, host=host, port=port) -async def async_main(): - parser = build_parser() - args = parser.parse_args() - +async def async_main(args): if not args.mode: parser.print_help() return @@ -354,13 +345,18 @@ async def async_main(): await cmd_audit(args) elif args.mode == "process": await cmd_process(args) - elif args.mode == "serve": - cmd_serve(args) def main(): logging.basicConfig(level=logging.INFO, format="%(asctime)s %(name)s %(levelname)s %(message)s") - asyncio.run(async_main()) + parser = build_parser() + args = parser.parse_args() + + if args.mode == "serve": + cmd_serve(args) + return + + asyncio.run(async_main(args)) if __name__ == "__main__":