[PR #2869] fix: sanitize message history to prevent API errors #10471

Closed
opened 2026-02-16 18:15:08 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/2869

State: closed
Merged: No


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

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/2869 **State:** closed **Merged:** No --- ## 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](https://claude.com/claude-code)
yindo added the pull-request label 2026-02-16 18:15:08 -05:00
yindo closed this issue 2026-02-16 18:15:08 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#10471