tests: test_mcp_client.py has order-dependent flakiness and a stale VCR cassette after the mcp 2.0 upgrade
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- python
- Domain
- testing-qa
Research direction
Start by running python -m pytest tests/test_mcp_client.py -q -p no:randomly to reproduce the stale-cassette failure in test_call_http_mcp_tool, then look at tests/_vcr/test_mcp_client/test_call_http_mcp_tool.yaml. The flakiness lives in the http_mcp_server fixture near line 28 of tests/test_mcp_client.py: port reuse, missing process.wait() after kill, and the TCP-only readiness probe. Done means the cassette test passes, which needs a re-recording that requires API access, and the file passes repeatedly with pytest-randomly enabled. Coordinate with #457 first, since it changes the same cassette.
Written by the indexing model from the issue text.
Description
While auditing MCP support, I found that tests/test_mcp_client.py fails frequently on main (tested at 1a8e07d1, macOS, Python 3.13, mcp 2.0.0). There are two distinct problems.
1. Deterministic: stale cassette for test_call_http_mcp_tool
test_call_http_mcp_tool fails in every run:
vcr.stubs.httpx_stubs.py: CannotOverwriteExistingCassetteException
No match for the request (POST https://api.openai.com/v1/responses) ...
Matchers failed: body
which surfaces as openai.APIConnectionError when there is no network/API key.
Root cause: the cassette (tests/_vcr/test_mcp_client/test_call_http_mcp_tool.yaml, recorded 2026-05-06) pins the MCP client traffic too, and it was recorded against an mcp 1.x client — the recorded first request is initialize with "clientInfo": {"name": "mcp", "version": "0.1.0"}. The installed mcp 2.0.0 SDK sends a different body, so the body matcher never matches.
Fix: re-record the cassette. Note that #457 will require re-recording it anyway (its mcp.Client(mode="auto") sends server/discover before/instead of initialize), so it may be most efficient to re-record as part of landing that PR.
2. Order-dependent flakiness in the HTTP server fixture
With pytest-randomly active (the default here), full-file runs fail roughly 50% of the time (3/4 runs on main in my testing). With -p no:randomly, only the stale-cassette test above fails. Failure signatures observed:
test_register_multiple_mcp_servers—KeyError: 'add'(HTTP server's tools missing fromchat._tools)test_register_http_mcp_server—RuntimeErrorTestMCPErrorHandling::test_register_overlapping_tool_names_error
Likely causes in the http_mcp_server fixture (tests/test_mcp_client.py:28):
- Fixed port 8081 reused across tests, and
process.kill()with noprocess.wait()— the next test can start its server while the previous one is still dying: the new bind can fail, or the readiness probe/registration can hit the previous server mid-shutdown (explaining empty tool lists and connection errors). - Readiness probe only checks TCP connectability (
GET /— a 404 counts as "ready"), not that the/mcpapp is actually serving. stdout=subprocess.PIPEis never drained — a server that logs enough (uvicorn INFO logs) can block on a full pipe buffer.- The
process.returncode is not Nonecheck immediately afterPopenis a no-op (the process hasn't been polled yet).
Suggested fixes:
- Bind an ephemeral free port per test (e.g. port 0, or allocate then pass via
MCP_PORT) instead of a shared fixed port. process.wait()afterkill()(or useterminate()+wait(timeout=)thenkill()).- Probe the MCP endpoint itself (or wait for the uvicorn startup log line).
- Send server output to
DEVNULL, or drain the pipes.
Reproduction
# flaky failures (~50% of runs)
for i in 1 2 3 4; do python -m pytest tests/test_mcp_client.py -q 2>&1 | tail -1; done
# deterministic cassette failure
python -m pytest tests/test_mcp_client.py -q -p no:randomly
- Dominant language
- Python
- Stars
- 179
- Forks
- 32
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 10
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from posit-dev/chatlas
-
A streaming text delta that repeats everything streamed so far is missing from the recorded turnPossibly taken @cpsievert claimed this 81 days ago. Openai-triage:done Priority: Medium
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
ai-triage:needs-review documentation
Difficulty 2/5 1-2 days Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
Maintainers usually reply within 1 day
-
ai-triage:done Priority: Low
Difficulty 3/5 1-2 days Newbie friendliness 55/100
Maintainers usually reply within 1 day
-
ai-triage:done Priority: Medium
Difficulty 5/5 Over a week Newbie friendliness 35/100
posit-dev/chatlas#432 · 2 comments ·
Maintainers usually reply within 1 day
All issues in posit-dev/chatlas
Similar issues
-
jira: an unquoted JQL number of more than 4300 digits is a plain-text 500, where real answers 200Openfidelity
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
A JSON chat answer blocks the backend event loop for the whole RAG runPossibly taken @NopeCharon claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
The-OpenROAD-Project/ORAssistant#656 ·
Maintainers usually reply within 1 day
-
bug(operator): VolterraOperator built inside jax.jit with a concrete decay raises TracerBoolConversionErrorPossibly taken @jejjohnson claimed this today. Opentype:bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
jejjohnson/integrix#144 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
finos/ai-governance-framework#459 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
autowarefoundation/autoware_carla_scenario#2963 ·
Maintainers usually reply within 1 day