Skip to content

fix: _kanban_dispatcher_watcher fires false "stuck" alert when hook fills concurrency cap #46800

Description

@risers-chevron

fix_kanban_watchers.patch

Bug Description

Hermes has two dispatcher paths that both act on the kanban DB but share no state:

  1. Gateway's embedded _kanban_dispatcher_watcher — runs dispatch_once() every 60s inside the gateway process, increments bad_ticks when it spawns 0 workers.
  2. Hook's per-profile-dispatcher — runs as a separate OS hook every 60s, does the actual spawning when max_spawn > 0.

When max_spawn=2 and the hook fills both concurrency slots, dispatch_once() inside the gateway returns spawned=0 — not because of a stall, but because all slots are occupied. The embedded watcher sees spawned=0 and increments bad_ticks, eventually logging:

kanban dispatcher stuck: 3 tasks ready, 0 workers spawned (bad_ticks=3)

This is a false alarm. Tasks are processing normally; the concurrency cap is simply full.

Steps to Reproduce

  1. Set max_spawn=2 in local-admin/config.yaml
  2. Have ≥2 tasks running (hook dispatcher fills both concurrency slots)
  3. Have ≥1 additional task in ready state
  4. Wait 3+ watcher ticks (3+ minutes)
  5. Gateway logs: kanban dispatcher stuck: N tasks ready, 0 workers spawned
  6. All tasks are processing normally — alarm is false

Expected Behavior

No "stuck" alarm fires when the concurrency cap is full and tasks are actively running. The watcher distinguishes between "cap is full" (healthy throttling) and "slots available but nothing spawned" (genuine stall).

Actual Behavior

Gateway repeatedly logs kanban dispatcher stuck: N tasks ready, 0 workers spawned (bad_ticks=N) every 3 ticks (~3 minutes) during normal operation when max_spawn=2 and both slots are occupied by hook-spawned workers. False alarm — the board is healthy.

Affected Component

Gateway (Telegram/Discord/Slack/WhatsApp)

Messaging Platform (if gateway-related)

No response

Debug Report

gateway:          running (s0 (container supervisor), pid 2050)
platforms:        telegram
cron_jobs:        8 active / 13 total
skills:           48
config_overrides:
  agent.max_turns: 150
  agent.gateway_timeout: 3600
Note: gateway deployment in Docker container; hermes debug share --local used instead of upload.

Operating System

macOS host + Docker Desktop (gRPC-FUSE/virtiofs); container: Linux 6.12.76-linuxkit aarch64

Python Version

3.13.5

Hermes Version

0.16.0 (2026.6.5) [a118b94]

Additional Logs / Traceback (optional)

Repeated in gateway log every ~60s when max_spawn=2 and both slots occupied:
kanban dispatcher stuck: 3 tasks ready, 0 workers spawned (bad_ticks=3)
kanban dispatcher stuck: 3 tasks ready, 0 workers spawned (bad_ticks=4)
kanban dispatcher stuck: 3 tasks ready, 0 workers spawned (bad_ticks=5)

Same period — three tasks in kanban DB:
  task-abc: status=running (hook dispatcher, slot 1)
  task-def: status=running (hook dispatcher, slot 2)
  task-ghi: status=ready (waiting for a free slot)
All tasks completed normally; alarm was entirely spurious.

Root Cause Analysis (optional)

_kanban_dispatcher_watcher in gateway/kanban_watchers.py (~line 1034 in 0.15.1 / 0.16.0) increments bad_ticks when ready_pending and not any_spawned.

The problem: any_capped is only set when dispatch_once() itself hits skipped_per_profile_capped — it is NOT set when the hook's per-profile-dispatcher has already filled the global max_spawn cap before the embedded watcher runs. So when max_spawn=2 and the hook holds both slots, dispatch_once() returns spawned=0 without setting skipped_per_profile_capped, and the watcher increments bad_ticks on every tick.

The fix: before incrementing bad_ticks, query the kanban DB for the total count of status='running' tasks across all boards. If running >= max_spawn, the cap is full — set bad_ticks = 0 instead of incrementing. Only a genuine stall (slots available, nothing spawned) should increment.

Proposed Fix (optional)

Patch: fix_kanban_watchers.patch — 54 lines, 1 hunk, applies with patch -p0

--- a/gateway/kanban_watchers.py
+++ b/gateway/kanban_watchers.py
@@ -1034,9 +1034,49 @@
                             len(res.auto_blocked) if hasattr(res.auto_blocked, "__len__") else 0,
                         )
                 # Health telemetry (aggregate across boards)
+                # Suppress false-alarm "stuck" warnings when tasks are blocked by
+                # per-profile or global max_spawn concurrency caps — that is normal
+                # throttled behaviour driven by the hook dispatcher, not a stall.
+                any_capped = any(
+                    res is not None
+                    and bool(getattr(res, "skipped_per_profile_capped", None))
+                    for _, res in (results or [])
+                )
                 ready_pending = await asyncio.to_thread(_ready_nonempty)
-                if ready_pending and not any_spawned:
-                    bad_ticks += 1
+                if ready_pending and not any_spawned and not any_capped:
+                    # Also suppress when the global max_spawn cap is already
+                    # exhausted by hook-spawned workers (dispatch_once breaks
+                    # early before touching skipped_per_profile_capped).
+                    def _get_running_count():
+                        try:
+                            boards_ = _kb.list_boards(include_archived=False)
+                        except Exception:
+                            boards_ = [_kb.read_board_metadata(_kb.DEFAULT_BOARD)]
+                        total = 0
+                        for b_ in boards_:
+                            slug_ = b_.get("slug") or _kb.DEFAULT_BOARD
+                            conn_ = None
+                            try:
+                                conn_ = _kb.connect(board=slug_)
+                                row_ = conn_.execute(
+                                    "SELECT COUNT(*) FROM tasks WHERE status='running'"
+                                ).fetchone()
+                                total += row_[0] if row_ else 0
+                            except Exception:
+                                pass
+                            finally:
+                                if conn_:
+                                    try:
+                                        conn_.close()
+                                    except Exception:
+                                        pass
+                        return total
+                    running = await asyncio.to_thread(_get_running_count)
+                    at_global_cap = max_spawn is not None and running >= max_spawn
+                    if not at_global_cap:
+                        bad_ticks += 1
+                    else:
+                        bad_ticks = 0
                 else:
                     bad_ticks = 0
                 if bad_ticks >= HEALTH_WINDOW:

Apply with: patch -p0 < fix_kanban_watchers.patch

Are you willing to submit a PR for this?

  • I'd like to fix this myself and submit a PR

Activity

  1. added
    type/bugSomething isn't working
    comp/cronCron scheduler and job management
    comp/gatewayGateway runner, session dispatch, delivery
    P3Low — cosmetic, nice to have
    on Jun 15, 2026
  2. hermesy-theshwal commented on Jul 10, 2026

    @hermesy-theshwal

    Confirmed reproduction + manual workaround applied 2026-07-10.

    Symptoms (VisiPDP, ~1043 tests queued):

    • hermes kanban dispatch --max N returns 0/0/0/0/0/0/0 despite 4 ready + 4 free WIP slots
    • Gateway logs: kanban dispatcher stuck: ready queue non-empty for N consecutive ticks but 0 workers spawned (reached 431+ ticks)
    • Workers spawned (PIDs 706038/039 then 707274/604/918) die silently after ~90-180s
    • Scheduler respawns same card instead of moving to next ready

    Root cause (not just false stuck warning):

    Manual workaround that worked (cf. #22926 suggestion):

    UPDATE tasks SET
      claim_lock = NULL, claim_expires = NULL, worker_pid = NULL,
      current_run_id = NULL, consecutive_failures = 0,
      max_runtime_seconds = 7200
    WHERE status = 'ready';

    Then hermes kanban dispatch --max 5 spawns 1 worker per cycle (~3 min/card).

    Confirmation that #46800 is just false-positive log: spawn DOES happen, but watcher thinks it doesn't. The real fix is #22926 (claim cleanup).

    Thanks for #22926 + #46892 — VisiPDP unblocked. Documented in incident 2026-07-10.

  3. Wild-Eep commented on Jul 10, 2026

    @Wild-Eep

    I think this is mixing up two different bugs that just happen to log the same line.

    Our repro for #46800 has no crashed workers at all. max_spawn=2, the hook’s own dispatcher fills both slots with tasks that are actively and healthily running, and a third task sits in ready. The gateway’s embedded watcher calls dispatch_once(), which correctly returns spawned=0 because there’s nothing left for it to spawn (the hook already did it). But any_capped only gets set from that call’s own skipped_per_profile_capped flag, so it has no idea the hook filled the cap in a different process. bad_ticks climbs even though the board is completely fine. No crashes, no stale claims, nothing to clean up. It’s a logging bug, full stop.

    What you hit is different. Workers with real PIDs spawn and then die silently (OOM/timeout), and claim_lock/claim_expires/worker_pid never get cleared. That’s #22926: the dispatcher can’t tell a dead worker’s leftover claim from a live one, so the card never gets reassigned. The fix you applied (nulling those columns) is #22926’s fix, not #46800’s. Same symptom, totally different cause.

    One thing your report does surface though: our fix (checking running >= max_spawn via a plain status=‘running’ count) would get fooled by your exact scenario too, since a dead worker’s stale row still counts as “running.” Might be worth having #22926’s cleanup also filter on claim_expires before either of these two fixes counts a row as real.

    But that’s a reason to land both patches, not a reason #46800 isn’t a real bug.

  4. hermesy-theshwal commented on Jul 10, 2026

    @hermesy-theshwal

    Thanks @Wild-Eep — you're right, my report conflated the two bugs. Correcting on the record:

    The UPDATE tasks SET claim_lock=NULL... is #22926's fix, not #46800's.

    One useful tie-in for whoever lands both: after my manual #22926 cleanup, #46800's "stuck" log also stopped — fresh workers spawned, no stranded cards, no false-positive. So #22926 cleanup is effectively a prerequisite for #46800's watcher fix to count "running" rows accurately (without it, stale claims would still pollute the count, as you noted). Folding the claim_expires < now filter into the running-row check seems like the right shape.

    Will post the focused repro to #22926 separately.

  5. GottZ commented on Jul 30, 2026

    @GottZ

    This was generated by AI during triage.

    Summary

    Twelve PRs were triaged in this complex, but only #46892 and #65581 modify the false-stuck health predicate reported in #46800. #46892 probes externally occupied capacity but aggregates incompatible board-local counts, while #65581 introduces explicit deferral results and board-local gateway accounting, though its shown global-cap flag covers max_in_progress rather than every external max_spawn-cap path.

    Related pull requests

    Duplicates

    #41679, #44919, and merged #49068 are substantially the same #41448 singleton-lock change, with #49068 carrying the machine-global implementation from #44919. #46892 and #65581 overlap on false-stuck suppression, but #65581 has the stronger board-local design; #59588 and the max_spawn-validation portion of #65644 substantially overlap on raw max_spawn coercion.

    Suggested consolidation

    Merge #65581 as the consolidation base for #46800 after retaining its revised board-local gateway/daemon accounting and adding or verifying an explicit board-local deferral for the reported external max_spawn-full path. This recommendation explicitly departs from the earlier keep_open review because its blocking cross-board aggregation finding is addressed in the shown revised diff and multi-board regression; #46892 can then be closed as a superseded partial duplicate because its aggregate count can suppress real per-board stalls. Keep the unrelated fixes outside this consolidation, and treat merged #49068 only as the reference implementation for the separate singleton-dispatcher issue.

    Complex graph

    flowchart TD
        classDef open fill:#dbeafe,stroke:#1d4ed8,color:#1e3a8a
        classDef merged fill:#dcfce7,stroke:#15803d,color:#14532d
        classDef closed fill:#e5e7eb,stroke:#6b7280,color:#1f2937
        classDef unverified fill:#f3f4f6,stroke:#9ca3af,color:#374151
        classDef best stroke-width:3px,stroke:#b45309
        classDef target stroke-width:3px,stroke:#4338ca
        I41448(["issue #41448 (closed)"])
        I46800(["issue #46800 (open)"])
        I49859(["issue #49859 (open)"])
        P49861["PR #49861 (open)"]
        subgraph Dup41679 ["PRs duplicating each other"]
            P41679["PR #41679 (closed)"]
            P44919["PR #44919 (closed)"]
            P49068["PR #49068 (merged)"]
        end
        subgraph Dup46892 ["PRs duplicating each other"]
            P46892["PR #46892 (open)"]
            P65581["PR #65581 (open)"]
        end
        subgraph Dup59588 ["PRs duplicating each other"]
            P59588["PR #59588 (open)"]
            P65644["PR #65644 (open)"]
        end
        MoreI(["+1 more issues not shown"])
        P46892 -.->|partial| I46800
        P65581 -->|best fix| I46800
        P41679 -.->|partial| I41448
        P44919 -->|fixes| I41448
        P49068 -->|best fix| I41448
        P49861 -->|best fix| I49859
        class I41448 closed
        class I46800 open
        class I49859 open
        class I46800 target
        class P41679 closed
        class P44919 closed
        class P46892 open
        class P49068 merged
        class P49861 open
        class P59588 open
        class P65581 open
        class P65644 open
        class P49068 best
        class P49861 best
        class P65581 best
        class MoreI closed
        click I41448 "https://github.com/NousResearch/hermes-agent/issues/41448"
        click I46800 "https://github.com/NousResearch/hermes-agent/issues/46800"
        click I49859 "https://github.com/NousResearch/hermes-agent/issues/49859"
        click P41679 "https://github.com/NousResearch/hermes-agent/pull/41679"
        click P44919 "https://github.com/NousResearch/hermes-agent/pull/44919"
        click P46892 "https://github.com/NousResearch/hermes-agent/pull/46892"
        click P49068 "https://github.com/NousResearch/hermes-agent/pull/49068"
        click P49861 "https://github.com/NousResearch/hermes-agent/pull/49861"
        click P59588 "https://github.com/NousResearch/hermes-agent/pull/59588"
        click P65581 "https://github.com/NousResearch/hermes-agent/pull/65581"
        click P65644 "https://github.com/NousResearch/hermes-agent/pull/65644"
    
    Loading

    Graph: solid arrow = fixes / best fix, dashed arrow = partial or unverified (see edge label); boxed group = PRs duplicating each other; amber border = best fix; indigo border = target; gray node = closed (state tag in the node label).

    Cross-PR triage: Reviewed 12 pull requests and 4 issues in this complex. Each diff was read against this issue; Assessment working set: 134 kB of PR diffs, 44 kB of issue/PR text, 33 kB of discussion (34 comments), 9 verify verdicts. verdicts reflect diff content, not PR titles. Part of an automated triage batch.

  6. GottZ commented on Aug 3, 2026

    @GottZ

    This was generated by AI during triage.

    Delta since our previous triage comment

    Since the previous triage comment, @bwoliveira supplied production evidence confirming #57837's separate multiplex auto-decomposition failure and validating the proposed profile-secret-scope fix with a stale card decomposed after deployment. This strengthens #57837 on its own merits but does not connect its diff to #46800's false stuck-warning predicate.

    Changed pull requests

    Suggested consolidation

    The consolidation recommendation is unchanged: #65581 remains the best existing partial fix, but no PR in this complex is currently merge-lane eligible.

    Complex graph unchanged since our previous triage comment.

    Cross-PR triage: Reviewed 12 pull requests and 4 issues in this complex. Each diff was read against this issue; Assessment working set: 134 kB of PR diffs, 44 kB of issue/PR text, 28 kB of discussion (29 comments), 10 verify verdicts. verdicts reflect diff content, not PR titles. Part of an automated triage batch.

  7. rodrigogs commented on Sep 6, 2026

    @rodrigogs

    Opened #104144 for this. It records the cap outcome where it is decided - _tick_spawn_budget now sets capacity_deferred at both the max_spawn and max_in_progress early returns - and the watcher treats a board whose only reason for spawned=0 is a full cap as healthy instead of stuck. The hook-filled scenario in this report is covered because count_running_tasks already counts hook-spawned rows; the fix is that the watcher finally reads that result. The same classification is applied per board, so a capped board cannot hide a stalled sibling, and the --daemon path uses the same decision. No DB re-query inside the watcher.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low — cosmetic, nice to havecomp/cronCron scheduler and job managementcomp/gatewayGateway runner, session dispatch, deliverytype/bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions