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
test(isolation): module-scope sys.modules stubs leak across xdist workers — one guard + one canonical fixture for the class (#18181, #18529, #18601, #18618, #18511, #17648 are instances) #18893
Class defect: test modules install sys.modules stubs at import or module scope, or in conftest without a matching teardown. The stub outlives the file and breaks whichever test the same xdist worker collects next. Each instance has been filed and fixed one at a time. This issue is the single home for the class: one fix (a guard plus a canonical fixture), with every instance listed below.
Instances already filed (each one is a witness of this class):
New, seen 2026-10-19 in a targeted -n 4 run on branch issue-18825-graph-owner-scope. Most of 96 failures came from these two:
autobot-backend/tests/memory_graph/test_property_graph.py stubs autobot_shared.ssot_config at module scope.
autobot-backend/tests/memory_graph/test_invalidate_endpoints.py replaces the autobot_memory_graph package at import time. Production modules doing from autobot_memory_graph import X then fail in later tests.
Fix (once, for the class):
One canonical fixture in autobot_shared test helpers, or the root conftest, that installs stubs through monkeypatch.setitem(sys.modules, ...), so pytest restores them after each test.
A ratchet guard (AST) that rejects module-scope sys.modules[...] =, sys.modules.update, and patch.dict(sys.modules, ...) started outside a fixture, in test files and conftests. The baseline lists the current offenders and only shrinks.
AC:
The canonical fixture exists and is documented.
The guard rejects a planted module-scope stub (control) and passes with the baseline.
Every instance above is migrated, or carries a baseline entry linking its issue.
The linked instance issues close against this fix.
Another instance (2026-10-19): running autobot-slm-backend/tests/services/ as one -n 4 invocation from inside autobot-slm-backend produces ModuleNotFoundError: No module named 'services.playbook_output_stream'; 'services' is not a package in 6 tests: test_extra_vars_file_11735.py (3) and collection errors in test_dynamic_inventory_group_vars_11781.py, test_self_update_systemd_detach_11492.py and test_wizard_inventory_parity_14286.py. Some earlier file in that directory leaves a non-package services in sys.modules. The branch under test touched no SLM backend services code.
Another instance (2026-10-20), order-dependent in the other direction: autobot-slm-backend/tests/services/test_token_denylist.py::TestDecodeTokenAsyncRevocation::test_a_healthy_epoch_store_with_no_marker_accepts_tokenfails when the file runs alone with RevocationCheckUnavailable: no Redis client → 503, and passes when run in a batch with tests/api/test_auth_*. The test patches password_epoch.get_async_redis_client, but the SLM process uses its own epoch store (#18663use_epoch_store). That store is set up, or not, by whichever test ran first. The fix belongs to the canonical fixture: install the epoch store explicitly per test.
Another instance (2026-10-20): in one -n 4 invocation over whole autobot-backend/services + knowledge + chat_workflow + chat_history, these failed. knowledge/connectors/egress_vendor_behaviour_test.py::test_the_default_vendor_host_is_allowed[gdrive|notion|onedrive|slack] gave RuntimeError: Event loop is closed and the mock was awaited 0 times. services/knowledge/test_kb_synthesizer.py::test_synthesize_docs_uses_collection_config_prompt saw chat awaited 2 times. All five pass in a small batch on the same tree (1121 passed). The branch under test (#16664) touches neither file.
Sighting (2026-11-12), same class: autobot-backend/conftest.py (around line 929) registers code_intelligence.pattern_analysis in sys.modules as a bare stub package with no storage submodule. Two new tests in PR #21328 patched …pattern_analysis.storage.<name> by dotted string, which only set a throwaway attribute on the stub; the code under test then failed its function-local from code_intelligence.pattern_analysis.storage import … with No module named …storage in two python-suite shards. Fixed locally in that PR with fakes installed through monkeypatch.setitem; the stub in the shared conftest remains.
A second effect seen while reviewing PR #21361: that conftest installs about 50 such stubs, and they are visible to every test module that runs in the same worker — so a test outside autobot-backend/ can depend on them without declaring it, and would fail when run without that conftest (for example in a narrower guard-only run).
The backend conftest's package stubs are scoped (fixture + monkeypatch) or complete enough that a dotted-path patch cannot silently hit a stub.
Activity
mrveiss commentedon Oct 19, 2026
Another instance (2026-10-19): running
autobot-slm-backend/tests/services/as one -n 4 invocation from insideautobot-slm-backendproducesModuleNotFoundError: No module named 'services.playbook_output_stream'; 'services' is not a packagein 6 tests:test_extra_vars_file_11735.py(3) and collection errors intest_dynamic_inventory_group_vars_11781.py,test_self_update_systemd_detach_11492.pyandtest_wizard_inventory_parity_14286.py. Some earlier file in that directory leaves a non-packageservicesinsys.modules. The branch under test touched no SLM backend services code.mrveiss commentedon Oct 19, 2026
Another instance (2026-10-20), order-dependent in the other direction:
autobot-slm-backend/tests/services/test_token_denylist.py::TestDecodeTokenAsyncRevocation::test_a_healthy_epoch_store_with_no_marker_accepts_tokenfails when the file runs alone withRevocationCheckUnavailable: no Redis client→ 503, and passes when run in a batch withtests/api/test_auth_*. The test patchespassword_epoch.get_async_redis_client, but the SLM process uses its own epoch store (#18663use_epoch_store). That store is set up, or not, by whichever test ran first. The fix belongs to the canonical fixture: install the epoch store explicitly per test.mrveiss commentedon Oct 20, 2026
Another instance (2026-10-20): in one -n 4 invocation over whole
autobot-backend/services+knowledge+chat_workflow+chat_history, these failed.knowledge/connectors/egress_vendor_behaviour_test.py::test_the_default_vendor_host_is_allowed[gdrive|notion|onedrive|slack]gaveRuntimeError: Event loop is closedand the mock was awaited 0 times.services/knowledge/test_kb_synthesizer.py::test_synthesize_docs_uses_collection_config_promptsawchatawaited 2 times. All five pass in a small batch on the same tree (1121 passed). The branch under test (#16664) touches neither file.github-actions commentedon Nov 4, 2026
needs-structure: this issue is missing:M<n> - ...: none is setphase:M<n>.<k>label whose<n>matches the goal milestone: found noneParent: #Nin the body), unless this is an umbrella with sub-issuesThe label clears on the next issue event once all three are present (#19522).
mrveiss commentedon Nov 12, 2026
Sighting (2026-11-12), same class:
autobot-backend/conftest.py(around line 929) registerscode_intelligence.pattern_analysisinsys.modulesas a bare stub package with nostoragesubmodule. Two new tests in PR #21328 patched…pattern_analysis.storage.<name>by dotted string, which only set a throwaway attribute on the stub; the code under test then failed its function-localfrom code_intelligence.pattern_analysis.storage import …withNo module named …storagein two python-suite shards. Fixed locally in that PR with fakes installed throughmonkeypatch.setitem; the stub in the shared conftest remains.A second effect seen while reviewing PR #21361: that conftest installs about 50 such stubs, and they are visible to every test module that runs in the same worker — so a test outside
autobot-backend/can depend on them without declaring it, and would fail when run without that conftest (for example in a narrower guard-only run).monkeypatch) or complete enough that a dotted-path patch cannot silently hit a stub.