You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(intercom): send mapped external_id with email in rETL v2 identify - #5763
Rows in a v2 rETL Intercom identify aborted with 410 retry limit reached. The real reply was a 409: the search used external_id, but POST /contacts carried only the email, so Intercom refused it when a contact held that email. The handler retries a 409 as search lag, so the row ran out of retries. New contacts also lost their external_id, so no later sync could find them.
Setups with lookup: external_id now send external_id with the email, and one search by external_id or email decides the outcome: update the contact that holds the external_id, else claim a contact that holds the email with no external_id, else create. A new user takes one Intercom call and a claim two. When a full page of 50 results has no external_id match, a second search by external_id alone covers a match past page one. Other setups do not change. The search reports whether it matched by external_id or by email, so only a contact found by external_id can get a company detach, never a claimed one.
Real Intercom answers POST /contacts with an email and a new external_id as follows:
Contact holding the email
Intercom's answer
This PR
None
creates
POST
Different external_id
creates a separate user
POST
No external_id
409
PUT on that contact, adding the external_id
A PUT with a different external_id answers 200 and silently replaces it, and Intercom has no conditional update. So a claim has these guards:
A direct GET confirms the contact is still free, because search lags behind writes.
The GET also confirms the contact still holds the row's email.
An external_id match needs the contact to actually hold one, so the IDs "null" and "undefined" never match an email-only contact.
Only the first row in a router call claims a contact. The others answer 429 and retry, because the rETL retry limit applies only from 500 up.
sent; search by external_id, then claim by email on a miss
rETL identify, external_id + email, no such lookup
external_id dropped
unchanged
rETL identify, no email
external_id sent
unchanged
rETL track or group
unchanged
API v1, event stream
unchanged
Please review these points
A race remains. Rows on different router workers at the same moment can both pass the GET and both PUT, and the later one replaces the earlier ID. This was not reproduced on mini. It needs rows that share an email, and an email-only contact that holds it.
A contact with no external_id takes the row's ID and field values. We cannot tell whose contact it was. The customer needs to agree to this before release.
Rate limits. A row that misses makes one more search, and a claim makes one GET. Deferred rows answer 429, which feeds pickup throttling where adaptive throttling is on.
Review panel
Self-check with 6 lenses and Codex, then a Claude and Codex adversary on each of 6 claims. The single search was checked against the earlier two-search flow over 40,000 simulated cases, and Intercom's external_id search was confirmed to be exact (case and spaces matter). Findings were fixed on this branch.
A v2 rETL identify with a mapped external_id and an email searched by
external_id but sent POST /contacts with only the email. When a contact
already matched, Intercom answered 409, which the network handler retries
as search-index lag, so the row ran out of retries and was aborted.
Keep the mapped external_id on the identify payload and search by it
whenever the payload carries it. Track and group are unchanged.
Add live scenarios for a new contact, an email-only contact and an email
held by another external_id.
Refs ACT2-1371, INT-7464
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Auto reviews are disabled on this repository. 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.
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 4b8b5af6-e153-445a-9c54-9397d797ccb6
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
❌ Patch coverage is 98.75000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.43%. Comparing base (a74c408) to head (7b9ea25). ⚠️ Report is 6 commits behind head on develop.
Intercom answers 409 to a create when a contact holds the email without an external_id, even if the create carries one, and accepts a create when the email belongs to a different external_id (seen in the live suite). When the external_id search misses, search by email and update a contact with no external_id. Otherwise keep creating, so users sharing an email stay separate.
Refs ACT2-1371, INT-7464
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Intercom has no conditional update and a PUT silently replaces an external_id, so rows sharing an email could overwrite each other on one contact. Read the contact directly before claiming it, because search lags behind writes, and let only the first row in a router call claim a contact; the others retry. Rows on different router workers can still collide.
Gate the path on lookup external_id, and use one check for payload and search, so other setups keep today's behaviour. Log each claim with ids only.
Refs ACT2-1371, INT-7464
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The router step changed event stream rows that resolve to one contact, so apply it only to rETL rows that opted in. A deferred row could also run out of its rETL retry limit before it was sent, so defer with a 429, which that limit exempts.
Refs ACT2-1371, INT-7464
Co-Authored-By: Claude Opus 5.5 <[email protected]>
An email search can lag by minutes, so it can't show that two contacts exist. Refs ACT2-1371, INT-7464
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unresolved contact-adoption flaws can overwrite a contact’s changed email, let losing claims delete company associations, and miss later-page candidates, causing repeated conflict failures.
This PR fixes Intercom v2 rETL identify requests that use lookup: external_id, preserving the mapped ID alongside email and adding guarded adoption of email-only contacts.
Changes:
Preserve mapped external_id and search by it for opted-in identify events.
Check email-only contacts with a direct read and defer competing claims within a router call.
Add unit, component, and live coverage while checking unchanged behavior for other flows.
A company detach ran before the claim check, so a deferred row could remove a company from the contact, and a claimed contact has nothing to detach anyway. Claim in a separate step, so only a contact found by external_id detaches. The direct read now also confirms the contact still holds the row's email.
Refs ACT2-1371, INT-7464
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The email fallback ignores pagination, so an unclaimed contact on a later page is missed and triggers the same POST 409 retry-exhaustion failure the change aims to fix.
An object or array external_id makes the search return early with no result, and the claim step then treated that as not found, so a bad value could reach a real contact. Such rows now behave as before this change.
Refs ACT2-1371, INT-7464
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The per-group claim guard allows cross-job external_id overwrites within one router request, while incomplete search pagination can still cause repeated contact creation and retry exhaustion.
This guard runs per workflow group, not per router request: src/services/destination/cdkV2Integration.ts:126–145 splits inputs using groupRouterTransformEvents, whose key includes message.context.sources.job_id. Two source jobs targeting the same destination can therefore both emit a PUT claiming the same email-only contact in one request, allowing the later write to overwrite the first external_id without involving separate workers. Coordinate claims across the request while preserving separate transformation contexts, and add a router regression case with distinct source-job IDs.
The reason will be displayed to describe this comment to others. Learn more.
The root cause analysis and the fix shape look right to me: keep the mapped external_id in the payload, search by it, and claim an ID-less contact holding the email when the search misses. #4739's = null was never meant to drop an explicitly mapped external_id, so restoring it is the correct fix, and the claim is the only way to converge the contacts this flow created since February. The GET before a claim and the per-batch guard are both needed, since Intercom has no conditional update and a PUT with a new external_id answers 200. One ask below: fold the two searches into one.
One external_id-or-email search now decides all three outcomes: update the contact that holds the external_id, else claim a contact that holds the email with no external_id, else create. A new user takes one call instead of two and a claim two instead of three. When a full page of results has no external_id match, search by external_id alone, since the match may sit past the first page.
The result names how the contact was matched, so a company detach still runs only on an external_id match. Suggested in review by ItsSudip.
Refs ACT2-1371, INT-7464
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The external-ID comparison can mistake null or absent fields for literal mapped IDs, selecting the wrong contact, bypassing the direct GET guard, and potentially allowing company detachment.
String(null) and String(undefined) equal the IDs "null" and "undefined", so an email-only contact could count as the row's external_id match, skipping the direct read and allowing a company detach. Found in review by Codex and Copilot.
Refs ACT2-1371, INT-7464
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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
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.
ACT2-1371 · INT-7464
What changed and why
Rows in a v2 rETL Intercom identify aborted with 410
retry limit reached. The real reply was a 409: the search usedexternal_id, butPOST /contactscarried only the email, so Intercom refused it when a contact held that email. The handler retries a 409 as search lag, so the row ran out of retries. New contacts also lost theirexternal_id, so no later sync could find them.Setups with
lookup: external_idnow sendexternal_idwith the email, and one search byexternal_idor email decides the outcome: update the contact that holds theexternal_id, else claim a contact that holds the email with noexternal_id, else create. A new user takes one Intercom call and a claim two. When a full page of 50 results has noexternal_idmatch, a second search byexternal_idalone covers a match past page one. Other setups do not change. The search reports whether it matched byexternal_idor by email, so only a contact found byexternal_idcan get a company detach, never a claimed one.Real Intercom answers
POST /contactswith an email and a newexternal_idas follows:POSTexternal_idPOSTexternal_idPUTon that contact, adding theexternal_idA
PUTwith a differentexternal_idanswers 200 and silently replaces it, and Intercom has no conditional update. So a claim has these guards:GETconfirms the contact is still free, because search lags behind writes.GETalso confirms the contact still holds the row's email.external_idmatch needs the contact to actually hold one, so the IDs"null"and"undefined"never match an email-only contact.external_id+ email,lookup: external_idexternal_iddroppedexternal_id, then claim by email on a missexternal_id+ email, no such lookupexternal_iddroppedexternal_idsentPlease review these points
GETand bothPUT, and the later one replaces the earlier ID. This was not reproduced on mini. It needs rows that share an email, and an email-only contact that holds it.external_idtakes the row's ID and field values. We cannot tell whose contact it was. The customer needs to agree to this before release.GET. Deferred rows answer 429, which feeds pickup throttling where adaptive throttling is on.Review panel
Self-check with 6 lenses and Codex, then a Claude and Codex adversary on each of 6 claims. The single search was checked against the earlier two-search flow over 40,000 simulated cases, and Intercom's
external_idsearch was confirmed to be exact (case and spaces matter). Findings were fixed on this branch.7b9ea25ccVerification
Real rETL syncs on mini through rudder-server and the transformer, delivered to the Intercom test workspace. This ran a build of
7b9ea25cc.external_idlostexternal_id7b9ea25cc, including 3 new scenariosnpm run test:ts -- component --destination=intercom: 80 passednpm test -- --testPathPattern="destinations/intercom" --no-coverage: 84 passedNot in this PR
sendAnonymousIdcan replace anexternal_idon a contact found by email.🤖 Generated with Claude Code