Skip to content

feat(telemetry): record each CLI usage error by name and kind #4839

Closed

Description

@dan-petty

Problem or Motivation

No record shows which names people and agents try and fail. _delegate (src/devops_cli/main.py:187) records only the error class (#2024) and devops_cli_command_total{status=error}: no command path, no kind, no typed name. A help query (main.py:122) and a dry run (core/cli.py:146-148) record nothing. To find the 1,737 usage errors in 230 forms for this plan, agents had to read 4,338 Claude Code transcripts, the Kilo store, the Antigravity logs and Loki by hand. The Loki records of the implement Jobs were only inferred, because the Job log shows no exit status.

Tracker #4833, child 2. 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

Premise check (Feasibility section): Typer 0.27.2 vendors Click as typer._click and exports only BadParameter and TyperException; Click raises a plain UsageError for an unknown command and for extra arguments; record which environment markers Kilo and Antigravity set (Claude Code sets AI_AGENT, CLAUDECODE and CLAUDE_CODE_ENTRYPOINT). Rule 3: check PyPI for a maintained port of @vercel/detect-agent; if there is none, keep its marker list as data and write the cost in the issue. Hook: give the root app (main.py:87) a TyperGroup subclass as cls; it catches the vendored UsageError except NoArgsIsHelpError, records it and raises it again, so the printed error and exit code 2 stay the same. The CLI, help queries and the MCP dispatcher all pass this group. new_typer (core/cli.py:244) sets a default group class whose resolve_command tags unknown_command with the typed word and the difflib close match that Typer also uses, and a command class whose parse_args tags extra_argument. Map the other kinds from Click's types in one module (imported from typer._click.exceptions): NoSuchOption unknown_option, MissingParameter missing_argument or missing_option, BadParameter bad_value, BadOptionUsage option_usage, else other. Read no message text. The dry-run branch (core/cli.py:146-148) raises the error again. Fields: kind; command_path (exc.ctx.command_path without the program name); name (typed word, NoSuchOption.option_name or param.name; <value> when mask_secrets changes it, when it is longer than 40 characters or when it is not a CLI name of letters, digits, - and _); suggestion; caller (agent when AI_AGENT or a known tool marker is set, mcp from a context variable that the dispatcher sets, ci from CI or GITHUB_ACTIONS, else person); agent_tool from a data table (claude_code, gemini_cli, codex, cursor, kilo, opencode, antigravity, devops_implement, other); the devops version. The implement runner exports AI_AGENT=devops-implement. Sinks: counter devops_cli_usage_error_total through emit() and the OtlpExporter seam (#1319) with the labels kind, command_path and caller only; one structured record cli_usage_error on logger devops_cli.usage that logging_bridge exports and that never prints to the console; the same record as one JSON line in <user data root>/usage-errors.jsonl through the stdlib RotatingFileHandler (1 MiB, 3 backups). The setting telemetry.usage_ledger (default true) turns the file off. A ledger write error prints one warning and keeps exit code 2. Never record exc.message, argv, option values, bodies, paths, hosts or user names. Add the metric to the generated metrics reference.

Target Subsystem

SDLC, Git & PR Governance (CLI telemetry: src/devops_cli/main.py, src/devops_cli/core/cli.py).

Existing Tool Considered

Click's own exception types (vendored by Typer 0.27.2 as typer._click) give the kind, and Click's difflib match gives the suggestion. The stdlib logging module with RotatingFileHandler writes the ledger. The OtlpExporter seam (#1319) and emit() send the counter. mask_secrets decides <value>. The @vercel/detect-agent marker list gives the caller kind: use a maintained PyPI port if one exists; else keep its marker list as data and write the cost here. The study found no open tool that records Click usage errors; the hook is one group class on these parts.

Acceptance Criteria

Tests with DEVOPS_CLI_USER_DATA_ROOT in a temporary directory, one per kind: an unknown group word under devops gh writes one ledger line with kind unknown_command, command_path gh, the typed name and Click's suggestion; an unknown option on devops pr view gives unknown_option and command_path pr view; devops pr describe with no input gives missing_argument; an extra argument gives extra_argument; a text value for an int option gives bad_value with the parameter name. A token-shaped value, a number and a path in the command position each record <value>, and a test checks that no ledger line, log record or counter label holds any argument value of the call. The same error through --help, through --dry-run and through the MCP dispatcher (caller mcp) records one line each. stderr and exit code 2 are the same as before the change (snapshot). With AI_AGENT set the caller is agent; with no marker it is person. The counter has only the labels kind, command_path and caller. The CLI start-time test stays in its budget.

Dependencies

None. An agent can start it now.

Source: #4833

Activity

  1. added
    source/agent
    on Nov 11, 2026
  2. added
    type/feature
    scope/telemetry
    status/new
    value/medium
    on Nov 11, 2026
  3. added
    effort/high
    on Nov 11, 2026
  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.

    • Scope: scope/telemetry. The (telemetry) scope of the title gives the scope.
    • Priority: P2-Medium. The owner asked for this record, but it enables a later analysis and blocks no user command.
    • Value: Medium. The records show which names and flags users miss, but they change no command output for users.
    • Effort: High. The change adds a TyperGroup subclass, Click exception mapping, a metric, a log record, a rotating file sink and a setting.
    • Related: feat(gh): name the gh groups issue, run, label and secret #4835, which asks for a different change. Both items are children of tracker #4833 and use the same study of usage errors. Item 4835 renames the gh groups, but the candidate records each usage error.
  5. 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 observability for planning but does not block a user workflow or fix a defect.
    • Value: Medium. It replaces manual transcript reading with structured records, aiding feature and alias planning.
    • Effort: High. It requires a TyperGroup subclass, Click exception mapping, three sinks, environment detection, and a rotating file handler.
    • Related: fix(cli): every command reports a DevOpsCLIError through one exit seam, with its exit status and no traceback #2487, which asks for a different change. Both deal with CLI error handling, but #2487 fixes how errors are reported to the user (exit code, no traceback) while the candidate adds structured telemetry recording of those errors for later analysis.
  6. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/new
    status/in-progress
    on Nov 12, 2026
  7. removed
    status/in-review
    owner/agent
    on Nov 12, 2026
  8. devops-cli-service commented on Nov 12, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-12 12:40 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/highpriority/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