mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-09-24 20:22:53 +00:00
8d0d74e35c
Fixes #1640. Three defects around POST /api/ai/patrol/readiness on slow local hardware behind a reverse proxy: 1. The handler ran up to four sequential provider calls (~45s and more on slow Ollama boxes) while writing nothing to the response, so any intermediary with a ~30s read timeout severed the request mid-run. The handler now commits headers up front and streams flushed newline keepalives every 10s while the evaluation runs, then appends the normal JSON payload. Leading newlines are insignificant JSON whitespace, so existing clients parse the response unchanged. 2. A severed connection cancels the request context, and patrolRuntimeFailureFromError classified the resulting context.Canceled as a generic "Provider analysis error", blaming the provider and model for an infrastructure event. Mid-run cancellation is now classified as the new "interrupted" cause: the overall status and every unfinished dimension and autonomy mode report not assessed, per-scenario evidence completed before the interruption is preserved in the returned result, and the readiness cache keeps the last completed evaluation. context.DeadlineExceeded keeps its provider-path timeout classification. 3. createAPIErrorFromResponse pre-seeded the error message with the raw response body, making its non-JSON guard dead code, so full HTML proxy error pages became Error.message and were rendered into the readiness result boxes. Non-JSON bodies now surface only when they are short plain text; anything with markup or excessive length collapses to a generic status-derived message. Regression tests: internal/ai/issue1640_readiness_cancellation_test.go, internal/api/issue1640_readiness_transport_test.go, and frontend-modern/src/utils/__tests__/apiClient.issue1640.test.ts, all registered in the subsystem verification registry. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>