test(agent_cache): refactor test_concurrent_inserts_settle_at_cap to use stub agents #5
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Severity: medium
Symptom
tests/gateway/test_agent_cache.py::TestAgentCacheSpilloverLive::test_concurrent_inserts_settle_at_cappasses when run in isolation (~30s) but fails under parallel xdist load when scheduled alongside other heavy tests, blocking the per-PR CI gate.Root cause
The test creates 160 real
AIAgentinstances (8 threads × 20 inserts) inside a 30s pytest-timeout budget. EachAIAgent.__init__does tool registry scan, MCP discovery, config loading, and file I/O. On a runner that's already saturated (the operator host runs at load avg 16-37 on 8 CPUs), the budget is too tight.The test's INTENT is to verify the cache eviction logic handles concurrent inserts correctly. It does not need real
AIAgentinstances to do that — a lightweight stub that exposes the small subset of attributes the cache code reads (session_id, etc.) suffices and runs in microseconds.Proposed fix
Replace
_real_agent()with a stub class. The cache logic operates on(agent, signature)tuples and walks_running_agentsbyid(); the stub needs no real init work to satisfy that contract.The sister tests
test_fill_to_cap_then_spilloverandtest_spillover_all_active_keeps_cache_over_capuse the same pattern and would benefit from the same refactor; consider doing all three in one PR.Verification
After the refactor, the test should run in well under 1s even under parallel xdist load. Mutation-test mentally: deleting
_enforce_agent_cache_cap()should still fail the test (it asserts cache size == CAP after concurrent inserts).Surfaced by
Fix attempt while addressing the broader hermes-agent CI red set (PRs #1, #3, #4 as of 2026-05-08). After those land this is the last deterministic remaining failure on
main.