You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fetch: Readability tests fail under machine load (subprocess killed at the production timeout) #5658
choreMaintenance: deps, build tooling, CI, cleanup — no user-facing behavior changeserver-fetchReference implementation for the Fetch MCP server - src/fetchv2
The fetch server's pytest suite fails when the machine is under heavy load, and passes when it is run alone. It cost two npm run local:gate runs while working on #5652 (a change that does not touch fetch).
Observed (macOS, load average around 11 while other builds ran):
with readability_js logging node did not finish within 10 s and was killed / … within 30 s …, and the suite taking about 5 minutes instead of the usual ~26 s. The same suite then passed alone (608 passed), and the next gate run passed.
Cause (likely)
src/fetch/src/mcp_server_fetch/readability_js.py runs each subprocess under a production timeout (VERSION_TIMEOUT_SECONDS = 10.0 for node -v, EXTRACT_TIMEOUT_SECONDS = 30.0 for extraction). The tests above spawn real processes under those same timeouts, so when the machine is slow enough the subprocess is killed, node_path() / extraction returns None, and the assertion fails. The behavior under test (stderr routing, simplification) is not what failed; the wall-clock budget was.
Expected
The tests pass regardless of machine load. AGENTS.md forbids retries (verify:no-test-retries), so the fix is in what makes the test time-sensitive, for example:
tests that do not exercise the timeout path run with the timeouts raised (monkeypatched), and
the timeout behavior itself stays covered by its dedicated tests with short, deliberate timeouts (as test_readability_subprocess.py already does for npm at 0.5 s).
Reproduce
Run npm run coverage:py -- fetch (or uv run pytest in src/fetch) while the machine is saturated, for example alongside another workspace's build and tests.
When a test suite runs under parallel CI load or machine CPU contention (e.g. load average 11), process spawning, V8 initialization in Node, and IPC pipe flushing take substantially longer. Because the timeout is static and wall-clock based, subprocess.run kills a process that is actively making progress, returning None and causing assertion failures for tests that only care about content simplification and stderr routing.
Architectural Solution: Two-Tier Remediation
1. Environment-Aware Timeout Scaling for Tests & CI
To fix CI/gate flakiness without breaking verify:no-test-retries, the simplest immediate fix in readability_js.py is respecting an optional scaling factor:
# Allow CI or heavy test runs to scale timeouts proportionallyTIMEOUT_SCALE=float(os.getenv("MCP_SUBPROCESS_TIMEOUT_SCALE", "1.0"))
VERSION_TIMEOUT_SECONDS=10.0*TIMEOUT_SCALEEXTRACT_TIMEOUT_SECONDS=30.0*TIMEOUT_SCALE
In the test gate or test harness, setting MCP_SUBPROCESS_TIMEOUT_SCALE=3.0 (or monkeypatching the constants for non-timeout tests) prevents load-induced premature kills while dedicated timeout tests (like test_npm_install_output_goes_to_stderr_not_stdout) pass an explicit, small timeout directly.
For long-running tools under high load, a static wall-clock timer is fundamentally brittle. A more resilient production pattern splits the timeout into:
Inactivity Timeout (Heartbeat): If no stdout/stderr chunks arrive for e.g. 5.0s, the process is considered hung/deadlocked and killed.
Activity Extension: As long as the child process is actively writing chunks to the pipe, the inactivity deadline resets.
Hard Ceiling: A maximum absolute cutoff (e.g. 60s) to prevent infinite streaming loops.
3. Graceful Extractor Degradation
In production agent loops, if the heavy Node/Readability subprocess is killed under extreme CPU load, falling back to a lightweight regex or basic DOM cleaner ensures the agent's fetch tool call still succeeds with usable text rather than crashing with an empty response.
(Disclosure: As maintainers of the open-source MCP Production Kit, we have integrated load-aware heartbeat extensions and graceful extractor fallbacks into our production hardening test suite).
choreMaintenance: deps, build tooling, CI, cleanup — no user-facing behavior changeserver-fetchReference implementation for the Fetch MCP server - src/fetchv2
Activity
A7mdMe commentedon Nov 25, 2026
This is a very common failure mode for MCP servers that delegate extraction or transformation to external subprocesses (Node, Python, Pandoc, etc.).
Root Cause Analysis: Static Wall-Clock Budgets vs. Machine Saturation
In
readability_js.py, the timeout is currently hardcoded as a static wall-clock budget:When a test suite runs under parallel CI load or machine CPU contention (e.g. load average 11), process spawning, V8 initialization in Node, and IPC pipe flushing take substantially longer. Because the timeout is static and wall-clock based,
subprocess.runkills a process that is actively making progress, returningNoneand causing assertion failures for tests that only care about content simplification and stderr routing.Architectural Solution: Two-Tier Remediation
1. Environment-Aware Timeout Scaling for Tests & CI
To fix CI/gate flakiness without breaking
verify:no-test-retries, the simplest immediate fix inreadability_js.pyis respecting an optional scaling factor:In the test gate or test harness, setting
MCP_SUBPROCESS_TIMEOUT_SCALE=3.0(or monkeypatching the constants for non-timeout tests) prevents load-induced premature kills while dedicated timeout tests (liketest_npm_install_output_goes_to_stderr_not_stdout) pass an explicit, small timeout directly.2. Activity-Aware Heartbeat Extensions (Production Pattern)
For long-running tools under high load, a static wall-clock timer is fundamentally brittle. A more resilient production pattern splits the timeout into:
3. Graceful Extractor Degradation
In production agent loops, if the heavy Node/Readability subprocess is killed under extreme CPU load, falling back to a lightweight regex or basic DOM cleaner ensures the agent's fetch tool call still succeeds with usable text rather than crashing with an empty response.
(Disclosure: As maintainers of the open-source MCP Production Kit, we have integrated load-aware heartbeat extensions and graceful extractor fallbacks into our production hardening test suite).
cliffhall commentedon Nov 30, 2026
Fixed by #5721 (merged into v2/main).
test(fetch): run subprocesses under stretched budgets in tests