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,12 +319,6 @@ 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))
@ -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__":