Skip to content

fix(mcp): map wrapped load failures by their cause - #843

Open
vishal-bala wants to merge 8 commits into
mainfrom
fix/mcp-map-wrapped-load-errors
Open

vishal-bala wants to merge 8 commits into
mainfrom
fix/mcp-map-wrapped-load-errors

Conversation

@vishal-bala

@vishal-bala vishal-bala commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

A write through the MCP server that fails on a lost Redis connection is reported as a non-retryable internal_error, although retrying it is exactly what a client should do. AsyncSearchIndex.load wraps every failure other than schema validation in a plain RedisVLError raised from the original exception, and map_exception classified only the wrapper. Measured on main: RedisVLError("Failed to load data") raised from redis.ConnectionError("down") maps to internal_error with retryable=False, and SchemaValidationError, which is the caller's bad input, also maps to internal_error. Both upsert-records and code tools that call ctx.index.load are affected.

Changes

Wrapped load failures map by their cause

map_exception now looks under a RedisVLError wrapper. When the cause is a connection or timeout error (redis.ConnectionError, redis.TimeoutError or the builtin TimeoutError), the result is a retryable backend_unavailable that keeps the wrapper's message, which names the failed operation. Any other wrapped error keeps its old mapping, a non-retryable internal_error: a wrapped WRONGTYPE or OOM reply fails identically on every retry, and the load pipeline is not transactional, so each retry would also repeat the batches that succeeded. SchemaValidationError now maps to invalid_request.

Failed writes say when they may be partial

FastMCP sends a client only Error calling tool '<name>': <message>. Neither RedisVLMCPError.code, .retryable nor .metadata reaches the wire, so the partial_write_possible flag that upsert-records already set was invisible. A new helper, with_partial_write_warning in redisvl/mcp/errors.py, appends a warning to the message and sets that flag.

upsert-records uses it whenever load failed or timed out, with "some records may already have been written", plus "retrying without id_field writes them again under new keys" when the call had no id_field, because load then generates a fresh ULID for every record. It adds no warning for an invalid_request, which load raises before it writes anything, or for a call that run_guarded refused before load ran.

A code tool declared with writes=True uses it on every error the server maps, invalid_request included because the tool may have written before it rejected its input, with "the tool may have written some records before it failed". The server cannot tell which of the tool's calls failed, and a client cannot see whether the error is retryable, so the warning does not depend on either. A tool that raises RedisVLMCPError itself keeps its own message.

  • docs/concepts/mcp.md now gives the codes a failed ctx.index.load produces and the code-tool warning, replacing the sentence that called a lost connection a non-retryable internal_error.
  • docs/user_guide/how_to_guides/mcp.md notes that a failed upsert-records write may be partial and that id_field makes a retry overwrite, and tells code-tool authors that a RedisVLMCPError they raise gets no warning.

Notes

The error codes are part of the documented MCP contract but are never transmitted to clients: they reach Python callers of map_exception and the server's own tests only. This PR corrects the codes and puts the client-relevant part, the partial-write warning, in the one channel clients do see. Sending the code and retry flag on the wire is a separate change to the client-facing contract and is left out of this PR.

An unwrapped ResponseError still maps to a retryable backend_unavailable, as it does on main. That predates this PR and affects search-records, drop_documents and expire_documents as well, so this PR does not change it.

Release Notes

MCP write tools now say in their error message when a failed write may have stored some records. A lost connection or timeout during an index load now maps to a retryable backend_unavailable, and a schema validation failure to invalid_request.

Reviewer Brief

Start here: redisvl/mcp/errors.py, the new RedisVLError branch in map_exception. It decides which wrapped failures a client is told to retry.

Where it could fail

  • redisvl/mcp/errors.py:75: redis.ConnectionError has subclasses AuthenticationError and AuthorizationError, so a wrapped auth failure during load is now retryable; check that one wasted retry is acceptable (the unwrapped path already treats every RedisError this way).
  • redisvl/mcp/tools/upsert.py:367: the warning is skipped for any exception that is not a RedisVLError or a timeout; check that load cannot write records and then raise something else.
  • redisvl/mcp/tools/code.py:206: a writing tool warns on every failure the server maps, including one raised before it wrote anything; check that this over-warning is acceptable.

Not verified: cluster mode; how a real MCP client renders the longer message.

Beyond CI: each new test fails against main's source, and each regression guard fails against the commit before its fix; a real AsyncSearchIndex.load, given a client pointed at a closed port, raises RedisVLError from ConnectionError, which now maps to retryable backend_unavailable; an in-memory FastMCP client confirmed that only the message text reaches clients.

Since the last brief: 2e21a99 makes upsert-records reject a non-scalar value on a hash index as invalid_request before load, instead of letting load raise TypeError mid-pipeline.

Reviewed a8d835a and f6db189, fixes in 31c8039, 1188f05 and 155f01c · Claude Code (claude-opus-5-5) · lenses: correctness, design, tests and docs on both; security and Redis behaviour on a8d835a


Note

Medium Risk
Changes retryability and client-visible error text for write and code-tool paths; wrapped auth-related connection errors during load would now be treated as retryable like other Redis errors.

Overview
Fixes MCP error mapping when index load wraps Redis failures in RedisVLError: connection or timeout causes now become retryable backend_unavailable, SchemaValidationError becomes invalid_request, and other wrapped Redis errors (e.g. WRONGTYPE) stay non-retryable internal_error.

Adds with_partial_write_warning so clients see partial-write guidance in the error message (not only metadata). upsert-records appends warnings when load may have written some keys, including id_field retry guidance; writing code tools get a similar warning on server-mapped failures unless they raise RedisVLMCPError themselves.

upsert-records also rejects non-scalar HASH field values before load as invalid_request. Docs and unit tests cover the updated contract.

Reviewed by Cursor Bugbot for commit 2e21a99. Bugbot is set up for automated code reviews on this repo. Configure here.

AsyncSearchIndex.load wraps every non-validation failure, a lost
connection included, in a plain RedisVLError, which map_exception sent
to a non-retryable internal_error. map_exception now classifies a
RedisVLError wrapper by its __cause__ and keeps the wrapper's message,
and maps SchemaValidationError to invalid_request.

FastMCP sends clients only the error message, not the code or metadata,
so upsert-records now says in the message when a failed write may have
landed partially, and that a retry without id_field duplicates records.
A wrapped WRONGTYPE or OOM reply from load fails the same way on every
retry, so only a wrapped connection or timeout error maps to a retryable
backend_unavailable; other wrapped Redis errors stay non-retryable.

upsert-records no longer warns of a partial write when run_guarded
refused the call before load ran. Document in the how-to that a failed
write may be partial and that id_field makes a retry overwrite.
The code-tools stack now on main maps a tool's exceptions through
map_exception, so a lost connection during ctx.index.load is a
retryable backend_unavailable. A retry runs the whole tool again, so a
tool declared with writes=True now warns in the message, on any
retryable error the server maps, that it may already have written
records. The warning moves into with_partial_write_warning, shared with
upsert-records.

docs/concepts/mcp.md no longer says a lost connection during
ctx.index.load is a non-retryable internal_error.
Clients see only the message, never the retry flag, so gating the
code-tool warning on retryable hid a partial write behind a WRONGTYPE
or OOM reply. A writes=True tool now warns on every error the server
maps except invalid_request, matching upsert-records. The docs name
the schema-validation, drop and expire cases, and the how-to tells
authors who raise RedisVLMCPError that they get no warning.
A code tool can store one batch and then reject its next input, so an
invalid_request from a writing tool may follow a partial write. Every
failure the server maps for a writes=True tool now carries the warning.
Python 3.10 support is gone, and from 3.11 asyncio.TimeoutError is the
builtin TimeoutError.
@vishal-bala vishal-bala added the auto:patch Increment the patch version when merged label Nov 19, 2026
@vishal-bala
vishal-bala marked this pull request as ready for review November 24, 2026 08:59
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T09:00:52.082322Z e6787eb Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e6787eb. Configure here.

Comment thread redisvl/mcp/tools/upsert.py Resolved
A None or nested value on a hash index passed schema validation, then
made load raise TypeError while it built the write pipeline. That
reached clients as internal_error with a partial-write warning,
although nothing had been written and the input was at fault.
upsert-records now rejects it as invalid_request before calling load.

This branch has not been deployed

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

Labels

auto:patch Increment the patch version when merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant