Skip to content

Fix monitor Running status and CPU accuracy#128

Merged
maximusunc merged 2 commits into
mainfrom
claude/worker-monitor-updates-oa5dqh
Jul 15, 2026
Merged

Fix monitor Running status and CPU accuracy#128
maximusunc merged 2 commits into
mainfrom
claude/worker-monitor-updates-oa5dqh

Conversation

@maximusunc

Copy link
Copy Markdown
Collaborator

Two monitor accuracy fixes for worker heartbeats:

Running status: get_tasks reserved a concurrency-semaphore permit before the blocking broker poll (a 5s XREADGROUP), and the heartbeat reported task_limit minus free permits as "in flight". An idle worker sitting in the poll therefore reported one task running even though it was only checking for work. Introduce a TaskSlots limiter that separates slot reservation (backpressure around the poll) from dispatch (a task actually handed to a worker); the heartbeat now reports only dispatched-and-not-yet-finished tasks. Workers already call limiter.release() once per task, so every worker is covered without per-worker changes.

CPU accuracy: cpu_pct was derived from /proc/self/stat, which counts only the parent process. The CPU-bound workers offload their heavy work to ProcessPoolExecutor children, whose CPU never appears in the parent's counters, so those workers reported near-zero CPU while pegging cores. Read cgroup-wide CPU accounting (cpu.stat usage_usec on v2, cpuacct.usage on v1) when running in a container so pool children are included; fall back to /proc/self on a bare host (where /sys/fs/cgroup is the whole machine). This is accurate under both local Docker Compose and Kubernetes. Also report cpu_count (cgroup-limit aware) so the top-style "% of a core" reading is interpretable in the dashboard.

Claude-Session: https://claude.ai/code/session_016L2RdZQn1gJ1iHd5FN6Dwf

claude and others added 2 commits July 14, 2026 02:47
Two monitor accuracy fixes for worker heartbeats:

Running status: get_tasks reserved a concurrency-semaphore permit *before*
the blocking broker poll (a 5s XREADGROUP), and the heartbeat reported
task_limit minus free permits as "in flight". An idle worker sitting in the
poll therefore reported one task running even though it was only checking for
work. Introduce a TaskSlots limiter that separates slot reservation
(backpressure around the poll) from dispatch (a task actually handed to a
worker); the heartbeat now reports only dispatched-and-not-yet-finished tasks.
Workers already call limiter.release() once per task, so every worker is
covered without per-worker changes.

CPU accuracy: cpu_pct was derived from /proc/self/stat, which counts only the
parent process. The CPU-bound workers offload their heavy work to
ProcessPoolExecutor children, whose CPU never appears in the parent's counters,
so those workers reported near-zero CPU while pegging cores. Read cgroup-wide
CPU accounting (cpu.stat usage_usec on v2, cpuacct.usage on v1) when running in
a container so pool children are included; fall back to /proc/self on a bare
host (where /sys/fs/cgroup is the whole machine). This is accurate under both
local Docker Compose and Kubernetes. Also report cpu_count (cgroup-limit aware)
so the top-style "% of a core" reading is interpretable in the dashboard.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016L2RdZQn1gJ1iHd5FN6Dwf
@maximusunc
maximusunc merged commit f73292d into main Jul 15, 2026
2 checks passed
@maximusunc
maximusunc deleted the claude/worker-monitor-updates-oa5dqh branch July 15, 2026 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants