Skip to content

fix(roadmap): a model call that Ollama refuses for a broken tool call ends the step with no cause #2794

Description

@dan-petty

What happened

On 2026-10-30 the implement Job devops-cli-runner-20261030-183930-529c ran #2656 with the 0.22.6 image. The step stopped at group 1 with this reason, and nothing more:

ModelHTTPError: HTTP 400, model devops-coder

The reason does not say why the gateway answered 400. The cause was only in the log of the gateway pod at 18:42:32 UTC:

litellm.BadRequestError: Ollama_chatException - KeyError: 'message', Got unexpected response from Ollama: {'error': 'XML syntax error on line 75: unexpected EOF'}

The model began a tool call, and its XML ended early. Ollama could not read the call and answered with an error, and the gateway turned that into HTTP 400. The agent had written a test and was about to edit src/devops_cli/config/round_trip.py. The step discarded the test.

What should happen

  • The stop reason shows the body of the 400, cut to the same limit as other stop text, so the cause is in the comment.
  • A model call that fails with this answer is sent again with the same history, a small fixed number of times, because the next sample of the model can give a whole call. After the last try, the step stops with the body of the answer.
  • Before the retry rule, check whether the early end comes from an output limit of the model (num_predict or max_tokens of the route devops-coder). If a limit cuts the call, raise the limit in the route instead of retrying.

Evidence

Acceptance criteria

  • The stop comment for an HTTP 400 holds the body of the answer.
  • A test replays a 400 with the body XML syntax error ... unexpected EOF once, then a good answer, and the step ends done.
  • A test with the same 400 on every try ends in a stop that names the body.
  • The pull request records whether an output limit cuts the call.
  • uv run devops ci passes.

Proposed design

Problem statement

When the implement job's step calls the model and the gateway returns HTTP 400, the stop reason shows only the status code and model name. The body of the 400, which names the cause, is lost. A single transient truncation ends the step when a retry would likely succeed. The step also does not check whether an output limit caused the truncation before retrying.

Acceptance criteria

Requirement: Stop comment holds 400 body

The stop comment for an HTTP 400 from the model gateway SHALL include the body of the response, truncated to the same limit as other stop text.

Scenario: 400 with body

  • WHEN The model gateway returns HTTP 400 with a non-empty body
  • THEN The stop comment contains the body text, truncated to the stop-text limit

Requirement: Retry on transient 400

A model call that fails with an HTTP 400 that is not caused by an output limit SHALL be retried a fixed number of times with the same history before the step stops.

Scenario: Retry then succeed

  • WHEN The first call returns 400 and the second call returns a valid response
  • THEN The step ends done

Requirement: Exhaust retries

When all retries of a model call fail with the same HTTP 400, the step SHALL stop with the body of the last response in the stop reason.

Scenario: All retries fail

  • WHEN Every attempt returns the same HTTP 400 with a body
  • THEN The step stops and the stop reason names the body

Requirement: Output limit check before retry

Before retrying a model call that failed with a truncation error, the step SHALL check whether the route's num_predict or max_tokens caused the truncation, and if so, raise the limit instead of retrying.

Scenario: Limit causes truncation

  • WHEN The 400 body indicates truncation and the route has num_predict or max_tokens set
  • THEN The step raises the limit and does not retry

Requirement: CI passes

The command uv run devops ci SHALL pass after the change.

Scenario: CI run

  • WHEN The pull request runs uv run devops ci
  • THEN All checks pass

Existing Tool Considered

No check has run. No open, maintained tool covers the need of surfacing a 400 body in a job stop comment and conditionally retrying a model call in a step. The project builds its own code. The written cost is the tokens to build, keep and fix the retry and error-surfacing code in the implement job's step execution, and the elapsed time for the implement job to run the step and the person to review the pull request.

Key questions

  • What is the fixed retry count for a 400 that is not caused by an output limit?: 2 retries (3 total attempts). The body says 'a small fixed number of times.' Two retries give the model two more samples to produce a whole call without wasting tokens. (proposed)
    • Rejected: 1 retry (2 total attempts). Too few. The model may need another sample to produce a whole call.
    • Rejected: 2 retries (3 total attempts). Chosen. A small fixed number that gives the model a chance to produce a whole call.
    • Rejected: 3 or more retries. Too many. Wastes tokens and time on a call that is likely to keep failing.
  • How does the step detect that the 400 is caused by an output limit rather than a malformed tool call?: Check the 400 body for a truncation indicator such as 'unexpected EOF'. If the body indicates truncation and the route has num_predict or max_tokens set, treat it as a limit issue and raise the limit. If the body indicates truncation but no limit is set, retry. (best practice) [sources: src/devops_cli/ai/client/ollama.py:311]
    • Rejected: Check the 400 body text for a truncation pattern. Chosen. The body text from Ollama names the cause. A pattern match on 'unexpected EOF' or similar is simple and direct.
    • Rejected: Check the finish_reason of the last successful call. Rejected. The call failed, so there is no finish_reason to check.
    • Rejected: Always retry and never raise the limit. Rejected. The body says to check the limit first and raise it if it caused the truncation.

Open questions

  • Where in the code is the stop reason for a failed step written? (missing verified source)
  • What is the truncation limit for stop text that the 400 body must be cut to? (missing verified source)

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/bug
    scope/roadmap
    status/new
    value/medium
    effort/medium
    on Oct 30, 2026
  2. dan-petty commented on Oct 30, 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/bug. The fix prefix of the title gives the type.
    • Scope: scope/roadmap. The (roadmap) scope of the title gives the scope.
    • Priority: P2-Medium. A step loses work and the operator cannot diagnose the cause, but the trigger is a specific Ollama XML parsing edge case.
    • Value: Medium. Operators lose visibility into why a step stopped and discard in-progress work, which erodes trust in the implement pipeline.
    • Effort: Medium. Requires surfacing the 400 body, adding bounded retry with the same history, and checking the route output limit before retrying.
    • Related: fix(roadmap): an implement step that stops on UnexpectedModelBehavior hides the cause and logs no tool call #2758, which asks for a different change. Both address the stop reason hiding the real cause of a model call failure in an implement step, but #2758 targets UnexpectedModelBehavior/UsageLimitExceeded while the candidate targets ModelHTTPError (HTTP 400) and adds retry and output-li
  3. added
    priority/p2-medium
    on Oct 30, 2026
  4. devops-cli-service commented on Oct 30, 2026

    @devops-cli-service
    Contributor

    Refine cannot set this item to Ready at 524db95 until a person answers the questions below. Reply in a comment or edit the body, and the next refine round looks at the item again.

    • Where in the code is the stop reason for a failed step written? (missing verified source)
    • What is the truncation limit for stop text that the 400 body must be cut to? (missing verified source)
  5. added
    status/in-progress
    status/in-review
    and removed
    status/new
    status/in-progress
    on Oct 30, 2026
  6. removed
    status/in-review
    on Oct 30, 2026
  7. added a commit that references this issue on Oct 30, 2026
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