Skip to content

feat(roadmap): rank refused tool calls and propose safe tool changes #5180

Open

Description

@dan-petty

Part of #5164 (child 14).

Problem or Motivation

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

Facts on 2026-11-12 (Loki, implement runner Jobs, 24 hours):

  • Two runner pods (the implement attempts on test(warnings): Turn all warnings into errors with reasoned exceptions #1878 and refactor(ai): rank the benchmark with numpy and pytrec-eval #1928) logged 10 refused calls of run_command: program uv 4 times, git 2 times, and other:<digest> 4 times. The runner logs show the same 3 patterns in both runs: uv run python -c ... (inline Python, twice in each run), git status && git log ... (a chain of two allowed read-only commands, once in each run), and programs outside the allowlist.
  • logged_program (roadmap/implement/implement_tool_log.py) writes a program that is not in _KNOWN_PROGRAMS as other: and an HMAC digest with a key of the process. The key changes in each run, so the same program gives a different digest in each run. No count across runs can show which tool the model wanted.
  • Refusal hints exist (roadmap/implement/implement_shell_refusal.py, IMPLEMENT_SHELL_REPLACEMENTS). The model still repeats python -c in each run, so the hint does not fit that case.
  • The self-improvement loop (docs/SELF_IMPROVEMENT.md) learns from review verdicts. feat(telemetry): rank CLI usage errors and propose fixes #4840 ranks devops usage errors (cli_usage_error, feat(telemetry): record each CLI usage error by name and kind #4973) and proposes a fix class, at 5 or more errors on 3 or more days. No part of the loop ranks refused or failing tool calls.

Proposed Solution & Architectural Design

  • Safe category of a refused call. The runner logs, and the counter of feat(roadmap): count tool call errors by class for each workflow #5179 counts, a refusal key with no command text: the tool, the program (the name when it is in a widened list of common developer programs, else other), and the refusal reason (program_not_allowed, inline_code such as -c or -e, chain such as &&, ; or a pipe, argument_refused, path_refused, interactive). The digest stays only in the line of one run, for a drill-down.
  • Ranking. devops telemetry tool-refusals reuses the grouping, the thresholds and the house --format of feat(telemetry): rank CLI usage errors and propose fixes #4840. It ranks refusal keys and tool error classes (feat(roadmap): count tool call errors by class for each workflow #5179) by count, distinct days, distinct items and workflows. It gives one proposal class from fixed rules:
    • allowlist_candidate: an allowed-program chain or a program that is safe to allow.
    • narrow_tool_candidate: a use case that needs a new narrow tool (for example a short Python snippet in the same sandbox and limits).
    • split_candidate: a chain of allowed read-only commands that the runner can run as separate calls.
    • hint_candidate: a refusal that repeats after its hint, so the hint does not fit.
    • resolved: the key has had no refusal since a change merged.
  • Minimum data. A key is a proposal only at 10 or more refusals on 3 or more days in 3 or more items, after 14 days of data from feat(roadmap): count tool call errors by class for each workflow #5179. A few hours of data give no proposal (the owner rule for CLI usage errors).
  • Proposal to change. A proposal becomes one issue through the fingerprint module (feat(roadmap): file, update and close finding issues by fingerprint #5153), with the evidence (counts, days, items, the grade of each workflow). Each change to the shell allowlist gets its own security review before a build (owner decision 5 of the generalization plan, feat(roadmap): track one project profile for all repositories #4627). No proposal changes the allowlist by itself.
  • Trial. After a change merges, the release compare (feat(roadmap): find a success or efficiency change after a release #5175) checks the result: the refusal rate of the key falls, and the success and first-pass ratios of the workflow do not fall. A worse result reverts the change by a pull request.
  • First candidates for the loop to rank (each needs its own security look): run a chain of allowed read-only commands as separate calls, or allow && between allowlisted read-only programs; a narrow way to run a short Python snippet in the same sandbox (a test run already runs repository code, so measure what python -c adds); widen the known-program list of the log.
  • docs/SELF_IMPROVEMENT.md gets a section on tool refusals in the loop.

Target Subsystem

SDLC, Git & PR Governance (src/devops_cli/roadmap/implement/, the CLI telemetry commands) and Security & Vulnerability Scanners (the shell allowlist review).

Existing Tool Considered

#4840 builds the ranking and the proposal rules for CLI usage errors; this item reuses them for tool refusals. The pydantic-ai tool wrappers give no ranking. No open tool ranks the refused commands of an agent sandbox. Custom code: the refusal key (about 80 lines) and the ranking source (about 150 lines). Cost: about 300,000 tokens, 7 hours elapsed, then 14 days of data before the first proposal.

Acceptance Criteria

  • A refused uv run python -c ... call gives the key run_command, uv, inline_code, and the log holds no word of the command after the program.
  • A refused git status && git log call gives the key run_command, git, chain.
  • An unknown program gives other in the key, and two runs give the same key.
  • On a fixture of 14 days, a key with 12 refusals on 4 days in 3 items gives one proposal row with its class. A key with 12 refusals on 1 day gives none.
  • --dry-run sends 0 requests.

Dependencies

#5179 (the tool error counter), #4840 (the ranking rules), #5153 (the fingerprint module), #5175 (the release compare).

Alternatives check of 2026-11-19: in-use.
The repository already uses this tool.
Tool: grafana/loki (https://github.com/grafana/loki), AGPL-3.0, last activity 2026-11-19, maintained.
Reason: Searches found only log and agent-observability stacks plus a research architecture; Loki, which the project runs, counts and groups refusal lines by labels, but no open tool ranks refusal keys by the data minimum or drafts allowlist proposals.

Covers:

  • Counts refusal lines by label across runs
  • Groups log lines by parsed program and reason fields
  • Keeps the multi-day history the ranking reads

Lacks:

  • Refusal key of gate, program, source and rule
  • Proposal classes with the data minimum per key
  • Draft allowlist entry with match and not_match examples
  • Filing proposal issues with a devops-signal line

Proposed design

Problem statement

The implement step refuses no tool call since #6527: it runs the stock harness Shell with no allowed command, no denied command and no refusal wrapper, so the refusal key, the refusal reasons and the shell allowlist that this item was to rank and widen no longer exist. What a step still leaves is the line of each tool call in the Job log (the tool, the program, the outcome and a masked retry reason), and no part of the self-improvement loop ranks those failing calls across runs; the per-process other:<digest> of the log also stops a count from crossing runs. Build devops telemetry tool-errors to rank the failing tool calls by tool, program and tool error class, apply the #4840 data minimum, and file one proposal issue (a hint or a narrow tool) through the fingerprint module, without changing any control. The trial of a merged change waits on #5175 and is deferred.

Acceptance criteria

Requirement: Command registration

devops telemetry tool-errors SHALL be a registered command of the telemetry group.

Scenario: Help output

  • WHEN A test runs uv run devops telemetry tool-errors --help.
  • THEN The command exits 0 and prints the --format and --dry-run options.

Requirement: Grouping by tool error key

The command SHALL group the tool lines of the implement step by tool, program or other, and tool error class.

Scenario: Two lines share one key

  • WHEN A fixture holds two lines with the same tool, program and class, and a third line with a different class.
  • THEN The output holds two rows, and the shared row holds count 2.

Requirement: Stable program name

The key SHALL hold the name of a program in the runner tool table and other for any other program, the same in every run.

Scenario: Unknown program across two runs

  • WHEN A fixture holds one line for git and one line for other:1a2b3c4d5e6f from another run.
  • THEN The output holds program git and program other, and the two runs give the same key.

Requirement: Tool error class of a failing call

The command SHALL give the class exit_status with the status, timeout, retry or repeat from the record that #5179 writes.

Scenario: One call of each class

  • WHEN A fixture holds a run_command that ended with [exit code: 1], one that ran past its wait, one retry and one repeated failed call.
  • THEN The output holds four rows with the classes exit_status with status 1, timeout, retry and repeat.

Requirement: Masked reason evidence

The command SHALL use the masked text of a retry reason and SHALL NOT read an unmasked command.

Scenario: Retry with a masked reason

  • WHEN A fixture holds a retry line with a masked reason and no unmasked command.
  • THEN The retry row holds the masked reason and no command text.

Requirement: Data minimum

The command SHALL give one proposal row at 10 or more tool errors on 3 or more days in 3 or more items after 14 days of data.

Scenario: 14-day fixture meets the minimum

  • WHEN A 14-day fixture holds one key with 12 errors on 4 days in 3 items.
  • THEN The output holds one proposal row for the key with its class.

Requirement: One day gives no proposal

The command SHALL NOT give a proposal row for a key with 12 tool errors on 1 day.

Scenario: One day of errors

  • WHEN A fixture holds a key with 12 errors on 1 day in 3 items.
  • THEN The output holds no proposal row for the key.

Requirement: Proposal classes

The command SHALL give hint_candidate for a key that repeats after the hint that addresses it, narrow_tool_candidate for a use case that needs a tool the step lacks, and resolved for a key with no error since a change merges.

Scenario: One key of each class

  • WHEN A 14-day fixture holds a key that repeats after its hint, a key whose masked shape is a command form that the step has no tool for, and a key with a merge date and no error after it.
  • THEN The output holds one hint_candidate row, one narrow_tool_candidate row and one resolved row.

Requirement: Ranking order

The command SHALL rank rows by count, then distinct days, then distinct items, then distinct workflows.

Scenario: Higher count ranks first

  • WHEN A 14-day fixture holds one key with 12 errors on 4 days in 3 items and one key with 10 errors on 3 days in 3 items.
  • THEN The output lists the 12-error row before the 10-error row.

Requirement: Dry run sends no request

devops telemetry tool-errors --dry-run SHALL send 0 requests.

Scenario: Dry run with a fixture

  • WHEN The command runs with --dry-run on a fixture and a request spy.
  • THEN The request spy records 0 requests, and the command prints each LogQL query that a run would send.

Requirement: House format

devops telemetry tool-errors SHALL use the --format of #4840.

Scenario: JSON format

  • WHEN The command runs with --format json on a fixture.
  • THEN The output is valid JSON with one object for each ranked key.

Requirement: Proposal issue evidence and signal

Each proposal issue SHALL hold the count, distinct days, distinct items, the grade of each workflow, and a devops-signal line with source tool_error, the tool, the program and the class.

Scenario: Filed proposal issue body

  • WHEN The command files one proposal issue from a fixture with a workflow grade.
  • THEN The issue body holds the count, distinct days, distinct items, the workflow grade, and a devops-signal line with source tool_error, the tool, the program and the class.

Requirement: Proposal fingerprint

The command SHALL file one proposal issue through the fingerprint module of #5153.

Scenario: Second run files no duplicate

  • WHEN The command runs twice on the same fixture.
  • THEN The fingerprint module receives one proposal, and the command files one issue.

Requirement: Known class share

The command SHALL report the share of tool lines with a known error class and SHALL NOT rank a line with no error.

Scenario: Line with no error

  • WHEN A fixture holds one retry line and one line of a call that returned.
  • THEN The output reports 1 of 2 lines with a known class and holds one ranked row.

Requirement: No control change

A proposal SHALL NOT change a shell control, a setting or the code of the project; the command SHALL file one issue.

Scenario: Proposal generation

  • WHEN The command runs on a fixture that meets the minimum, with a proposal writer spy and a digest of the source tree.
  • THEN The proposal writer records 1 call, and the source tree digest is the same after the run.

Requirement: Self-improvement document

docs/SELF_IMPROVEMENT.md SHALL have a section that names devops telemetry tool-errors in the loop.

Scenario: Docs row

  • WHEN uv run devops ci --check --only docs runs.
  • THEN The docs row exits 0 and reports no broken link and no stale generated page for docs/SELF_IMPROVEMENT.md.

Existing Tool Considered

Grafana Loki (https://github.com/grafana/loki), AGPL-3.0 and maintained, is the tool that the alternatives check of 2026-11-19 records as in-use: the project runs it, and it counts and groups the tool lines of the Job pods across runs and keeps the multi-day history that the ranking reads. The Lacks: list of the block of that check in the issue body names what it does not do, and this item adds exactly that. The command reads Loki through the same LogQL metric instant queries as devops roadmap eval grades, with --dry-run printing each query and sending no request (docs/roadmap/job-success.md:68), and the test uses LokiFake (tests/support/fakes/loki.py:295).

Key questions

  • Which refusal reasons have a known class?: None: no code produces a refusal reason at this commit. Since refactor(roadmap): run implement on stock Coder with a real shell #6527 the implement step runs the stock harness Shell with allowed_commands=[], denied_commands=[], denied_operators=[] and no refusal wrapper, so every program of the runner image runs, and implement_shell_policy.py and implement_shell_refusal.py are deleted. The tool log records an outcome (ok, refused for a repeated failed call, retry, failed) and a masked retry reason, and no gate, program-and-rule refusal key. [sources: src/devops_cli/roadmap/implement/implement_shell.py:59, docs/ROADMAP_WORKFLOW.md:314, src/devops_cli/roadmap/implement/implement_tool_log.py:100]
  • Which key and proposal classes does the ranking use?: The key is (tool, program or other, class), where the class is the tool error class of feat(roadmap): count tool call errors by class for each workflow #5179 (exit_status with the status, timeout, retry, repeat). The proposal classes are hint_candidate (a key repeats after the hint that addresses it), narrow_tool_candidate (the masked shape is a command form that the step has no tool for, such as a chain or a heredoc) and resolved (no error since a change merged). allowlist_candidate and split_candidate are gone, because the step has no allowlist to widen and no chain refusal to split. (best practice) [sources: src/devops_cli/roadmap/implement/implement_tool_log.py:434, src/devops_cli/roadmap/implement/implement_tool_log.py:100, docs/ROADMAP_WORKFLOW.md:314]
  • Where does the command read the tool lines?: From Loki, with LogQL metric instant queries over the streams of the Job pods, as devops roadmap eval grades reads the result lines: --dry-run prints each query and sends no request, and the test serves the queries with LokiFake. The trace is no source, because it stays in the job record and not in a store that a command can count. (best practice) [sources: docs/roadmap/job-success.md:68, tests/support/fakes/loki.py:295, src/devops_cli/roadmap/implement/implement_trace.py:1]
    • Chosen: Read Loki with LogQL instant queries. The Job log is the only evidence of a step, Loki keeps it for days, and the house reader already counts and groups such lines.
    • Rejected: Read a local ledger under the user data root. A Job pod discards its checkout and its local files, so no ledger survives the run.
    • Rejected: Read the implement trace. The trace stays in the job record of one run and holds no store to count across runs.
  • How does the key name a program that is not in the common list?: The key holds the clear name for a program in the fixed runner tool table and other for any other program. The HMAC digest of the process stays only in the line of one run, for a drill-down, so the same program gives the same key in every run. (best practice) [sources: src/devops_cli/roadmap/implement/implement_tool_log.py:84, src/devops_cli/roadmap/implement/implement_tool_log.py:158]
    • Chosen: Runner tool name plus other. The same program gives the same key across runs, and the digest still names it inside one run.
    • Rejected: Keep the per-process digest in the key. The key changes in each run and no count can cross runs.
  • What data minimum makes a proposal?: A key needs 10 or more errors on 3 or more days in 3 or more items, after 14 days of data. The tests use 12 errors on 4 days in 3 items, and 12 errors on 1 day gives no proposal. This is the owner rule of feat(telemetry): rank CLI usage errors and propose fixes #4840 for CLI usage errors, reused here. (best practice) [sources: docs/guidelines/agentic-jobs.md:208, docs/guidelines/agentic-jobs.md:230]
  • How does the ranking use command text?: The ranking reads the masked text that the log keeps (the masked retry reason and the masked command shape) and never an unmasked command. The key holds no command text; the masked shape only decides between hint_candidate and narrow_tool_candidate. (best practice) [sources: src/devops_cli/roadmap/implement/implement_tool_log.py:196, src/devops_cli/roadmap/implement/implement_tool_log.py:283, docs/TELEMETRY.md:254]
    • Chosen: Use the masked text only. The kept masked text is the evidence, and the house telemetry rule keeps a command line and an argument value out of a record.
    • Rejected: Store the full command for ranking. It puts private command text in the log and breaks the masking rule.
  • Does the command change a shell control?: No. The step has no allowlist, no denied command and no refusal wrapper since refactor(roadmap): run implement on stock Coder with a real shell #6527, so the command files one issue with the evidence and writes no code and no setting. A security control gets no tuning pass from a ranking rule. (best practice) [sources: docs/guidelines/agentic-jobs.md:237, src/devops_cli/roadmap/implement/implement_shell.py:59]
    • Chosen: File one proposal issue. The command proposes a hint or a tool, and a person decides the change in the issue.
    • Rejected: Change the shell directly. There is no allowlist to change, and a ranking rule must not widen a control.
  • What is the command called?: devops telemetry tool-errors, a new command of the existing telemetry group. tool-refusals would name data that no longer exists. (best practice) [sources: docs/ROADMAP_WORKFLOW.md:314, docs/CLI_REFERENCE.md:408]
    • Chosen: devops telemetry tool-errors. The name states the data that the command ranks.
    • Rejected: Keep devops telemetry tool-refusals. The step refuses nothing, so the name promises a key and a class that no run writes.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

#6521, #5179, #4840, #5153

Activity

  1. added
    type/feature
    source/agent
    scope/roadmap
    status/new
    value/medium
    effort/high
    on Nov 12, 2026
  2. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor
  3. added
    priority/p2-medium
    on Nov 12, 2026
  4. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor

    The command gate plan (tracker #5199) changes the scope of this item.

    What moves out: #5201 now makes the refusal key (gate, program or other, source, entry or rule id) and the wider known-program list. This item keeps the ranking and the proposals.

    New scope:

    Dependencies: #5179 (after its update) and #5206.

    Acceptance to add:

    1. On a 14-day fixture, a key with 12 continue answers on 4 days in 3 items, no flag, and a labelled sample of 0 dangerous gives one allowlist_candidate. Its draft entry passes the load check and has no ** after a network or write program.
    2. The same key with no labelled sample gives no allowlist_candidate.
    3. A key with 3 flag answers gives one blocklist_candidate.
    4. Real transcripts, before the merge: the ranking over the refusal lines of the 7 days after the deploy of feat(roadmap): check shell commands with a parser and configured lists #5201 lists its top 5 keys with counts in the pull request comment.
  5. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor

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

    • Write a devops-signal line (source tool_refusal, with tool, program and reason) in each proposal issue that this item files, so the review can measure the effect of each tool change.
    • Add Table N-6 (refused tool calls and their proposals) to section self_improvement.

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

  6. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor

    New evidence of 2026-11-13 (review of failing jobs): 50 of 71 refusals cannot be explained or ranked from the log today.

    • Loki, implement runner, 17 runs, 2026-11-10 to 2026-11-13: Tool call: run_command, program git, refused. holds no operator and no reason, so it looks like a ban of git. In fact 322 of 339 git calls passed, and the refusals were for && and |.
    • 23 program other:<digest> refusals in 10 runs with 16 different digests. The per-process HMAC (src/devops_cli/roadmap/implement/implement_tool_log.py, near lines 170-181 and 498-502) hides common harmless words.

    Scope points for the refusal key of this item:

    1. The log line adds the refusal class (operator with its symbol, not_allowed, replacement, inline_code) and the exit status of an allowed call.
    2. The first word goes in clear text when it is in one fixed list of common programs: sed, awk, echo, mkdir, rm, cp, mv, sort, diff, xargs, bash, sh, env, timeout, printf, jq, which, openspec, devops. All other words keep the digest, so no private name goes in clear text.

    #5452 fixes the hint text for the two largest classes (python -c with ;, and chains of allowed programs) now. This ranking then shows if the new hints work.

    Measure: the share of refusals with a known class goes to 100%.

  7. dan-petty commented on Nov 13, 2026

    @dan-petty
    OwnerAuthor

    New counts of refused runner calls, from the start-context review of the roadmap jobs (2026-11-13). Loki, job="devops/runner", names and counts only.

    Since the run_command prompt (2026-11-12 04:00Z to 2026-11-13 16:00Z, n = 10 runs): 47 refused calls. By program: unknown program (logged as other) 19, uv 18, git 9, openspec 1.

    The 7 days before (45 runs, 35 of them before the new prompt): 212 refused calls in 43 of 45 runs (median 4, max 15):

    Cause Calls Runs
    uv run python -c with ; or a new line 79 29
    unknown program (digest) 52 26
    chains (&&, ;, ||), mostly git status && git log at the start 51 32
    heredoc 11
    pipe 11

    24 of the 79 python -c refusals came again with the same cause in the same streak. limit_reached occurred 16 times in 7 days. The share of these stops that refusals caused is not known; #5460 adds the limit class.

    Proposals for this item:

    • A refusal row for python -c with ; or a new line. It names the correct form: write a script file and run it. No alias of the wrong form.
    • Rows for the common POSIX words (sed, awk, echo). Each row names the tool that does the job (edit_file, read_file, grep).
    • Log a fixed list of common POSIX program names in place of the digest other. Names only.
    • feat(roadmap): the implement step message states the checkout state #5468 gives the checkout state at step start, which removes the main cause of the chain refusals.
    • The refusal table is about 180 tokens today. The new rows add about 30-60.

    Measure: refusals for each run by cause, same-cause streaks, and limit_reached by limit class. The baseline since 2026-11-12 has n = 10; extend the window until n is at least 30 runs.

  8. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    Refine cannot set this item to Ready at 8ccd95a while the items below stay open. The next refine round looks at the item again when they close, or when a person replies in a comment or edits the body.

    The next refine round also looks at the item again when a commit on the default branch changes one of these files: src/devops_cli/roadmap/implement/implement_tool_log.py.

  9. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.

    Searches (9)

    Tools considered:

    Searches run:

    • LLM agent observability tool call error grouping refusals analytics open source, results: 5
    • open source tool rank refused agent sandbox tool calls and propose allowlist changes, results: 5
    • Langfuse LLM observability tool calls error rates dashboards, results: 5
    • Open Policy Agent decision logs count policy denials by rule, results: 5
    • Grafana Loki LogQL count log lines by label, results: 5
    • Langfuse, results: 5
    • analyze agent command denials propose allowlist rules from logs open source, results: 5
    • sandbox shell allowlist tuning telemetry denied commands tool, results: 5
    • LogQL parse regexp count by label Grafana Loki documentation, results: 5

    Sources:

  10. devops-cli-service commented on Nov 19, 2026

    @devops-cli-service
    Contributor

    Next step: the open items close, or a person replies in a comment or edits the body. See Dependencies in the section Proposed design of the body.

  11. dan-petty commented on Nov 20, 2026

    @dan-petty
    OwnerAuthor

    Frozen on 2026-11-20. The stage, implement and fix-checks jobs grade under 60%, so the owner rule asks for a re-architecture before more fixes inside the current design (tracker #6519). This item is incremental work on those jobs, so its Dependencies section now names #6521 first. Stage and implement leave this item while #6521 is open. When the experiments of #6519 decide, a person closes #6521 (this item can then continue) or closes this item as not planned.

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

    @devops-cli-service
    Contributor

    Next step: the open items close, or a person replies in a comment or edits the body. See Dependencies in the section Proposed design of the body.

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/roadmapsource/agentstatus/newtype/featurevalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions