Skip to content

fix: deduplicate message IDs in saveChat to prevent ON CONFLICT error#713

Merged
ngoiyaeric merged 1 commit into
QueueLab:mainfrom
ngoiyaeric:fix/message-id-deduplication
Jul 9, 2026
Merged

fix: deduplicate message IDs in saveChat to prevent ON CONFLICT error#713
ngoiyaeric merged 1 commit into
QueueLab:mainfrom
ngoiyaeric:fix/message-id-deduplication

Conversation

@ngoiyaeric

Copy link
Copy Markdown
Collaborator

Problem

When the AI state submit function builds messages, it uses a shared groupeId for multiple message types (response, resolution_search_result, related, followup), giving them all the same ID.

When onSetAIState calls saveChat, the batch insert hits:

ERROR: ON CONFLICT DO UPDATE command cannot affect row a second time (21000)

Fix

Before inserting, saveChat now scans for duplicate IDs within the batch and appends a unique suffix to any duplicates, ensuring every row in the INSERT has a distinct primary key.

Files Changed

  • lib/actions/chat-db.ts — saveChat deduplication logic

The AI state submit function uses a shared groupeId for multiple message types
(response, resolution_search_result, related, followup), which all get the same ID.
When onSetAIState calls saveChat, the batch insert hits:
  ERROR: ON CONFLICT DO UPDATE command cannot affect row a second time (21000)

Fix: Before inserting, scan for duplicate IDs within the batch and append a unique
suffix to any duplicates, ensuring every row in the INSERT has a distinct primary key.
@qodo-code-review

Copy link
Copy Markdown
Contributor

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@vercel

vercel Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Someone is attempting to deploy a commit to the QCX-MAIN Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


ngoiyaeric seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@ngoiyaeric, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 32 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9f98428c-665b-420a-8076-51613b43f31e

📥 Commits

Reviewing files that changed from the base of the PR and between de1c5c0 and b506e86.

📒 Files selected for processing (1)
  • lib/actions/chat-db.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@ngoiyaeric ngoiyaeric merged commit 951886e into QueueLab:main Jul 9, 2026
2 of 4 checks passed
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.

2 participants