From 117a16aca5e34e0204e8016998bddfca1506707a Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Mon, 15 Jun 2026 21:52:17 +0200 Subject: [PATCH] Add explicit 'run_interrupted' event when streaming workflow events --- backend/agent/api.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/backend/agent/api.py b/backend/agent/api.py index d2aac03..ce9265d 100644 --- a/backend/agent/api.py +++ b/backend/agent/api.py @@ -536,6 +536,7 @@ def get_workflow_events(run_id: str, after_sequence: int = Query(0, ge=0), follo async def stream(): sequence = after_sequence idle_after_terminal = 0 + emitted_interrupted = False while True: db = SessionLocal() try: @@ -555,6 +556,17 @@ def get_workflow_events(run_id: str, after_sequence: int = Query(0, ge=0), follo "payload": _json(item.payload_json, {}), }, ensure_ascii=False) + "\n" terminal = run.status in {"completed", "failed", "cancelled", "interrupted"} + if run.status == "interrupted" and not emitted_interrupted: + emitted_interrupted = True + yield json.dumps({ + "run_id": run.id, + "workflow_id": run.workflow_id, + "node_id": None, + "sequence": sequence + 1, + "timestamp": (run.finished_at or datetime.utcnow()).isoformat(), + "type": "run_interrupted", + "payload": _json(run.error_json, {"message": "Workflow run was interrupted."}), + }, ensure_ascii=False) + "\n" finally: db.close() if not follow: