Skip to content

fetch: Readability tests fail under machine load (subprocess killed at the production timeout) #5658

Todo

Description

@cliffhall

Problem

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):

  • tests/test_missing_content_type.py::test_html_without_content_type_is_still_simplified[doctype-upper]
  • tests/test_readability_subprocess.py::test_npm_install_output_goes_to_stderr_not_stdout

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.

Activity

  1. added this to the v2.7.0 milestone on Nov 25, 2026
  2. added
    server-fetch
    chore
    on Nov 25, 2026
  3. A7mdMe commented on Nov 25, 2026

    @A7mdMe

    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:

    VERSION_TIMEOUT_SECONDS = 10.0
    EXTRACT_TIMEOUT_SECONDS = 30.0

    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 proportionally
    TIMEOUT_SCALE = float(os.getenv("MCP_SUBPROCESS_TIMEOUT_SCALE", "1.0"))
    VERSION_TIMEOUT_SECONDS = 10.0 * TIMEOUT_SCALE
    EXTRACT_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.

    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:

    1. Inactivity Timeout (Heartbeat): If no stdout/stderr chunks arrive for e.g. 5.0s, the process is considered hung/deadlocked and killed.
    2. Activity Extension: As long as the child process is actively writing chunks to the pipe, the inactivity deadline resets.
    3. 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).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    choreserver-fetchv2

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions