Skip to content

fix(taboola): retry the initial token mint on transient errors - #76422

Merged
trunk-io[bot] merged 2 commits into
masterfrom
posthog-code/fix-taboola-initial-token-mint-retry
Aug 3, 2026
Merged

fix(taboola): retry the initial token mint on transient errors#76422
trunk-io[bot] merged 2 commits into
masterfrom
posthog-code/fix-taboola-initial-token-mint-retry

Conversation

@Gilbert09

Copy link
Copy Markdown
Member

Problem

Error tracking surfaced a TaboolaRetryableError ("Taboola token endpoint error (retryable): status=503") escaping a Taboola data warehouse sync, raised from _mint_token in products/warehouse_sources/backend/temporal/data_imports/sources/taboola/taboola.py.

Looking at the call sites: get_rows mints an access token once up front, then defines a fetch helper wrapped in a tenacity retry (covering rate limits and transient 5xx) that re-mints the token if it expires mid-sync (401). The up-front mint happens before that retry wrapper exists, so a transient failure from the token endpoint at that point raised straight out of the activity instead of backing off — even though the code's own comment says these failures "must be retryable."

Changes

  • Extracted the token mint into a small mint_token closure decorated with the same retry policy already used for fetch (retry on TaboolaRetryableError, capped attempts, exponential jitter backoff).
  • Both the initial mint and the mid-sync re-mint now go through this shared, retried closure, so a transient 429/5xx from the token endpoint backs off and retries instead of failing the sync immediately.

This is a fragile-code fix rather than a user/upstream error — the request shape/config is fine, our own retry coverage just had a gap.

How did you test this code?

Added test_initial_token_mint_retries_on_transient_error to test_taboola.py, which returns a 503 on the first token POST and a valid token on the second. Verified it fails without the fix (raises TaboolaRetryableError immediately) and passes with it (retries and succeeds), so it locks in the fix.

Ran the full taboola test suite (test_taboola.py + test_taboola_source.py, 40 tests) — all pass. Ran ruff check --fix and ruff format --diff — clean. Ran mypy against the changed file — no issues.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Docs update

N/A — internal retry-handling fix, no user-facing behavior or documented workflow changed.

🤖 Agent context

Autonomy: Fully autonomous

I (an agent) triaged a Taboola error-tracking issue reporting TaboolaRetryableError: Taboola token endpoint error (retryable): status=503. I pulled the issue's stack trace and confirmed it originated in this source's own _mint_token/get_rows code, read the implementation to find the retry gap described above, and applied the minimal fix plus a regression test that fails without it. No skills beyond the repo's testing conventions were needed for a change this scoped.

The initial access-token mint in `get_rows` ran before the `@retry`-decorated `fetch` closure existed, so a transient 429/5xx from the token endpoint raised `TaboolaRetryableError` straight out of the sync activity instead of backing off, even though the mid-sync re-mint on a 401 already benefited from that retry. Wrap both call sites in the same retry policy via a shared `mint_token` closure.

Generated-By: PostHog Code
Task-Id: 34f1efbd-102b-40cc-a9a6-655f9adb71b3
Copilot AI review requested due to automatic review settings August 2, 2026 13:53
@trunk-io

trunk-io Bot commented Aug 2, 2026

Copy link
Copy Markdown

😎 Merged successfully - details.

@github-actions

github-actions Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Hey @Gilbert09! 👋

It looks like your git author email on this PR isn't your @posthog.com address (owerstom@gmail.com). Since you're on the PostHog team, it's worth pointing your local git author email at your @posthog.com address. Why it matters:

  • Consistent work identity in git history — internal tooling that attributes commits to team members keys off your @posthog.com address.
  • Keeps team contributions easy to tell apart from external community ones when scanning history.

You can fix it for this repo with:

git config user.email "you@posthog.com"

Or set it globally with git config --global user.email "you@posthog.com". No need to redo this PR — just a nudge for next time. 🙂

Copilot AI 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.

Pull request overview

This PR hardens the Taboola warehouse source sync by ensuring the initial OAuth token mint is covered by the same transient-error retry policy already applied to API fetching, preventing TaboolaRetryableError (e.g. token endpoint 503) from escaping the sync activity immediately.

Changes:

  • Added a mint_token() closure in get_rows decorated with tenacity retry on TaboolaRetryableError.
  • Routed both the initial token mint and the mid-sync re-mint (after a 401) through mint_token().
  • Added a regression test ensuring the initial token mint retries on a transient 503 and then succeeds.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
products/warehouse_sources/backend/temporal/data_imports/sources/taboola/taboola.py Adds a shared tenacity-retried token mint closure and uses it for initial + 401 re-mints.
products/warehouse_sources/backend/temporal/data_imports/sources/taboola/tests/test_taboola.py Adds a test that simulates a transient token endpoint failure on the first mint and validates retry behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…fetch

Only the initial token mint needs its own retry decorator — it's the one call site nothing else covers. The mid-sync re-mint on a 401 already propagates into fetch's own retry, so decorating it too let both retries stack (up to 25 attempts in the worst case). Address Copilot review feedback on the PR.

Generated-By: PostHog Code
Task-Id: 34f1efbd-102b-40cc-a9a6-655f9adb71b3
@Gilbert09 Gilbert09 added the stamphog Request AI approval (no full review) label Aug 2, 2026 — with PostHog

@stamphog stamphog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Small, contained retry-logic fix in a warehouse source connector by an owning-team author, with a regression test and the reviewer's compounding-retry concern already resolved in a follow-up commit.

  • 👍 on the PR from hex-security-app[bot].
Gate mechanics and policy version
Gate Result
prerequisites all clear
deny-list no deny categories matched
size 20L, 1F substantive, 34L/2F incl. docs/generated/snapshots — within ceiling
tier T1-agent / T1b-small (34L, 2F, single-area, fix)
stamphog 2.0.0b4 .stamphog/policy.yml @ f381e58 · reviewed head 45268ed

@talyn-app

talyn-app Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

/trunk merge

@trunk-io
trunk-io Bot merged commit 1f87915 into master Aug 3, 2026
284 checks passed
@trunk-io
trunk-io Bot deleted the posthog-code/fix-taboola-initial-token-mint-retry branch August 3, 2026 11:39
@deployment-status-posthog

deployment-status-posthog Bot commented Aug 3, 2026

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-08-03 12:18 UTC Run
prod-us ✅ Deployed 2026-08-03 12:30 UTC Run
prod-eu ✅ Deployed 2026-08-03 12:33 UTC Run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stamphog Request AI approval (no full review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants