crewAIInc/crewAI · error · RuntimeError

Query failed after all retries

Error message

Query failed after all retries

What it means

SnowflakeSearchTool wraps query execution in a retry loop over DatabaseError/OperationalError. On the final attempt it re-raises the original exception, so the trailing `raise RuntimeError("Query failed after all retries")` is effectively unreachable defensive code — in practice you will see the last DatabaseError/OperationalError, not this RuntimeError, unless the loop is exited abnormally.

Source

Thrown at lib/crewai-tools/src/crewai_tools/tools/snowflake_search_tool/snowflake_search_tool.py:246

                        with _cache_lock:
                            _query_cache[self._get_cache_key(query, timeout)] = results

                    return results
                finally:
                    cursor.close()
                    if (
                        self._pool_lock is not None
                        and self._connection_pool is not None
                    ):
                        with self._pool_lock:
                            self._connection_pool.append(conn)
            except (DatabaseError, OperationalError) as e:  # noqa: PERF203
                if attempt == self.max_retries - 1:
                    raise
                await asyncio.sleep(self.retry_delay * (2**attempt))
                logger.warning(f"Query failed, attempt {attempt + 1}: {e!s}")
                continue
        raise RuntimeError("Query failed after all retries")

    async def _run(
        self,
        query: str,
        database: str | None = None,
        snowflake_schema: str | None = None,
        timeout: int = 300,
        **kwargs: Any,
    ) -> Any:
        """Execute the search query."""
        try:
            if database:
                await self._execute_query(f"USE DATABASE {database}")
            if snowflake_schema:
                await self._execute_query(f"USE SCHEMA {snowflake_schema}")

            return await self._execute_query(query, timeout)
        except Exception as e:

View on GitHub (pinned to 754d7323be)

Solutions

  1. Look at the chained/original snowflake-connector exception and the logged 'Query failed, attempt N' warnings — the root cause is there, not in this RuntimeError.
  2. For transient errors, increase max_retries / retry_delay on the tool; for persistent errors (bad SQL, permissions) fix the query or grants — retrying will not help.
  3. Verify connectivity and warehouse status (e.g. warehouse suspended) if errors are OperationalError.
Defensive patterns

Strategy: retry

Try / catch

from snowflake.connector.errors import DatabaseError, OperationalError
try:
    result = await tool._run(query=sql)
except (DatabaseError, OperationalError) as e:
    # final attempt already re-raised the driver error; inspect it for root cause
    logger.error("Snowflake query failed permanently: %s", e)
    raise

Prevention

When it happens

Trigger: A Snowflake query raising DatabaseError or OperationalError (connection loss, lock timeout, syntax/permission error) for every attempt up to max_retries; the final attempt re-raises the driver error. The RuntimeError would only surface if the loop ended without re-raising, which the current code structure prevents.

Common situations: Persistent failures: wrong warehouse/database, expired or invalid credentials, network partitions to Snowflake, SQL errors that retries cannot fix. Users searching for this exact message usually find the underlying snowflake-connector error instead.

Related errors


AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15). Data as JSON: /api/errors/ef9a6ea76dd9a7eb. Report an issue: GitHub.