feat(gateway): respect kanban.max_spawn config to limit concurrent tasks

The dispatch_once function already accepts a max_spawn parameter but the
gateway was calling it without passing any value, effectively ignoring
the configuration. This change reads kanban.max_spawn from config.yaml
and passes it through, allowing users to limit concurrent kanban tasks.

This prevents resource exhaustion scenarios where kanban dispatcher
spawns too many parallel workers on constrained hardware.
This commit is contained in:
Moonyeah 2026-05-04 14:38:43 +08:00 committed by Teknium
parent 0b9cbc8b23
commit f0d278412f

View file

@ -3623,6 +3623,11 @@ class GatewayRunner:
if interval < 1.0:
interval = 1.0 # sanity floor — tighter than this is a footgun
# Read max_spawn config to limit concurrent kanban tasks
max_spawn = kanban_cfg.get("max_spawn", None)
if max_spawn is not None:
logger.info(f"kanban dispatcher: max_spawn={max_spawn}")
# Initial delay so the gateway finishes wiring adapters before the
# dispatcher spawns workers (those workers may hit gateway notify
# subscriptions etc.). Matches the notifier watcher's delay.
@ -3651,7 +3656,7 @@ class GatewayRunner:
_kb.init_db(board=slug) # idempotent, handles first-run
except Exception:
pass
return _kb.dispatch_once(conn, board=slug)
return _kb.dispatch_once(conn, board=slug, max_spawn=max_spawn)
except Exception:
logger.exception("kanban dispatcher: tick failed on board %s", slug)
return None