Repository navigation
fix(tiktok_audience): keep batch_data aligned with id_schema - #5520
maheshkutty merged 1 commit into
Conversation
TikTok reads each batch_data row positionally against id_schema, but
prepareIdentifiersPayload built the row by iterating the identifiers object
and pushing only truthy values. Two ways that misaligns the row:
- A user missing an identifier produced a shorter row, shifting every later
id into the wrong slot. A user with only an email was sent as a one-entry
row against a four-entry schema, so TikTok read the email hash as an
AAID_SHA256.
- id_schema is sorted but the row followed the identifiers object's own key
order, so even a fully populated user could be emitted out of order.
Walk the sorted schema instead and emit `{}` for any slot the user has no
usable value for, which is how TikTok expects "this user has no such id".
Events whose slots are all placeholders still abort with "No identifiers
found" — a row of nothing but placeholders identifies no one.
Native Test 18 had frozen the old behaviour into its expected payload
(two ids against a four-entry schema); its fixture is updated to match.
Reported by Chatbooks, who worked around it by rebuilding the connection to
match on email only.
Co-Authored-By: Claude Opus 5 <[email protected]>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## hotfix/tiktok_ads_id_schema #5520 +/- ##
============================================================
Coverage 93.00% 93.00%
============================================================
Files 719 719
Lines 39047 39054 +7
Branches 9137 9084 -53
============================================================
+ Hits 36314 36323 +9
- Misses 2510 2532 +22
+ Partials 223 199 -24 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|



What are the changes introduced in this PR?
TikTok reads each
batch_datarow positionally againstid_schema.prepareIdentifiersPayloadbuilt the row by iterating theidentifiersobject and pushing only truthy values, which misaligned it in two independent ways:AAID_SHA256. This is the customer report.id_schemais sorted, the row was not. The row followed theidentifiersobject's own key order, so even a fully populated user could be emitted out of order —AAIDandPHONEsilently swapped. This was not in the report and is the more insidious of the two, since nothing about the record looks wrong.The fix walks the sorted schema instead of the object, and emits
{}for any slot the user has no usable value for.Events whose slots are all placeholders still abort with
No identifiers found— a row of nothing but placeholders identifies no one.Why
{}and not a reorderedid_schemaTwo independent confirmations that the placeholder is the contract:
audienceListpath intransform.tsmaps over the schema and emits{}for a missing trait:recordpath match it.What is the related Linear task?
Not yet filed — reported by Chatbooks in a shared Slack channel and triaged in #. Happy to link one before merge.
Please explain the objectives of your changes below
Restore correct identifier attribution for TikTok audiences. Any record with a missing or invalid identifier currently has its remaining ids attributed to the wrong identifier types, which corrupts audience matching silently — TikTok returns
200either way. Customers only notice as unexplained low match rates.The affected customer worked around it by rebuilding their connection to match on email only, which is exactly the configuration in which the bug cannot appear (a single-slot schema is always aligned). Enriching with any additional identifier re-exposes it.
Any changes to existing capabilities/behaviour, mention the reason & what are the changes ?
batch_datarows now always have exactlyid_schema.lengthentries, where previously they had only as many entries as the record had non-null identifiers. This is the fix, and it is a wire-format change for everyrecord-path TikTok audience payload with a sparse or unsorted identifier set.test/integrations/destinations/tiktok_audience/router/data.ts— "Native Test 18: record events: invalid identifiers" had frozen the old behaviour into its expected payload (two ids against a four-entryid_schema, i.e. the misalignment itself) and had always passed. Its fixture is updated; please sanity-check that fixture rather than assuming it was collateral damage.Any new dependencies introduced with this change?
N/A
Any new generic utility introduced or modified. Please explain the changes.
N/A — one new local type,
BatchIdentifier = Identifier | IdentifierPlaceholder, so a placeholder is representable.Any technical or performance related pointers to consider with the change?
Payload size grows for sparse records (an extra
{}per unfilled slot). Grouping is unchanged: it already keys onid_schema, and rows are now uniformly that length.Verification
Unit — 12/12 in
recordTransform.test.ts, including 3 new alignment cases. All three were confirmed to fail before the fix (row length 1 vs schema 4; AAID/PHONE hashes swapped), so they can actually catch a regression.Component — 16/16 for
tiktok_audience. Repo-widetsc --noEmit, eslint and prettier clean.End-to-end on a local stack, against the real TikTok API. Transformer built from this branch and deployed into the stack, verified the patched code was actually in the running container, then drove a real rETL sync from a warehouse source into a live TikTok audience with
AAID_SHA256,EMAIL_SHA256,PHONE_SHA256mapped and nulls seeded across every gap shape. The payload was captured off the wire between rudder-server and the transformer:Sync result: 20 changed → 20 successful, 0 failed / dropped / invalid. TikTok accepted the
{}placeholders.Running the identical payload against the current published transformer image reproduces both bugs:
Row 2 is bug #2: all identifiers present,
AAIDandPHONEswapped.Linear ticket
Resolve INT-7054
Developer checklist
My code follows the style guidelines of this project
No breaking changes are being introduced. — see changes to existing behaviour above: the emitted
batch_datashape changes. That is the fix, but it is a wire-format change worth a reviewer's eyes.All related docs linked with the PR?
All changes manually tested?
Any documentation changes needed with this change?
Is the PR limited to 10 file changes? — 4 files
Is the PR limited to one linear task?
Are relevant unit and component test-cases added in new readability format?