fix(vector): URL-encode DAV paths and unwrap TaskGroup exceptions

Two ingest-robustness fixes from card 309 (OHR-Bench smoke-test triage).

WebDAV paths flowed through the client already URL-decoded (unquote on the
PROPFIND/REPORT <d:href>, or raw MCP-tool input), so a '#' reached httpx as a
URL fragment and silently truncated the request -> spurious 404 on otherwise
valid files (e.g. law filenames with '#', commas, double/trailing spaces).
Route every caller-path builder through a new _webdav_path helper that
percent-encodes the path once (preserving separators); the MOVE/COPY
Destination header is encoded too.

Vector-sync runs inside anyio task groups, so a child-task failure surfaced as
a BaseExceptionGroup whose str() is the useless "unhandled errors in a
TaskGroup (N sub-exception)" -- hiding the real ConnectError operators need.
Add format_exception_group to flatten the group to its leaf exceptions and use
it at the broad catch/log sites in processor.py and oauth_sync.py.

Refs: Deck board 12 card 309 (AC #4 filename handling, AC #2 observability).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Chris Coutinho
2026-06-11 04:59:53 +02:00
co-authored by Claude Opus 4.8
parent 457c115ef4
commit 0388735593
6 changed files with 216 additions and 29 deletions
+36
View File
@@ -0,0 +1,36 @@
"""Error-formatting helpers for the vector-sync pipeline.
Vector-sync work runs inside anyio task groups, so a failure in a child task
surfaces as a ``BaseExceptionGroup`` whose default ``str()`` is the useless
``"unhandled errors in a TaskGroup (N sub-exception)"`` -- it hides the real
``ConnectError`` / ``APIConnectionError`` that operators need to triage embed
drops (card 309). ``format_exception_group`` flattens the group to the leaf
exceptions so log lines name the actual cause; pair it with ``exc_info=True`` to
keep the full traceback.
"""
from __future__ import annotations
def format_exception_group(exc: BaseException) -> str:
"""Return a concise, leaf-naming string for ``exc``.
For a (possibly nested) ``BaseExceptionGroup`` this joins the ``repr`` of
each leaf exception; for an ordinary exception it returns its ``repr``. The
result is meant for the human-readable portion of a log message, not for
parsing.
"""
leaves = _flatten(exc)
if len(leaves) == 1 and leaves[0] is exc:
return repr(exc)
return f"{len(leaves)} sub-exception(s): " + "; ".join(repr(e) for e in leaves)
def _flatten(exc: BaseException) -> list[BaseException]:
"""Depth-first list of the leaf exceptions within ``exc``."""
if isinstance(exc, BaseExceptionGroup):
leaves: list[BaseException] = []
for sub in exc.exceptions:
leaves.extend(_flatten(sub))
return leaves
return [exc]
+12 -4
View File
@@ -30,6 +30,7 @@ from httpx import BasicAuth, HTTPStatusError
from nextcloud_mcp_server.auth.storage import RefreshTokenStorage
from nextcloud_mcp_server.client import NextcloudClient
from nextcloud_mcp_server.config import get_settings
from nextcloud_mcp_server.vector._errors import format_exception_group
from nextcloud_mcp_server.vector.processor import process_document
from nextcloud_mcp_server.vector.queue.ports import TaskProducer
from nextcloud_mcp_server.vector.scanner import DocumentTask, scan_user_documents
@@ -257,7 +258,7 @@ async def user_scanner_task(
logger.error(
"[BasicAuth] Scanner error for %s: %s (%s/%s)",
user_id,
e,
format_exception_group(e),
consecutive_errors,
max_consecutive_errors,
exc_info=True,
@@ -347,12 +348,15 @@ async def multi_user_processor_task(
worker_id,
doc_task.doc_type,
doc_task.doc_id,
e,
format_exception_group(e),
exc_info=True,
)
else:
logger.error(
"[BasicAuth] Processor %s error: %s", worker_id, e, exc_info=True
"[BasicAuth] Processor %s error: %s",
worker_id,
format_exception_group(e),
exc_info=True,
)
finally:
@@ -481,7 +485,11 @@ async def user_manager_task(
logger.info("[BasicAuth] Stopped %s scanner(s)", len(revoked_users))
except Exception as e:
logger.error("[BasicAuth] User manager error: %s", e, exc_info=True)
logger.error(
"[BasicAuth] User manager error: %s",
format_exception_group(e),
exc_info=True,
)
# Sleep until next poll
try:
+4 -3
View File
@@ -31,6 +31,7 @@ from nextcloud_mcp_server.observability.tracing import trace_operation
from nextcloud_mcp_server.search.pdf_highlighter import PDFHighlighter
from nextcloud_mcp_server.usage import UsageEventStore
from nextcloud_mcp_server.vector import payload_keys
from nextcloud_mcp_server.vector._errors import format_exception_group
from nextcloud_mcp_server.vector.document_chunker import (
DocumentChunker,
PageAwareChunker,
@@ -269,7 +270,7 @@ async def processor_task(
worker_id,
doc_task.doc_type,
doc_task.doc_id,
e,
format_exception_group(e),
exc_info=True,
)
# Continue to next document (no task_done() needed with streams)
@@ -443,7 +444,7 @@ async def process_document(
max_retries,
doc_task.doc_type,
doc_task.doc_id,
e,
format_exception_group(e),
extra={
"doc_id": doc_task.doc_id,
"doc_type": doc_task.doc_type,
@@ -460,7 +461,7 @@ async def process_document(
doc_task.doc_type,
doc_task.doc_id,
max_retries,
e,
format_exception_group(e),
extra={
"doc_id": doc_task.doc_id,
"doc_type": doc_task.doc_type,