Skip to content

Commit 3175da3

Browse files
authored
Merge pull request #95 from zestones/26-m44-lifespan-integration
feat(lifespan): integrate sentinel loop within MCP lifespan management
2 parents efa38aa + 4382523 commit 3175da3

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

backend/agents/investigator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ def _spawn_work_order_generator(work_order_id: int) -> None:
494494
instead of a throwaway stub.
495495
"""
496496
try:
497-
from agents.work_order_generator import (# type: ignore[import-not-found]
497+
from agents.work_order_generator import ( # type: ignore[import-not-found]
498498
run_work_order_generator,
499499
)
500500
except ImportError:

backend/main.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
from __future__ import annotations
44

5+
import asyncio
56
import logging
67
from contextlib import asynccontextmanager
78

9+
from agents.sentinel import sentinel_loop
810
from aria_mcp.server import http_app as mcp_http_app
911
from core.config import get_settings
1012
from core.database import db
@@ -38,9 +40,19 @@ async def lifespan(app: FastAPI):
3840
log.info("ARIA backend ready")
3941
async with mcp_http_app.lifespan(mcp_http_app):
4042
log.info("MCP server ready at /mcp")
43+
# Sentinel must start INSIDE the MCP lifespan wrapper — its first
44+
# `mcp_client.call_tool()` hits 404 otherwise (MCP HTTP app not
45+
# yet mounted). See #26 audit comment.
46+
sentinel_task = asyncio.create_task(sentinel_loop(), name="sentinel")
4147
try:
4248
yield
4349
finally:
50+
sentinel_task.cancel()
51+
try:
52+
await sentinel_task
53+
except asyncio.CancelledError:
54+
pass
55+
log.info("Sentinel cancelled")
4456
await db.disconnect()
4557

4658

0 commit comments

Comments
 (0)