Skip to content

refactor(batch): add record event dispatch to BatchDestination framework - #5324

Merged
shekhar-rudder merged 5 commits into
developfrom
feat/INT-6653-batch-destination-record-dispatch
Jul 7, 2026
Merged

shekhar-rudder merged 5 commits into
developfrom
feat/INT-6653-batch-destination-record-dispatch

Conversation

@shekhar-rudder

@shekhar-rudder shekhar-rudder commented Jun 29, 2026 •

Copy link
Copy Markdown
Member

Summary

  • makeRouterInputSchema is now a single-variant builder. It takes one message schema plus an optional destinationConfig (→ destination.Config) and optional connectionConfig (→ connection.config). The previous multi-variant variants: [...] API — which built a z.union internally and validated destinationConfig outside the union — has been removed. All existing batching destinations (posthog, custom_audience, google_adwords_enhanced_conversions, iterable_audience) are migrated to the flat shape.
  • Union responsibility moved to VDMV2ObjectDestination. Hybrid (record + event-stream) destinations declare two schemas — recordSchema and eventStreamSchema, each built via makeRouterInputSchema with the shared destinationConfig — and the framework unions them in getInputSchema(). Record events validate the connection config (requires object); event-stream events don't, so the record schema is never wrongly applied to them.
  • Adds VDMV2ObjectDestination, an object-based record-dispatch layer on top of BatchDestination:
    • transformObjectRecord(input) returns a handler map of object type → action → handler for record events; transformEventStream(input) returns a message type → handler map for event-stream events.
    • The framework validates object types, actions, and message types automatically before invoking handlers, making the handler map the single source of truth (removes redundant validation from buildRecordEvent).
    • Constrains TConnectionConfig to { destination: { object: string } } so object-type access is type-checked, moves MappedToDestination pre-processing into the framework, and uses ConfigurationError for framework-level validation.
  • Migrates CustomerIO to extend VDMV2ObjectDestination with record + event-stream support. Transform-method parameters are typed inline with z.infer<typeof recordInputSchema> / z.infer<typeof eventStreamInputSchema> so the types are unmistakably schema-derived and cannot drift.
  • Documents the onboarding flow and conventions in the vdm-v2-object-destination skill.

Test plan

  • Unit tests pass for makeRouterInputSchema (single-variant) and the union built by VDMV2ObjectDestination
  • Unit tests pass for the BatchDestination / VDMV2ObjectDestination framework
  • Unit tests pass for CustomerIO record + event-stream transforms and buildRecordEvent
  • Integration tests pass for CustomerIO
  • Lint clean

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@shekhar-rudder, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 42 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 1bfdb32c-befc-4432-a002-477ec10ab971

📥 Commits

Reviewing files that changed from the base of the PR and between bb1bb87 and e54f9fa.

📒 Files selected for processing (3)
  • src/services/destination/nativeBatching/__tests__/batchDestination.test.ts
  • src/services/destination/nativeBatching/__tests__/vdmV2ObjectDestination.test.ts
  • src/services/destination/nativeBatching/vdmV2ObjectDestination.ts

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key: "auto_resolve_threads"
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Walkthrough

This PR replaces the multi-variant makeRouterInputSchema union approach with a single-variant schema contract, updates validateInputs union error classification, and introduces VDMV2ObjectDestination, an abstract base class routing record and event-stream inputs to per-object/action handlers. Customer.io is migrated to this new base class, with several destinations updated to the flattened schema call shape.

Changes

Native batching schema and dispatch framework

Layer / File(s) Summary
Single-variant router input schema
src/services/destination/nativeBatching/inputSchema.ts, src/services/destination/nativeBatching/__tests__/inputSchema.test.ts
InputVariant/RouterInput union types removed; SingleRouterInput and a rewritten makeRouterInputSchema build one combined schema from {message, destinationConfig?, connectionConfig?}; tests updated to the single-variant API.
Union validation error classification
src/services/destination/nativeBatching/processBatchedDestination.ts, src/services/destination/nativeBatching/__tests__/processBatchedDestination.test.ts
validateInputs now resolves invalid_union Zod errors, preferring configuration-only branches, and derives errorType/errorMessage from resolved issues; new tests cover union schema classification.
VDMV2ObjectDestination base class
src/services/destination/nativeBatching/vdmV2ObjectDestination.ts, .../__tests__/vdmV2ObjectDestination.test.ts, .../__tests__/batchDestination.test.ts
New abstract class exposes getInputSchema (union of record/event-stream schemas), transformObjectRecord contract, transformEventStream default, and transformEvent dispatch with ConfigurationError for unsupported types/actions; new and extended tests validate dispatch behavior.

Customer.io migration

Layer / File(s) Summary
Schema split and builder cleanup
src/v0/destinations/customerio/v2/types.ts, .../v2/recordTransform.ts, .../v2/recordTransform.test.ts, .../v2/util.ts
customerIOInputSchema split into recordInputSchema/eventStreamInputSchema; validateAction hook removed from RecordPayloadBuilder and buildRecordEvent; deviceActionFor exported; buildEnvelope removed.
Router transform migration to V2 dispatch
src/v0/destinations/customerio/routerTransform.ts, routerTransform.test.ts
CustomerIO integration switches from BatchDestination to VDMV2ObjectDestination, replacing buildBody/transformEvent with buildRecord, transformObjectRecord, wrapEventStreamBody, transformEventStream; tests updated to async transformEvents with success/error payload assertions.

Downstream schema call updates

Layer / File(s) Summary
Flattened makeRouterInputSchema calls
src/v0/destinations/custom_audience/routerTransform.ts, .../google_adwords_enhanced_conversions/routerTransform.ts, .../iterable_audience/types.ts, .../posthog/routerTransform.ts
Each destination's schema call changes from a variants: [...] wrapper to passing message/connectionConfig directly, matching the new single-variant contract.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Router as RouterTransform
  participant VDM as VDMV2ObjectDestination
  participant Conn as ConnectionConfig
  participant Handler as ObjectActionHandler

  Router->>VDM: transformEvent(input, metadata)
  alt record input
    VDM->>Conn: resolve objectType
    Conn-->>VDM: objectType
    VDM->>VDM: transformObjectRecord(objectType)
    VDM->>Handler: handler(action, identifiers)
    Handler-->>VDM: TransformedEvent
  else event-stream input
    VDM->>VDM: derive messageType
    VDM->>VDM: transformEventStream()
    VDM->>Handler: handler(message)
    Handler-->>VDM: TransformedEvent
  end
  VDM-->>Router: TransformedEvent or ConfigurationError
Loading

Possibly related PRs

Suggested reviewers: achettyiitr, krishna2020, ItsSudip

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the summary and test plan, but it omits the required Linear task, objectives details, and the checklist/template sections. Add the required template sections, especially the Linear task, detailed objectives, and the checklist items, or fill them with N/A where appropriate.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: adding record event dispatch in the batch destination framework.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/INT-6653-batch-destination-record-dispatch

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.

@shekhar-rudder
shekhar-rudder force-pushed the feat/INT-6653-batch-destination-record-dispatch branch from a620d8f to c4e8276 Compare June 29, 2026 09:31
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

An error occurred during the review process. Please try again later.

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

⚠️ Parsing warnings (1)
Validation error: Unrecognized key: "auto_resolve_threads"
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/INT-6653-batch-destination-record-dispatch

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 Jun 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.74%. Comparing base (b4030a0) to head (e54f9fa).

Files with missing lines Patch % Lines
...stination/nativeBatching/vdmV2ObjectDestination.ts 92.68% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #5324   +/-   ##
========================================
  Coverage    92.74%   92.74%           
========================================
  Files          703      704    +1     
  Lines        38255    38281   +26     
  Branches      8992     8940   -52     
========================================
+ Hits         35479    35505   +26     
- Misses        2548     2566   +18     
+ Partials       228      210   -18     

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

@shekhar-rudder
shekhar-rudder force-pushed the feat/INT-6653-batch-destination-record-dispatch branch 6 times, most recently from 9794692 to 9f37cca Compare July 3, 2026 14:23
shekhar-rudder and others added 2 commits July 6, 2026 12:10
… schema cache

Annotate customerio's transform-method parameters inline with
`z.infer<typeof recordInputSchema>` / `z.infer<typeof eventStreamInputSchema>`
instead of separate named aliases, so it is unmistakable the types are the
schema and cannot drift; remove the now-unused aliases.

Drop `cachedInputSchema` from VDMV2ObjectDestination: getInputSchema is called
once per instance, and an eagerly-computed field cannot work anyway since the
subclass's recordSchema/eventStreamSchema initialize after the base. Build the
union directly.

Codify the inline-`z.infer` convention in the vdm-v2-object-destination skill.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@shekhar-rudder
shekhar-rudder force-pushed the feat/INT-6653-batch-destination-record-dispatch branch from 9f37cca to b2ac46e Compare July 6, 2026 06:51
Remove the "memoizes the schema" test — getInputSchema no longer caches its
result (the union is built once per instance), so reference equality across
calls is no longer guaranteed.

Type the unionInput test helper's return as RouterTransformationRequestData so
the four validateInputs call sites no longer need `as any`; the single cast is
localized to where the deliberately-malformed envelope is produced.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@shekhar-rudder
shekhar-rudder marked this pull request as ready for review July 6, 2026 07:12
@shekhar-rudder
shekhar-rudder requested review from a team as code owners July 6, 2026 07:12
@shekhar-rudder
shekhar-rudder force-pushed the feat/INT-6653-batch-destination-record-dispatch branch from 68df4ff to d568317 Compare July 7, 2026 10:01
The suite imported RecordInput from the framework, which a prior review
comment made module-local, so tsc failed to run the test (TS2459) and CI
went red. Declare the record envelope type locally in the test instead.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@sonarqubecloud

sonarqubecloud Bot commented Jul 7, 2026

Copy link
Copy Markdown

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

LGTM

@shekhar-rudder
shekhar-rudder merged commit 3611c0b into develop Jul 7, 2026
58 of 66 checks passed
@shekhar-rudder
shekhar-rudder deleted the feat/INT-6653-batch-destination-record-dispatch branch July 7, 2026 13:04
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.

2 participants