Skip to content

fix(roadmap): Find why refine stops on the local qwen3.8 model #5991

Done

Description

@dan-petty

Problem

Refine does not work reliably on local/qwen3.8:27b. From 00:07Z to 03:08Z on 2026-11-16 (release 0.159.0), refine ran on the local model. 4 of its 15 results in that window stopped with no proposal:

Refine's investigation of #4895 ... stopped with no proposal (UnexpectedModelBehavior: Tool <text> exceeded max retries count of 2. Consider raising the retry limit, or see the docs on tool retries).

The same error stopped #4895 (01:06Z), #4899 (01:18Z and 02:07Z) and #4904 (02:50Z). The log masks the tool name (<text>), so the log does not show if the output tool or a function tool failed. Refine allows 2 retries for a tool and for its output (CONST_ROADMAP_REFINE_INVESTIGATION_RETRIES, src/devops_cli/config/constants.py; refine_investigation.py, retries={"tools": ..., "output": ...}). Refine went back to DeepSeek at 03:08Z (#5909). On DeepSeek, refine had 103 of 120 in 24 hours with no such error.

Owner, 2026-11-16: investigate why refine does not work on the local model. Refine stays on DeepSeek until then.

Expected behavior

The investigation answers, with evidence:

  • Which tool fails: the output tool (the structured reply) or a function tool. Use the Tempo traces of the four runs, or a replay.
  • What the model sent: invalid JSON arguments, a missing field, a wrong type, text in place of a tool call, or a tool name that does not exist.
  • Whether the cause is the model, the Ollama tool-call template of the model, the output mode of pydantic-ai (tool output against NativeOutput or PromptedOutput), the schema of the refine reply, or the retry limit of 2.
  • Whether the same items pass on local/qwen3.8:27b with a changed output mode or a higher retry limit, in a replay (devops roadmap eval or a local run against the gateway) that compares the results with DeepSeek on the same items.

The result is a short report on this issue and, for each cause, a fix item or a change of the model choice. Also file the masked tool name in the log as its own fix if the log must name the tool.

Related

Alternatives check of 2026-11-24: in-use.
The repository already uses this tool.
Tool: pydantic/pydantic-ai (https://github.com/pydantic/pydantic-ai), MIT, last activity 2026-11-24, maintained.
Reason: Searches found no diagnostic or tracing tool for this failure; the agent framework that raises the retry error, sets the per-tool limit, offers the output modes and provides the offline test double is the one the project already uses.

Covers:

  • Per-tool retry limit that raises the retry error
  • Selectable structured output: tool call, NativeOutput, PromptedOutput
  • FunctionModel test double reproduces the stop with no live model
  • Ollama models reachable through the gateway

Lacks:

  • Stop text names no registered tool names or output mode
  • No trace analysis of the four historical runs
  • No replay that compares the local model with DeepSeek
  • No check of the model's Ollama tool-call template

Proposed design

Problem statement

Refine stops on local/qwen3.8:27b with UnexpectedModelBehavior: Tool <text> exceeded max retries count of 2, and 4 of its 15 results in that window stopped with no proposal. The stop text does not say which tool failed or what the model sent, so the cause stays unknown, and refine stays on DeepSeek. This change makes the stop text answer those questions on the next run. It moves the reading of the four historical runs to its own item.

Acceptance criteria

Requirement: The refine stop names the tool

The refine investigation MUST write the name of the tool that exceeded its retry limit, and the tool names that it registered, into the stop reason.

Scenario: A model calls a tool that the investigation did not register

  • WHEN the investigation runs against a pydantic-ai FunctionModel that returns a tool call named <text> on every turn
  • THEN the stop reason holds the name <text> and the list of the tool names that the investigation registered.

Requirement: The refine stop records the output mode and the parts

The refine investigation MUST write its structured-output mode and the kind of each part of the last model response into the stop reason.

Scenario: The model returns text in place of the output call

  • WHEN the investigation runs with NativeOutput against a FunctionModel that returns a text part and no output tool call
  • THEN the stop reason states the output mode NativeOutput and the part kind text.

Existing Tool Considered

pydantic-ai (https://github.com/pydantic/pydantic-ai), verdict in-use; the alternatives check in this issue body lists what it covers and lacks. The proposal keeps its per-tool retry limit, its output modes and the retry error as they are. It adds the registered tool names, the output mode and the part kinds to the stop reason, which the tool does not record, and it reproduces the stop with the FunctionModel test double of the tool. The tool gives no trace analysis, no model-comparison replay and no check of the Ollama template; the deferred item reads the traces and runs the replay.

Key questions

  • How does the refine investigation report which tool exceeded its retries?: Catch UnexpectedModelBehavior in refine_investigation.py. Write a stop that holds the exception text, the tool names that the investigation registered and the kind of each part of the last model response. Do not parse the tool name out of the message. (best practice) [sources: src/devops_cli/roadmap/refine/refine_investigation.py]
    • Chosen: Stop text with the registered tool names. The message names the tool as the model sent it, and the registered names show at once whether that name exists.
    • Rejected: Parse the tool name out of the exception message. The message format belongs to pydantic-ai, and a change of that format breaks the parse.
    • Rejected: Log the exception at DEBUG and keep the current stop. The Service keeps no DEBUG line of a stopped run, so the next run answers nothing.
  • How does a test reproduce the stop with no live model?: Use the FunctionModel test double of pydantic-ai. It returns a fixed response on every turn, so the test needs no gateway and no Ollama host. (best practice) [sources: src/devops_cli/roadmap/refine/refine_investigation.py]
    • Chosen: FunctionModel test double. It runs offline, and it gives the exact tool name and part kinds that the test asserts.
    • Rejected: A recorded HTTP cassette of the gateway. It pins one private answer and breaks when the model or its template changes.
    • Rejected: A live run against the gateway. CI has no gateway and no local/qwen3.8:27b.
  • Does this change raise the retry limit of 2?: No. The tool limit and the output limit stay at the value of CONST_ROADMAP_REFINE_INVESTIGATION_RETRIES. A higher limit delays the same stop, and no evidence shows that the model sends a different call at a higher count. (best practice) [sources: src/devops_cli/config/constants.py:3457]
    • Chosen: Keep the limit of 2 and record the failure. The stop text then shows the tool, the mode and the parts, and the deferred replay decides if the limit matters.
    • Rejected: Raise the limit to 5. The four runs stopped at the limit, and no evidence shows that more retries change the call of the model.
    • Rejected: Make the limit a setting. No evidence yet that another value helps, and a new setting needs a default and a document.

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

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

    @dan-petty
    OwnerAuthor
  3. added
    effort/medium
    priority/p2-medium
    on Nov 16, 2026
  4. devops-cli-service commented on Nov 17, 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 (10)

    Tools considered:

    Searches run:

    • ollama qwen tool calling template invalid JSON arguments retries, results: 5
    • pydantic-ai output retries tool call max retries exceeded NativeOutput, results: 5
    • pydantic-ai documentation retries structured output, results: 5
    • pydantic-evals compare two models on same dataset, results: 5
    • pydantic-ai, results: 5
    • ollama, results: 5
    • pydantic-ai retries tool output docs, results: 5
    • pydantic-ai output modes native tool prompted, results: 5
    • pydantic-ai retries, results: 5
    • pydantic-ai output, results: 5

    Sources:

  5. added
    status/ready
    and removed
    status/new
    on Nov 18, 2026
  6. devops-cli-service commented on Nov 18, 2026

    @devops-cli-service
    Contributor

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

    Moved to new items: #6305.

  7. added
    owner/agent
    status/in-progress
    and removed
    status/ready
    on Nov 25, 2026
  8. added
    status/in-review
    and removed
    status/in-progress
    on Nov 25, 2026
  9. removed
    status/in-review
    owner/agent
    on Nov 25, 2026
  10. devops-cli-service commented on Nov 25, 2026

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

    @devops-cli-service
    Contributor

    Live since 2026-11-25 17:09 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/roadmapsource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions