Skip to content

Graph-Native Infrastructure for Context and Accountable AI Systems

fix(explorer): resolve PR review bugs (lock, import mapping, traceback, static route)

ZohaibHassan16a6654ba570c1
diff --git a/semantica/explorer/app.py b/semantica/explorer/app.py
index ba797d75..1082d38a 100644
--- a/semantica/explorer/app.py
+++ b/semantica/explorer/app.py
@@ -73,10 +73,9 @@ def create_app(session: Optional[GraphSession] = None) -> FastAPI:
@app.exception_handler(Exception)
async def generic_error_handler(request: Request, exc: Exception):
- tb = traceback.format_exc()
return JSONResponse(
status_code=500,
- content={"detail": f"Internal Server Error: {exc}", "traceback": tb},
+ content={"detail": "Internal Server Error"},
)
from .routes.graph import router as graph_router
@@ -124,8 +123,8 @@ def create_app(session: Optional[GraphSession] = None) -> FastAPI:
static_dir = Path(__file__).resolve().parent.parent / "static"
- if static_dir.is_dir():
- from fastapi.staticfiles import StaticFiles
- app.mount("/", StaticFiles(directory=str(static_dir), html=True), name="static")
+ static_dir.mkdir(parents=True, exist_ok=True)
+ from fastapi.staticfiles import StaticFiles
+ app.mount("/", StaticFiles(directory=str(static_dir), html=True), name="static")
return app
diff --git a/semantica/explorer/routes/export_import.py b/semantica/explorer/routes/export_import.py
index 608db5ff..7b2e3e35 100644
--- a/semantica/explorer/routes/export_import.py
+++ b/semantica/explorer/routes/export_import.py
@@ -154,8 +154,14 @@ async def import_file(
nodes = data.get("nodes", data.get("entities", []))
edges = data.get("edges", data.get("relationships", []))
- added_nodes = await asyncio.to_thread(session.graph.add_nodes, nodes)
- added_edges = await asyncio.to_thread(session.graph.add_edges, edges)
+ for edge in edges:
+ if "source" in edge and "source_id" not in edge:
+ edge["source_id"] = edge["source"]
+ if "target" in edge and "target_id" not in edge:
+ edge["target_id"] = edge["target"]
+
+ added_nodes = await asyncio.to_thread(session.add_nodes, nodes)
+ added_edges = await asyncio.to_thread(session.add_edges, edges)
result = {
"status": "success",
diff --git a/semantica/explorer/session.py b/semantica/explorer/session.py
index de0ff3b2..61262bb1 100644
--- a/semantica/explorer/session.py
+++ b/semantica/explorer/session.py
@@ -209,3 +209,13 @@ class GraphSession:
"""Delete an annotation. Returns True if found and deleted."""
with self._lock:
return self.annotations.pop(annotation_id, None) is not None
+
+ def add_nodes(self, nodes: List[Dict[str, Any]]) -> int:
+ """Thread-safe node addition."""
+ with self._lock:
+ return self.graph.add_nodes(nodes)
+
+ def add_edges(self, edges: List[Dict[str, Any]]) -> int:
+ """Thread-safe edge addition."""
+ with self._lock:
+ return self.graph.add_edges(edges)