Skip to content

fix(roadmap): implement refusal hints fit the refused command #5452

Closed

Description

@dan-petty

Problem Description

The implement step answers a refused shell command with a hint that does not fit the refused form, and the hint names a directory that does not exist. The model then sends the same form again, or it stops after 3 refusals in a row.

Evidence (Loki, implement runner, 17 runs, 2026-11-10 to 2026-11-13):

  • 71 refusals in 1,231 shell calls (5.8%) in 14 runs. python -c code with ; or a new line: 27 in 10 runs. git with &&: 15, and with | to a program that is not allowed: 2, in 9 runs. ls with ;: 2.
  • git itself is allowed: 322 of 339 git calls passed.
  • After a python -c refusal, the model sent the same form again in 17 of 27 cases (7 of them were refused again). After a git ... && refusal, it sent read_file 9 times and one git command only 2 times.
  • An earlier review counted 175 refusals in 4,823 shell calls in 37 of 37 runs, and 13 stops after 3 refusals in a row. Each stop loses a full paid run.
  • 14 uv run python -c '...mkdir...' calls in 9 runs, 13 of them followed by a passing write_file. 3 write_file retries with "Parent directory ... does not exist" in 3 runs.

Causes in the code on main (0.129.1):

  • refusal_hint (src/devops_cli/roadmap/implement/implement_shell_refusal.py, lines 52-62) selects the text from the first word only. So uv run python -c with ; and git status && git log get the same text, implement_refusal_operator (src/devops_cli/lang/en/messages.py, lines 3223-3229). That text starts with "Run one command in each call. Do not chain commands", and the instruction about the file comes last.
  • That text, and the prompt, send the model to .data/agent/scratch/. A fresh checkout does not have this directory.
  • The step offers read_file, write_file, edit_file, list_files, grep and run_command (IMPLEMENT_LOCAL_TOOL_NAMES, src/devops_cli/roadmap/implement/implement_step.py, line 641). It leaves out the create_directory tool of pydantic-ai-harness 0.59.0, which the lock file already holds.
  • src/devops_cli/ai/tasks/roadmap_implement_step.md, lines 40 and 59, tell the model to make a directory with uv run python -c '...mkdir...'. So the 14 mkdir calls follow the prompt.
  • The pipe refusal names head, tail, grep and wc, not read_file with offset and limit.

Expected vs Actual Behavior

Expected: the hint names the exact next call for the refused form, and every path that it names exists. Actual: one generic text for all operator refusals, and a missing directory.

Proposed Solution

  • The job makes .data/agent/scratch/ (git-ignored) in the checkout before step 1.
  • The step offers the harness tool create_directory. Change lines 40 and 59 of roadmap_implement_step.md to name create_directory, and remove the python -c mkdir text.
  • refusal_hint selects the text from the refused form, not only from the first word:
    • python -c with ;, a new line or a heredoc: "Write the code with write_file to .data/agent/scratch/<name>.py, then run uv run python .data/agent/scratch/<name>.py." This text comes first.
    • A chain with && or ; of allowed programs: "Send each command as its own call, for example git status --short, then git log --oneline -5."
    • A pipe to a program that is not allowed, such as sed: "Use read_file with offset and limit."
  • Add SHELL_REFUSALS rows for openspec and a bare devops, which name uv run devops openspec check and uv run devops.

This item changes only the hint text, the scratch directory and the tool list. It changes no allowlist and no operator rule. The parser and the split of chained commands stay in #5201.

Acceptance Criteria

  • A test (written first, fails on the base) gives refusal_hint a refused uv run python -c "a=1; print(a)" and proves that the text starts with the write_file instruction.
  • A test gives a refused git status && git log and proves that the text names two separate calls.
  • A test proves that the step offers create_directory and that the job makes .data/agent/scratch/ before step 1.
  • A test proves that the prompt holds no python -c mkdir text.
  • uv run devops ci fail-to-pass --base origin/main shows that the new tests fail on the base.
  • Measure in telemetry, 7 days after the release (runner log lines in Loki): refusals per implement run go down from about 4, a repeat of the same refused form after its hint goes to 0, stops after 3 refusals in a row go to 0, and python -c mkdir calls go to 0.

Existing Tool Considered

pydantic-ai-harness create_directory (0.59.0, already locked) for the directory. The hint is project text in the existing _RefusingToolset wrapper, which already removes a cd <checkout> && prefix by itself. No new tool. Cost to build (estimate): 0.2 M model input and output, and 2 to 3 hours. Cost to keep: one hint per refused form.

Related

#5201 (shell parser, parent), #5180 (refusal ranking), #5179 (tool error classes).

Source: #5201

Proposed design

Problem statement

The implement step answers a refused shell command with a hint selected from the first word only, so uv run python -c code with a separator and git status && git log get the same text, and the instruction about the file comes last. That text, and the prompt, send the model to .data/agent/scratch/, which a fresh checkout does not have, and the prompt tells the model to make a directory with uv run python -c. The model then sends the same form again, or it stops after three refusals in a row. The change selects the hint from the whole refused form, creates the scratch directory in the job, registers a create_directory tool (the locked harness 0.59.0 has none), and removes the python -c mkdir text from the prompt.

Acceptance criteria

Requirement: Python code refusal names write_file first

The refusal hint for a python -c command that holds ;, a new line or a heredoc SHALL start with the write_file instruction for a file under .data/agent/scratch/ and then give the uv run python command.

Scenario: Refused python -c with a separator

  • WHEN refusal_hint receives the whole command uv run python -c "a=1; print(a)", a form with a new line, and a heredoc form.
  • THEN Each returned text starts with the write_file instruction and names .data/agent/scratch/ and uv run python.

Requirement: Allowed command chain names separate calls

The refusal hint for a chain of allowed programs with && or ; SHALL name each command as its own call and SHALL give an example of two calls.

Scenario: Refused git chain

  • WHEN refusal_hint receives git status && git log.
  • THEN The returned text names git status --short and git log --oneline -5 as separate calls.

Requirement: Pipe refusal names read_file

The refusal text for a pipe to a program that the shell does not allow SHALL name read_file with offset and limit.

Scenario: Refused pipe to sed

  • WHEN pipe_refusal receives git status | sed -n 1,20p.
  • THEN The returned text names read_file with offset and limit and still names the program after the pipe.

Requirement: Implement step offers create_directory

The implement step SHALL register a create_directory tool that creates a directory inside the checkout.

Scenario: Tool list includes create_directory

  • WHEN The implement tool names are read and the local tool set of the agent is built.
  • THEN create_directory is in IMPLEMENT_LOCAL_TOOL_NAMES, the agent offers it, and a call with a path outside the checkout is refused.

Requirement: Job creates scratch directory

The implement job SHALL create .data/agent/scratch/ in the checkout before it builds the inputs of the first step.

Scenario: Fresh checkout has the scratch directory

  • WHEN The implement job starts a run in a clean checkout with no .data/agent/scratch/.
  • THEN The directory exists before the first model request, and git check-ignore .data/agent/scratch/ reports it ignored.

Requirement: Prompt names create_directory

The implement prompt SHALL name create_directory for a new directory and SHALL hold no python -c mkdir text.

Scenario: Prompt text has no mkdir shell command

  • WHEN The prompt roadmap_implement_step.md is rendered for a step.
  • THEN The text names create_directory and holds no python -c command that calls mkdir.

Requirement: Refusal table names openspec and devops

SHELL_REFUSALS SHALL hold a row for openspec that names uv run devops openspec check and a row for a bare devops that names uv run devops, and docs/ROADMAP_WORKFLOW.md SHALL show the same rows.

Scenario: Refusal table rows for project commands

  • WHEN SHELL_REFUSALS and the refusal table of docs/ROADMAP_WORKFLOW.md are read.
  • THEN Both hold an openspec row with uv run devops openspec check and a devops row with uv run devops.

Requirement: New tests fail on base

Each new test for the refusal hints, the tool list, the scratch directory and the prompt MUST fail on the base commit.

Scenario: Fail-to-pass replay

  • WHEN uv run devops ci fail-to-pass --base origin/main runs.
  • THEN The command reports that each new test failed on the base commit and passes on the change.

Existing Tool Considered

No alternatives list was given. The locked pydantic-ai-harness 0.59.0 (pyproject.toml:41) covers the file tools and the shell, but it has no create_directory: Coder gives six tools, and its write_file creates no directory (src/devops_cli/ai/knowledge_base/devops_cli/libraries/pydantic_ai_harness.md:34, :59), and mkdir is not on the shell allowlist either (openspec/changes/archive/2026-10-29-2664-roadmap-implement-step/design.md:14). It also has no setting for the refusal text. The project therefore builds a small create_directory tool (a pydantic-ai function tool that refuses a path outside the checkout) and the hint text in _RefusingToolset: about 60 lines of code and 150 lines of tests, about 0.15 M model input and output tokens and 3 hours of elapsed time. Cost to keep: one tool and one hint per refused form.

Key questions

  • How should the hint choose the replacement text for a refused command?: Pass the whole refused command to refusal_hint and match it in a fixed order. A python -c command with ;, a new line or a heredoc gets the write_file text first, before the text of the shell. A chain of allowed programs gets the separate-call text. The pipe text stays in pipe_refusal, which already reads the stages, and names read_file with offset and limit when a stage is not allowed. (best practice) [sources: src/devops_cli/roadmap/implement/implement_shell_refusal.py:52, src/devops_cli/lang/en/messages.py:3235, src/devops_cli/roadmap/implement/implement_shell_policy.py:327, docs/ROADMAP_WORKFLOW.md:286]
    • Rejected: First word only. It gives the same operator text to python -c and git status && git log, and it puts the file instruction last.
    • Chosen: Whole-form match with ordered rules. It selects the exact next call for each refused form, puts the file instruction first for python -c, and leaves the pipe text in the function that reads the stages.
    • Rejected: Model-generated hint. It is not deterministic for an offline test and adds a model request to each refusal.
  • How should the step create a directory?: The locked pydantic-ai-harness 0.59.0 has no create_directory: Coder gives six tools, write_file creates no directory, and mkdir is not on the shell allowlist. So the job creates .data/agent/scratch/ before step 1, the step registers a small project create_directory tool for any other new directory, and the prompt names that tool and drops the python -c mkdir text. (best practice) [sources: src/devops_cli/ai/knowledge_base/devops_cli/libraries/pydantic_ai_harness.md:34, src/devops_cli/ai/knowledge_base/devops_cli/libraries/pydantic_ai_harness.md:59, openspec/changes/archive/2026-10-29-2664-roadmap-implement-step/design.md:14, src/devops_cli/roadmap/implement/implement_step.py:648, src/devops_cli/ai/tasks/roadmap_implement_step.md:40, src/devops_cli/ai/tasks/roadmap_implement_step.md:59]
    • Rejected: Harness create_directory. It does not exist in 0.59.0: Coder gives six tools and the knowledge page states that write_file creates no directory.
    • Chosen: Project create_directory tool. The step can register a small pydantic-ai function tool, and the tool refuses a path outside the checkout.
    • Rejected: python -c mkdir in the prompt. The model adds a ; or a new line, and the shell refuses it; the evidence shows the repeated refusals and the failed write_file retries.
    • Rejected: Shell mkdir. mkdir is not on the allowlist, and this change keeps the allowlist as it is.
  • Should the scratch directory stay at .data/agent/scratch/?: Yes. The job creates .data/agent/scratch/, and the prompt keeps scratch files there, because the repository ignores that path. (best practice) [sources: src/devops_cli/ai/tasks/roadmap_implement_step.md:40, AGENTS.md:18]
    • Chosen: .data/agent/scratch/. The prompt already names it as the git-ignored scratch path, .gitignore ignores .data/*, and the job can create it before step 1.
    • Rejected: The checkout root. The step commits every file in the checkout root, so a scratch file there reaches a commit.
    • Rejected: A system temporary directory. It is outside the checkout, so write_file and uv run python <file> cannot use it as the prompt describes.
  • Should SHELL_REFUSALS gain rows for openspec and a bare devops?: Yes. Add openspec -> uv run devops openspec check and devops -> uv run devops, so each refusal names the exact project command, and render the same rows in docs/ROADMAP_WORKFLOW.md. (best practice) [sources: src/devops_cli/roadmap/implement/implement_shell_policy.py:199, docs/ROADMAP_WORKFLOW.md:286]
    • Chosen: Add both rows. The table then gives the exact replacement for each refused project command, and a test keeps the document equal to the table.
    • Rejected: Keep only the generic allowed-program list. The generic list does not name the command that replaces openspec or a bare devops.
    • Rejected: Add only openspec. A bare devops still gets no exact replacement.
  • Should the post-release telemetry measurement stay in this item?: Yes. It stays in the item as a check that only a person can run: the change's tasks.md carries it as a plain bullet starting Pending a person: with the Loki query, the date window and the release version, and the stage job maps that criterion to pending-person with a reason. It is not a code requirement and not a new issue. (best practice) [sources: docs/adr/0010-openspec-is-the-spec-and-change-proposal-layer.md:113, docs/ROADMAP_WORKFLOW.md:348]
    • Chosen: A Pending a person: bullet in the change's tasks.md. The project records this form for a check only a person can run, and the stage job maps the criterion to pending-person with a reason.
    • Rejected: A separate issue. A follow-up issue is for work the item will not do; this measurement is the item's own post-release check.
    • Rejected: An offline acceptance criterion. No offline test can read Loki 7 days after a release, and the stage gate has no group for it.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

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

    @dan-petty
    OwnerAuthor
    • Priority: P1-High. The bug causes 71 refusals in 17 runs, model loops on the same form, and 13 stops that each lose a full paid run.
    • Related: feat(roadmap): rank refused tool calls and propose safe tool changes #5180, which asks for a different change. Both address refused command patterns (python -c with ;, git with &&) and propose safe alternatives, but the candidate fixes the hint text selection and tool list while #5180 ranks refusals and proposes tool changes as a broader feature.
  4. added
    priority/p1-high
    on Nov 13, 2026
  5. added
    status/ready
    and removed
    status/new
    on Nov 14, 2026
  6. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor

    Status set to Ready at 1eb3ea4 (see proposed design in issue body).

  7. added
    owner/service
    and removed
    owner/service
    on Nov 14, 2026
  8. 3 remaining items

  9. added 3 commits that reference this issue on Nov 14, 2026
  10. added
    status/planned
    and removed
    status/ready
    on Nov 14, 2026
  11. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/planned
    status/in-progress
    on Nov 14, 2026
  12. removed
    status/in-review
    owner/agent
    on Nov 14, 2026
  13. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor
  14. devops-cli-service commented on Nov 14, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-14 21:08 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/p1-highscope/roadmapsource/agenttype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions