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.
This commit is contained in:
OpenHarness Self-Healing
2026-07-18 12:32:40 +00:00
parent cc0a37e9fa
commit 53764a88a5
2 changed files with 16 additions and 3 deletions

View File

@@ -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"}

View File

@@ -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"}