Repository navigation
test(crewai): keep the tests off the network - #287
Merged
Merged
Conversation
Since 2026-10-26, 13 of 36 crewai CI jobs failed, each on one or two tests: with a real 401 from DashScope for the fake key (litellm.AuthenticationError), with "OpenAIException - Connection error." (litellm.InternalServerError), or, in an error test, with no ERROR span. Before that, all 80 crewai jobs of the 20 runs since 2026-09-22 passed. crewAI exports anonymous telemetry to telemetry.crewai.com from a background thread, and the conftest listed that host in ignore_hosts, so vcrpy sent the exports to the real host. It sends such http.client requests inside vcr.patch.force_reset(), which puts back the original methods of every HTTP client it patches, httpx included, for the whole process while it connects and sends: 0.3 to 0.5 s for the TLS connection to telemetry.crewai.com. An LLM call that crewAI made on its worker thread in that window bypassed the cassette and reached the provider. When the window spanned the end of a test, the patches went back out of order and the next test was replayed from the previous test's cassette, which had no match for its requests (the connection error) or answered an error test with a success. The exports only go out since vcrpy 8.5.0, which made filter_post_data_parameters leave binary bodies alone. Before, it failed on their protobuf body with UnicodeDecodeError, which crewAI's exporter swallowed, so nothing was sent. Turn off crewAI's telemetry and its PyPI version check, which runs for verbose crews, and drop ignore_hosts, so that VCR passes nothing through to the network. Mark the crewai tests with pytest-recording's block_network, so that a request getting past VCR fails with "Network is disabled" instead of reaching a real host. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GwUvhmzgfkiZ6vo4uGyesN
github-actions
Bot
requested review from
123liuziming,
Cirilla-zmh and
ralf0131
October 27, 2026 03:29
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No unresolved blocking issues were identified, and the changes address the reported test flakiness.
No open issues 🎉
What changed in this PR
This pull request makes CrewAI instrumentation tests deterministic and network-isolated by disabling background network activity and blocking unintended external requests.
Changes:
- Disable CrewAI telemetry and version checks during tests.
- Remove VCR pass-through hosts and apply
block_networkto collected tests. - Document the reliability fix in the CrewAI changelog.
| File | Description |
|---|---|
instrumentation-loongsuite/loongsuite-instrumentation-crewai/tests/conftest.py |
Configures CrewAI and VCR for offline, network-blocked tests. |
instrumentation-loongsuite/loongsuite-instrumentation-crewai/CHANGELOG.md |
Records the test hermeticity and flakiness fix. |
Review effort: Lite
ralf0131
approved these changes
Oct 27, 2026
7 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The crewai tests have failed at random in CI since 2026-10-26: 13 of the 36 crewai jobs in 9 runs (#285 and other PRs), each on one or two tests, with a real 401 from DashScope for the fake key (
litellm.AuthenticationError), withOpenAIException - Connection error.(litellm.InternalServerError, e.g.test_agent_with_multiple_tools), or, in an error test, with no ERROR span. The 80 crewai jobs of the 20 runs before, since 2026-09-22, all passed.crewAI exports anonymous telemetry to telemetry.crewai.com from a background thread, and the conftest lists that host in
ignore_hosts, so vcrpy sends the exports to the real host. It sends such http.client requests insidevcr.patch.force_reset(), which puts back the original methods of every HTTP client it patches, httpx included, for the whole process while it connects and sends (0.3 to 0.5 s here). An LLM call that crewAI makes on its worker thread in that window bypasses the cassette and reaches the provider. When the window spans the end of a test, the patches go back out of order and the next test is replayed from the previous test's cassette. The exports only go out since vcrpy 8.5.0 (2026-10-25): before,filter_post_data_parametersfailed on their binary body withUnicodeDecodeError, which the exporter swallowed.Changes, in the crewai tests'
conftest.py:CREWAI_DISABLE_TELEMETRYandCREWAI_DISABLE_VERSION_CHECK(crewAI's PyPI lookup when a verbose crew starts);ignore_hosts, so VCR passes nothing through to the network;block_network, so a request that gets past VCR fails with "Network is disabled" instead of reaching a real host. Recording with a--record-modeother thannonestill has network access.Type of change
How Has This Been Tested?
tox -c tox-loongsuite.ini -e py312-test-loongsuite-instrumentation-crewai -- -raas CI runs it (tox-uv, GitHub's CPython 3.12.13 build), with the package versions of the failing CI jobs (crewai 1.15.30, vcrpy 9.2.0, litellm 1.95.0, openai 2.54.0), onmainand on this branch:main, 1 run failed (test_sync_call_with_error), and 19 of the 20 sent LLM requests to DashScope (401 for the fake key; the error tests accept any error). On this branch, 20 passed and no request reached the network.bwrap --unshare-net), this branch: 20 of 20 passed in a row.mainfailed 4 of 13 runs, e.g.test_agent_with_multiple_toolswithlitellm.InternalServerError: ... OpenAIException - Connection error.; this branch passed 13 of 13.tox -c tox-loongsuite.ini -e lint-loongsuite-instrumentation-crewai(Python 3.13) andtox -e precommit(Python 3.11) pass.Does This PR Require a Core Repo Change?
Checklist:
🤖 Generated with Claude Code
https://claude.ai/code/session_01GwUvhmzgfkiZ6vo4uGyesN