fix: Pydantic datetime serialization for API endpoints

Problem:
Several API endpoints return 500 Internal Server Error because datetime
objects are not serializable by Pydantic. The error occurs when:
- GET /agent/{project}/status
- GET /devserver/{project}/status
- GET /schedules/{project}/next

Root cause:
Pydantic models expect strings for Optional datetime fields, but the code
was passing raw datetime objects.

Solution:
Convert datetime objects to ISO 8601 strings using .isoformat() before
returning in Pydantic response models.

Changes:
- server/routers/agent.py: Fix started_at serialization
- server/routers/devserver.py: Fix started_at serialization
- server/routers/schedules.py: Fix next_start/next_end serialization

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
cabana8471
2026-01-25 08:04:14 +01:00
parent 486979c3d9
commit 43c37c52fe
3 changed files with 4 additions and 4 deletions

View File

@@ -93,7 +93,7 @@ async def get_agent_status(project_name: str):
return AgentStatus(
status=manager.status,
pid=manager.pid,
started_at=manager.started_at,
started_at=manager.started_at.isoformat() if manager.started_at else None,
yolo_mode=manager.yolo_mode,
model=manager.model,
parallel_mode=manager.parallel_mode,

View File

@@ -129,7 +129,7 @@ async def get_devserver_status(project_name: str) -> DevServerStatus:
pid=manager.pid,
url=manager.detected_url,
command=manager._command,
started_at=manager.started_at,
started_at=manager.started_at.isoformat() if manager.started_at else None,
)

View File

@@ -256,8 +256,8 @@ async def get_next_scheduled_run(project_name: str):
return NextRunResponse(
has_schedules=True,
next_start=next_start if active_count == 0 else None,
next_end=latest_end,
next_start=next_start.isoformat() if (active_count == 0 and next_start) else None,
next_end=latest_end.isoformat() if latest_end else None,
is_currently_running=active_count > 0,
active_schedule_count=active_count,
)