Repository navigation
fix(mcp): map wrapped load failures by their cause - #843
Open
vishal-bala wants to merge 8 commits into
Open
vishal-bala wants to merge 8 commits into
vishal-bala wants to merge 8 commits into
Conversation
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
marked this pull request as ready for review
November 24, 2026 08:59
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ 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.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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.loadwraps every failure other than schema validation in a plainRedisVLErrorraised from the original exception, andmap_exceptionclassified only the wrapper. Measured onmain:RedisVLError("Failed to load data")raised fromredis.ConnectionError("down")maps tointernal_errorwithretryable=False, andSchemaValidationError, which is the caller's bad input, also maps tointernal_error. Bothupsert-recordsand code tools that callctx.index.loadare affected.Changes
Wrapped load failures map by their cause
map_exceptionnow looks under aRedisVLErrorwrapper. When the cause is a connection or timeout error (redis.ConnectionError,redis.TimeoutErroror the builtinTimeoutError), the result is a retryablebackend_unavailablethat keeps the wrapper's message, which names the failed operation. Any other wrapped error keeps its old mapping, a non-retryableinternal_error: a wrappedWRONGTYPEorOOMreply fails identically on every retry, and the load pipeline is not transactional, so each retry would also repeat the batches that succeeded.SchemaValidationErrornow maps toinvalid_request.Failed writes say when they may be partial
FastMCP sends a client only
Error calling tool '<name>': <message>. NeitherRedisVLMCPError.code,.retryablenor.metadatareaches the wire, so thepartial_write_possibleflag thatupsert-recordsalready set was invisible. A new helper,with_partial_write_warninginredisvl/mcp/errors.py, appends a warning to the message and sets that flag.upsert-recordsuses it wheneverloadfailed 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 noid_field, becauseloadthen generates a fresh ULID for every record. It adds no warning for aninvalid_request, whichloadraises before it writes anything, or for a call thatrun_guardedrefused beforeloadran.A code tool declared with
writes=Trueuses it on every error the server maps,invalid_requestincluded 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 raisesRedisVLMCPErroritself keeps its own message.docs/concepts/mcp.mdnow gives the codes a failedctx.index.loadproduces and the code-tool warning, replacing the sentence that called a lost connection a non-retryableinternal_error.docs/user_guide/how_to_guides/mcp.mdnotes that a failedupsert-recordswrite may be partial and thatid_fieldmakes a retry overwrite, and tells code-tool authors that aRedisVLMCPErrorthey 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_exceptionand 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
ResponseErrorstill maps to a retryablebackend_unavailable, as it does onmain. That predates this PR and affectssearch-records,drop_documentsandexpire_documentsas 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
loadnow maps to a retryablebackend_unavailable, and a schema validation failure toinvalid_request.Reviewer Brief
Start here:
redisvl/mcp/errors.py, the newRedisVLErrorbranch inmap_exception. It decides which wrapped failures a client is told to retry.Where it could fail
redisvl/mcp/errors.py:75:redis.ConnectionErrorhas subclassesAuthenticationErrorandAuthorizationError, so a wrapped auth failure duringloadis now retryable; check that one wasted retry is acceptable (the unwrapped path already treats everyRedisErrorthis way).redisvl/mcp/tools/upsert.py:367: the warning is skipped for any exception that is not aRedisVLErroror a timeout; check thatloadcannot 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 realAsyncSearchIndex.load, given a client pointed at a closed port, raisesRedisVLErrorfromConnectionError, which now maps to retryablebackend_unavailable; an in-memory FastMCP client confirmed that only the message text reaches clients.Since the last brief:
2e21a99makesupsert-recordsreject a non-scalar value on a hash index asinvalid_requestbeforeload, instead of lettingloadraiseTypeErrormid-pipeline.Reviewed
a8d835aandf6db189, fixes in31c8039,1188f05and155f01c· Claude Code (claude-opus-5-5) · lenses: correctness, design, tests and docs on both; security and Redis behaviour ona8d835aNote
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
loadwraps Redis failures inRedisVLError: connection or timeout causes now become retryablebackend_unavailable,SchemaValidationErrorbecomesinvalid_request, and other wrapped Redis errors (e.g.WRONGTYPE) stay non-retryableinternal_error.Adds
with_partial_write_warningso clients see partial-write guidance in the error message (not only metadata).upsert-recordsappends warnings whenloadmay have written some keys, includingid_fieldretry guidance; writing code tools get a similar warning on server-mapped failures unless they raiseRedisVLMCPErrorthemselves.upsert-recordsalso rejects non-scalar HASH field values beforeloadasinvalid_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.