From 53764a88a51fdae397b53347594562d37790d9b1 Mon Sep 17 00:00:00 2001 From: OpenHarness Self-Healing Date: Sat, 18 Jul 2026 12:32:40 +0000 Subject: [PATCH] Fix controlled-failure crash in run skill The run skill raised RuntimeError for scenario=controlled-failure, causing HTTP500. Return the safe recovered result instead and add regression coverage. --- agent.py | 6 +++--- tests/test_agent.py | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/agent.py b/agent.py index 72a859a..9bfdc30 100644 --- a/agent.py +++ b/agent.py @@ -23,7 +23,7 @@ class SelfHealingDemo(A2AAgent): scenario: str = "normal", ) -> dict[str, object]: if scenario == "controlled-failure": - # Intentional smoke fixture: the regression test specifies the safe - # result. The production self-healing worker must repair this source. - raise RuntimeError("SELF_HEAL_SMOKE: controlled invoice total handler crashed") + # Previously this handler crashed with a controlled RuntimeError. + # It now returns the safe, recovered result the regression test expects. + return {"ok": True, "scenario": scenario, "result": "recovered"} return {"ok": True, "scenario": scenario, "result": "healthy"} diff --git a/tests/test_agent.py b/tests/test_agent.py index b8237f3..0420a63 100644 --- a/tests/test_agent.py +++ b/tests/test_agent.py @@ -12,6 +12,9 @@ async def test_controlled_failure_has_a_safe_result() -> None: agent = SelfHealingDemo() ctx = LocalRunContext(auth=NoAuth()) + # Regression: this scenario previously raised + # RuntimeError("SELF_HEAL_SMOKE: controlled invoice total handler crashed"). + # It must now return a safe, recovered result without raising. result = await agent.run(ctx, scenario="controlled-failure") assert result == { @@ -19,3 +22,13 @@ async def test_controlled_failure_has_a_safe_result() -> None: "scenario": "controlled-failure", "result": "recovered", } + + +@pytest.mark.asyncio +async def test_normal_scenario_stays_healthy() -> None: + agent = SelfHealingDemo() + ctx = LocalRunContext(auth=NoAuth()) + + result = await agent.run(ctx, scenario="normal") + + assert result == {"ok": True, "scenario": "normal", "result": "healthy"}