fix: MOIM injection causing trailing assistant message (#7425)#7459
fix: MOIM injection causing trailing assistant message (#7425)#7459michaelneale wants to merge 1 commit into
Conversation
When the conversation ends with a text-only assistant message (no tool call), inject_moim was inserting the MOIM user message *before* it, leaving the assistant message trailing. This violates the API constraint that conversations must end with a user message, producing a 400 error from Anthropic. Fix: detect when the last assistant message is also the last message in the conversation, and insert MOIM *after* it instead of before. This ensures the conversation always ends with a user message while preserving the trailing assistant content.
|
hey @tlongwell-block does this one make sense? |
|
I think this may make sense @angiejones |
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical bug (#7425) where MOIM injection causes API errors when a conversation ends with a text-only assistant message. The fix modifies the inject_moim function to insert MOIM after (instead of before) a trailing assistant message, ensuring conversations always end with a user message as required by the Anthropic API.
Changes:
- Updated MOIM injection logic to detect when the last message is an assistant message and insert MOIM after it in that case
- Added comprehensive regression test verifying the fix and ensuring the trailing assistant message is preserved
|
Fixed in #7424 |
|
Fat-fingered that close, sorry! Yeah, @michaelneale we looked at this in #7421 It is not caused by the MOIM. Just truncated tool call requests Also, it is important that the MOIM not be the latest message in context or it distracts goose too much |
|
@tlongwell-block well given that, should we close this one anyway? |
|
Yes, I think so. It just felt rude closing your PR 🙃 |
Tentative fix for #7425.
When a conversation ends with a text-only assistant message (no tool call), MOIM was inserted before it, leaving the assistant message trailing. Anthropic rejects this with 400 'conversation must end with user message'.
Fix: insert MOIM after the last assistant message when it's the final message. Includes regression test.
Note: supersedes the approach on
fix/moim-trailing-assistantwith a cleaner match-based implementation and a more thorough regression test that also verifies the trailing assistant message is preserved (not dropped).