Skip to content

fix: klaviyo upload partial failures - #7107

Merged
achettyiitr merged 3 commits into
release/1.77.xfrom
fix.klaviyo-upload-partial-failures
Jun 22, 2026
Merged

achettyiitr merged 3 commits into
release/1.77.xfrom
fix.klaviyo-upload-partial-failures

Conversation

@achettyiitr

@achettyiitr achettyiitr commented Jun 22, 2026 •

Copy link
Copy Markdown
Member

🔒 Scanned for secrets using gitleaks 8.29.1

Description

Klaviyo's Bulk Profile Import API validates each request all-or-nothing: a single profile that fails synchronous validation (e.g. a malformed email) causes Klaviyo to reject the entire batch with HTTP 400, importing zero profiles. Today rudder-server mirrors that by aborting the whole chunk, so one bad record takes down every valid profile alongside it.

This PR adds strip-and-retry on failure. When Klaviyo returns a 400 whose error pointers identify specific profiles, we abort only those jobs and re-upload the chunk once with the remaining valid profiles, so the good records still get delivered.

Behavior

  • Success → jobs imported as before.
  • 400 that pinpoints specific profiles → those jobs are aborted (with Klaviyo's per-profile reason), the rest are re-uploaded once; the retry's outcome is final (no looping).
  • 400 we can't attribute to a profile (e.g. invalid listId) → whole chunk aborted, unchanged.
  • 5xx / 429 / transport errors → whole chunk marked failed for the batch router to retry, unchanged.

The retry path is bounded to a single extra attempt — there is no loop.

Implementation

  • uploadChunk orchestrates the try → strip → retry-once flow.
  • tryUpload performs one upload attempt and normalizes the status/error.
  • strippableProfiles decides whether a failure is a per-profile 400 we can safely retry.
  • extractInvalidProfileIndices parses the offending profile indices from Klaviyo's JSON pointers.
  • recordError classifies remaining jobs as aborted (4xx) vs failed (5xx/429).
  • chunkUploadResult (added to types.go) carries the per-chunk outcome.

Linear Ticket

  • Resolves INT-6600

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

@achettyiitr
achettyiitr changed the base branch from master to release/1.77.x June 22, 2026 05:11
🔒 Scanned for secrets using gitleaks 8.29.1
@achettyiitr
achettyiitr force-pushed the fix.klaviyo-upload-partial-failures branch from fc16e3c to e596615 Compare June 22, 2026 05:13
🔒 Scanned for secrets using gitleaks 8.29.1
@achettyiitr
achettyiitr requested a review from ItsSudip June 22, 2026 06:43
@krishna2020

Copy link
Copy Markdown
Contributor

abortReason collapses multiple per-profile reasons into one

In uploadChunk, the strip loop overwrites res.abortReason on each iteration:

res.abortReason = fmt.Sprintf("profile rejected by Klaviyo's synchronous validation: %s", reason)

So when a chunk has more than one invalid profile, only the last rejected profile's reason survives into AsyncUploadOutput.AbortReason (and the cross-chunk assignment in Upload then keeps only the last chunk's value). Since this PR is specifically about per-profile attribution, the per-profile detail is mostly discarded in the user-visible abort reason.

Not a regression (the single-reason field predates this PR), but worth considering aggregating the reasons — e.g. joining idx -> reason pairs, or at least appending rather than overwriting — so a chunk with several bad profiles doesn't surface an arbitrary single reason.

Copy link
Copy Markdown
Member

This looks like a limitation of the framework. Since we return multiple AbortJobIDs, we should be able to return AbortReason as a map of jobID → reason, so each aborted job can carry its own reason rather than sharing a single one.

@achettyiitr
achettyiitr requested a review from krishna2020 June 22, 2026 07:43
@krishna2020

Copy link
Copy Markdown
Contributor

ImportCount is always serialized as 0 (pre-existing, but worth fixing here)

At the marshal site:

importParameters, err := jsonrs.Marshal(common.ImportParameters{
    ImportId:    strings.Join(importIds, IMPORT_ID_SEPARATOR),
    ImportCount: len(successJobs),
})
...
successJobs, _ = lo.Difference(importingJobIDs, append(failedJobs, abortedJobs...))

successJobs is declared nil and only computed after the marshal, so ImportCount always serializes as 0. It's not dead — it's read back during polling (handle_async.go:106 → pollInput.ImportCount) and used in two ways:

  • handle_async.go:361-364 — when 0, updatePollStatusToDB falls back to maxEventsInABatch instead of the real count.
  • handle_async.go:369 — the len(statusList) != ImportCount mismatch warning is gated on ImportCount > 0, so it's effectively disabled for this destination.

Pre-existing (not introduced by this PR), but the fix is a one-liner — move the successJobs computation above the marshal so len(successJobs) reflects the actual count:

successJobs, _ = lo.Difference(importingJobIDs, append(failedJobs, abortedJobs...))
importParameters, err := jsonrs.Marshal(common.ImportParameters{
    ImportId:    strings.Join(importIds, IMPORT_ID_SEPARATOR),
    ImportCount: len(successJobs),
})

@achettyiitr

achettyiitr commented Jun 22, 2026 •

Copy link
Copy Markdown
Member Author

ImportCount is always serialized as 0 (pre-existing, but worth fixing here)

At the marshal site:

importParameters, err := jsonrs.Marshal(common.ImportParameters{
    ImportId:    strings.Join(importIds, IMPORT_ID_SEPARATOR),
    ImportCount: len(successJobs),
})
...
successJobs, _ = lo.Difference(importingJobIDs, append(failedJobs, abortedJobs...))

successJobs is declared nil and only computed after the marshal, so ImportCount always serializes as 0. It's not dead — it's read back during polling (handle_async.go:106 → pollInput.ImportCount) and used in two ways:

  • handle_async.go:361-364 — when 0, updatePollStatusToDB falls back to maxEventsInABatch instead of the real count.
  • handle_async.go:369 — the len(statusList) != ImportCount mismatch warning is gated on ImportCount > 0, so it's effectively disabled for this destination.

Pre-existing (not introduced by this PR), but the fix is a one-liner — move the successJobs computation above the marshal so len(successJobs) reflects the actual count:

successJobs, _ = lo.Difference(importingJobIDs, append(failedJobs, abortedJobs...))
importParameters, err := jsonrs.Marshal(common.ImportParameters{
    ImportId:    strings.Join(importIds, IMPORT_ID_SEPARATOR),
    ImportCount: len(successJobs),
})

Seems like an existing bug, let me fix it. Fixed existing test as well.

🔒 Scanned for secrets using gitleaks 8.29.1
@achettyiitr
achettyiitr merged commit 621a070 into release/1.77.x Jun 22, 2026
103 of 107 checks passed
@achettyiitr
achettyiitr deleted the fix.klaviyo-upload-partial-failures branch June 22, 2026 09:35
achettyiitr pushed a commit that referenced this pull request Jun 22, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.77.4](v1.77.3...v1.77.4)
(2026-06-22)


### Bug Fixes

* klaviyo upload partial failures
([#7107](#7107))
([621a070](621a070))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
achettyiitr added a commit that referenced this pull request Jun 22, 2026
# Description

Syncing patch release v1.77.4 to main branch

**↓↓ Please review and edit commit overrides before merging ↓↓**

BEGIN_COMMIT_OVERRIDE
fix: klaviyo upload partial failures (#7107)
END_COMMIT_OVERRIDE

---------

Co-authored-by: Aris Tzoumas <[email protected]>
Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
Co-authored-by: shekhar-rudder <[email protected]>
Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
Co-authored-by: Sudip Paul <[email protected]>
Co-authored-by: Akash Chetty <[email protected]>
Co-authored-by: Akash Chetty <[email protected]>
This was referenced Jun 22, 2026
atzoum pushed a commit that referenced this pull request Jun 23, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.78.0-rc.1](v1.77.0...v1.78.0-rc.1)
(2026-06-22)


### Features

* add and register bq stream v2 async destination manager
([#7057](#7057))
([787b7ac](787b7ac))
* add BQSTREAM_V2 destination type and bqstreamv2 building blocks
([#7056](#7056))
([02e84e5](02e84e5))
* **batchrouter:** raise getImportingJobs max iterations and remove
payload size limit
([#7076](#7076))
([15707f6](15707f6))
* **gateway:** throttling support for internal batch endpoint
([#7055](#7055))
([6b6ba65](6b6ba65))
* **jobsdb:** introduce compaction min ds age
([#7077](#7077))
([4d6d97a](4d6d97a))
* **processor:** new intermediate jobsdb
([#7048](#7048))
([dfef1f1](dfef1f1))


### Bug Fixes

* abort non-retryable Klaviyo upload errors instead of retrying
([#7085](#7085))
([4c3e4f1](4c3e4f1))
* **batchrouter:** correlate poll results by externalId instead of
whole-row hash
([09326d2](09326d2))
* **batchrouter:** report real status code and sample event for drained
jobs ([#7104](#7104))
([d3fab82](d3fab82))
* internal endpoints enabled in open source version of rudder-server
([#7075](#7075))
([dc071cd](dc071cd))
* **jobsdb:** get jobs lateral join against the v_last view
([#7105](#7105))
([853d14c](853d14c))
* klaviyo upload partial failures
([#7107](#7107))
([37e79e9](37e79e9))
* **router:** shared barrier causing illegal job sequence errors
([#7101](#7101))
([b5435ba](b5435ba))


### Miscellaneous

* add BQSTREAM_V2 integration tests
([#7058](#7058))
([478e217](478e217))
* add rudderai announcement
([#7046](#7046))
([ff02fe8](ff02fe8))
* bump codecov-action to 7.0.0
([#7070](#7070))
([31f0623](31f0623))
* cleanup embedded warehouse transformations
([#7072](#7072))
([31f0623](31f0623))
* **deps:** bump actions/checkout from 6.0.2 to 6.0.3
([#7084](#7084))
([745d5ab](745d5ab))
* **deps:** bump aws-actions/configure-aws-credentials from 6.1.2 to
6.2.0 ([#7081](#7081))
([19251cd](19251cd))
* **jobsdb:** refactoring and cleanup
([#7043](#7043))
([2e4ea92](2e4ea92))
* remove legacy warehouse endpoints
([#7090](#7090))
([6f85153](6f85153))
* rename bqstream all events
([#7088](#7088))
([4d9ad19](4d9ad19))
* **router:** rename experimental buffer size calculator to dynamic
([#7103](#7103))
([52896cd](52896cd))
* support using the full event schema key as pulsar ordering key
([#7086](#7086))
([ff50611](ff50611))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
atzoum pushed a commit that referenced this pull request Jun 23, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.78.0](v1.77.0...v1.78.0)
(2026-06-22)


### Features

* add and register bq stream v2 async destination manager
([#7057](#7057))
([787b7ac](787b7ac))
* add BQSTREAM_V2 destination type and bqstreamv2 building blocks
([#7056](#7056))
([02e84e5](02e84e5))
* **batchrouter:** raise getImportingJobs max iterations and remove
payload size limit
([#7076](#7076))
([15707f6](15707f6))
* **gateway:** throttling support for internal batch endpoint
([#7055](#7055))
([6b6ba65](6b6ba65))
* **jobsdb:** introduce compaction min ds age
([#7077](#7077))
([4d6d97a](4d6d97a))
* **processor:** new intermediate jobsdb
([#7048](#7048))
([dfef1f1](dfef1f1))


### Bug Fixes

* abort non-retryable Klaviyo upload errors instead of retrying
([#7085](#7085))
([4c3e4f1](4c3e4f1))
* **batchrouter:** correlate poll results by externalId instead of
whole-row hash
([09326d2](09326d2))
* **batchrouter:** report real status code and sample event for drained
jobs ([#7104](#7104))
([d3fab82](d3fab82))
* internal endpoints enabled in open source version of rudder-server
([#7075](#7075))
([dc071cd](dc071cd))
* **jobsdb:** get jobs lateral join against the v_last view
([#7105](#7105))
([853d14c](853d14c))
* klaviyo upload partial failures
([#7107](#7107))
([37e79e9](37e79e9))
* **router:** shared barrier causing illegal job sequence errors
([#7101](#7101))
([b5435ba](b5435ba))


### Miscellaneous

* add BQSTREAM_V2 integration tests
([#7058](#7058))
([478e217](478e217))
* add rudderai announcement
([#7046](#7046))
([ff02fe8](ff02fe8))
* bump codecov-action to 7.0.0
([#7070](#7070))
([31f0623](31f0623))
* cleanup embedded warehouse transformations
([#7072](#7072))
([31f0623](31f0623))
* **deps:** bump actions/checkout from 6.0.2 to 6.0.3
([#7084](#7084))
([745d5ab](745d5ab))
* **deps:** bump aws-actions/configure-aws-credentials from 6.1.2 to
6.2.0 ([#7081](#7081))
([19251cd](19251cd))
* **jobsdb:** refactoring and cleanup
([#7043](#7043))
([2e4ea92](2e4ea92))
* remove legacy warehouse endpoints
([#7090](#7090))
([6f85153](6f85153))
* rename bqstream all events
([#7088](#7088))
([4d9ad19](4d9ad19))
* **router:** rename experimental buffer size calculator to dynamic
([#7103](#7103))
([52896cd](52896cd))
* support using the full event schema key as pulsar ordering key
([#7086](#7086))
([ff50611](ff50611))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
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