#5362·PraisonAI

Gateway back-pressure, watchdog and drain tuning has no declarative YAML/Python surface — it is CLI-only and replayed from a hidden start-flags artifact

Author: MervinPraisonCreated Sep 29, 2026Updated Sep 29, 2026
Labelsclaude

Summary

PraisonAI's stated design contract is that every feature runs three ways — CLI, YAML, and Python. The gateway honours this for most options (api.*, preflight, verify_turn, reliability all have gateway.yaml keys), but a cluster of production-critical robustness knobs is CLI-only: --watchdog/--watchdog-timeout, --drain-timeout, --max-concurrent-runs, --queue-depth, and --overflow-policy.

These flags have no first-class gateway.yaml key and no equivalent field on the public GatewayConfig dataclass. Worse, on gateway restart they are not re-read from the config file at all — they are replayed from a hidden persisted start-flags artifact written on the previous start. The canonical home of the gateway's back-pressure and self-healing posture is therefore an opaque CLI invocation, not a declarative config an operator can review, diff, version-control, or reproduce.

For an SDK whose gateway aims to be "world-class, easy to use, robust", the knobs that decide whether the gateway sheds load, self-restarts on an event-loop wedge, or drains cleanly on deploy should be declarative and reproducible, not trapped in shell history.

Current behaviour

gateway start declares these as Typer flags (src/praisonai-bot/praisonai_bot/cli/commands/gateway.py:125):

python
# gateway start (abbreviated) — CLI-primary lifecycle/back-pressure flags
def start(
    ...
    max_concurrent_runs: int = typer.Option(None, "--max-concurrent-runs"),
    queue_depth: int = typer.Option(None, "--queue-depth"),
    overflow_policy: str = typer.Option(None, "--overflow-policy"),
    drain_timeout: float = typer.Option(None, "--drain-timeout"),
    watchdog: bool = typer.Option(None, "--watchdog"),
    watchdog_timeout: float = typer.Option(None, "--watchdog-timeout"),
    ...
): ...

Options that do have YAML equivalents are resolved with an explicit flag-over-YAML-over-default precedence (src/praisonai-bot/praisonai_bot/cli/commands/gateway.py:381-412, _resolve_strict_preflight, _resolve_verify_turn), e.g.:

python
# an unset flag does not override a YAML gateway.api.* value

But the back-pressure/watchdog/drain flags never enter that resolution path. On restart they are rehydrated from a persisted artifact, not the config file (src/praisonai-bot/praisonai_bot/cli/commands/gateway.py:518):

python
saved = load_start_flags(...)   # restart replays the previous CLI invocation, not gateway.yaml

The public core config object (src/praisonai-agents/praisonaiagents/gateway/config.py, GatewayConfig) has no fields for these knobs, so there is also no Python-first way to set them equivalently to the CLI — they only flow through GatewayHandler.start(**kwargs) originating from the CLI layer (src/praisonai-bot/praisonai_bot/cli/features/gateway.py).

Net effect: an operator cannot express "this gateway runs with max_concurrent_runs: 8, overflow_policy: reject, watchdog on at 30s, 20s drain" in gateway.yaml or in Python — only on a command line whose values then disappear into a start-flags file.

Desired behaviour

  • gateway.yaml gains first-class keys for the full back-pressure/lifecycle posture, e.g. under a gateway.runtime (or gateway.backpressure) block:
    yaml
    gateway:
      runtime:
        max_concurrent_runs: 8
        queue_depth: 256
        overflow_policy: reject      # reject | shed_oldest | block
        drain_timeout: 20
        watchdog: true
        watchdog_timeout: 30
  • The same fields exist on the public GatewayConfig dataclass so a Python embedder sets them directly.
  • CLI flags continue to work and override the YAML/Python value via the existing flag-over-YAML-over-default resolver.
  • gateway restart re-reads these from the config file (the config becomes the source of truth); the persisted start-flags artifact is used only to carry genuinely CLI-only, non-config invocation state.

Layer placement

  • Primary layer: core (praisonaiagents)
  • Why not core: — (this is core) the canonical config contract/dataclass (praisonaiagents/gateway/config.py, GatewayConfig) and the versioned-config/migration rules already live in core; adding the fields there is what lets CLI, YAML, Python and BotOS share one schema.
  • Why not wrapper: the wrapper is only the secondary touch (YAML parsing in _load_gateway_config, CLI flag wiring/override, restart re-reading YAML). Putting the field definitions only in the wrapper would fork the schema away from the core dataclass and break the Python-first surface.
  • Why not tools: these are gateway runtime settings, not an agent-callable integration.
  • Why not plugins: this is core runtime configuration, not a lifecycle hook, guardrail, or policy extension.
  • Secondary touch (optional): wrapper — gateway.yaml loader reads the new keys; CLI resolver applies flag-over-YAML precedence; restart sources from config.
  • 3-way surface (CLI + YAML + Python): yes — this is precisely a parity fix, so both the core config field and the wrapper CLI/YAML wiring are required.

Proposed approach

  • Extension point: config (extend the GatewayConfig dataclass + a gateway.runtime YAML block) + CLI (reuse the existing _resolve_* flag-over-YAML pattern).
  • Minimal API sketch:
    python
    # praisonaiagents/gateway/config.py
    @dataclass
    class GatewayRuntimeConfig:
        max_concurrent_runs: int | None = None
        queue_depth: int | None = None
        overflow_policy: str = "reject"
        drain_timeout: float | None = None
        watchdog: bool = False
        watchdog_timeout: float = 30.0
    
    @dataclass
    class GatewayConfig:
        ...
        runtime: GatewayRuntimeConfig = field(default_factory=GatewayRuntimeConfig)

Resolution sketch

python
# Before (today): only reproducible via the CLI; lost to a hidden artifact on restart
# $ praisonai gateway start --max-concurrent-runs 8 --overflow-policy reject \
#     --watchdog --watchdog-timeout 30 --drain-timeout 20
# gateway.yaml cannot express this; GatewayConfig has no such fields;
# `gateway restart` replays load_start_flags(...), not gateway.yaml.

# After (proposed): declarative, reproducible, three-way
# gateway.yaml
# gateway:
#   runtime: { max_concurrent_runs: 8, overflow_policy: reject,
#              watchdog: true, watchdog_timeout: 30, drain_timeout: 20 }

# Python
cfg = GatewayConfig(runtime=GatewayRuntimeConfig(
    max_concurrent_runs=8, overflow_policy="reject",
    watchdog=True, watchdog_timeout=30, drain_timeout=20))
WebSocketGateway(config=cfg).start()

# CLI still overrides YAML/Python when a flag is passed; `gateway restart`
# re-reads gateway.yaml as the source of truth.

Severity

High — it breaks PraisonAI's own CLI+YAML+Python parity contract for the settings that most directly govern gateway robustness (load shedding, event-loop watchdog, graceful drain). Operators cannot pin or review these in a config file or set them from Python, which undermines reproducibility and GitOps for production deployments.

Validation

  • src/praisonai-bot/praisonai_bot/cli/commands/gateway.py — gateway start declares --watchdog/--watchdog-timeout, --drain-timeout, --max-concurrent-runs, --queue-depth, --overflow-policy as CLI options (~line 125); the flag-over-YAML resolver at ~381-412 and _resolve_strict_preflight/_resolve_verify_turn cover api/preflight/verify_turn but not these knobs.
  • src/praisonai-bot/praisonai_bot/cli/commands/gateway.py:518 — load_start_flags(...) shows restart replays the persisted start-flags artifact rather than re-reading gateway.yaml.
  • src/praisonai-agents/praisonaiagents/gateway/config.py — GatewayConfig has no fields for these options; confirmed the YAML loader (_load_gateway_config/_load_channels) reads channels, gateway.api.*, gateway.preflight.*, gateway.reliability, strict_tools, but no back-pressure/watchdog/drain keys.
  • src/praisonai-bot/praisonai_bot/cli/features/gateway.py — lifecycle flags flow through GatewayHandler.start(**kwargs) from the CLI, with no Python-config equivalent.
  • Cross-checked against closed #4913 (schedules parity) — same principle, different capability; this is not a duplicate.