test-core (root) flake: TestRegistryImportErrorIsContained fails when the framework availability cache is warm
Symptom
test-core (root) fails intermittently with exactly two failures, both in tests/unit/test_framework_validators.py, including on branches that do not touch the framework adapters:
FAILED tests/unit/test_framework_validators.py::TestRegistryImportErrorIsContained::test_is_available_swallows_constructor_import_error - AssertionError: assert True is False
FAILED tests/unit/test_framework_validators.py::TestRegistryImportErrorIsContained::test_assert_framework_available_gives_friendly_hint_on_import_error - Failed: DID NOT RAISE ImportError
===== 2 failed, 1795 passed, 41 skipped, 18 warnings in 228.06s =====
Seen in 5 of the last 25 test-core.yml runs, on 5 different branches, always in the test-core (root) job (in run 34983698248 every other shard passed):
| run | branch | root |
|---|---|---|
| 34983698248 | fix/5051-bookend-archived-tag | fail |
| 34975530549 | claude/issue-5092-... | fail |
| 34973502707 | claude/issue-5097-... | pass |
| 34974270325 | claude/issue-5097-... | fail |
| 34974039795 | claude/issue-5100-... | fail |
| 34975085384 | claude/issue-5095-... | pass |
| 34973445830 | claude/issue-5095-... | fail |
Two of those branches both passed and failed on separate runs - the outcome is timing/order dependent, not branch dependent. (It is also why the CI of #5113 went red on a PR whose diff only touches src/praisonai-agents/praisonaiagents/session/store.py.)
Root cause
FrameworkAdapterRegistry.is_available() memoises its probe in self._avail_cache (src/praisonai/praisonai/framework_adapters/registry.py, current main):
- L63 declares the cache;
- L241-245: on a cache hit it
return cachedwithout callingself.create(name); - L260-261: the probe result is written back;
- L264
invalidate_availability()is the documented way to drop it.
Both failing tests assume the patched create() is the only path:
registry = get_default_registry()
with patch.object(registry, "create", side_effect=ImportError("missing dep")):
assert registry.is_available("crewai") is False # test_framework_validators.py L170-171
with patch(...get_default_registry, return_value=registry), \
patch.object(registry, "create", side_effect=ImportError("missing dep")):
with pytest.raises(ImportError, match="was requested but is not installed"):
assert_framework_available("crewai") # L180-182
If anything earlier in the same process already probed crewai, the cache holds the real result and the patched create() is never reached:
- test 1 returns the memoised value ->
assert True is False. TheTruealso shows the real probe succeeded in that environment:test-core.ymlinstallswrapper-extras: ".[ui,gradio,api,agentops,google,openai,anthropic,cohere,chat,code,realtime,call,crewai,autogen]". - test 2 returns early at
validators.pyL27 (if registry.is_available(name): return) ->DID NOT RAISE ImportError.
Why it is intermittent: the root shard runs every top-level tests/unit/test_*.py with -n 2 --dist loadfile, so which files share a worker - and therefore whether some earlier file in that worker probed crewai (anything calling list_available_frameworks(), list_framework_choices() or pick_default()) - varies from run to run. Whichever worker hits a warm cache fails.
Local reproduction
Run against the project's own test file (current main, sha256 of test_framework_validators.py = 31632daede01...). Three arms; arm 2 differs only by an earlier probe of crewai (a stand-in adapter, since the local env has no crewai installed):
ARM 1 no earlier probe : 14 passed
ARM 2 crewai probed first : 2 failed, 12 passed
E AssertionError: assert True is False
+ where True = is_available('crewai')
test_framework_validators.py:171: AssertionError: assert True is False
E Failed: DID NOT RAISE ImportError
test_framework_validators.py:181: Failed: DID NOT RAISE ImportError
ARM 3 arm 2 + cache cleared per test: 14 passed
Same two test ids, same line numbers (171 / 181) and the same messages as CI.
Suggested fix
The is_available docstring already names the escape hatch ("Use invalidate_availability to drop cached results in tests"); the two tests just do not use it. Either of these makes arm 2 green (verified as arm 3):
- call
registry.invalidate_availability("crewai")before thepatch.object(...)in both tests, or - add an autouse fixture for that module:
get_default_registry().invalidate_availability().
I can send a PR for whichever shape you prefer if that helps.
👋 Thanks for opening this issue, @pm25coder!
A maintainer will review this shortly. In the meantime:
- Make sure you've included steps to reproduce (for bugs)
- Check existing issues for duplicates
- Review the documentation for related guides
Bug and enhancement reports are auto-triaged with Claude. Questions and other issues: a maintainer can comment @claude to trigger analysis.
Routing: Agent-callable tools → PraisonAI-Tools; lifecycle plugins (tracing/hooks/guardrails) → PraisonAI-Plugins. TypeScript/JavaScript SDK fixes land in src/praisonai-ts/ in this repo.
Claude finished @pm25coder's task —— View job • claude/issue-5115-20260916-1315 • [Create PR ➔](https://github.com/MervinPraison/PraisonAI/compare/main...claude/issue-5115-20260916-1315?quick_pull=1&title=Issue%20%235115%3A%20Changes%20from%20Claude&body=This%20PR%20addresses%20issue%20%235115%0A%0AGenerated%20with%20%5BClaude%20Code%5D(https%3A%2F%2Fclaude.ai%2Fcode)
Fixing test flake: TestRegistryImportErrorIsContained
- [x] Read
test_framework_validators.pyand registry - [x] Apply minimal cache-invalidation fix
- [x] Run tests (verified against a warm cache)
- [x] Commit, push, create PR
Root cause confirmed: is_available() memoises probes in _avail_cache, so when an earlier file in the same xdist worker warmed crewai, the patched create() was never reached and the real (installed) result leaked through.
Fix: Call registry.invalidate_availability("crewai") before patch.object(...) in both tests — exactly what the is_available docstring prescribes. Test-only, minimal.
Verification: Reproduced by warming _avail_cache['crewai']=True before running the file. Before the fix the two tests fail as in CI; after the fix the full file is 14 passed.
PR: https://github.com/MervinPraison/PraisonAI/pull/5116
• Branch: claude/issue-5115-20260916-1315