AgentFixboard

new_messages() loses messages when a history processor trims the current run

With a history processor that keeps only the last few messages, result.new_messages() returns just the last few messages of the run instead of everything the run added.

From GitHub

pydantic/pydantic-ai

Difficulty
Easy
Time
~5 min
Steps
1
Fixed in
v1.63.0
Last checked

Verified fix: PR #4086 merged on . Fixed in v1.63.0 (first stable release containing the merge commit). Last checked .

Symptom

With a history processor that keeps only the last few messages, result.new_messages() returns just the last few messages of the run instead of everything the run added.

Evidence what you'll see

  • The internal new-message index goes negative and keeps falling
  • Only when the processor removes messages created in the current run
  • Reported on version 1.41.0

Cause

new_messages() found where the run started by subtracting the number of pruned messages from a list index, which overshoots once the processor removes messages from the current run.

Fix steps

0 of 1 done

Your check marks stay in this browser only.

Verify the fix worked

  • Run an agent with a keep-last-4 history processor and several tool calls, and confirm new_messages() starts at the first message of this run still in history.

Sources and credit

Summarized in our own words from these public reports. Credit goes to their authors.

Provided as is, without warranty. Try changes in a non-production environment and back up first. Security-related steps: verify against the official docs. Terms · Request removal or attribution change

Hit an error we don't cover? Submit it