Summary
The CapacityManager refactor (commit 76a6a10, shipped in 202e2d4) deleted services/slot_service.py and replaced it with services/capacity_manager.py. The unit tests in test_orphaned_execution_recovery.py still mock services.slot_service, so all four recovery scenario tests now fail with 'Mock' object can't be awaited. The orphaned execution recovery code has no working unit test coverage as a result.
Component
Backend / Cleanup Service / Tests
Priority
P3 — no runtime impact; tests fail locally and in CI
Error
ERROR cleanup_service.py:772 [Recovery] Error recovering execution exec-1:
'Mock' object can't be awaited
assert 0 == 1 # recovered count
Location
- File:
tests/unit/test_orphaned_execution_recovery.py
- Line: ~30 (
_SYS_MOCKS definition)
- Function:
_SYS_MOCKS dict / TestRecoverOrphanedExecutions
Root Cause
test_orphaned_execution_recovery.py injects a sys-module mock for services.slot_service:
_SYS_MOCKS = {
...
'services.slot_service': Mock(get_slot_service=Mock(return_value=_mock_slot_service)),
...
}
After the refactor, cleanup_service.py no longer imports from services.slot_service. It now calls get_capacity_manager() from services.capacity_manager and awaits capacity.release(agent_name, execution_id). The test's mock dict doesn't include services.capacity_manager, so capacity is an un-mocked None-like object and await capacity.release(...) raises TypeError: 'Mock' object can't be awaited.
Affected Tests
All four orphaned-recovery scenario tests fail:
test_container_down_marks_orphaned
test_not_in_registry_marks_orphaned
test_multiple_agents_mixed
test_agent_unreachable_treats_as_orphaned
(test_no_running_executions still passes because the recovery path is never entered.)
Suggested Fix
Replace the stale slot_service mock with a capacity_manager mock:
# REMOVE:
_mock_slot_service = AsyncMock()
...
'services.slot_service': Mock(get_slot_service=Mock(return_value=_mock_slot_service)),
# ADD:
_mock_capacity = AsyncMock()
_mock_capacity.release = AsyncMock()
_mock_capacity.release_if_matches = AsyncMock(return_value=True)
...
'services.capacity_manager': Mock(get_capacity_manager=Mock(return_value=_mock_capacity)),
Any assertions that previously checked _mock_slot_service.release_slot calls should be updated to check _mock_capacity.release instead.
Reproduction Steps
- Check out commit
202e2d4 or later
- Run:
cd tests && python -m pytest unit/test_orphaned_execution_recovery.py -v
- Observe 4 failures with
'Mock' object can't be awaited
Environment
- Trinity version:
202e2d4
- Introduced by:
76a6a10 (CapacityManager consolidation)
Related
src/backend/services/cleanup_service.py — function _recover_execution() (uses capacity.release)
src/backend/services/capacity_manager.py — new consolidated service
tests/unit/test_capacity_manager.py — new test file (all passing)
Summary
The CapacityManager refactor (commit
76a6a10, shipped in202e2d4) deletedservices/slot_service.pyand replaced it withservices/capacity_manager.py. The unit tests intest_orphaned_execution_recovery.pystill mockservices.slot_service, so all four recovery scenario tests now fail with'Mock' object can't be awaited. The orphaned execution recovery code has no working unit test coverage as a result.Component
Backend / Cleanup Service / Tests
Priority
P3 — no runtime impact; tests fail locally and in CI
Error
Location
tests/unit/test_orphaned_execution_recovery.py_SYS_MOCKSdefinition)_SYS_MOCKSdict /TestRecoverOrphanedExecutionsRoot Cause
test_orphaned_execution_recovery.pyinjects a sys-module mock forservices.slot_service:After the refactor,
cleanup_service.pyno longer imports fromservices.slot_service. It now callsget_capacity_manager()fromservices.capacity_managerand awaitscapacity.release(agent_name, execution_id). The test's mock dict doesn't includeservices.capacity_manager, socapacityis an un-mockedNone-like object andawait capacity.release(...)raisesTypeError: 'Mock' object can't be awaited.Affected Tests
All four orphaned-recovery scenario tests fail:
test_container_down_marks_orphanedtest_not_in_registry_marks_orphanedtest_multiple_agents_mixedtest_agent_unreachable_treats_as_orphaned(
test_no_running_executionsstill passes because the recovery path is never entered.)Suggested Fix
Replace the stale
slot_servicemock with acapacity_managermock:Any assertions that previously checked
_mock_slot_service.release_slotcalls should be updated to check_mock_capacity.releaseinstead.Reproduction Steps
202e2d4or latercd tests && python -m pytest unit/test_orphaned_execution_recovery.py -v'Mock' object can't be awaitedEnvironment
202e2d476a6a10(CapacityManager consolidation)Related
src/backend/services/cleanup_service.py— function_recover_execution()(usescapacity.release)src/backend/services/capacity_manager.py— new consolidated servicetests/unit/test_capacity_manager.py— new test file (all passing)