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.
This commit is contained in:
annguyenNous 2026-06-03 18:03:09 +07:00 committed by Teknium
parent cbfe1d21d1
commit 28ca4460a1

View file

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