Skip to content

fix: sanitize message history to prevent API errors#2869

Closed
paulbettner wants to merge 1 commit into
anomalyco:devfrom
Smarty-Pants-Inc:fix/sanitize-history-clean
Closed

fix: sanitize message history to prevent API errors#2869
paulbettner wants to merge 1 commit into
anomalyco:devfrom
Smarty-Pants-Inc:fix/sanitize-history-clean

Conversation

@paulbettner

Copy link
Copy Markdown

Summary

  • Add sanitizeMessages() function to strip reasoning parts and empty messages from provider input
  • Update abort error filtering to only include messages with contentful parts (text or completed/errored tools)
  • Prevents OpenAI API errors when reasoning parts appear in conversation history

Changes

  1. transform.ts: Added sanitizeMessages() function that filters out:

    • Messages with only reasoning content type
    • Empty string messages
    • Messages with empty content arrays
  2. prompt.ts: Improved abort error handling to use hasContentfulPart logic:

    • Only includes aborted messages that have text parts
    • Or tool parts with completed/error status
    • Excludes messages with only step-start or reasoning parts

Test plan

  • Verify that conversations with reasoning parts don't cause API errors
  • Confirm that aborted messages with meaningful content are still included in history
  • Test that empty or reasoning-only messages are filtered out correctly

🤖 Generated with Claude Code

- Add sanitizeMessages() to strip reasoning parts and empty messages from provider input
- Update abort error filtering to only include messages with contentful parts (text or completed/errored tools)
- Prevents OpenAI API errors when reasoning parts appear in conversation history

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@paulbettner

Copy link
Copy Markdown
Author

Closing obsolete PR - changes already on dev branch through other merges

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.

1 participant