Skip to content

llm messages normalization#335

Open
forhad-hosain wants to merge 2 commits intodevfrom
fix/message-normalization
Open

llm messages normalization#335
forhad-hosain wants to merge 2 commits intodevfrom
fix/message-normalization

Conversation

@forhad-hosain
Copy link
Contributor

@forhad-hosain forhad-hosain commented Feb 13, 2026

📝 Description

When interacting with the Chatbot, canceling a request can sometimes lead to malformed message history (e.g., multiple consecutive user messages). We need to normalize the message order before sending it to the LLM to prevent API errors.

🔗 Related Issues

  • Fixes #
  • Relates to #

🔧 Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 📚 Documentation update
  • 🔧 Code refactoring (no functional changes)
  • 🧪 Test improvements
  • 🔨 Build/CI changes

✅ Checklist

  • Self-review performed
  • Tests added/updated
  • Documentation updated (if needed)

forhad-hosain and others added 2 commits February 14, 2026 02:37
Replace removeDuplicateUserMessages with a robust normalizeMessages
pipeline that handles consecutive user/assistant messages, errored tool
calls from debug sessions, and orphaned tool_use blocks without matching
tool_results. The 3-pass pipeline (remove errored → remove orphans →
merge consecutive) fixes malformed message sequences across all LLM
connectors (Anthropic, Bedrock, GoogleAI, Groq, Ollama, OpenAI,
Perplexity, xAI). Includes comprehensive unit tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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