From 17f30eaf3a993dc4e0c9586cf03457b11485585a Mon Sep 17 00:00:00 2001 From: ayoubdiourin7 Date: Sun, 20 Sep 2026 19:14:11 +0200 Subject: [PATCH] Fix Slack agent run dispatch Use ActionValue.params and await HackbotClient.trigger_run so Slack button clicks create agent runs instead of failing or discarding the coroutine. --- services/hackbot-api/app/routers/slack.py | 5 ++- .../hackbot-api/tests/test_slack_webhook.py | 44 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 services/hackbot-api/tests/test_slack_webhook.py diff --git a/services/hackbot-api/app/routers/slack.py b/services/hackbot-api/app/routers/slack.py index 454ed27404..0badd9e4e3 100644 --- a/services/hackbot-api/app/routers/slack.py +++ b/services/hackbot-api/app/routers/slack.py @@ -47,7 +47,10 @@ async def slack_interactions(request: Request) -> Response: match action.value.type: case "start_agent_run": client = get_hackbot_client() - client.trigger_run(action.value.agent_name, action.value.inputs) + await client.trigger_run( + action.value.agent_name, + action.value.params, + ) case _: raise ValueError("Unsupported action type: %s" % action.value.type) diff --git a/services/hackbot-api/tests/test_slack_webhook.py b/services/hackbot-api/tests/test_slack_webhook.py new file mode 100644 index 0000000000..c4b8e85d9c --- /dev/null +++ b/services/hackbot-api/tests/test_slack_webhook.py @@ -0,0 +1,44 @@ +import json + +from app.auth import require_slack_signature +from app.main import app +from app.routers import slack + + +class _FakeHackbotClient: + def __init__(self): + self.calls = [] + + async def trigger_run(self, agent_name, inputs): + self.calls.append((agent_name, inputs)) + + +def test_start_agent_run_action_triggers_run(client, monkeypatch): + api_client = _FakeHackbotClient() + app.dependency_overrides[require_slack_signature] = lambda: None + monkeypatch.setattr(slack, "get_hackbot_client", lambda: api_client) + payload = { + "type": "block_actions", + "user": {"id": "U123", "username": "user"}, + "actions": [ + { + "action_id": "start", + "value": json.dumps( + { + "type": "start_agent_run", + "agent_name": "bug-fix", + "params": {"bug_id": 123}, + } + ), + } + ], + "trigger_id": "trigger-123", + } + + response = client.post( + "/webhooks/slack/interactions", + data={"payload": json.dumps(payload)}, + ) + + assert response.status_code == 200 + assert api_client.calls == [("bug-fix", {"bug_id": 123})]