Skip to content

fix(marketo_audience): cap 1003 splits, clear failed tokens, check unique lead IDs - #5704

Merged
am6010 merged 4 commits into
developfrom
fix/marketo-audience-leo-followups
Oct 21, 2026
Merged

am6010 merged 4 commits into
developfrom
fix/marketo-audience-leo-followups

Conversation

@am6010

@am6010 am6010 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

What are the changes introduced in this PR?

Follow-up to #5681 for MARKETO_AUDIENCE. It fixes the 3 items @lvrach left at c543f42, one commit each. Only src/v0/destinations/marketo_audience and its unit tests change.

  1. Cap on 1003 splits (review comment 4323376958, then 4327977981, lookup.ts). A 1003 split sent its lookups one after another with no limit: if every 20th email matches more than 1,000 leads, one 300-email chunk made 163 calls. One lookupLeadsByEmail call (one per transformEvents call) now makes at most 19 lookup calls. Every page counts, and all chunks of the batch share the budget. 19 calls is what splitting one email out of a 300-email chunk takes when each lookup fits in one page (one lookup, then nine halvings of two), and it is under a fifth of Marketo's 100 calls per 20 s per instance. Without a 1003, a chunk reads at most 4 pages, so for up to 1,200 emails only a split reaches the cap. Emails still unresolved when the budget runs out retry with the fixed reason Marketo lead lookup split limit reached (code 1003), and every email still gets exactly one outcome. A lookup cut short mid-pages drops its partial matches, so all of its emails retry. The retry carries fewer rows, because the rows split out or resolved in this pass are gone.
  2. Token memo (review comment 4323376968, routerTransform.ts). A dontBatch row's call now uses the memoised token only while it equals the cached one. Otherwise it clears the memoised token and the pending request together. This fixes both reported cases:
    • After a refetch fails, the later dontBatch rows fail with that error without calling identity again. Before, 200 rows with a 401 identity made 201 calls.
    • When another request has cached a newer token B, the row takes B instead of sending its own older token A.
  3. Unique sent lead IDs (review comment 4323376974, delivery.ts). A lead ID sent twice would let one result answer two jobs. That now retries the batch like any other unmatched response. The router can't send a duplicate today (internalGroupKey keeps IDs unique per request), so this is only a second defence.

What is the related Linear task?

Part of ACT2-1230 (parent ACT2-1013): review follow-ups from #5681

Please explain the objectives of your changes below

#5681 was merged without these 3 non-blocking items so it would keep its approval; this PR fixes them. Both Marketo Flagsmith flags (enable-marketo-audience-destination, enable-lookout-marketo-audience-activation) are off in every environment, so no traffic reaches this code until the flags are turned on.

Each item started as a failing test (known-bad run before each fix):

Item Test Before the fix
1 stops after 19 lookup calls and retries the emails left 163 calls instead of 19
1 counts each page call against the limit (first email 1,001 leads, others 3) 20 calls instead of 19
1 shares one call limit across the chunks of one lookup (1,200 emails, one 1003 per chunk) 76 calls instead of 19
2 fails later dontBatch rows without another identity call after a refetch fails 4 identity calls instead of 2
2 sends the token another request cached, not its own older one Bearer token-a instead of Bearer token-b
3 retries every job: the same lead sent twice both jobs success instead of retry

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

Only MARKETO_AUDIENCE, which is behind flags that are off. A chunk with many 1003 emails now retries the rows it could not resolve instead of making unlimited calls.

Any new dependencies introduced with this change?

N/A

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

N/A. The shared marketo/util.js is unchanged.

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

The cap covers one transformEvents call: every chunk of the batch and every page count against it. The router transforms each dontBatch row in a call of its own, so each of those calls gets its own budget.

Not covered: Marketo calls from other transformEvents calls, requests or pods against the same instance. The cap limits one call; it doesn't pace the instance as a whole.


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? (mocked only: unit and component tests)

  • Any documentation changes needed with this change?

  • Is the PR limited to 10 file changes? (7 files)

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

Checks run locally

  • marketo_audience unit tests: 160 passed (154 before, plus 6 new)
  • marketo_audience component tests (router + proxy v1): 17 passed
  • Pre-commit hook on each commit (latest e8ff489): ts 6527 passed / 2 skipped, js 2021 passed, lint-staged clean
  • tsc --noEmit, eslint and prettier clean; generate:secret-paths for marketo_audience gives the same ["headers.Authorization"]

🤖 Generated with Claude Code

A 1003 split sent its lookups one after another with no limit: every 20th
email matching more than 1,000 leads made 163 calls for one chunk, against
Marketo's 100 calls per 20 s per instance. Each 300-email chunk now makes at
most 19 lookups, enough to split out one such email; emails still unresolved
then retry with a fixed reason.

Addresses review comment 4323376958 on #5681.
…ng after a failure

After a token fetch failed, the cache stayed empty while the old token stayed
memoised, so every later dontBatch row called the identity endpoint again
(200 rows with a 401 made 201 calls). And when another request cached a newer
token, this instance kept sending its own older one. The memoised token is now
compared with the cached one, and both it and the pending request are cleared
when they differ; a failed fetch then fails the remaining rows on this
instance without another call.

Addresses review comment 4323376968 on #5681.
Results are matched to jobs by lead ID, so a lead ID sent twice would let one
result answer two jobs. The router cannot send one today (internalGroupKey
keeps IDs unique per request); as a second defence, a repeated sent ID now
retries the batch like any other unmatched response.

Addresses review comment 4323376974 on #5681.
@am6010
am6010 requested review from a team as code owners October 20, 2026 12:44
@am6010
am6010 requested a review from lvrach October 20, 2026 12:44
@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: 62d5e5bc-b6c2-4b4c-aa12-1c5ff536c0ac

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 (e8ff489).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #5704   +/-   ##
========================================
  Coverage    92.28%   92.29%           
========================================
  Files          731      731           
  Lines        40616    40633   +17     
  Branches      9513     9518    +5     
========================================
+ Hits         37484    37501   +17     
  Misses        2868     2868           
  Partials       264      264           

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

lvrach
lvrach previously approved these changes Oct 20, 2026

@lvrach lvrach left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approving. All three fixes do what their commits say. The 158 unit tests pass. Each fix has a mutant that fails a test. When a chunk reaches the cap, every email still gets exactly one outcome. One small follow-up, not blocking.

Agent fleet for @lvrach: Claude Opus and OpenAI astra lanes. LLM findings, needs human review.

The 1003 cap counted lookups per 300-email chunk, but each lookup can read
up to 4 pages and the cap restarted for every chunk: 300 emails where the
first matches 1,001 leads and the others 3 made 20 calls, and 1,200 emails
with one such email per chunk made 76. The cap now counts every page call,
19 per lookupLeadsByEmail call (one per transformEvents call), shared by all
chunks. Emails still open at the cap keep the fixed retry reason.

Addresses review comment 4327977981 on #5704.
@sonarqubecloud

Copy link
Copy Markdown

@lvrach lvrach left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approving again at e8ff489. Page calls now count against one 19-call budget for the batch, and the 160 unit tests pass. A batch holds at most 300 jobs (operator noOfJobsToBatchInAWorker), so without a 1003 the cap is not reached.

@am6010
am6010 merged commit cae58e7 into develop Oct 21, 2026
39 checks passed
@am6010
am6010 deleted the fix/marketo-audience-leo-followups branch October 21, 2026 08:14
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