Skip to content

The agent that grows with you

fix(web/firecrawl): pass timeout to scrape API to match asyncio deadline

liuhao1024e0daebeb6b32
diff --git a/plugins/web/firecrawl/provider.py b/plugins/web/firecrawl/provider.py
index 950611e2f8b..5e960553680 100644
--- a/plugins/web/firecrawl/provider.py
+++ b/plugins/web/firecrawl/provider.py
@@ -258,7 +258,19 @@ async def _scrape_one(url: str, formats: List[str], format: Optional[str]) -> Di
try:
logger.info("Firecrawl scraping: %s", url)
try:
- scrape_result = await asyncio.wait_for(asyncio.to_thread(_get_firecrawl_client().scrape, url=url, formats=formats), timeout=60)
+ # Pass timeout (ms) to Firecrawl so the server-side deadline
+ # matches our asyncio deadline. Without this the API uses its
+ # 30 s default, causing SCRAPE_TIMEOUT before our 60 s
+ # client-side wait expires. See #43272.
+ scrape_result = await asyncio.wait_for(
+ asyncio.to_thread(
+ _get_firecrawl_client().scrape,
+ url=url,
+ formats=formats,
+ timeout=60_000,
+ ),
+ timeout=60,
+ )
except asyncio.TimeoutError:
logger.warning("Firecrawl scrape timed out for %s", url)
return _error_entry(url, _SCRAPE_TIMEOUT_MSG)
@@ -326,6 +338,7 @@ class FirecrawlWebSearchProvider(BaseWebSearchProvider):
for url in urls
]
+
def get_setup_schema(self) -> Dict[str, Any]:
return setup_schema(
"Firecrawl", "keyless/paid · optional gateway",
diff --git a/tests/plugins/web/test_web_search_provider_plugins.py b/tests/plugins/web/test_web_search_provider_plugins.py
index 99ec814cf9b..113ddc370dd 100644
--- a/tests/plugins/web/test_web_search_provider_plugins.py
+++ b/tests/plugins/web/test_web_search_provider_plugins.py
@@ -18,6 +18,8 @@ glue layer simultaneously.
"""
from __future__ import annotations
+import asyncio
+
import pytest
@@ -244,3 +246,55 @@ class TestRegistryResolution:
assert result.is_available() or result.is_keyless_available()
+
+
+
+# ---------------------------------------------------------------------------
+# Firecrawl timeout alignment (#43272)
+# ---------------------------------------------------------------------------
+
+
+class TestFirecrawlScrapeTimeout:
+ """Verify the server-side scrape timeout matches the asyncio deadline."""
+
+ def test_extract_passes_timeout_ms_to_scrape(self, monkeypatch: pytest.MonkeyPatch) -> None:
+ """scrape() must receive timeout=60000 (ms) so the server-side
+ deadline matches the 60 s asyncio.wait_for deadline. Without this
+ the API uses its 30 s default, causing SCRAPE_TIMEOUT."""
+ from unittest.mock import MagicMock, patch
+ from plugins.web.firecrawl import provider as firecrawl_provider
+
+ # Direct-credential mode: with no FIRECRAWL_API_KEY extract() routes
+ # to the keyless ring instead of the direct scrape path under test.
+ monkeypatch.setenv("FIRECRAWL_API_KEY", "test-key")
+
+ # Set up a fake client whose scrape() returns a minimal response
+ fake_client = MagicMock()
+ fake_client.scrape.return_value = {
+ "metadata": {"title": "Test", "sourceURL": "https://example.com"},
+ "markdown": "content",
+ }
+
+ # Patch _get_firecrawl_client to return our fake client
+ monkeypatch.setattr(
+ firecrawl_provider, "_get_firecrawl_client", lambda: fake_client
+ )
+ # Patch check_website_access to allow the URL
+ monkeypatch.setattr(
+ firecrawl_provider, "check_website_access", lambda url: None
+ )
+
+ p = firecrawl_provider.FirecrawlWebSearchProvider()
+ results = asyncio.run(p.extract(["https://example.com"]))
+
+ # Verify scrape was called with timeout=60000
+ fake_client.scrape.assert_called_once()
+ call_kwargs = fake_client.scrape.call_args
+ assert call_kwargs.kwargs.get("timeout") == 60_000, (
+ f"Expected timeout=60000, got {call_kwargs.kwargs.get('timeout')}"
+ )
+
+ # Verify the result was processed correctly
+ assert len(results) == 1
+ assert results[0]["url"] == "https://example.com"
+ assert results[0]["content"] == "content"