From 28ca4460a1f830812a884bc4b043d081954334e9 Mon Sep 17 00:00:00 2001 From: annguyenNous Date: Wed, 3 Jun 2026 18:03:09 +0700 Subject: [PATCH] fix(gateway): guard kanban dispatcher against malformed config and empty summaries Two error handling gaps in the gateway kanban dispatcher: 1. float() on dispatch_interval_seconds crashes with ValueError if the config value is a non-numeric string. Wrap in try/except and fall back to the default 60-second interval with a warning log. 2. splitlines()[0] on payload_summary and task.result raises IndexError when the string is whitespace-only (truthy but strip() produces empty string, splitlines() returns []). Guard with a check on the lines list before indexing. --- gateway/run.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/gateway/run.py b/gateway/run.py index 80cd6f5fea7..4bd93ec92a0 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -5402,10 +5402,12 @@ class GatewayRunner: if ev.payload and ev.payload.get("summary"): payload_summary = str(ev.payload["summary"]) if payload_summary: - h = payload_summary.strip().splitlines()[0][:200] + lines = payload_summary.strip().splitlines() + h = lines[0][:200] if lines else payload_summary[:200] handoff = f"\n{h}" elif task and task.result: - r = task.result.strip().splitlines()[0][:160] + lines = task.result.strip().splitlines() + r = lines[0][:160] if lines else task.result[:160] handoff = f"\n{r}" msg = ( f"✔ {tag}Kanban {sub['task_id']} done" @@ -5753,7 +5755,14 @@ class GatewayRunner: logger.warning("kanban dispatcher: kanban_db not importable; dispatcher disabled") return - interval = float(kanban_cfg.get("dispatch_interval_seconds", 60) or 60) + try: + interval = float(kanban_cfg.get("dispatch_interval_seconds", 60) or 60) + except (ValueError, TypeError): + logger.warning( + "kanban dispatcher: invalid dispatch_interval_seconds=%r, using default 60", + kanban_cfg.get("dispatch_interval_seconds"), + ) + interval = 60.0 interval = max(interval, 1.0) # sanity floor — tighter than this is a footgun # Read max_spawn config to limit concurrent kanban tasks