Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/backend/src/utils/ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export function findLastCompactionPart(
): [CompactionPart, messageIdx: number] | [undefined, undefined] {
for (let i = messages.length - 1; i >= 0; i--) {
for (const part of messages[i].parts) {
if (part.type === 'data-compaction') {
if (part.type === 'data-compaction' && part.data.summary.trim()) {
return [part.data, i];
}
}
Expand Down
19 changes: 19 additions & 0 deletions apps/backend/tests/compaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,23 @@ describe('compactionService.useLastCompaction', () => {
expect(result[3]).toEqual(messages[4]);
expect(result).toHaveLength(4);
});

it('returns messages unchanged when the only compaction entry has a blank summary (failed compaction)', () => {
// Regression test for issue #950:
// When compaction fails, summary: '' is persisted to the DB.
// Re-hydrating that blank summary creates { type: 'text', text: '' } in the assistant message,
// which Anthropic rejects with "text content blocks must be non-empty".
Comment on lines +174 to +177

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these comments are just a duplicate of the previous description so maybe you can remove them

const messages: UIMessage[] = [
{ id: '1', role: 'user', parts: [{ type: 'text', text: 'Hello' }] },
{
id: '2',
role: 'assistant',
parts: [{ type: 'data-compaction', data: { summary: '', error: 'LLM error' } }],
},
{ id: '3', role: 'user', parts: [{ type: 'text', text: 'Follow-up' }] },
];

const result = compactionService.useLastCompaction(messages);
expect(result).toBe(messages);
});
});
Loading