Handle lease loss during adapter errors

Assistant: codex
Assistant-Model: gpt-5.6-sol
Assistant-Session: 01a02b6f-7db1-7222-918b-e813a6bda38d
This commit is contained in:
tegwick 2026-08-23 14:40:29 +02:00
parent 75f4914777
commit ad4074c20a
3 changed files with 98 additions and 32 deletions

View file

@ -135,6 +135,48 @@ def test_process_one_refuses_close_after_lease_loss() -> None:
client.fail.assert_not_called()
def test_process_one_records_adapter_exception_without_unbound_result() -> None:
client = MagicMock(spec=ActivityCoreOpsClient)
client.config = OpsRunConfig(worker_id="w", lease_seconds=90)
client.claim.return_value = [_claimed_run()]
with patch(
"rein_aharness.claim_loop.execute_approach",
side_effect=RuntimeError("provider output must not be retained"),
):
result = process_one(client)
assert result.ok is False
assert result.reason == "approach failed (RuntimeError)"
assert result.detail == {"execution_error_type": "RuntimeError"}
client.complete.assert_not_called()
client.fail.assert_not_called()
def test_profiled_exception_after_lease_loss_skips_close() -> None:
client = MagicMock(spec=ActivityCoreOpsClient)
client.config = OpsRunConfig(worker_id="w", lease_seconds=90)
run = _claimed_run()
run.harness_profile_ref = "harness.agent-dev-local@1.0.0"
client.claim.return_value = [run]
client.heartbeat.side_effect = OpsRunError("lease rejected")
def slow_profile(*_args, **_kwargs):
time.sleep(0.05)
raise GlasExecutionError("profile failed")
with (
patch("rein_aharness.claim_loop._heartbeat_interval", return_value=0.01),
patch("rein_aharness.claim_loop.execute_profiled_run", side_effect=slow_profile),
):
result = process_one(client)
assert result.ok is False
assert result.reason.startswith("lease lost")
client.complete.assert_not_called()
client.fail.assert_not_called()
def test_poll_peek() -> None:
client = MagicMock(spec=ActivityCoreOpsClient)
client.list_open.return_value = [_claimed_run()]