fix(session): filter empty text content before sending to API#1350
Open
walker83 wants to merge 2 commits into
Open
fix(session): filter empty text content before sending to API#1350walker83 wants to merge 2 commits into
walker83 wants to merge 2 commits into
Conversation
…ng-running sessions Add MAX_MESSAGES_PER_SESSION constant (1000) and warning log when sessions exceed this limit. This helps users identify when to start a new session or run /compact to avoid the memory issues reported in XiaomiMiMo#1221. Related: XiaomiMiMo#1221, XiaomiMiMo#813, XiaomiMiMo#680 Refs: XiaomiMiMo#1221
Add checks to skip text parts with empty strings when converting messages to API format. This prevents the 'all messages must have non-empty content' error (400) that occurs after pruning clears reasoning content. Fixes XiaomiMiMo#1326
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Filter out empty text content when converting messages to API format. This prevents the "all messages must have non-empty content" error (HTTP 400) that can occur after pruning clears reasoning content.
Problem
As reported in #1326, long-running sessions can hit a 400 error:
The root cause is in
toModelMessagesEffect:prune.ts:225clears reasoning content by settingtext: ""message-v2.ts:683,745converts these empty-text parts to API messages without filteringFix
Add
part.text.length > 0checks when building user and assistant message parts:Changes
packages/opencode/src/session/message-v2.ts: Add empty text content filterTesting
Related Issues
Checklist