Skip to content

Conversation

@mguttmann
Copy link

Summary

Fixes AI_InvalidPromptError that breaks sessions when compaction is triggered.

Problem

When a session's context overflows and compaction is triggered, the following error occurs:

AI_InvalidPromptError: Invalid prompt: The messages must be a ModelMessage[]. 
If you have passed a UIMessage[], you can use convertToModelMessages to convert them.

This happens because step-start parts are being added to UIMessage objects, but step-start is not a valid UIMessagePart type in the AI SDK's convertToModelMessages() function.

Solution

  • Remove step-start from being added to UIMessage parts (it's only used internally for tracking)
  • Simplify the result filter since step-start is no longer included

Testing

  • Sessions can now compact without errors
  • Existing sessions with context overflow can be recovered

The AI SDK's convertToModelMessages() does not accept 'step-start' as a valid
UIMessagePart type. This caused AI_InvalidPromptError during session compaction.

- Remove step-start from being added to UIMessage parts
- Simplify the filter since step-start is no longer included
- Fixes compaction breaking sessions with context overflow
@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

Found a potential related PR:

PR #8888 - fix(session): safeguard message conversion against invalid prompts

@mguttmann
Copy link
Author

Closing - issue resolved

@mguttmann mguttmann closed this Jan 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant