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 <noreply@anthropic.com>
This commit is contained in:
slothitude 2026-05-30 12:12:09 +10:00
parent 6374aea0a2
commit 792dbceab5

View file

@ -319,14 +319,8 @@ def cmd_serve(args):
database=config.storage.neo4j_database, database=config.storage.neo4j_database,
) )
# VectorIndex requires ChromaDB directory — skip for memory backend in tests from aucourt_ingest.storage.vector_index import VectorIndex
vector_index = None vector_index = VectorIndex(str(config.storage.chromadb_dir))
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.api.app import create_app from aucourt_ingest.api.app import create_app
app = create_app(graph_db, vector_index, max_tokens) app = create_app(graph_db, vector_index, max_tokens)
@ -336,10 +330,7 @@ def cmd_serve(args):
uvicorn.run(app, host=host, port=port) uvicorn.run(app, host=host, port=port)
async def async_main(): async def async_main(args):
parser = build_parser()
args = parser.parse_args()
if not args.mode: if not args.mode:
parser.print_help() parser.print_help()
return return
@ -354,13 +345,18 @@ async def async_main():
await cmd_audit(args) await cmd_audit(args)
elif args.mode == "process": elif args.mode == "process":
await cmd_process(args) await cmd_process(args)
elif args.mode == "serve":
cmd_serve(args)
def main(): def main():
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(name)s %(levelname)s %(message)s") 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__": if __name__ == "__main__":