diagnose

diagnose is a command for coding agents from themoah/klag. It costs 25 tokens per session (868 once invoked), scanned A, original, Apache-2.0.

A command for investigating Kafka consumer lag with a running Klag installation. Kafka is a system that stores ordered streams of messages, and consumer lag is the amount of work a consumer group has not yet processed.

In plain words
What is it for?
Use it to inspect a whole Kafka cluster or named group, review per-partition lag, and assess velocity, time to catch up, commit staleness, trends, and retention risk.
Why use it?
It ranks delayed consumer groups and reports likely causes while warning when the monitoring snapshot is too old to trust.

Command

Part of the klag plugin — 1 skill, 3 commands shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/themoah/klag/diagnose
Clone the repo
git clone --depth 1 https://github.com/themoah/klag

Or install klag, the plugin that ships this one along with the rest of its 1 skill, 3 commands.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for diagnose

README.md
[![agentmods](https://agentmods.dev/badge/commands/themoah/klag/diagnose.svg)](https://agentmods.dev/commands/themoah/klag/diagnose)
Your own site
<a href="https://agentmods.dev/commands/themoah/klag/diagnose"><img src="https://agentmods.dev/badge/commands/themoah/klag/diagnose.svg" alt="Measured on agentmods" height="20"></a>
Per session 25 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 868 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00025 $0.00868
Opus 5 $0.00013 $0.00434
Sonnet 5 $0.00005 $0.00174
Haiku 4.5 $0.00003 $0.00087

Measured 4d ago against content hash ff3017d55b4f, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

diagnose scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

curl -s <klag>/metrics | grep -E '^klag_consumer_lag(_sum)?\{|^klag_consumer_commit_staleness_seconds|^klag_consumer_lag_retention_percent|^klag_consumer_group_state|^klag_consumer_lag_velocity'
plugin/commands/diagnose.md · 62 lines

How it starts

The opening of the file, as written. The whole thing — 62 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Triage consumer lag with the user's running Klag. Group: $ARGUMENTS (empty = whole cluster).

Prefer the MCP tools. If the klag MCP server is not registered in this session, say so, fall back to scraping /metrics, and point at /klag:connect.

Path A — MCP (preferred)

  1. find_lagging_groups (sortBy: lag | velocity | retention, limit) for the cluster view, or go straight to the named group.
  2. diagnose <group> — returns severity (OK | INFO | WARNING | CRITICAL), a summary, and findings[] of {severity, title, detail}.
  3. get_consumer_group_lag <group> when you need per-partition detail. Response keys: partitions[] (lag, committedOffset, logEndOffset, logStartOffset), velocity, lagMs, timeToClose, retentionRisk, trends, overallTrend, recentTransitions, commitStalenessSeconds. Read the keys off the response rather than assuming — this list is a convenience, the server is the authority.

Check snapshotAgeMs in the response. Anything much older than METRICS_INTERVAL_MS means you are reading a stale picture — say so rather than diagnosing confidently off it.

Path B — no MCP

curl -s <klag>/metrics | grep -E '^klag_consumer_lag(_sum)?\{|^klag_consumer_commit_staleness_seconds|^klag_consumer_lag_retention_percent|^klag_consumer_group_state|^klag_consumer_lag_velocity'

Same reasoning, less structure. Note in your answer that MCP would give a better one.

Reading the result

Map findings to causes, worst first:

Signal Reading
state dead group gone — consumers crashed or never restarted. Look at the app, not Kafka.
state empty + lag nobody consuming; work is piling up.
commitStalenessSeconds high while lag > 0 stuck consumer: alive but not advancing — poison message, wedged handler, or a blocked downstream. Lag alone misses this.
many recentTransitions rebalance storm / flapping: max.poll.interval.ms too low, slow processing, or unstable pods.
retention_percent climbing toward 100 data loss risk — messages will expire unread. This outranks raw lag size.
lag growing, velocity positive producers outpace consumers: scale out, or the partition count caps parallelism.
hot partition skewed keys, not a consumer problem — repartition or change the key.
under-replicated partitions broker-side fault tolerance loss, unrelated to the consumer.

Read the full file on GitHub · 62 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 62 lines · 25 tokens per session scan A ff3017d55b4f

Subscribe to this mod's changes

diagnose is a command published in the GitHub repository themoah/klag (82 stars, last pushed 3d ago), licensed Apache-2.0. It adds 25 tokens to every session and 868 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.