From ad8dd18746f7e1c48ed9a7bfd26b900cdcd53335 Mon Sep 17 00:00:00 2001 From: Diwank Singh Tomer Date: Tue, 31 Dec 2024 14:35:32 +0530 Subject: [PATCH] hotfix(agents-api): Session APIs throw Internal Server Error Signed-off-by: Diwank Singh Tomer --- agents-api/agents_api/activities/utils.py | 1 - agents-api/agents_api/metrics/counters.py | 8 ++++---- agents-api/agents_api/models/session/list_sessions.py | 8 +++++++- agents-api/agents_api/models/session/patch_session.py | 2 +- agents-api/agents_api/models/utils.py | 7 ++++++- agents-api/agents_api/routers/healthz/check_health.py | 3 +-- sdks/node-sdk | 2 +- sdks/python-sdk | 2 +- 8 files changed, 21 insertions(+), 12 deletions(-) diff --git a/agents-api/agents_api/activities/utils.py b/agents-api/agents_api/activities/utils.py index a6746bbe5..5923ec3cb 100644 --- a/agents-api/agents_api/activities/utils.py +++ b/agents-api/agents_api/activities/utils.py @@ -305,7 +305,6 @@ def get_handler(system: SystemDef) -> Callable: from ..models.docs.list_docs import list_docs as list_docs_query from ..models.entry.get_history import get_history as get_history_query from ..models.session.create_session import create_session as create_session_query - from ..models.session.delete_session import delete_session as delete_session_query from ..models.session.get_session import get_session as get_session_query from ..models.session.list_sessions import list_sessions as list_sessions_query from ..models.session.update_session import update_session as update_session_query diff --git a/agents-api/agents_api/metrics/counters.py b/agents-api/agents_api/metrics/counters.py index c5455248b..d9707ea56 100644 --- a/agents-api/agents_api/metrics/counters.py +++ b/agents-api/agents_api/metrics/counters.py @@ -34,17 +34,17 @@ INF, ) counter = Counter( - f"db_query_counter", - f"Number of db calls", + "db_query_counter", + "Number of db calls", labelnames=labelnames, ) summary = Summary( - f"db_query_latency_summary", + "db_query_latency_summary", "Database query latency summary", labelnames=labelnames, ) hist = Histogram( - f"db_query_latency_hist", + "db_query_latency_hist", "Database query latency histogram", labelnames=labelnames, buckets=buckets, diff --git a/agents-api/agents_api/models/session/list_sessions.py b/agents-api/agents_api/models/session/list_sessions.py index 4adb84a6c..2a4a7d47b 100644 --- a/agents-api/agents_api/models/session/list_sessions.py +++ b/agents-api/agents_api/models/session/list_sessions.py @@ -29,7 +29,13 @@ TypeError: partialclass(HTTPException, status_code=400), } ) -@wrap_in_class(make_session) +@wrap_in_class( + make_session, + transform=lambda d: { + "updated_at": d.pop("updated_at") / (1000000.0), + **d, + }, +) @cozo_query @beartype def list_sessions( diff --git a/agents-api/agents_api/models/session/patch_session.py b/agents-api/agents_api/models/session/patch_session.py index 4a119a684..c8a036ef3 100644 --- a/agents-api/agents_api/models/session/patch_session.py +++ b/agents-api/agents_api/models/session/patch_session.py @@ -46,7 +46,7 @@ one=True, transform=lambda d: { "id": d["session_id"], - "updated_at": d.pop("updated_at")[0], + "updated_at": d.pop("updated_at")[0] / (1000000.0), "jobs": [], **d, }, diff --git a/agents-api/agents_api/models/utils.py b/agents-api/agents_api/models/utils.py index 1c8244ecc..d9bc066bc 100644 --- a/agents-api/agents_api/models/utils.py +++ b/agents-api/agents_api/models/utils.py @@ -478,7 +478,12 @@ def _return_data(df: pd.DataFrame): transform = transform or (lambda x: x) if one: - assert len(data) >= 1, "Expected one result, got none" + resource_name = cls.__name__ if isinstance(cls, type) else "Resource" + if len(data) < 1: + raise HTTPException( + status_code=404, detail=f"{resource_name} not found" + ) + obj: ModelT = cls(**transform(data[0])) return obj diff --git a/agents-api/agents_api/routers/healthz/check_health.py b/agents-api/agents_api/routers/healthz/check_health.py index 74e9f5c6c..5a466ba39 100644 --- a/agents-api/agents_api/routers/healthz/check_health.py +++ b/agents-api/agents_api/routers/healthz/check_health.py @@ -1,7 +1,6 @@ import logging from uuid import UUID -from ...autogen.openapi_model import Agent, ListResponse from ...models.agent.list_agents import list_agents as list_agents_query from .router import router @@ -10,7 +9,7 @@ async def check_health() -> dict: try: # Check if the database is reachable - agents = list_agents_query( + list_agents_query( developer_id=UUID("00000000-0000-0000-0000-000000000000"), ) except Exception as e: diff --git a/sdks/node-sdk b/sdks/node-sdk index 6cb742bba..ff0443945 160000 --- a/sdks/node-sdk +++ b/sdks/node-sdk @@ -1 +1 @@ -Subproject commit 6cb742bba2b408ef2ea070bfe284595bcdb974fe +Subproject commit ff0443945294c2638b7cc796456d271c1b669fa2 diff --git a/sdks/python-sdk b/sdks/python-sdk index 7f9bc0c59..96cd8e74b 160000 --- a/sdks/python-sdk +++ b/sdks/python-sdk @@ -1 +1 @@ -Subproject commit 7f9bc0c59d2e80f6e707f5dcc9e78fecd197c3ca +Subproject commit 96cd8e74bc95bc83158f07489916b7f4214aa002