Skip to content

fix(chat): prevent crash when sending attachment without text (#725) - #736

Merged
Israeltheminer merged 1 commit into
mainfrom
fix/725-empty-message-dedup
Mar 10, 2026
Merged

Israeltheminer merged 1 commit into
mainfrom
fix/725-empty-message-dedup

Conversation

@Israeltheminer

@Israeltheminer Israeltheminer commented Mar 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Empty/whitespace-only messages no longer match as duplicates in computeDeduplicationState
  • Fixes crash: Expected lastUserMessage to exist when messageAlreadyExists is true

Test plan

  • 7 unit tests added covering empty, whitespace, and normal dedup scenarios
  • Send attachment with no text in chat - should work without error

Closes #725

Summary by CodeRabbit

  • Bug Fixes

    • Improved message deduplication to correctly handle empty and whitespace-only messages.
  • Tests

    • Added comprehensive test coverage for message deduplication behavior across multiple scenarios.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai

coderabbitai Bot commented Mar 10, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This pull request adds comprehensive test coverage for the computeDeduplicationState function and refines its deduplication logic. A new test suite covers various scenarios including empty threads, duplicate message detection, handling of empty or whitespace-only messages, and edge cases with non-user content. The implementation is updated to add a guard that ensures trimmed messages are non-empty before marking duplicates, along with clarifying documentation. The changes are isolated to the message deduplication feature.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main fix: preventing crashes when sending attachments without text, which directly addresses the core issue in the changeset.
Linked Issues check ✅ Passed The PR addresses issue #725 by modifying deduplication logic to prevent empty messages from being treated as duplicates, which resolves the crash when submitting attachments without text.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the deduplication bug identified in issue #725; no out-of-scope modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/725-empty-message-dedup

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@services/platform/convex/lib/message_deduplication.test.ts`:
- Around line 33-38: Add an assertion to the existing test that verifies the
trimmedMessage value produced by computeDeduplicationState: inside the 'detects
duplicate when same user message is latest' test (where createMessages and
computeDeduplicationState are used), add
expect(result.trimmedMessage).toBe('Hello') to ensure trimming consistency when
a duplicate is detected and lastUserMessage is defined.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 11d43252-2504-4b5a-854d-3fb5d4d15796

📥 Commits

Reviewing files that changed from the base of the PR and between d1bbf90 and 2b98c55.

📒 Files selected for processing (2)
  • services/platform/convex/lib/message_deduplication.test.ts
  • services/platform/convex/lib/message_deduplication.ts

Comment on lines +33 to +38
it('detects duplicate when same user message is latest', () => {
const messages = createMessages([{ role: 'user', content: 'Hello' }]);
const result = computeDeduplicationState(messages, 'Hello');
expect(result.messageAlreadyExists).toBe(true);
expect(result.lastUserMessage).toBeDefined();
});

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.

🧹 Nitpick | 🔵 Trivial

Consider adding an assertion for trimmedMessage consistency.

For completeness, you might consider adding expect(result.trimmedMessage).toBe('Hello') to verify trimming also works correctly in duplicate scenarios. This is optional.

♻️ Optional enhancement
   it('detects duplicate when same user message is latest', () => {
     const messages = createMessages([{ role: 'user', content: 'Hello' }]);
     const result = computeDeduplicationState(messages, 'Hello');
     expect(result.messageAlreadyExists).toBe(true);
     expect(result.lastUserMessage).toBeDefined();
+    expect(result.trimmedMessage).toBe('Hello');
   });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it('detects duplicate when same user message is latest', () => {
const messages = createMessages([{ role: 'user', content: 'Hello' }]);
const result = computeDeduplicationState(messages, 'Hello');
expect(result.messageAlreadyExists).toBe(true);
expect(result.lastUserMessage).toBeDefined();
});
it('detects duplicate when same user message is latest', () => {
const messages = createMessages([{ role: 'user', content: 'Hello' }]);
const result = computeDeduplicationState(messages, 'Hello');
expect(result.messageAlreadyExists).toBe(true);
expect(result.lastUserMessage).toBeDefined();
expect(result.trimmedMessage).toBe('Hello');
});
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@services/platform/convex/lib/message_deduplication.test.ts` around lines 33 -
38, Add an assertion to the existing test that verifies the trimmedMessage value
produced by computeDeduplicationState: inside the 'detects duplicate when same
user message is latest' test (where createMessages and computeDeduplicationState
are used), add expect(result.trimmedMessage).toBe('Hello') to ensure trimming
consistency when a duplicate is detected and lastUserMessage is defined.

@Israeltheminer
Israeltheminer force-pushed the fix/725-empty-message-dedup branch from 2b98c55 to a8df593 Compare March 10, 2026 10:02
@Israeltheminer
Israeltheminer merged commit 4d057ef into main Mar 10, 2026
15 checks passed
@Israeltheminer
Israeltheminer deleted the fix/725-empty-message-dedup branch March 10, 2026 10:56
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.

Bug: Chat attachment shows failure when submitting message with file

1 participant