Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(data-warehouse): widen Linear in-process retry budget for transient 5xx (#66272)

Tom Owersc272c4e90f37
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/linear/linear.py b/products/warehouse_sources/backend/temporal/data_imports/sources/linear/linear.py
index d1237236bf67..981c34289f45 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/linear/linear.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/linear/linear.py
@@ -15,13 +15,18 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.linear.set
LINEAR_ENDPOINTS,
)
-LINEAR_MAX_RETRY_ATTEMPTS = 5
-# Cap how long a single Retry-After can stall us, so a misbehaving header can't pin the
-# activity open. Kept under the activity heartbeat timeout; longer waits are handled by
-# Temporal rescheduling the whole activity, which resumes from the saved cursor.
+# Linear's edge returns short bursts of 5xx/429 that clear within a minute or two, so
+# retry in-process long enough to ride those out before failing the activity. The backoff
+# blocks the source thread, but heartbeats are sent from an independent background task
+# (LivenessHeartbeater), so a multi-minute wait here doesn't trip the activity heartbeat
+# timeout. Genuine outages still fall through to Temporal rescheduling the whole activity,
+# which resumes from the saved cursor.
+LINEAR_MAX_RETRY_ATTEMPTS = 8
+# Cap how long a single Retry-After can stall us, so a misbehaving header sending a huge
+# value can't pin the activity open for an unreasonable time.
LINEAR_MAX_RETRY_AFTER_SECONDS = 60
# Stateless backoff used when a 429 carries no usable Retry-After hint.
-_LINEAR_FALLBACK_WAIT = wait_exponential_jitter(initial=1, max=30)
+_LINEAR_FALLBACK_WAIT = wait_exponential_jitter(initial=1, max=60)
class LinearRetryableError(Exception):
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/linear/test_linear.py b/products/warehouse_sources/backend/temporal/data_imports/sources/linear/test_linear.py
index 298aaf68104d..7a0ea1018796 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/linear/test_linear.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/linear/test_linear.py
@@ -11,6 +11,7 @@ from tenacity import Future, RetryCallState
from products.warehouse_sources.backend.temporal.data_imports.sources.linear.linear import (
LINEAR_MAX_RETRY_AFTER_SECONDS,
+ LINEAR_MAX_RETRY_ATTEMPTS,
LinearResumeConfig,
LinearRetryableError,
_make_paginated_request,
@@ -208,7 +209,7 @@ class TestMakePaginatedRequest:
self, mock_session_cls: MagicMock, _mock_sleep: MagicMock
) -> None:
session = MagicMock()
- session.post.side_effect = [_make_rate_limited_response() for _ in range(5)]
+ session.post.side_effect = [_make_rate_limited_response() for _ in range(LINEAR_MAX_RETRY_ATTEMPTS)]
mock_session_cls.return_value = session
manager = _make_resumable_manager()
@@ -224,7 +225,7 @@ class TestMakePaginatedRequest:
)
)
- assert session.post.call_count == 5
+ assert session.post.call_count == LINEAR_MAX_RETRY_ATTEMPTS
@parameterized.expand(
[
@@ -269,7 +270,8 @@ class TestMakePaginatedRequest:
) -> None:
session = MagicMock()
session.post.side_effect = [
- requests.exceptions.ReadTimeout("Read timed out. (read timeout=60)") for _ in range(5)
+ requests.exceptions.ReadTimeout("Read timed out. (read timeout=60)")
+ for _ in range(LINEAR_MAX_RETRY_ATTEMPTS)
]
mock_session_cls.return_value = session
@@ -286,7 +288,7 @@ class TestMakePaginatedRequest:
)
)
- assert session.post.call_count == 5
+ assert session.post.call_count == LINEAR_MAX_RETRY_ATTEMPTS
class TestRateLimitBackoff:
@@ -313,14 +315,16 @@ class TestRateLimitBackoff:
def test_wait_strategy_falls_back_to_backoff_without_retry_after(self) -> None:
exc = LinearRetryableError("Linear: rate limited (429)")
- assert 0 < _wait_strategy(_retry_state(exc)) <= 30
+ assert 0 < _wait_strategy(_retry_state(exc)) <= 60
@patch("time.sleep", return_value=None)
@patch("products.warehouse_sources.backend.temporal.data_imports.sources.linear.linear.make_tracked_session")
def test_429_carries_retry_after_into_exception(self, mock_session_cls: MagicMock, _mock_sleep: MagicMock) -> None:
# Retry-After of 0 keeps the test fast while still exercising the honored-wait path.
session = MagicMock()
- session.post.side_effect = [_make_rate_limited_response({"Retry-After": "0"}) for _ in range(5)]
+ session.post.side_effect = [
+ _make_rate_limited_response({"Retry-After": "0"}) for _ in range(LINEAR_MAX_RETRY_ATTEMPTS)
+ ]
mock_session_cls.return_value = session
manager = _make_resumable_manager()
@@ -337,7 +341,7 @@ class TestRateLimitBackoff:
)
assert exc_info.value.retry_after == 0.0
- assert session.post.call_count == 5
+ assert session.post.call_count == LINEAR_MAX_RETRY_ATTEMPTS
class TestLinearSource: