Skip to content

Graph-Native Infrastructure for Context and Accountable AI Systems

fix(explorer): resolve sync blocking calls and 500 error propagation

ZohaibHassan164a3b1676d633
diff --git a/semantica/explorer/dependencies.py b/semantica/explorer/dependencies.py
index b59c72d9..5e29f07e 100644
--- a/semantica/explorer/dependencies.py
+++ b/semantica/explorer/dependencies.py
@@ -5,7 +5,7 @@ Provides ``Depends()``-compatible callables for injecting the
current ``GraphSession`` and ``ConnectionManager`` into route handlers.
"""
-from fastapi import Request
+from fastapi import Request, HTTPException, status
from .session import GraphSession
from .ws import ConnectionManager
@@ -13,6 +13,11 @@ from .ws import ConnectionManager
def get_session(request: Request) -> GraphSession:
"""Retrieve the GraphSession stored on ``app.state``."""
+ if not hasattr(request.app.state, "session") or request.app.state.session is None:
+ raise HTTPException(
+ status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
+ detail="GraphSession not initialized."
+ )
return request.app.state.session
diff --git a/semantica/explorer/routes/enrich.py b/semantica/explorer/routes/enrich.py
index 606130fe..854c9870 100644
--- a/semantica/explorer/routes/enrich.py
+++ b/semantica/explorer/routes/enrich.py
@@ -66,8 +66,8 @@ async def predict_links(
raise KeyError(body.node_id)
# Build graph dict
- nodes, _ = session.get_nodes(skip=0, limit=999_999)
- edges, _ = session.get_edges(skip=0, limit=999_999)
+ nodes, _ = await asyncio.to_thread(session.get_nodes, skip=0, limit=999_999)
+ edges, _ = await asyncio.to_thread(session.get_edges, skip=0, limit=999_999)
graph_dict = {
"entities": [{"id": n.get("id"), "type": n.get("type", "entity")} for n in nodes],
"relationships": [
diff --git a/semantica/explorer/routes/temporal.py b/semantica/explorer/routes/temporal.py
index 844b9221..300e124d 100644
--- a/semantica/explorer/routes/temporal.py
+++ b/semantica/explorer/routes/temporal.py
@@ -103,8 +103,8 @@ async def temporal_patterns(
detector = TemporalPatternDetector()
- nodes, _ = session.get_nodes(skip=0, limit=999_999)
- edges, _ = session.get_edges(skip=0, limit=999_999)
+ nodes, _ = await asyncio.to_thread(session.get_nodes, skip=0, limit=999_999)
+ edges, _ = await asyncio.to_thread(session.get_edges, skip=0, limit=999_999)
graph_dict = {
"entities": [
{"id": n.get("id"), "type": n.get("type"), "metadata": n.get("metadata", {})}