Coverage for app / services / executor.py: 100%
15 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-10-31 11:23 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-10-31 11:23 +0000
1"""
2executor — thin dispatch layer for svc-ai inference requests.
4All execution logic lives in ``app.inference``. This module provides:
5 - ``execute()`` — batch entry point (used by routers/execute.py)
6 - The ``_checkpointer`` / ``_store`` singletons — re-exported from
7 graph_based so routers that need them (HITL resume, streaming) import from
8 a single well-known location.
9"""
11from __future__ import annotations
13import uuid
14from typing import Any
16from app.inference import InferenceEngineFactory, InferenceContext
17from app.inference.engines.graph_based import _checkpointer, _store # noqa: F401 — re-exported
18from app.models.spec import ExecuteRequest, ExecuteResponse
19from app.util.logger import get_logger, set_correlation_id
21logger = get_logger(__name__)
24async def execute(request: ExecuteRequest, db: Any = None) -> ExecuteResponse:
25 """
26 Execute a request through the appropriate inference engine.
28 Assigns a correlation ID for the request, creates the engine via the
29 factory, and runs the full engine lifecycle (rules → infer → audit).
30 """
31 cid = request.session_id or str(uuid.uuid4())
32 set_correlation_id(cid)
33 logger.info(
34 "execute type=%s user=%s session=%s", request.type, request.user_id, cid
35 )
37 engine = InferenceEngineFactory.create(
38 request.type,
39 db=db,
40 rules_list=request.rules,
41 )
42 ctx = InferenceContext(request=request, db=db)
43 return await engine.infer(ctx)