-
由 Will Chen 提交于
When mid-turn compaction ran during a multi-step tool loop (e.g., after web_crawl completed), injected user messages (like screenshots) were registered at an array index based on the compacted message history. The AI SDK's internal messages don't include the compaction summary, so in subsequent steps the stale index caused the injected user message to land between a tool_use and its tool_result, breaking the SDK's validation. Fix 1: Track the delta between compacted and SDK base message counts, and adjust injection indices after prepareStepMessages runs so future re-injections land at the correct position. Fix 2: Add ensureToolResultOrdering() as a defensive safety net that detects and fixes any user messages misplaced between tool_use/ tool_result pairs before returning from prepareStep. <!-- devin-review-badge-begin --> --- <a href="https://app.devin.ai/review/dyad-sh/dyad/pull/3213" target="_blank"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-open-in-devin-review-dark.svg?v=1"> <img src="https://static.devin.ai/assets/gh-open-in-devin-review-light.svg?v=1" alt="Open with Devin"> </picture> </a> <!-- devin-review-badge-end --> --------- Co-authored-by:
Claude Opus 4.6 (1M context) <noreply@anthropic.com>