From 9b3d35669ffaf05676c3d70eddc62fe3ac3d76e3 Mon Sep 17 00:00:00 2001 From: Viktor Barzin Date: Mon, 23 Feb 2026 19:22:01 +0000 Subject: [PATCH] Fix API crash: status_code=204 with response body assertion error FastAPI rejects status_code=204 on routes with a return type annotation. Return an explicit Response(status_code=204) instead. --- api/perf_routes.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/api/perf_routes.py b/api/perf_routes.py index e5bcac2..bbf4a12 100644 --- a/api/perf_routes.py +++ b/api/perf_routes.py @@ -1,7 +1,7 @@ """Frontend performance metrics ingestion endpoint.""" from __future__ import annotations -from fastapi import APIRouter +from fastapi import APIRouter, Response from pydantic import BaseModel, Field, field_validator import api.metrics as app_metrics @@ -26,8 +26,8 @@ class PerfSample(BaseModel): perf_router = APIRouter(tags=["perf"]) -@perf_router.post("/api/perf", status_code=204) -async def record_perf(samples: list[PerfSample]) -> None: +@perf_router.post("/api/perf") +async def record_perf(samples: list[PerfSample]) -> Response: if len(samples) > MAX_BATCH_SIZE: samples = samples[:MAX_BATCH_SIZE] @@ -41,3 +41,5 @@ async def record_perf(samples: list[PerfSample]) -> None: app_metrics.frontend_main_thread.record(s.value, attrs) elif s.metric == "feature_count": app_metrics.frontend_feature_count.record(s.value) + + return Response(status_code=204)