Skip to content

/improve fails when the model answers in prose or omits the suggestions key #2902

Description

@dwin-gharibi

Git provider

Other

System Info

  • PR-Agent version: 0.43.0, branch main (commit 739ea8a6)
  • Python: 3.12 (CI image python:3.12.13-slim); also reproduced on 3.13
  • Deployment type: app / action / cli
  • Model: any (the defect is independent of the model)

Bug details

/improve fails when the model answers in prose or omits the suggestions key

_prepare_pr_code_suggestions iterates data['code_suggestions'] without checking that the key exists or holds a list.

Steps to reproduce

Run /improve on a PR with nothing worth suggesting, where the model replies:

No suggestions found for this PR.

The same failure occurs when the model renames the key, emits it with no value, or returns something that
cannot be parsed as YAML at all.

Expected behaviour

The tool reports that there are no suggestions.

Actual behaviour

prose answer   -> TypeError: string indices must be integers, not 'str'
renamed key    -> KeyError: 'code_suggestions'
empty value    -> TypeError: 'NoneType' object is not iterable

The per-suggestion try starts inside the loop, so it cannot protect the subscript. On the single-call path
nothing catches it and run() publishes "Failed to generate code suggestions for PR".

Root cause

Answering in prose when there is nothing to suggest is the behaviour of a helpful assistant, and it is
exactly the case the tool should report cleanly. Instead it is the case that loses the run.

Activity

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions