You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
daemon/http.py has 10 broad except Exception blocks (density: 1 per 47 lines) that map ALL errors to identical 500 responses. Contains an undefined function call (_get_or_create_polylogue() at L425) that will crash the reset endpoint with NameError. Uses asyncio.run() per request inside thread-pool workers, creating nested event loop risks. 80% of the file is repetitive error-handling boilerplate.
Proposed fix
Replace the if self.path.startswith(...) routing with a dispatch table
Define a @safe_handler decorator that discriminates exception types (NameError→500, sqlite3.OperationalError→503, ValueError→400, unexpected→500 with logging)
Fix the missing _get_or_create_polylogue function or inline Polylogue() creation
Replace BaseHTTPRequestHandler with a lightweight ASGI framework or at minimum factor routing
Acceptance criteria
_get_or_create_polylogue defined and wired
Exception discrimination: different error types produce different HTTP status codes
Broad except blocks reduced from 10 to under 3
Reset endpoint works when daemon API is enabled
No regression in health/status/conversations/messages/facets/sources endpoints
Activity
refactor: SQL single-sourcing, CLI dispatch, daemon http rewrite (#784,
Sinity commentedon May 4, 2026
Resolved by PR #787. Daemon http.py rewritten with @daemon_safe_handler decorator, dispatch table routing, _get_or_create_polylogue defined, except Exception reduced from 10 to 2.
refactor: SQL single-sourcing, CLI dispatch, daemon http rewrite (#784,