Skip to content

Fix AttributeError when patch summary content is a list of blocks - #6980

Open
AmirF194 wants to merge 1 commit into
mozilla:masterfrom
AmirF194:fix/6517-patch-summary-list-content
Open

AmirF194 wants to merge 1 commit into
mozilla:masterfrom
AmirF194:fix/6517-patch-summary-list-content

Conversation

@AmirF194

Copy link
Copy Markdown

Fixes #6517.

PatchSummarizationTool.run() read result["messages"][-1].content and called
.rfind() on it directly. LangChain message content is a plain str for
ordinary replies, but for extended-thinking responses it comes back as a
list of content blocks instead, and .rfind has no meaning on a list. That
is exactly the traceback in the issue.

BaseMessage.text (langchain-core) is built for this: it joins only the
type: "text" blocks into a string when content is a list, and returns the
string unchanged when it already is one. Swapping .content for .text
fixes both cases with no other change to the method.

Verified live (not just read):

  • AIMessage(content=[...]).text returns the joined text for list content,
    the original string for str content, and "" for an empty list, all
    confirmed against the pinned langchain 1.3.15.
  • Added tests/test_patch_summarization.py: one test reproduces the crash
    with list content, without the fix it raises the same AttributeError
    and with the fix it passes; a second test pins the existing plain-string
    path still works.
  • ruff check, ruff format --check, codespell, and a scoped mypy run
    on the changed file are all clean.
  • Not run: the repo's full bugbug tests CI task (it clones Mercurial
    history and installs the full ML dependency set); I verified the changed
    module and its new tests against the actual production code path with
    only the packages that module imports.

PatchSummarizationTool.run() called .rfind() on the last message's
.content, which is a plain str for ordinary replies but a list of
content blocks for extended-thinking responses. Use BaseMessage.text,
which normalizes both shapes to a string.

Fixes mozilla#6517.
@AmirF194
AmirF194 requested a review from a team as a code owner September 30, 2026 07:47
Copilot AI balanced review requested due to automatic review settings September 30, 2026 07:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

# .text normalizes list-of-blocks content (e.g. extended thinking) to a
# plain string; .content does not, and the .rfind below needs a str.
summary = str(result["messages"][-1].text)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need here the final result, without the extended thinking.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The focused fix addresses the reported crash, preserves existing behavior, and includes regression coverage with no unresolved findings.

Review effort: Balanced
Findings: None

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AttributeError: 'list' object has no attribute 'rfind'

3 participants