fix(agents): bound runtime receipt db entry
Some checks failed
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Successful in 1m11s
CD Pipeline / post-deploy-checks (push) Has been cancelled
CD Pipeline / build-and-deploy (push) Has been cancelled
Some checks failed
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Successful in 1m11s
CD Pipeline / post-deploy-checks (push) Has been cancelled
CD Pipeline / build-and-deploy (push) Has been cancelled
This commit is contained in:
@@ -76,6 +76,15 @@ class _BudgetRuntimeDbContext:
|
||||
return False
|
||||
|
||||
|
||||
class _SlowEnterRuntimeDbContext:
|
||||
async def __aenter__(self):
|
||||
await asyncio.sleep(1)
|
||||
return _FailingRuntimeDb()
|
||||
|
||||
async def __aexit__(self, _exc_type, _exc, _tb) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
def _assert_log_controlled_writeback_executor(payload: dict):
|
||||
assert payload["schema_version"] == "ai_agent_log_controlled_writeback_executor_readback_v1"
|
||||
assert payload["priority"] == "P1-LOG-KM-RAG-MCP-PLAYBOOK"
|
||||
@@ -287,6 +296,74 @@ async def test_live_runtime_receipt_keeps_consumer_readback_when_trace_query_fai
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_live_runtime_receipt_db_context_timeout_returns_degraded_payload(
|
||||
monkeypatch,
|
||||
):
|
||||
runtime_control_module._clear_runtime_receipt_readback_cache()
|
||||
|
||||
async def _fake_consumer_readback(*, project_id: str):
|
||||
assert project_id == "awoooi"
|
||||
return _log_controlled_writeback_consumer_readback()
|
||||
|
||||
monkeypatch.setattr(
|
||||
runtime_control_module,
|
||||
"_RUNTIME_RECEIPT_DB_CONTEXT_TIMEOUT_SECONDS",
|
||||
0.01,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
runtime_control_module,
|
||||
"get_db_context",
|
||||
lambda project_id: _SlowEnterRuntimeDbContext(),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
runtime_control_module,
|
||||
"_load_log_controlled_writeback_consumer_readback",
|
||||
_fake_consumer_readback,
|
||||
)
|
||||
|
||||
try:
|
||||
loader = getattr(
|
||||
runtime_control_module,
|
||||
"_load_ai_agent_autonomous_runtime_receipt_readback_uncached",
|
||||
)
|
||||
readback = await loader()
|
||||
finally:
|
||||
runtime_control_module._clear_runtime_receipt_readback_cache()
|
||||
|
||||
assert readback["db_read_status"] == "unavailable"
|
||||
assert readback["error"]["type"] == "RuntimeReceiptDbContextTimeout"
|
||||
_assert_log_controlled_writeback_consumer(
|
||||
readback["log_controlled_writeback_consumer"]
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_live_runtime_receipt_lock_timeout_returns_degraded_payload(
|
||||
monkeypatch,
|
||||
):
|
||||
runtime_control_module._clear_runtime_receipt_readback_cache()
|
||||
lock = asyncio.Lock()
|
||||
await lock.acquire()
|
||||
monkeypatch.setattr(runtime_control_module, "_runtime_receipt_readback_lock", lock)
|
||||
monkeypatch.setattr(
|
||||
runtime_control_module,
|
||||
"_RUNTIME_RECEIPT_LOCK_TIMEOUT_SECONDS",
|
||||
0.01,
|
||||
)
|
||||
|
||||
try:
|
||||
readback = (
|
||||
await runtime_control_module.load_ai_agent_autonomous_runtime_receipt_readback()
|
||||
)
|
||||
finally:
|
||||
lock.release()
|
||||
runtime_control_module._clear_runtime_receipt_readback_cache()
|
||||
|
||||
assert readback["db_read_status"] == "unavailable"
|
||||
assert readback["error"]["type"] == "RuntimeReceiptReadbackLockTimeout"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_live_runtime_receipt_readback_returns_partial_when_query_budget_expires(
|
||||
monkeypatch,
|
||||
|
||||
Reference in New Issue
Block a user