Skip to content

AI-powered virtual executive team — a single coherent executive persona backed by 8 specialist agents (FastAPI + Next.js).

fix(alerts): answer a create_alert call missing its subject or body (#518)

Rufus3b6975c708bc
diff --git a/packages/core/openexecutive/orchestrator/alert_tools.py b/packages/core/openexecutive/orchestrator/alert_tools.py
index 4acee4a6..9cb1e5d5 100644
--- a/packages/core/openexecutive/orchestrator/alert_tools.py
+++ b/packages/core/openexecutive/orchestrator/alert_tools.py
@@ -163,6 +163,15 @@ async def handle_create_alert(tool_input: dict[str, Any]) -> str:
"source": "email",
"from_address": sender,
}
+ # A script or saved workflow calls this without the tool schema's checks,
+ # so a missing field gets an answer the caller can act on, not a KeyError.
+ missing = [k for k in ("subject", "body") if not str(tool_input.get(k) or "").strip()]
+ if missing:
+ logger.warning("create_alert: missing %s", ", ".join(missing))
+ return json.dumps({"error": (
+ f"create_alert needs {' and '.join(missing)}: pass a short 'subject' "
+ "headline and a 'body' saying what needs attention"
+ )})
source, external_id, from_address = (
str(tool_input.get("source") or "unknown"),
str(tool_input.get("external_id") or ""),
diff --git a/packages/core/tests/unit/test_create_alert_input.py b/packages/core/tests/unit/test_create_alert_input.py
new file mode 100644
index 00000000..82e4b625
--- /dev/null
+++ b/packages/core/tests/unit/test_create_alert_input.py
@@ -0,0 +1,51 @@
+"""create_alert called without the fields its schema requires.
+
+A chat script or saved workflow calls the handler directly, past the tool
+schema, so a missing subject or body has to come back as an error the caller
+can fix rather than a KeyError.
+"""
+from __future__ import annotations
+
+import asyncio
+import json
+from typing import Any
+from unittest.mock import patch
+
+import pytest
+
+from openexecutive.orchestrator.alert_tools import handle_create_alert
+
+
+def _call(tool_input: dict[str, Any]) -> tuple[dict[str, Any], list[Any]]:
+ scheduled: list[Any] = []
+ with (
+ patch("openexecutive.alerts.pipeline.schedule_evaluation", scheduled.append),
+ patch("openexecutive.audit.log_event"),
+ ):
+ out = json.loads(asyncio.run(handle_create_alert(tool_input)))
+ return out, scheduled
+
+
+ ("tool_input", "named"),
+ [
+ ({"body": "Server is down"}, "subject"),
+ ({"title": "Server down", "body": "Server is down"}, "subject"),
+ ({"subject": "Server down"}, "body"),
+ ({"subject": " ", "body": ""}, "subject and body"),
+ ],
+)
+def test_missing_field_is_named_and_nothing_is_raised(
+ tool_input: dict[str, Any], named: str,
+) -> None:
+ out, scheduled = _call(tool_input)
+
+ assert out["error"].startswith(f"create_alert needs {named}:")
+ assert scheduled == []
+
+
+def test_complete_input_still_schedules() -> None:
+ out, scheduled = _call({"subject": "Server down", "body": "Server is down"})
+
+ assert out["status"] == "alert_scheduled"
+ assert len(scheduled) == 1