Skip to content

fix(intercom): send mapped external_id with email in rETL v2 identify - #5763

Merged
arpl merged 10 commits into
developfrom
fix/act2-1371-intercom-retl-external-id
Nov 3, 2026
Merged

arpl merged 10 commits into
developfrom
fix/act2-1371-intercom-retl-external-id

Conversation

@arpl

@arpl arpl commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

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 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.
Record Before After
rETL identify, external_id + email, lookup: external_id external_id dropped 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.

Verification

Real rETL syncs on mini through rudder-server and the transformer, delivered to the Intercom test workspace. This ran a build of 7b9ea25cc.

Row state Stock This PR
New user Created, external_id lost Created with external_id
Email-only contact 410 Same contact, now with the ID
Email held by another user 410 Separate contact, the other user unchanged
Contact found by ID Updated Updated
Three users share an email an email-only contact holds Not run Three contacts with three IDs
Re-sync straight after Not run 7 of 7 delivered, nothing moved
  • Live Integration Tests on real Intercom: passed on 7b9ea25cc, including 3 new scenarios
  • npm run test:ts -- component --destination=intercom: 80 passed
  • npm test -- --testPathPattern="destinations/intercom" --no-coverage: 84 passed

Not in this PR

  • A search-lag 409 can still end as a masked 410 inside the rETL retry limit.
  • Event-stream destinations can get the same 409.
  • A row whose email-only contact is past the first 50 search results still gets the 409. It needs over 50 users on one email.
  • sendAnonymousId can replace an external_id on a contact found by email.

🤖 Generated with Claude Code

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]>
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

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.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@codecov

codecov Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ 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.

Files with missing lines Patch % Lines
src/cdk/v2/destinations/intercom/utils.js 98.75% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #5763   +/-   ##
========================================
  Coverage    92.42%   92.43%           
========================================
  Files          741      741           
  Lines        41059    41123   +64     
  Branches      9641     9677   +36     
========================================
+ Hits         37949    38012   +63     
+ Misses        2926     2849   -77     
- Partials       184      262   +78     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

arpl and others added 5 commits November 2, 2026 19:02
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]>
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]>
@arpl
arpl marked this pull request as ready for review November 2, 2026 19:02
@arpl
arpl requested review from a team as code owners November 2, 2026 19:02
@arpl
arpl requested review from ItsSudip and krishna2020 and a balanced review from Copilot November 2, 2026 19:02

Copilot AI 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.

🟡 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.

3 open issues
What changed in this PR

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.
File Description
test/​integrations/​destinations/​intercom/​router/​data.ts Tests competing claims and 429 deferral.
test/​integrations/​destinations/​intercom/​processor/​trackTestData.ts Checks unchanged rETL track behavior.
test/​integrations/​destinations/​intercom/​processor/​identifyTestData.ts Covers mapped IDs, adoption, and stale ownership.
test/​integrations/​destinations/​intercom/​network.ts Adds search and direct-read response fixtures.
test/​integrations/​destinations/​intercom/​live/​spec.ts Adds three real-Intercom identify scenarios.
src/​cdk/​v2/​destinations/​intercom/​utils.test.js Tests opt-in detection, adoption, and claim deferral.
src/​cdk/​v2/​destinations/​intercom/​utils.js Adds adoption checks and repeated-claim handling.
src/​cdk/​v2/​destinations/​intercom/​rtWorkflow.yaml Applies claim arbitration to transform results.
src/​cdk/​v2/​destinations/​intercom/​procWorkflow.yaml Retains mapped IDs alongside email for opted-in identify events.

Review effort: Balanced

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]>
Copilot AI balanced review requested due to automatic review settings November 2, 2026 19:10

Copilot AI 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.

🔵 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.

2 open issues
1 resolved since last review

Review effort: Balanced

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]>
Copilot AI balanced review requested due to automatic review settings November 2, 2026 19:16

Copilot AI 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.

🔵 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.

2 open issues
1 previously missed issue

In code that hasn't changed since last review

High severity Coordinate contact claims across router groups

src/​cdk/​v2/​destinations/​intercom/​rtWorkflow.yaml:21

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.

Review effort: Balanced

@ItsSudip ItsSudip left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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]>
Copilot AI balanced review requested due to automatic review settings November 3, 2026 16:04

Copilot AI 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.

🟡 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.

2 open issues
1 resolved since last review

Review effort: Balanced

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]>
Copilot AI balanced review requested due to automatic review settings November 3, 2026 16:14

Copilot AI 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.

🔵 Needs a closer look

A subtle zero-valued ID edge case can still cause identity loss across multiple processing paths, warranting human assessment.

1 open issue
1 resolved since last review

Review effort: Balanced

@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 2026

Copy link
Copy Markdown

@arpl
arpl requested a review from ItsSudip November 3, 2026 16:32
@arpl
arpl merged commit 86aa9b8 into develop Nov 3, 2026
54 checks passed
@arpl
arpl deleted the fix/act2-1371-intercom-retl-external-id branch November 3, 2026 18:22
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.

3 participants