Skip to content

feat(telemetry): rank CLI usage errors and propose fixes #4840

Description

@dan-petty

Problem or Motivation

A record alone does not tell what to fix. This plan ranked 1,737 errors by hand: 759 of 1,285 other-tool records (59%) follow a gh command form, and the top rows are a wrong group name (630), missing gh flags (--json 138, --search 53, --comments 42, --head and --base 41), missing commands (pr comment 42, pr status 27) and names of commands that exist under another name (roadmap show 25, openspec validate 20). No command repeats this ranking for a window, so the owner cannot see missing flags, features or aliases without a new manual study.

Tracker #4833, child 3. The owner asked on 2026-11-11 to fix the devops gh issue name and to record such errors for a later analysis of missing flags, features and aliases. The counts come from a study of Claude Code, Kilo, Antigravity and Loki records from 2026-09-23 to 2026-11-11.

Proposed Solution & Architectural Design

Add devops telemetry usage-errors with --since (default 7d), --until, --caller agent|person|ci|mcp|all, --source ledger|loki (default ledger), --limit and the house --format. It groups the records by kind, command path and name, and prints count, distinct days, callers, first and last date, Click's suggestion and one proposal class from fixed rules: alias_candidate (Click found a close declared name; an alias needs the owner's exception), flag_candidate (unknown option with no close name), feature_candidate (unknown command with no close name), help_candidate (missing or bad parameter), hinted (the hint table covers it) and resolved (the typed path resolves today through core/command_resolver.py). A row is a proposal only at 5 or more errors on 3 or more days; two settings hold these defaults. --source loki reads the cli_usage_error records through the existing Loki client with one topk query, and --dry-run lists that query and sends 0 requests. Register the dry-run class and the MCP mirror as for other commands (#3296). No model call.

Target Subsystem

SDLC, Git & PR Governance (CLI telemetry: a new devops telemetry usage-errors command).

Existing Tool Considered

The command reads the ledger of the capture child, the existing Loki client and core/command_resolver.py, and prints with the house --format. The study found no open tool that ranks Click usage errors and proposes a fix class. #2346 reads agent transcripts on one host for recurring problems of all kinds; this command reads the records of the CLI itself, so it needs no transcript and also covers the cluster Jobs.

Acceptance Criteria

On a fixture ledger of 40 lines, the table and the --format json output match a snapshot, rank by count and hold each proposal class at least once. A record outside the window does not count. An empty or missing ledger prints one line and exits 0. --source loki --dry-run prints 1 query and sends 0 requests. The command finishes in less than 2 s on a 4 MiB ledger.

Dependencies

Merge first: #4839.

Source: #4833

Alternatives check of 2026-11-27: partly.
Tool: getsentry/sentry (https://github.com/getsentry/sentry), NOASSERTION, last activity 2026-11-27, maintained.
Reason: Searches found no open tool that ranks Click usage errors into fix classes. Sentry, already in use, groups and counts error events with first and last seen dates, but lacks Click-specific proposal classes, ledger and Loki reading, and the house table.

Covers:

  • Groups repeated error events into issues by fingerprint or tag
  • Counts events per group with first and last seen dates
  • Filters and breaks down events by tags such as caller
  • Self-hosted ingest of custom error events through SDKs

Lacks:

  • No Click suggestion or proposal class such as alias or flag
  • No local JSONL ledger read, including rotated backups
  • No proposal threshold on count and distinct days
  • No LogQL dry-run query preview
  • No house --format table of ranked rows

Proposed design

Problem statement

The CLI records each usage error, but no command ranks the records. The owner cannot see missing flags, features or aliases without a manual study. This item adds devops telemetry usage-errors. The command groups the records over a window and assigns one proposal class to each group.

Acceptance criteria

Requirement: Command surface

devops telemetry usage-errors SHALL accept --since, --until, --caller, --source, --limit, --dry-run and the house --format, with --since defaulting to 7d, --until to now, --caller to all, --source to ledger and --limit to 30.

Scenario: Default options

  • WHEN The operator runs devops telemetry usage-errors with no options on the fixture ledger.
  • THEN The command reads the last 7 days up to now, includes every caller from the ledger, and prints at most 30 table rows.

Requirement: Row fields

Each output row SHALL hold count, distinct_days, callers, first_date, last_date, suggestion, proposal_class and is_proposal.

Scenario: JSON row

  • WHEN The command prints one group with --format json.
  • THEN The row holds the eight fields, and callers is a list.

Requirement: Grouping and ranking

The command SHALL group records by kind, command_path and name, and SHALL rank the groups by count in descending order.

Scenario: Rank by count

  • WHEN The fixture ledger holds 40 lines with repeated and single errors.
  • THEN The table and the --format json output match the snapshot, and each group with a higher count comes first.

Requirement: Proposal classes

The command SHALL assign exactly one class from alias_candidate, flag_candidate, feature_candidate, help_candidate, hinted and resolved to each group.

Scenario: Each class appears

  • WHEN The fixture ledger holds at least one record for each proposal class.
  • THEN The output holds each class at least once, and no group holds two classes.

Requirement: Proposal threshold

The command SHALL set is_proposal true only when a group holds at least 5 errors on at least 3 distinct days.

Scenario: Below threshold

  • WHEN One group holds 4 errors on 4 days and another group holds 5 errors on 2 days.
  • THEN Both rows hold is_proposal false, and both stay in the table with their counts.

Requirement: Window filter

The command SHALL exclude every record whose timestamp is outside --since and --until.

Scenario: Record outside the window

  • WHEN The ledger holds one record dated before --since.
  • THEN The record counts in no group and in no total.

Requirement: Caller filter

The command SHALL filter records by --caller with the values agent, person, ci, mcp and all.

Scenario: Agent only

  • WHEN The operator passes --caller agent.
  • THEN Only records with caller agent count.

Requirement: Rotated ledger files

The command SHALL read usage-errors.jsonl and each rotated backup of it in the user data root.

Scenario: Record in a rotated file

  • WHEN The fixture ledger holds a record in a rotated backup within the window.
  • THEN The record counts in its group.

Requirement: Row limit

The command SHALL print at most --limit rows, with a default of 30.

Scenario: Limit

  • WHEN The operator passes --limit 2 on a fixture ledger with three groups.
  • THEN The command prints the two groups with the highest counts.

Requirement: Empty ledger

The command SHALL print one line and exit 0 when the ledger is empty or missing.

Scenario: Missing ledger

  • WHEN The ledger file does not exist.
  • THEN The command prints one line and exits 0.

Requirement: Loki source

The command SHALL read cli_usage_error lines for the window through one execute_loki_query log query and SHALL aggregate them locally, applying --until and --caller to the returned entries.

Scenario: Loki aggregation

  • WHEN The fake Loki client returns two cli_usage_error lines with different callers.
  • THEN The command groups the two lines, applies the caller filter, and sends one query.

Requirement: Loki dry run

--source loki --dry-run SHALL print exactly one LogQL query and send 0 requests.

Scenario: Dry run

  • WHEN The operator runs devops telemetry usage-errors --source loki --dry-run.
  • THEN The command prints one query, and the Loki client receives 0 requests.

Requirement: Dry-run class and MCP row

The command SHALL declare the request-plan dry-run class and SHALL join CONST_MCP_EXPOSURE_TABLE as a read-only tool with JSON output.

Scenario: Registration

  • WHEN uv run pytest tests/invariants/test_dry_run_class_ratchet.py tests/ai/mcp/test_mcp_exposure_table.py runs.
  • THEN Both tests pass, and the table holds telemetry usage-errors as a read-only tool with JSON output.

Requirement: No model call

The command SHALL make no model call.

Scenario: No model call

  • WHEN A test replaces the AI client factory with one that fails, and runs the command on the fixture ledger.
  • THEN The command exits 0, and the factory is not called.

Requirement: Ledger performance

The command SHALL finish in less than 2 seconds on a 4 MiB ledger.

Scenario: 4 MiB ledger

  • WHEN The test writes a 4 MiB fixture ledger and runs the command.
  • THEN The command exits in less than 2 seconds.

Existing Tool Considered

The alternatives check in the issue body records in-use for getsentry/sentry (https://github.com/getsentry/sentry). The repository already uses this tool. The check holds the Covers: and Lacks: lists. The command builds the Click-specific part that Sentry lacks: local ledger or Loki grouping, six proposal classes, the house --format table and a dry-run query preview. Written cost: about 30k output tokens to build, about 4k tokens a month to keep and fix, and 2 days elapsed.

Key questions

  • Which dependencies does this item have?: None. The usage-error ledger is in src/devops_cli/telemetry/usage_errors.py, and the hint table is in src/devops_cli/core/usage_hints.yaml, at the refined commit. [sources: src/devops_cli/telemetry/usage_errors.py:87, src/devops_cli/core/usage_hints.yaml:1, tests/core/test_usage_hints.py]
  • Which record fields group the usage errors?: Group by kind, command_path and name. A record with no name groups under its command path. The record also holds suggestion, caller, agent_tool and version. [sources: src/devops_cli/telemetry/usage_errors.py:87, src/devops_cli/telemetry/usage_errors.py:97, src/devops_cli/telemetry/usage_errors.py:104, docs/TELEMETRY.md:249]
  • Which proposal class does each record kind get, and which class wins?: resolved wins when resolve_devops_argv reports no finding for the typed path. hinted wins when src/devops_cli/core/usage_hints.yaml covers the typed name. alias_candidate wins for a record with a suggestion. flag_candidate wins for unknown_option with no suggestion. feature_candidate wins for unknown_command with no suggestion. help_candidate wins for missing_argument, missing_option, extra_argument, bad_value and option_usage. A group takes the most frequent suggestion of its records. (best practice) [sources: src/devops_cli/telemetry/usage_errors.py:65, src/devops_cli/core/command_resolver.py:85, src/devops_cli/core/usage_hints.yaml:1]
  • Where do the two threshold settings live, and what are their defaults?: TelemetryConfig gets usage_errors_min_count with default 5 and usage_errors_min_days with default 3, beside usage_ledger. (best practice) [sources: src/devops_cli/config/settings.py:602]
    • Chosen: Two fields in TelemetryConfig. The body asks for two settings. The usage_* prefix matches usage_ledger.
    • Rejected: Hard-coded constants. The body asks for two settings.
    • Rejected: Command flags only. A flag changes one run, not the project default.
  • How does the command expose the proposal mark in a row?: Each row holds is_proposal. It is true only when the group holds at least usage_errors_min_count errors on at least usage_errors_min_days distinct days. A group below the threshold stays in the table with its count. (best practice) [sources: src/devops_cli/telemetry/usage_errors.py:92, src/devops_cli/config/settings.py:602]
    • Chosen: A boolean is_proposal on each row. The threshold needs a field that a test can read. The group stays in the table below the threshold.
    • Rejected: Drop a row below the threshold. The body says the group stays in the table with its count.
    • Rejected: A separate proposal list. The table and the JSON row would disagree.
  • How does --source loki read the records?: One LogQL log query through execute_loki_query reads the cli_usage_error lines for the --since window with a source limit high enough for the window. The command aggregates them locally. execute_loki_query sends since and limit only, so the command applies --until and --caller to the returned entries. A metric topk through query_loki_metrics is rejected: it returns counts only and cannot fill distinct_days, callers, first_date or last_date. --dry-run prints the one query and sends 0 requests. (best practice) [sources: src/devops_cli/k8s/logql.py:323, src/devops_cli/k8s/logql.py:391, tests/ai/mcp/test_k8s_logql.py]
    • Chosen: One log query through execute_loki_query with local aggregation. It returns the lines that hold every row field, and one dry-run query sends no request.
    • Rejected: One LogQL topk metric query through query_loki_metrics. A metric vector holds counts only, not distinct days, callers, first date or last date.
    • Rejected: One query per kind. It sends several requests and breaks the dry-run count.
    • Rejected: A local scrape of Loki. It adds a second client and a new dependency.
  • Which ledger files does the command read?: The current usage-errors.jsonl and each rotated backup of it in the user data root. The 7-day window can cross a rotation. (best practice) [sources: src/devops_cli/telemetry/usage_errors.py:250, docs/TELEMETRY.md:249, tests/telemetry/test_usage_errors.py]
    • Chosen: The current file and each rotated backup. The 7-day window can cross a rotation, and the 4 MiB target covers the rotated files.
    • Rejected: The current file only. It drops records that a rotation moved to a backup.
    • Rejected: The newest file only. The window can cross a rotation, so the newest file is not enough.
  • Which caller values does the command accept?: agent, person, ci, mcp and all. The record already holds caller with these values. [sources: src/devops_cli/telemetry/usage_errors.py:78, docs/TELEMETRY.md:249]
  • Which default does --limit take?: 30 rows, the default of the project's listing commands such as devops pr list. (best practice) [sources: src/devops_cli/config/defaults.py:603, src/devops_cli/commands/pr.py:241]
    • Chosen: 30 rows. It matches the listing commands and shows the lower-count classes.
    • Rejected: No limit. It prints every group of a 4 MiB ledger and hides the proposal rows.
    • Rejected: 10 rows. It hides the lower-count proposal classes of the study.
  • How does the command meet the 2-second target on a 4 MiB ledger?: It streams the ledger line by line and keeps only the groups of the window. The memory stays bounded. (best practice) [sources: src/devops_cli/telemetry/usage_errors.py:261, docs/TELEMETRY.md:249]
    • Chosen: Stream and aggregate. The ledger is one JSON line for each record, and the window limits the groups.
    • Rejected: Load the whole ledger. It holds every line in memory and misses the target on a large file.
    • Rejected: Read only the newest file. The window can cross the rotated files.
  • How is the command registered for dry run and MCP?: It declares the request-plan dry-run class. It joins CONST_MCP_EXPOSURE_TABLE as a read-only tool with JSON output. (best practice) [sources: src/devops_cli/config/constants.py:302, tests/invariants/test_dry_run_class_ratchet.py, tests/ai/mcp/test_mcp_exposure_table.py]
    • Chosen: Request-plan class and a read-only MCP row. The command reads the ledger, or Loki for one query, and the telemetry group already has read-only rows.
    • Rejected: No dry-run class. The dry-run ratchet refuses a command with no class.
    • Rejected: No MCP row. The body asks for the MCP mirror as for other commands.
  • Where do the grouping and the command live?: The grouping and the class rules go in a new module src/devops_cli/telemetry/usage_error_report.py. The command joins the telemetry group in src/devops_cli/commands/telemetry.py. The writer module usage_errors.py stays as it is. (best practice) [sources: src/devops_cli/telemetry/usage_errors.py:1, src/devops_cli/commands/telemetry.py:62]
    • Chosen: A new report module. The writer runs on each usage error and stays small. The report is a read-only concern with its own tests.
    • Rejected: Extend usage_errors.py. It mixes the writer on the error path with a report that reads a 4 MiB file.
    • Rejected: Put the rules in the command module. A second caller cannot import the command module without the CLI.
  • Does the command propose pass-through entries in this item?: No. The six classes of this item are the scope. The passthrough_candidate class, its precedence after hinted, the never-wrapped list and the API-route field go to feat(telemetry): propose pass-through entries from usage errors #6598 under feat(cli): track gh-parity names and usage-error capture #4833. feat(telemetry): propose pass-through entries from usage errors #6598 needs feat(cli): add the tool pass-through registry and its ADR #6597, the registry item of feat(cli): tool commands pass unknown arguments to the tool #5223. This item does not wait for feat(telemetry): propose pass-through entries from usage errors #6598. (best practice) [sources: src/devops_cli/telemetry/usage_errors.py:65, src/devops_cli/core/command_resolver.py:56]
  • Can the command name the API route field of an unknown option?: No. The record holds the command path and the typed name only. No argument value reaches the ledger, so the endpoint is not available. The part goes to feat(telemetry): propose pass-through entries from usage errors #6598. [sources: src/devops_cli/telemetry/usage_errors.py:87, src/devops_cli/telemetry/usage_errors.py:97]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    on Nov 11, 2026
  2. added
    type/feature
    scope/telemetry
    status/new
    value/medium
    effort/medium
    on Nov 11, 2026
  3. dan-petty commented on Nov 11, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/feature. The feat prefix of the title gives the type.
    • Scope: scope/telemetry. The (telemetry) scope of the title gives the scope.
    • Priority: P2-Medium. It improves the owner's ability to fix CLI errors but is not blocking and depends on #4839.
    • Value: Medium. It turns 1,737 raw error records into ranked proposals, saving the owner a manual study each cycle.
    • Effort: Medium. It adds one command with six options, rule-based classification, a Loki query path, and a dry-run, but reuses the existing ledger and resolver.
    • Related: feat(ai): add devops ai agent-audit for recurring problems #2346, which asks for a different change. Both find recurring problems in CLI usage, but #2346 reads agent transcripts while this command reads the CLI's own error ledger.
  4. devops-cli-service commented on Nov 11, 2026

    @devops-cli-service
    Contributor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Priority: P2-Medium. The command gives the owner visibility of missing flags, features and aliases, but it blocks no other work.
    • Value: Medium. The ranking shows the owner which errors to fix, and the fixes reach users through other items.
    • Effort: Medium. The work adds one command with grouping rules, two sources, a dry run and snapshot tests.
    • Related: feat(telemetry): record each CLI usage error by name and kind #4839, which asks for a different change. #4839 records each CLI usage error by name and kind; the candidate reads those records, ranks them and proposes fixes.
  5. added
    priority/p2-medium
    on Nov 11, 2026
  6. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor

    Link from #5164 (job grades for each agentic workflow). The owner wrote on 2026-11-12, word for word: "can we make the tools a bit more flexible to support common use cases? That should be part of the project self-improvement loop".

    #5180 ranks the refused and failing tool calls of the agentic runs (the counter of #5179) and proposes safe tool changes. It reuses the grouping, the proposal rules, the thresholds and the house --format of this item, so build them as one module that both sources call. The scope of this item does not change.

  7. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor

    Scope change for #5219 (the self-improvement section of the project review):

    • Add a reader kind that calls the grouping and the threshold of this item, for Table N-4 and loop.candidates of the section. The LogQL usage row of feat(roadmap): read project review facts through a catalog #4692 reads through it.
    • Print the devops-signal line (source usage_error, with path and name) for each proposal row, so the issue that a proposal becomes names its signal.

    #5219 does not wait for this item. This item adds its own rows to section self_improvement in its own pull request.

  8. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor

    Re-scope (owner direction of 2026-11-12). The title stays.

    New scope

    After #5223, a pass-through command gives its options to the tool, so devops records no usage error for them. The ranking changes as follows:

    • New proposal class passthrough_candidate: an unknown command under a group whose registry entries (core/passthrough.py) name a tool. An example is devops openspec validate before feat(openspec): openspec validate, list and show run openspec #5227. The proposal is a pass-through entry, not a new flag.
    • Precedence: hinted comes before passthrough_candidate. A command that the registry lists as never wrapped (pr merge, auth, secret set, repo delete, release) never gets passthrough_candidate. The ranking reads that list from the registry, so the two lists stay the same.
    • flag_candidate never names a pass-through command.
    • For an unknown option of an API command, the proposal names the query field or the body field of its route (API naming in ADR 0026).
    • The proposal threshold (5 errors on 3 days) also decides when a deferred tool group of ADR 0026 gets its pass-through item: k8s, kustomize, tf, uv, test, pipeline, docker sign|verify, the single-tool rows of devops ci, and the root aliases lint, format and tui.

    Acceptance Criteria (additions)

    • On the fixture ledger, a record of devops openspec validate, when no such command exists, gets passthrough_candidate.
    • A record of devops pr merge gets hinted, not passthrough_candidate.
    • No row names a pass-through path as flag_candidate.

    Dependencies

    Merge first: #5223 (the registry) and #4860 (the hint table). Open the pull request after the pull request of #5228 merges.

  9. 9 remaining items

  10. added
    status/ready
    and removed
    status/new
    on Nov 25, 2026
  11. devops-cli-service commented on Nov 25, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  12. devops-cli-service commented on Nov 27, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: in-use, tool https://github.com/getsentry/sentry. A person decides what the new result means for the item.

    Searches (7)

    Tools considered:

    Searches run:

    • Sentry group errors by tag count first seen last seen self-hosted, results: 5
    • open source tool rank CLI usage errors suggest missing flags aliases, results: 5
    • "usage error" analytics for python click commands unknown option tracking, results: 5
    • getsentry sentry self-hosted error grouping issue counts tags, results: 5
    • sentry docs issue grouping fingerprint first seen last seen event count, results: 5
    • posthog self-hosted product analytics event grouping open source, results: 5
    • Sentry error monitoring software features, results: 5

    Sources:

  13. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 28, 2026
  14. removed
    status/in-review
    owner/agent
    on Nov 28, 2026
  15. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-28 18:38 UTC

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

    effort/mediumpriority/p2-mediumscope/telemetrysource/agenttype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions