Skip to content

feat(gainsight_px_audience): sync trait attributes for audience members - #5703

Merged
krishna2020 merged 9 commits into
developfrom
feature/gpx-audience-trait-mappings
Oct 22, 2026
Merged

krishna2020 merged 9 commits into
developfrom
feature/gpx-audience-trait-mappings

Conversation

@arpl

@arpl arpl commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

What

Members are written { <flag>: true, ...traits } (flag first); leavers { <flag>: false } only, so traits keep their last value. traits.ts converts each trait to its stored PX type (STRING/NUMBER/BOOLEAN/DATE_TIME; zone-less date-times as UTC; blank strings are not numbers); a null, unconvertible or untyped value is left out, so a value the transformer cannot convert never blocks the flag (PX rejects the whole write on one bad value). PX-side rejections still do — e.g. a trait attribute disabled or retyped in PX after setup. Malformed API-saved fieldMappings are parsed leniently. One warn per transform pass per (attribute, reason) with a count — never values or IDs. Delivery: a 404 is success only for a leave (exactly one key, value false). New router/dataDelivery fixtures and live scenarios.

Spec: rudder-specs#229 — trait-mappings.md (D17–D26), extending GPX Audience v1 (rudder-specs#216). Context: Cvent asked for membership flags and trait sync (2026-10-16).

Pre-ready review. Per-task spec+quality review, then a whole-branch cross-repo review (setup output ↔ client save paths ↔ transformer schema; listFields shape ↔ client splits; type stamping; leave detection; privacy; v1 back-compat). Final-review fixes re-reviewed. Deferred minors and rulings are in the spec PR's plan ledger.

Verification on rudder-mini against the PX sandbox (report: rudder-specs#229 verify/2026-10-20-trait-mappings-mini-verification.md): 20/20 PASS, 0 FAIL on the current heads (info 290f998, transformer c9bcca0, webapp 7eaa99b29, Lookout 4c7631480): flag + STRING/NUMBER/DATE_TIME traits end to end, leave keeps traits, unconvertible values left out with the flag still landing (incl. a pre-1970 date), 404 verdicts, mapping change → full sync, webapp and Lookout create/edit/remove-all, pre-v1.1 activations unchanged; live specs info 8/8, transformer 7/7. Reviewer feedback addressed (see comments).

Deploy order (spec §7): integrations-info and transformer first, then webapp and Lookout. No new flag; behind the v1 gates.

🤖 Generated with Claude Code

arpl and others added 5 commits October 20, 2026 12:10
Members get { flag: true, ...traits } with each value converted to its PX type; leavers get
{ flag: false } only. Unconvertible values are left out and logged once per call per
(attribute, reason) with a count (trait-mappings D18, D23, D25).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…dontBatch rows

Document that the left-out counter is per transformEvents pass and that dontBatch rows log
separately; add a test covering it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ave on 404

With traits a member write carries several attributes, so the 404 override now keys on
exactly one key whose value is false (trait-mappings D24). Adds trait dataDelivery fixtures
and two live scenarios (three trait types; an unconvertible trait left out).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A stored type: null, more than 50 fieldMappings rows or a non-object
fields value failed input-schema validation for the whole row, flag
included (trait-mappings D18). Make the trait inputs lenient: invalid
rows are dropped, rows beyond the first 50 are ignored, and a
non-object fields value is treated as no field values. A row with a
missing or null type still reaches collectTraits and is logged as
unknown_type. Also correct the delivery 404 comment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 20, 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
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a5ed164f-e692-46c4-8aa8-47fc3295c538

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

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

@am6010 am6010 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

rudder-transformer#5703 review: gainsight_px_audience trait mappings

Reviewed at ed2359442 (draft, base develop); the later 02bb5f2e7 only touches a time-zone guard in traits.test.ts and doesn't change the findings (it makes S2 more relevant). Spec: rudder-specs#229 @ 6bfafd1 trait-mappings.md.

Verdict

COMMENT. I found no confirmed blocker. v1 behaviour is unchanged, leavers write only the flag, and all 135 tests pass locally. The headline claim "a bad value never blocks the flag" holds for values the transformer rejects. It does not hold for values the transformer accepts but PX may reject (S1, S3). Two of those are cheap to guard (S1, S2). Re-check S1 after the NUMBER/DATE_TIME sandbox run. If PX rejects a fractional or out-of-range DATE_TIME, S1 becomes blocking.

BLOCKING

None confirmed.

SHOULD-FIX

S1. traits.ts:58: DATE_TIME numbers are sent unchecked.

  • Defect: any finite number goes out as-is. Fractional, out-of-range and epoch-seconds values are all sent.
  • Verified with a probe (convertTraitValue):
    • 1760000000000.5 → sent 1760000000000.5
    • 1e20 → sent 1e20 (not a valid JS Date)
    • -1 → sent
    • 1760000000 (epoch seconds) → sent, which PX reads as 1970-01-21
  • Scenario: a Postgres model with extract(epoch from ts)*1000 gives fractional ms. If PX wants a long, it returns 400 (unverified, since the spec §3 table says DATE_TIME was not probed). PX rejects the whole write (spec §3), and delivery aborts on 400 (delivery.ts:4, dataDelivery fixture 12). So that member's flag never lands, and the row is not retried.
  • Fix: for a number, require Number.isInteger(v) && Math.abs(v) <= 8.64e15, otherwise leave it out (or Math.trunc first). Add three rows to traits.test.ts:49-58.

S2. traits.ts:29: the Date.parse fallback takes non-ISO strings and junk, and their meaning depends on the host time zone.

  • Defect: only ISO zone-less strings are pinned to UTC. Every other string goes to V8's lenient Date.parse.
  • Verified with TZ=America/Los_Angeles:
    • "10/20/2026" → 2026-10-20T07:00Z
    • "Oct 20 2026 10:00" → 17:00Z
    • "1" → 2001-01-01T08:00Z
    • "12" → 2001-12-01
  • Scenario: a VARCHAR column holding "1", "12" or US-format dates writes a wrong date silently. The value is not left out and nothing is logged.
  • Fix: accept only ISO-8601 shapes, using one regex: YYYY-MM-DD, optional [ T]hh:mm[:ss[.f]], optional Z or ±hh[:mm]. Pin zone-less values to UTC and leave everything else out. This also replaces ZONELESS_DATE_TIME (traits.ts:23).

S3. PR body and spec §2: the claim is broader than the code.

  • Defect: some rejections happen on the PX side, where the transformer cannot see them. Each one still blocks the flag for every member write that carries the trait:
    • the attribute is disabled, deleted or retyped after /setup (spec §6 admits this)
    • PX limits nobody has probed: STRING max length (a 100 000-char string is sent as-is, verified), NUMBER range or float, negative DATE_TIME
  • Scenario: a PX admin disables CDP_userRole. From then on, every insert/update returns 400 → abort, so new members never get true. The only signal is the failed-row reason.
  • Fix (minimal): reword the claim to "a value the transformer cannot convert never blocks the flag". Add STRING length, NUMBER float/large and DATE_TIME bounds to the sandbox run that is already in progress. Add a guard only where PX actually rejects.

NITS

  • N0 traits.ts:92. The 50-row cap runs before the shape filter, and dropped rows are never logged. Only an API-written config that bypasses /setup can hit it.
    • Defect: slice(0, 50) runs before .filter(...). Rows 51+ and malformed rows vanish without a warn, despite the "never silently disappearing" doc at traits.ts:86-87.
    • Verified: 10 malformed rows plus 50 valid rows keeps only 40 valid rows.
    • Fix: delete the cap (MAX_TRAIT_MAPPINGS, config.ts:36-37, traits.ts:9,92, and the test at routerTransform.test.ts:481). /setup already enforces 50. Sending more traits does not put the flag at risk, so the cap only loses data.
  • N1 traits.ts:46. Number() accepts "0x1F"→31, "0b101"→5 and "1e3"→1000. It silently rounds "9007199254740993"→…992. All verified. Optional fix: a decimal regex before Number().
  • N2 routerTransform.ts:104,117, types.ts:64. "Flag first" is not guaranteed. JS orders integer-like keys first, and \w allows "123", so the result is {"123":"v","flag":true} (verified). This is harmless because isLeave counts keys. Drop the "flag first" wording and the test name at routerTransform.test.ts:293.
  • N3 traits.ts:118-123. With a duplicate to, the first value is written but the second row is logged as left out (verified). This only happens with API-saved configs, since /setup refuses duplicates. Ignore it, or dedupe by to.
  • N4 traits.ts:100. The type normalisation is redundant: convertTraitValue already rejects non-string types (traits.ts:64-65,72). Pass row.type through.
  • N5 config.ts:33-34. LOG_DEST_TYPE has a single use. Inline it.
  • N6 live/spec.ts. Every live scenario now carries fieldMappings, so nothing live exercises a v1 config with no fieldMappings. Unit coverage exists (routerTransform.test.ts:539). Optionally keep one live v1 scenario without the key.

Questions

  1. What does rudder-sources (mappers/record.go:119-123, passes column JSON through) emit for Snowflake TIMESTAMP_NTZ and NUMBER(38,0)? Does it send ISO with Z, and numeric strings? If epoch ms arrives as a string such as "1760000000000", DATE_TIME leaves it out on every run (verified). NUMBER, by contrast, accepts numeric strings. This is spec §8 Q2 and is unverified.
  2. Is "flag lost while a trait attribute is broken in PX" (S3) an accepted product trade-off? The alternative is a flag-only request plus a traits request, which doubles the PX quota. If it is accepted, the customer guide line in spec §6 is the only mitigation.
  3. PX sandbox results for NUMBER (int-only?) and DATE_TIME (string accepted? negative?): the PR body says these are pending.

Can be deleted (minimal scope)

  • The MAX_TRAIT_MAPPINGS cap and its test (N0).
  • The type ternary (N4).
  • The LOG_DEST_TYPE constant (N5).
  • ZONELESS_DATE_TIME plus the Date.parse fallback, folded into one strict ISO regex (S2).

What I checked / ran

  • Read the full diff: traits.ts, routerTransform.ts, delivery.ts, types.ts, config.ts, tests and fixtures. Read spec #229 trait-mappings.md.
  • Unit tests: jest -c jest.config.typescript.js src/v0/destinations/gainsight_px_audience under Node 22, 3 suites, 114/114 pass.
  • Component tests: component.test.ts --destination=gainsight_px_audience. 21/21 pass, covering router, EU base URL, 404 leave/member, 400 abort, 429 throttled and 500 retry.
  • Probe: a throwaway jest file ran convertTraitValue and collectTraits over ~50 inputs under TZ=UTC and TZ=America/Los_Angeles. Inputs included null, "", NaN, Infinity, numeric strings, booleans, a 100k-char string, zone-less and offset dates, non-ISO dates, epoch s and ms as numbers and strings, a fractional epoch, 1e20, __proto__/constructor, duplicate to, and 60 rows. The S1, S2, N0 and N1–N3 results come from this run.
  • v1 back-compat:
    • The test diff removes no assertions; only the buildConnection signature widened.
    • Router and dataDelivery v1 fixtures are untouched and pass.
    • With no fieldMappings, collectTraits(undefined) returns {}, so the body is {flag:true} / {flag:false}, identical to v1.
    • isLeave (delivery.ts:27-35) gives the same verdict as the old sentValue for v1 bodies.
  • Leavers: routerTransform.ts:73-76 writes {flag:false} only and never reads fields. Tests at routerTransform.test.ts:331 and router fixture 6 cover it.
  • Config: read per row from connection.config.destination.fieldMappings (routerTransform.ts:64,74), schema z.unknown() (types.ts:32). When /setup is skipped, untyped rows are left out as unknown_type, so they are never sent raw.
  • Batching: one record per PUT (routerTransform.ts:94-97), with flag and traits in the same body. A trait rejection therefore fails the flag (S1/S3).
  • Logging: one warn per pass per (attribute, reason) with no values or ids (routerTransform.ts:120-126). There is a new instance per request and passes run sequentially (processDestinationIntegration.ts:220,253,260), so the instance map is safe.
  • House pattern: no other audience destination in this repo reads message.fields (grep across braze/iterable/customerio/hs/linkedin audience), so there is no trait-conversion precedent to copy. hs_audience/routerTransform.ts:104 already overrides transformEvents.
  • Not verified: PX acceptance of floats, large numbers, long strings or DATE_TIME edge values; rudder-sources value serialisation per warehouse; live runs (none were run).

@codecov

codecov Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.30%. Comparing base (e518283) to head (25d1f04).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #5703      +/-   ##
===========================================
+ Coverage    92.28%   92.30%   +0.02%     
===========================================
  Files          731      732       +1     
  Lines        40616    40726     +110     
  Branches      9513     9480      -33     
===========================================
+ Hits         37484    37594     +110     
- Misses        2868     2948      +80     
+ Partials       264      184      -80     

☔ 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 2 commits October 20, 2026 16:09


- DATE_TIME numbers must be integers in 0..8.64e15 (PX 400s fractional,
  negative and 1e20); strings are strict ISO-8601 only, parsed to epoch ms
  (zone-less is UTC), never sent as strings (PX stores them as 0)
- NUMBER strings must be decimal text (no hex/binary)
- drop the 50-row cap, the type ternary and LOG_DEST_TYPE
- stop logging null values: normal for nullable columns
- reword the "never blocks the flag" comments to what the code can promise

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… strings

Parsed ISO strings now go through the same 0..8.64e15 integer rule as numbers
(PX 400s negative values), and impossible calendar dates such as 2026-02-30
are left out instead of rolling over into March.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@arpl

arpl commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

@am6010 thanks for the thorough review. Every point is addressed or answered below. The live PX sandbox probe (2026-10-20) settled the NUMBER/DATE_TIME questions: DATE_TIME takes only integer epoch ms (fractional, negative and 1e20 → 400; an ISO string → 204 but stored as 0), NUMBER takes any finite number but not a numeric string, and STRING is cut to 2000 chars. The deploy order is now transformer → webapp + Lookout → integrations-info (spec §7).

rudder-transformer #5703 replies (fix in 2aa3486)

  • S1: Fixed in 2aa3486. Your guess was right: PX 400s fractional (1792490400000.5), negative (-1000) and 1e20 DATE_TIME in the sandbox probe. DATE_TIME numbers now need to be integers in 0..8.64e15, otherwise they are left out as unconvertible. Rows added to traits.test.ts.
  • S2: Fixed in 2aa3486. One strict ISO-8601 regex (date, optional [ T]time, optional Z or offset); zone-less is UTC; "1", "12", "10/20/2026" and "Oct 20 2026 10:00" are now left out. ZONELESS_DATE_TIME and the Date.parse fallback are gone. The probe also showed PX returns 204 but stores 0 for a DATE_TIME string, so strings are always sent as epoch ms.
  • S3: Reworded the code comments to "a value the transformer cannot convert never blocks the flag", and they say a PX-side rejection (attribute disabled or retyped after setup) still fails the write. PR body is updated separately. Probe: STRING 100k chars is accepted (204, PX truncates to 2000), NUMBER accepts floats, negatives, 1e20 and 2^53+1, so no extra guards there.
  • N0: Deleted the 50-row cap (MAX_TRAIT_MAPPINGS, slice and its test; replaced with a 60-row test). Malformed rows are still dropped.
  • N1: Done. NUMBER strings must match a decimal regex before Number(); "0x1F" and "0b101" are left out. (The 2^53 rounding on an unsafe-integer string is not guarded; PX accepted 9007199254740993 in the probe.)
  • N2: Dropped the "flag first" wording and the test assertion/name.
  • N3: Not changed. /setup refuses duplicate to, so only an API-saved config can hit it.
  • N4: Done, row.type is passed through.
  • N5: Done, LOG_DEST_TYPE inlined.
  • N6: Skipped. Unit coverage for v1 without fieldMappings stays (routerTransform.test.ts); the live scenarios still pass the same assertions, only a comment changed.
  • Deletions: cap, type ternary, LOG_DEST_TYPE and ZONELESS_DATE_TIME/Date.parse all removed in 2aa3486.
  • Also (D25 ruling): null values are no longer logged, since they are normal for nullable columns. Only unconvertible and unknown_type are warned.
  • Q1: Not verified here; sources' value serialisation stays an open item in spec §8 Q2. Note numeric epoch strings are left out for DATE_TIME (PX would otherwise need a number).
  • Q2: Accepted trade-off for now: one PUT with flag and traits, so a PX-side rejection can fail the flag; mitigation is the customer guide line in spec §6. A flag-only plus traits request would double PX quota.
  • Q3: Sandbox results (2026-10-20): NUMBER 7/7.5/-3/1e20/2^53+1 -> 204, numeric string "7" -> 400. DATE_TIME int epoch ms -> 204; epoch seconds -> 204 (lands in 1970); fractional/negative/1e20 -> 400; ISO string -> 204 but stored as 0. STRING 100k -> 204, truncated to 2000.

re-review

  • Parsed ISO strings now get the same 0..8.64e15 range rule (so "1969-12-31" is left out, PX 400s negatives) and impossible dates like "2026-02-30" are left out instead of rolling into March; tests added first, fixed in c9bcca0.

Mini verification against the PX sandbox: 17 PASS, 0 FAIL (rudder-specs#229 verify/2026-10-20-trait-mappings-mini-verification.md). The Lookout enable/edit cases are still pending a test audience.

@arpl
arpl requested a review from am6010 October 20, 2026 13:51

@am6010 am6010 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed 02bb5f2e7..c9bcca00c. Every point from my review is addressed as described, and 140/140 unit + 21/21 component tests pass under both UTC and America/Los_Angeles.

  • S1/S2: DATE_TIME is always an integer epoch ms in 0..8.64e15. I probed the strict ISO parser with +05:30/+0530/+05, fractional seconds, leap days, 2026-02-30, T24:00, lowercase t/z and padding: correct, and independent of the host time zone. NUMBER strings are converted to numbers, so PX's 400 on "7" can't happen.
  • Optional nit: a space before the zone ("2026-10-20 10:00:00.000 -0700", "... UTC") is now left out, where Date.parse used to read it correctly. That only matters if Q1 shows rudder-sources sends text timestamps.
  • Optional nit: epoch seconds still lands in 1970 (PX 204). Worth one line in the customer guide.

@arpl
arpl marked this pull request as ready for review October 20, 2026 15:49
@arpl
arpl requested review from a team as code owners October 20, 2026 15:49
@sonarqubecloud

Copy link
Copy Markdown

@krishna2020
krishna2020 merged commit aef00d3 into develop Oct 22, 2026
38 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.

4 participants