From d6ff191198718e9b422e1109a701dbe5b6043012 Mon Sep 17 00:00:00 2001 From: Chris Bartholomew Date: Thu, 8 Jan 2026 14:38:35 -0500 Subject: [PATCH] Fix stats endpoint missing tenant authentication (#134) The /v1/default/banks/{bank_id}/stats endpoint was missing the request_context parameter and tenant authentication call, causing it to query the public schema instead of the tenant's schema. This resulted in stats always returning zeros for multi-tenant deployments since the data lives in tenant-specific schemas. Added request_context dependency and _authenticate_tenant() call to properly set the tenant schema before querying stats. --- hindsight-api/hindsight_api/api/http.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hindsight-api/hindsight_api/api/http.py b/hindsight-api/hindsight_api/api/http.py index 3f9c5c28..5de005a9 100644 --- a/hindsight-api/hindsight_api/api/http.py +++ b/hindsight-api/hindsight_api/api/http.py @@ -1360,9 +1360,14 @@ def _register_routes(app: FastAPI): operation_id="get_agent_stats", tags=["Banks"], ) - async def api_stats(bank_id: str): + async def api_stats( + bank_id: str, + request_context: RequestContext = Depends(get_request_context), + ): """Get statistics about memory nodes and links for a memory bank.""" try: + # Authenticate and set tenant schema + await app.state.memory._authenticate_tenant(request_context) pool = await app.state.memory._get_pool() async with acquire_with_retry(pool) as conn: # Get node counts by fact_type