Skip to content

Commit 99b317b

Browse files
authored
fix(test): gate models.dev background refresh out of tests (main) (#13597)
fix(test): gate models.dev background refresh out of tests Integration tests failed twice in nightly run 27260425158 with pyleak EventLoopBlockError - first Integration Tests 3.14, then 3.12 on the rerun, each time in a different test. The blocking stack points at refresh_models_dev_periodically: every app boot unconditionally starts a lifespan task that immediately fetches https://models.dev/api.json, so the request lands mid-test in whatever test happens to be running. Under pyleak's asyncio debug instrumentation the fetch blocked the loop 0.797s against a 0.2s threshold. Whichever test draws the short straw flakes - which is why it looked transient and moved between versions. Add a LANGFLOW_MODELS_DEV_REFRESH env gate (default unchanged: enabled) and disable it session-wide in the backend test conftest. Tests fall back to the bundled static model lists, which is also deterministic. Verified: with the gate set, app boot makes zero models.dev requests; the previously failing integration test passes.
1 parent 4c6e4bd commit 99b317b

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

.secrets.baseline

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2837,15 +2837,15 @@
28372837
"filename": "src/backend/tests/conftest.py",
28382838
"hashed_secret": "8bb6118f8fd6935ad0876a3be34a717d32708ffd",
28392839
"is_verified": false,
2840-
"line_number": 490,
2840+
"line_number": 515,
28412841
"is_secret": false
28422842
},
28432843
{
28442844
"type": "Secret Keyword",
28452845
"filename": "src/backend/tests/conftest.py",
28462846
"hashed_secret": "61fbb5a12cd7b1f1fe1624120089efc0cd299e43",
28472847
"is_verified": false,
2848-
"line_number": 700,
2848+
"line_number": 725,
28492849
"is_secret": false
28502850
}
28512851
],
@@ -9287,5 +9287,5 @@
92879287
}
92889288
]
92899289
},
9290-
"generated_at": "2026-06-08T16:38:06Z"
9290+
"generated_at": "2026-06-10T08:36:23Z"
92919291
}

src/backend/base/langflow/main.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,14 @@ async def refresh_models_dev_periodically() -> None:
479479

480480
await asyncio.sleep(refresh_interval_seconds)
481481

482-
models_dev_refresh_task = asyncio.create_task(refresh_models_dev_periodically())
482+
# LANGFLOW_MODELS_DEV_REFRESH=false disables the live models.dev
483+
# fetch. Tests set this: the startup fetch otherwise fires from a
484+
# background task during whatever test is running, hitting the
485+
# network and tripping event-loop-block detectors (pyleak).
486+
if os.getenv("LANGFLOW_MODELS_DEV_REFRESH", "true").lower() not in ("false", "0", "no"):
487+
models_dev_refresh_task = asyncio.create_task(refresh_models_dev_periodically())
488+
else:
489+
await logger.adebug("models.dev refresh disabled via LANGFLOW_MODELS_DEV_REFRESH")
483490

484491
# v1 and project MCP server context managers
485492
from langflow.api.v1.mcp import start_streamable_http_manager

src/backend/tests/conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@ def disable_rate_limiting():
5050
os.environ.pop("LANGFLOW_RATE_LIMIT_ENABLED", None)
5151

5252

53+
@pytest.fixture(scope="session", autouse=True)
54+
def disable_models_dev_refresh():
55+
"""Keep the models.dev background refresh out of tests.
56+
57+
Every app boot otherwise launches a lifespan task that fetches
58+
https://models.dev/api.json mid-test, which both hits the network and
59+
trips event-loop-block detectors (pyleak) in whatever test happens to be
60+
running when the request lands. The bundled static model lists are used
61+
instead, which is also deterministic.
62+
"""
63+
os.environ["LANGFLOW_MODELS_DEV_REFRESH"] = "false"
64+
yield
65+
os.environ.pop("LANGFLOW_MODELS_DEV_REFRESH", None)
66+
67+
5368
# TODO: Revert this to True once bb.functions[func].can_block_in("http/client.py", "_safe_read") is fixed
5469
@pytest.fixture(autouse=False)
5570
def blockbuster(request):

0 commit comments

Comments
 (0)