Skip to content

fix: error handling architecture — 12 orphans, zero classification, MCP isError never True #786

Closed

Description

@Sinity

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_transient and http_status_code properties on PolylogueError
  • Daemon HTTP maps exception types to differentiated status codes (not all 500)
  • MCP tools use isError=True for errors; error codes are integers per JSON-RPC
  • _safe_call overload fixed: Callable[[], None] returns str | None
  • CLI human mode has except Exception safety net (matching machine mode)

Ref: deep audit #2, #3, C3. Ref #783.

Activity

  1. Sinity commented on May 4, 2026

    @Sinity
    OwnerAuthor

    Resolved by PRs #787 (error hierarchy), #797 (MCP isError). All 11 orphans rebased onto PolylogueError, _safe_call now raises so FastMCP sets isError=True.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions