Skip to content

Conversation

@neekolas
Copy link
Collaborator

@neekolas neekolas commented Nov 18, 2025

Force pushing Docker images in build-node-go.yml and add an env-gated triple-insert path to store.Store.InsertWelcomeMessage and store.Store.InsertWelcomePointerMessage for a hack to duplicate welcomes

The workflow always pushes Docker images. The store layer adds an XMTP_ENABLE_DUPLICATE_WELCOMES='true' path that loops 3 times, appending a 4-byte big-endian index to the hash input to produce distinct InstallationKeyDataHash values, returning the first insert and erroring on any subsequent insert failure.

📍Where to Start

Start with InsertWelcomeMessage and InsertWelcomePointerMessage in store.go.


📊 Macroscope summarized 6cd1a15. 1 file reviewed, 7 issues evaluated, 5 issues filtered, 1 comment posted

🗂️ Filtered Issues

pkg/mls/store/store.go — 1 comment posted, 7 evaluated, 5 filtered
  • line 344: The function performs multiple inserts without transactional protection and returns an error immediately on any later failure, even if an earlier insert in the same loop succeeded. This can leave the system in a partially committed state (e.g., the first InsertWelcomeMessage succeeded, the second failed, and the function returns an error). This violates atomicity and can surprise callers who may interpret a non-nil error as "nothing inserted". Consider wrapping the loop in a transaction with rollback on failure, or altering the contract to tolerate partial inserts and return the successfully inserted IDs along with errors. [ Low confidence ]
  • line 345: Error classification relies on strings.Contains(err.Error(), "duplicate key value violates unique constraint"). This is brittle and dependent on the exact wording from the database driver/server. Different databases, locales, or driver versions may not match this substring, causing duplicate-key errors to be misclassified as generic errors. Prefer checking driver-specific error codes (e.g., PostgreSQL pq.Error code 23505) or a structured error type. [ Low confidence ]
  • line 378: Multi-insert without transactional all-or-nothing semantics can leave the database in a partially updated state when XMTP_ENABLE_DUPLICATE_WELCOMES is enabled. If any iteration after a successful insert fails (e.g., due to a unique constraint or other DB error), the function returns an error but prior inserts remain committed, violating atomicity/invariants and potentially creating inconsistent duplicates. There is no rollback or grouped transaction around the loop. This occurs in the for i := 0; i < numInserts; i++ { ... } loop and the error handling that immediately returns on any error. [ Low confidence ]
  • line 407: Casting wrapperAlgorithm to int16 (WrapperAlgorithm: int16(wrapperAlgorithm)) risks silent truncation if types.WrapperAlgorithm can hold values outside the int16 range. This is a data-conversion boundary with potential silent data loss and incorrect persistence of the algorithm identifier. [ Low confidence ]
  • line 411: Duplicate detection relies on substring matching of the error message text (strings.Contains(err.Error(), "duplicate key value violates unique constraint")). This is brittle across drivers/locales and may misclassify errors or miss duplicates, leading to incorrect error wrapping. Use driver-specific error codes or typed errors. [ Low confidence ]

@coderabbitai
Copy link

coderabbitai bot commented Nov 18, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 11-18-_do_not_merge_hack_duplicate_welcomes

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 and usage tips.

Copy link
Collaborator Author


How to use the Graphite Merge Queue

Add the label mergequeue to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

if strings.Contains(err.Error(), "duplicate key value violates unique constraint") {
return nil, NewAlreadyExistsError(err)

var firstMessage *queries.WelcomeMessage
Copy link

Choose a reason for hiding this comment

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

firstMessage = &message takes the address of the loop variable, so after later iterations it points to the last value, not the first. Consider storing the first result in a separate variable outside the loop and take its address instead.

-    var firstMessage *queries.WelcomeMessage
+    var firstMessage *queries.WelcomeMessage
+    var first queries.WelcomeMessage
@@
-        if i == 0 {
-            firstMessage = &message
-        }
+        if i == 0 {
+            first = message
+            firstMessage = &first
+        }

🚀 Reply to ask Macroscope to explain or update this suggestion.

👍 Helpful? React to give us feedback.

numInserts = 3
}

var firstMessage *queries.WelcomeMessage
Copy link

Choose a reason for hiding this comment

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

The loop aborts on the first duplicate-key error, so later attempts never run when XMTP_ENABLE_DUPLICATE_WELCOMES is true. Consider continuing on duplicate-key errors and only return an error after all attempts fail; return the first successful insert.

🚀 Reply to ask Macroscope to explain or update this suggestion.

👍 Helpful? React to give us feedback.

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