Repository navigation
Description
Problem
The error handling in Polylogue has three structural gaps that make errors hard to diagnose and impossible to handle programmatically.
1. 12 orphan error types bypass PolylogueError
errors.py defines PolylogueError as the intended root, but 12 error classes inherit from ValueError/RuntimeError/Exception instead. Top-level except PolylogueError misses them:
| Error | File:Line | Parent |
|---|---|---|
DaemonUnavailableError |
archive/write_gateway.py:39 |
Exception |
ConversationNotFoundError |
api/archive.py:146 |
ValueError |
InsightQueryError |
insights/registry.py:608 |
ValueError |
InsightExportBundleError |
insights/export_bundles.py:65 |
RuntimeError |
InsightCommandInputError |
cli/shared/insight_command_contracts.py:32 |
ValueError |
ArchiveInsightUnavailableError |
insights/archive.py:40 |
RuntimeError |
StageContractError |
pipeline/stage_specs.py:65 |
RuntimeError |
NeighborDiscoveryError |
archive/conversation/neighbor_candidates.py:56 |
ValueError |
QuerySpecError |
archive/query/spec.py:32 |
ValueError |
QueryPlanError |
cli/query_contracts.py:157 |
ValueError |
TailOverlayUnavailableError |
pipeline/tail_overlay.py:24 |
ValueError |
Three would crash with raw traceback in human CLI mode (the boundary only catches PolylogueError, not Exception).
2. Zero error classification infrastructure
No is_retryable, is_transient, ErrorClass, or equivalent. Every except site independently decides what to do. The daemon HTTP endpoint maps ALL exceptions to "internal_error". The MCP boundary flattens all errors to code="internal_error". MachineError codes in CLI are assigned manually per raise site.
3. MCP protocol errors are never surfaced
mcp/server_support.py:129-135: _safe_call/_async_safe_call catch every exception and return JSON-embedded error strings. isError is never True on any tool result. Error codes are strings ("internal_error") not JSON-RPC integers. Success and failure are wire-identical — clients must parse text content to detect errors.
4. _safe_call overload returns wrong type
mcp/server_support.py:121-122: Overload for Callable[[], None] declares return str, but implementation returns TResult | str = str | None. Callers relying on the type checker get str but receive None at runtime.
Acceptance criteria
- All 12 orphan errors rebased onto
PolylogueError - Error classification added: at minimum
is_transientandhttp_status_codeproperties onPolylogueError - Daemon HTTP maps exception types to differentiated status codes (not all 500)
- MCP tools use
isError=Truefor errors; error codes are integers per JSON-RPC -
_safe_calloverload fixed:Callable[[], None]returnsstr | None - CLI human mode has
except Exceptionsafety net (matching machine mode)
Activity
refactor: SQL single-sourcing, CLI dispatch, daemon http rewrite (#784,
fix: close audit gaps — MCP isError, ingestion events, pins wiring (#786
Sinity commentedon May 4, 2026
Resolved by PRs #787 (error hierarchy), #797 (MCP isError). All 11 orphans rebased onto PolylogueError, _safe_call now raises so FastMCP sets isError=True.
refactor: SQL single-sourcing, CLI dispatch, daemon http rewrite (#784,
fix: close audit gaps — MCP isError, ingestion events, pins wiring (#786