Skip to content

fix: group router transform events by source job so concurrent syncs reach their own list - #5705

Merged
arpl merged 5 commits into
developfrom
fix/act2-1257-group-router-events-by-connection
Oct 22, 2026
Merged

arpl merged 5 commits into
developfrom
fix/act2-1257-group-router-events-by-connection

Conversation

@arpl

@arpl arpl commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

What are the changes introduced in this PR?

When two rETL syncs feed the same audience destination and their runs overlap, rows from one sync are sent to the other sync's list, and both runs report success.

Cause: rudder-server sends every job of a destination in one /routerTransform call. groupRouterTransformEvents is meant to split those rows per source job (that was #3496), but it read ev.context?.sources?.job_id. Router inputs are { message, metadata, destination, connection }, so context is under message, and the key was always 'default'. Every sync on a destination landed in one group, and the batching framework builds the integration from the group's first connection (processDestinationIntegration.ts), so every request went to that connection's list.

Fix: key on ev.message?.context?.sources?.job_id. That is the only place the source job id reaches the router transform: rudder-server's router metadata (router/types/types.go JobMetadataT) has no source job field.

Exposed on develop (each takes the list / audience / module from one connection for the whole group):

Destination Where the target is read Path
Custom Activation (custom_audience) this.connectionConfig (endpoint audienceId, isHashRequired) batching framework
Reddit Audience audienceId from this.connectionConfig batching framework
Iterable Audience this.connection batching framework
HubSpot Audience audienceId from this.connection batching framework
Braze Audience customAttributeName from this.connectionConfig batching framework
LinkedIn Audience audienceId from the first row of each action group (transform.ts) v0 router
FB Custom Audience (VDM v2) groupedRecordInputs[0].connection (recordTransform.ts) v0 router
Google Ads Remarketing Lists, legacy and Data Manager (VDM v2) [0].connection (recordTransform.ts, dataManager/recordTransform.ts) v0 router
Customer.io Audience inputs[0].connection (segment, id_type) v0 router
Zoho (VDM v2) inputs[0].connection (object module, identifierMappings) cdk v2
Customer.io (VDM v2 object destination) object from this.connection (vdmV2ObjectDestination.ts): an event sync's rows went out as person identifies batching framework
HubSpot (rETL) path and objectType / identifierType from inputs[0] (hs/transform.ts, retl-transform.ts): a companies sync's rows went to the contacts upsert endpoint v0 router

Gainsight PX, Marketo and Pinterest Audience read each row's own connection and put the target in that row's request, so they were already safe (unchanged here).

When the two connections have different isHashRequired (Custom Activation, Reddit), the second sync's rows were checked against the first sync's flag and rejected as instrumentation errors ("Hashing is disabled but the value … appears to be unhashed"); nothing was sent unhashed.

Explainer: https://rudder-office.fly.dev/docs/audience-wrong-list-concurrent-syncs.html

What is the related Linear task?

Resolves ACT2-1257

Please explain the objectives of your changes below

  • src/v0/util/index.js: grouping key fix (one line) and comment.
  • src/v0/util/index.test.js: grouping tests rewritten with the real router input shape. The old tests put context at the top level, a shape production never sends, so they passed on the broken key.
  • A two-connection router component case for every exposed destination: custom_audience, reddit_audience, iterable_audience, hs_audience, braze_audience, linkedin_audience, fb_custom_audience, google_adwords_remarketing_lists (legacy and Data Manager), customerio_audience, zoho, customerio (person + event objects), hs (rETL contacts + companies). Two rows on one destination, each with its own message.context.sources.job_id, connection and matching metadata.sourceId (the shape rudder-server sends), asserting each request goes to its own list / module. Each case fails on the old key; the only other cases that fail there are the four regrouped fixtures below, which return to their old grouping.

Any changes to existing capabilities/behaviour, mention the reason & what are the changes ?

Rows that carry different source job ids, or a job id vs none, are now transformed in separate groups for every router destination. That is what #3496 intended. Effects:

  • Concurrent rETL syncs on one destination become separate vendor batches, each on its own connection (the fix).
  • Traffic from the stock SDKs and replays carries no context.sources.job_id, so its batching is unchanged. Events that do carry one (cloud/ETL extract sources run by rudder-sources, or a client that sets context.sources.job_id itself) now batch per job, in smaller batches.
  • A batch that mixes rETL rows with event-stream rows now goes out as two batches, and router output order can change. rudder-server validates router responses as a set of job ids, so no job is dropped or mis-attributed.
  • Delivery order for one user can change when that user's rows sit in two groups of one router call. rudder-server sends batched requests sorted by their lowest job id (router/worker.go:442-444), so with SDK rows j1, j3 in one group and an rETL row j2 in another, [j1, j3] is delivered before [j2] and j2's older value lands last, even when every request succeeds. If the second request fails, j3 is already delivered while j2 retries. Before, all three shared one request. Groups of an audience destination write different lists, so this matters only for destinations that mix one user's rETL and event-stream rows; dynamic-config grouping already behaves this way.
  • Braze with supportDedup: each group builds its own dedup lookup against Braze's current state (braze/transform.ts:618-630) and groups run concurrently, so when one user's rETL row and SDK row land in the same router call, the SDK group can drop the newer update as "Duplicate user detected". Rare; noted rather than handled here. Four existing fixtures had such mixes and were updated: marketo_static_list and customerio_audience (reorder only), mailchimp and google_adwords_offline_conversions (one batch becomes two, same rows and payloads).

Any new dependencies introduced with this change?

N/A

Any new generic utility introduced or modified. Please explain the changes.

groupRouterTransformEvents (shared by nativeIntegration.ts and cdkV2Integration.ts): grouping key reads the job id from message.context.sources.job_id instead of the non-existent top-level context.

Any technical or performance related pointers to consider with the change?

  • Smaller vendor batches only where one router call holds rows from several source jobs (concurrent rETL syncs; cloud/ETL or profiles sources that stamp context.sources.job_id sharing a destination with other traffic). At most one extra partial batch per extra group.
  • google_adwords_offline_conversions store sales: a mixed call now creates one offline user data job per group instead of one shared job.
  • Known edge, not changed here: a user transformation on an rETL connection that rebuilds the message without context.sources puts that sync's rows back in the default group.

Verification

  • Unit: src/v0/util/index.test.js 223/223.
  • Component: npm run test:ts -- component --feature=router 593 passed, 1 skipped.
  • npm test -- src/v0 src/services src/cdk src/v1: 3293 passed.
  • check:secret-paths against integrations-config main: no drift.
  • Local stack (rudder-mini), one Custom Activation destination, two mirror connections LIST_A / LIST_B from two 500-row tables, both full syncs started in the same second:
Transformer /LIST_A /LIST_B Requests carrying the other sync's rows Both runs reported
stock develop image (old key) 1,000 (500 from table B) 0 5 500 succeeded, 0 failed
this branch @ 98cf63f 500, all table A 500, all table B 0 500 succeeded, 0 failed

Pre-ready review

Independent review before opening, then a five-lens review panel (security, correctness, product, ops, coherence) with blinded adversarial checks on each finding and load-bearing claim. Findings and rulings:

  • Important, fixed: the first version keyed on metadata.sourceJobId first, and the new component cases only set that field. rudder-server never sends it on router requests, so the tests covered a path production doesn't take. Fixed in 98cf63f: key only on the message job id; cases now use the shape the router sends.
  • Minor, fixed: comment overstated "event-stream jobs share one group"; reworded. Fixture metadata.sourceId now matches each row's connection.
  • Should-fix, fixed: the first draft listed 5 exposed destinations; LinkedIn, FB Custom Audience, Google Ads Remarketing Lists (both paths), Customer.io Audience and Zoho have the same pattern. Review on the PR then added Customer.io (VDM v2 objects) and HubSpot rETL. Confirmed by executing two-connection inputs on base vs head, and each now has a test.
  • Nit, documented above: per-user delivery order across groups.
  • Minor, noted above: user transformations that drop context.sources. A possible follow-up is to also key rETL rows on metadata.sourceId (which the router does send) so a transformation cannot merge two syncs.
  • Not an issue: two connections cannot share a job_id (config-backend starts each rETL sync with its connection id; unique_source_destination on connections), and one connection keeps one job_id across runs and retries (checked in live rt_jobs).

Developer checklist

  • My code follows the style guidelines of this project

  • No breaking changes are being introduced.

  • 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? (32: 2 source/unit files, 30 component fixtures)

  • Is the PR limited to one linear task?

  • Are relevant unit and component test-cases added in new readability format?

Reviewer checklist

  • Is the type of change in the PR title appropriate as per the changes?

  • Verified that there are no credentials or confidential data exposed with the changes.

🤖 Generated with Claude Code

arpl and others added 2 commits October 20, 2026 19:08
…reach their own list

groupRouterTransformEvents read `ev.context?.sources?.job_id`, but router
inputs are `{ message, metadata, destination, connection }`, so the key was
always 'default'. Every rETL sync on one destination fell into one group, and
the batching framework built the integration from that group's first
connection: rows from a second concurrent sync went to the first sync's
list or audience while both runs reported success (ACT2-1257).

Key on `metadata.sourceJobId`, falling back to
`message.context.sources.job_id`. Event-stream jobs carry neither, so their
grouping is unchanged.

- rewrite the grouping unit tests with the real router input shape
- add a two-connection router case for custom_audience, reddit_audience,
  iterable_audience, hs_audience and braze_audience
- update marketo_static_list, mailchimp, google_adwords_offline_conversions
  and customerio_audience fixtures: rows with and without a source job id
  now batch separately (same per-row output, regrouped or reordered)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rudder-server's router request metadata has no source job field, so the
`metadata.sourceJobId` branch never matched in production; the source job id
reaches the transformer only as `message.context.sources.job_id`. Key on that
alone, and make the tests use the shape the router actually sends:

- grouping unit tests build the job id on the message only
- the five two-connection router cases give each row its own
  `message.context.sources.job_id` and a `metadata.sourceId` matching its
  connection, instead of `metadata.sourceJobId`

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: 9013c8c0-9db1-4157-b2c1-448b46009138

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.

@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.29%. Comparing base (e518283) to head (46940a7).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #5705   +/-   ##
========================================
  Coverage    92.28%   92.29%           
========================================
  Files          731      731           
  Lines        40616    40633   +17     
  Branches      9513     9441   -72     
========================================
+ Hits         37484    37502   +18     
- Misses        2868     2947   +79     
+ 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.

… read one connection per group

linkedin_audience, fb_custom_audience (VDM v2), google_adwords_remarketing_lists
(VDM v2 legacy and Data Manager), customerio_audience and zoho (VDM v2) take the
list, audience or module from one connection for the whole router group, so
they had the same wrong-list bug as the five audience destinations covered
earlier (ACT2-1257). Each new case sends two rows from two syncs (own
connection, own message.context.sources.job_id) and expects one request per
target; each fails on the old grouping key.

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

arpl commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Review panel: Approve with follow-ups

Reviewed at 98cf63ff1 by 5 lenses (security, correctness, product, ops, coherence), then 5 blinded adversarial checks on the findings and the claims the verdict depends on. The second-model (Codex) lane did not run: its provider key is missing in this environment. 0e1a282b6 landed after the panel. It adds tests only (one two-connection case each for the five extra destinations below); each case fails on the old key, and the full router suite passes (591 passed, 1 skipped).

Live check (rudder-mini, Custom Activation, two mirror syncs started in the same second)

Transformer /LIST_A /LIST_B Requests carrying the other sync's rows Runs reported
stock develop image (old key) 1,000 (500 from table B) 0 5 500 succeeded / 0 failed, both
PR head 500, all table A 500, all table B 0 500 succeeded / 0 failed, both

Findings

  • Should-fix, fixed in this PR: the exposed list missed five destinations with the same pattern: LinkedIn Audience, FB Custom Audience (VDM v2), Google Ads Remarketing Lists (legacy and Data Manager), Customer.io Audience and Zoho (VDM v2). Raised by two lenses, then confirmed by executing two-connection inputs on base and head for all six paths. The PR body table and tests now cover them.
  • Nit, documented in the PR body: per-user delivery order across groups. If one user's rows are in two groups of one router call and the second group's request fails, a later job can be delivered before an earlier one is retried. rudder-server sorts by MinJobID and the order barrier only blocks requests after a failure (router/worker.go:442, :903-925). Audience groups write different lists, so this matters only for destinations that mix one user's rETL and event-stream rows. Dynamic-config grouping already behaves this way.
  • Nit, follow-up: a user transformation on an rETL destination that drops context.sources puts that sync's rows back in the default group (processor/processor.go:1185-1198). The router already sends metadata.sourceId (router/types/types.go JobMetadataT), so adding it to the key for rETL rows would close this.
  • Nit: the first commit message describes the abandoned metadata.sourceJobId key. A squash merge (title = PR title) takes care of it.

Held up

  • Router metadata has no source job field; the router sends the raw rt_jobs payload as message (rudder-server router/types/types.go, router/worker.go:200). The message field is the only usable key.
  • context.sources.job_id is the connection: config-backend starts each rETL sync with its connection id, connections are unique per (source, destination), and one connection keeps one job_id across runs and retries. All of this was checked in live rt_jobs.
  • SDK event-stream batching is unchanged (no context.sources.job_id). Mixed rETL + event-stream calls split, with identical per-row output; the four regrouped fixtures were compared base vs head.
  • rudder-server validates router responses as a set of job ids, so regrouping and reordering drop or duplicate nothing (router/transformer/transformer.go:335-375).
  • Mutation table (9 keys): every wrong key fails at least one test, and both the original bug and a metadata.sourceJobId-only key fail all the two-connection cases.
  • Compacted router payloads keep message.context intact before grouping.
  • Mismatched isHashRequired across syncs: on base, the second sync's rows were rejected as instrumentation errors, not sent unhashed (executed). On head, each sync is hashed per its own connection.

Limits

  • Codex lane unavailable (missing AZURE_FOUNDRY_KEY).
  • Google Ads store-sales: one offline user data job per group on mixed calls. Not checked against Google's concurrency limits; worth watching error rates after deploy.
  • Prod per-destination router batch sizes were sampled, not read for every cluster.
  • The PR is in the same develop release as everything else; dedicated transformer environments need their own bump to get the fix.

@arpl
arpl marked this pull request as ready for review October 20, 2026 17:33
@arpl
arpl requested review from a team as code owners October 20, 2026 17:33
am6010
am6010 previously approved these changes Oct 21, 2026

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

Approving: the key fix is right, and the new cases prove it. Before merge, ideally (not blocking): add two-sync tests for CUSTOMERIO and hs rETL, and fix two lines in the description. Also one FYI on Braze.

I checked the router input shape against rudder-server master:

  • Inputs arrive as {message, metadata, destination, connection}.
  • The compacted payload is expanded before grouping (routes/destination.ts:21-28 → routerTransformCompactedPayloadV1.ts:31).
  • JobMetadataT sends no source job id: Parameters is json:"-", and Dehydrate() clears JobT.
  • The server only splits router calls by OAuth destination (worker.go:236-260).

So message.context.sources.job_id is the right key, and the fix is not redundant with anything on the server side. With the key reverted, the router suite fails only the 11 new cases and the 4 updated fixtures, and every new case fails because the second sync lands on the first sync's target.

1. FYI, not blocking: Braze supportDedup can keep an older value. Each group builds its own dedup lookup (braze/transform.ts:618-630), and groups run concurrently. When one user's rETL row and SDK row land in the same router call, the SDK group dedups against Braze's old state and can drop the newer update as "Duplicate user detected". We reproduced it through doRouterTransformation. It's a rare case, so I'm fine shipping as is. One line in the description is enough.

2. CUSTOMERIO and hs rETL have the same bug and this PR fixes both, but neither has a test or a row in the table.

  • CUSTOMERIO is GA on the batching framework (features.ts:81). vdmV2ObjectDestination.ts:139-145 reads object from this.connection, which is the group's first connection (processDestinationIntegration.ts:219). On the old key, an event-object sync's row goes out as a person identify, with attributes.name: 'Order Completed' overwriting the person's name.
  • hs rETL picks the path from inputs[0] (hs/transform.ts:56-60; the comment "a router call is homogeneous per source" is not true on develop). It takes objectType and identifierType from the first row (retl-transform.ts:66-70, util.ts:739-745).
    • A contacts sync and a companies sync in one call: on the old key, the companies row goes to /crm/v3/objects/contacts/batch/upsert.
    • An rETL row and an SDK row in one call: on the old key, whichever kind isn't first fails with 400.

Could you add one two-sync router case for each (customerio: person + event; hs: contacts + companies) and add both to the table? I'll ask for them to be added to the ACT2-1257 exposure count on our side.

3. Two claims in the description don't hold.

  • "Per-row output is unchanged" is refuted by point 1.
  • "Delivery order for one user can now differ when … the second group's request fails" is also incomplete: order changes on the success path too. rudder-server sends destination jobs sorted by MinJobID (router/worker.go:442-444). One user's SDK rows j1 and j3 become one batch (min 1) and the rETL row j2 another (min 2). So [j1, j3] is delivered before [j2], and j2's older value is the one that sticks, with every request succeeding.

Dynamic-config groups already behave this way, so I don't think it blocks, but the description should say it.

Nits:

  • src/v0/util/index.js:2465-2466: the JSDoc still says "groups the events by destination ID, source ID … sourceID is only used for rETL events". It is the source job id now, and it applies to every row.
  • src/v0/util/index.test.js (the groupRouterTransformEvents block, ~791-890): the rewritten tests only check group counts and sizes. The old ones checked which rows landed in each group. Two edge cases are also gone: sources: {} without a job_id, and a missing destination ID with a job_id. One assertion on group membership would bring that back.
  • customerio_audience/router/data.ts:282-312: the "Error Case" comments are now out of order (3, 4, 2).
  • The description says each new case "is the only case in its suite" that fails on the old key. That isn't true for customerio_audience: the existing "Comprehensive router test" fails there too, which is expected after its reorder.
  • Optional: no case covers the isHashRequired mismatch the description mentions (Custom Activation / Reddit).

Possible follow-up, not for this PR: the user-transformation gap (a UT that rebuilds the message without context.sources merges syncs again) could be closed by adding metadata.sourceId to the key for rETL rows only, e.g. metadata.sourceCategory === 'warehouse' ? metadata.sourceId : 'default'.

  • That element can only split groups further.
  • It survives a UT, because the server stamps sourceId and sourceCategory in router metadata (worker.go:169).
  • It changes none of the existing fixtures.
  • Keying every row on sourceId is not a good idea: it would split event-stream batches per source for every router destination.

… tests

Review on #5705 found two more destinations that take their target from
one row for the whole group: customerio (VDM v2 objects read `object` from
the group's connection) and hs rETL (path, objectType and identifierType
from inputs[0]). Add a two-sync router case for each; both fail on the old
grouping key (event rows sent as person identifies; company rows sent to
the contacts upsert endpoint).

Also from review:
- grouping unit tests assert which rows land in each group, and cover
  sources without job_id and a missing destination id again
- JSDoc describes the source job id key
- customerio_audience error-case comments follow output order

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

Give the customerio rows a destination ID and the hs rows the job_run_id /
task_run_id fields rudder-sources sends.

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

arpl commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @am6010, all of it taken. Fixed in cbc40b9 and 46940a7; the push dismissed your approval, so it needs a re-approve.

1. Braze supportDedup. Added to the description under behaviour changes, as you suggested.

2. CUSTOMERIO and hs rETL. Confirmed both, added a two-sync router case for each, and added both to the table:

  • cio-v2-router-record-concurrent-syncs (person sync + event sync). On the old key, both rows go out in one /v2/batch and the event row becomes a person identify with attributes.name: 'Order Completed'.
  • hs-retl-router-concurrent-syncs (contacts sync + companies sync). On the old key, both rows go into one /crm/v3/objects/contacts/batch/upsert, and no companies request is sent. This needed one new mock (GET /crm/v3/properties/companies); removing it fails only the new case.

Each fails only that case in its suite when the key is reverted.

3. Description. "Per-row output is unchanged" is gone. The ordering line now describes the success path: requests are sent sorted by lowest job id (worker.go:442-444), so an older rETL value can land after a newer SDK update even when every request succeeds. The failure-path case is kept.

Nits:

  • JSDoc now describes the source job id key.
  • The grouping unit tests assert group membership by job id, and both edge cases are back: sources without job_id, and a missing destination ID with a job_id.
  • The customerio_audience "Error Case" comments now run 1 to 4 in output order.
  • The description's "only failing case" claim now names the four regrouped fixtures as the other cases that fail on the old key.

Not added: an isHashRequired mismatch case. On base, mismatched rows are rejected by validateHashingConsistency rather than misrouted, so the existing cases already cover the grouping.

Follow-up: your metadata.sourceCategory === 'warehouse' ? metadata.sourceId : 'default' element is the right way to close the user-transformation gap. I'll open a separate ticket rather than widen this PR.

Full router suite: 593 passed, 1 skipped. Unit: 223/223. Secret-paths check: no drift.

@sonarqubecloud

Copy link
Copy Markdown

@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-approving at 46940a7. Checked locally: router suite 593 passed / 1 skipped, unit 223/223. With the key reverted, 18 router cases fail (the 13 two-sync cases, including the new customerio and hs ones, plus the 5 regrouped fixture cases) and 4 grouping unit tests fail. The description now covers Braze, ordering, CUSTOMERIO and hs. Agree on skipping the isHashRequired case, and on a separate ticket for the user-transformation gap.

@arpl
arpl merged commit 93fc7b2 into develop Oct 22, 2026
50 checks passed
@arpl
arpl deleted the fix/act2-1257-group-router-events-by-connection branch October 22, 2026 07:07
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