: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(data-warehouse): pace GitHub page fetches against the egress budget (#88250)
Tom Owers52b4183e3f12
diff --git a/posthog/egress/github/limiter.py b/posthog/egress/github/limiter.pyindex dfccb9c03e5a..fcc866f2840b 100644--- a/posthog/egress/github/limiter.py+++ b/posthog/egress/github/limiter.py@@ -351,3 +351,20 @@ def consume_github_installation_sync(return get_outbound_rate_limiter().consume_sync(github_installation_key(installation_id, resource=resource), n, priority=priority, source=source)+++def github_installation_pace_seconds(+ installation_id: str | int,+ *,+ priority: Priority = Priority.NORMAL,+ resource: GitHubRateResource = GitHubRateResource.CORE,+) -> float:+ """Seconds to wait before the next call on this installation's budget for ``resource``.++ For a caller that can wait rather than be shed, such as a bulk import walking pages. Zero means+ the budget has room to spare. See ``OutboundRateLimiter.pace_seconds`` for what the wait means+ and why it is not a wait for a reset.+ """+ return get_outbound_rate_limiter().pace_seconds(+ github_installation_key(installation_id, resource=resource), priority=priority+ )diff --git a/products/product_analytics/backend/tests/api/__snapshots__/test_insight.ambr b/products/product_analytics/backend/tests/api/__snapshots__/test_insight.ambrindex 017f23c3892b..17d46f5c097e 100644--- a/products/product_analytics/backend/tests/api/__snapshots__/test_insight.ambr+++ b/products/product_analytics/backend/tests/api/__snapshots__/test_insight.ambr@@ -34,7 +34,7 @@e.`$window_id` AS `$window_id`,if(equals(e.event, 'user signed up'), 1, 0) AS step_0,if(equals(e.event, 'user did things'), 1, 0) AS step_1,- ([e__person.properties___fish] AS value) AS prop_basic,+ ([replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'fish'), ''), 'null'), '^"|"$', '')] AS value) AS prop_basic,prop_basic AS propFROM events AS eLEFT OUTER JOIN@@ -44,16 +44,6 @@WHERE equals(person_distinct_id_overrides.team_id, 99999)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'fish'), ''), 'null'), '^"|"$', '') AS properties___fish- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('user did things', 'user signed up')), ifNull(less(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0)), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))@@ -121,17 +111,7 @@WHERE equals(person_distinct_id_overrides.team_id, 99999)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'fish'), ''), 'null'), '^"|"$', '') AS properties___fish- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('user did things', 'user signed up')), and(ifNull(less(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(e__person.properties___fish, '%fish%'), 0))), or(equals(step_0, 1), equals(step_1, 1))))+ WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('user did things', 'user signed up')), and(ifNull(less(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'fish'), ''), 'null'), '^"|"$', ''), '%fish%'), 0))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))GROUP BY breakdown@@ -188,8 +168,8 @@e.uuid AS uuid,e.`$session_id` AS `$session_id`,e.`$window_id` AS `$window_id`,- if(and(equals(e.event, 'user signed up'), and(ifNull(less(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(e__person.properties___fish, '%fish%'), 0))), 1, 0) AS step_0,- if(and(equals(e.event, 'user did things'), and(ifNull(less(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(e__person.properties___fish, '%fish%'), 0))), 1, 0) AS step_1+ if(and(equals(e.event, 'user signed up'), and(ifNull(less(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'fish'), ''), 'null'), '^"|"$', ''), '%fish%'), 0))), 1, 0) AS step_0,+ if(and(equals(e.event, 'user did things'), and(ifNull(less(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'fish'), ''), 'null'), '^"|"$', ''), '%fish%'), 0))), 1, 0) AS step_1FROM events AS eLEFT OUTER JOIN(SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,@@ -198,16 +178,6 @@WHERE equals(person_distinct_id_overrides.team_id, 99999)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'fish'), ''), 'null'), '^"|"$', '') AS properties___fish- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)WHERE and(equals(e.team_id, 99999), and(and(greaterOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC')), lessOrEquals(e.timestamp, toDateTime64('explicit_redacted_timestamp', 6, 'UTC'))), in(e.event, tuple('user did things', 'user signed up'))), or(equals(step_0, 1), equals(step_1, 1))))GROUP BY aggregation_targetHAVING ifNull(greaterOrEquals(step_reached, 0), 0))@@ -324,24 +294,7 @@(SELECT count() AS total,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_startFROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'fish'), ''), 'null'), '^"|"$', '') AS properties___fish- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-08 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2012-01-15 23:59:59', 'UTC'))), equals(e.event, '$pageview'), and(ifNull(greater(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(e__person.properties___fish, '%fish%'), 0)))+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-08 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2012-01-15 23:59:59', 'UTC'))), equals(e.event, '$pageview'), and(ifNull(greater(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'fish'), ''), 'null'), '^"|"$', ''), '%fish%'), 0)))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)@@ -373,24 +326,7 @@(SELECT count() AS total,toStartOfDay(toTimeZone(e.timestamp, 'UTC')) AS day_startFROM events AS e- LEFT OUTER JOIN- (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id,- person_distinct_id_overrides.distinct_id AS distinct_id- FROM person_distinct_id_overrides- WHERE equals(person_distinct_id_overrides.team_id, 99999)- GROUP BY person_distinct_id_overrides.distinct_id- HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0) SETTINGS optimize_aggregation_in_order=1) AS e__override ON equals(e.distinct_id, e__override.distinct_id)- LEFT JOIN- (SELECT person.id AS id,- replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(person.properties, 'fish'), ''), 'null'), '^"|"$', '') AS properties___fish- FROM person- WHERE and(equals(person.team_id, 99999), in(tuple(person.id, person.version),- (SELECT person.id AS id, max(person.version) AS version- FROM person- WHERE equals(person.team_id, 99999)- GROUP BY person.id- HAVING and(equals(argMax(person.is_deleted, person.version), 0), less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-08 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2012-01-15 23:59:59', 'UTC'))), equals(e.event, '$pageview'), and(ifNull(less(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(e__person.properties___fish, '%fish%'), 0)))+ WHERE and(equals(e.team_id, 99999), greaterOrEquals(e.timestamp, toStartOfInterval(assumeNotNull(toDateTime('2012-01-08 00:00:00', 'UTC')), toIntervalDay(1))), lessOrEquals(e.timestamp, assumeNotNull(toDateTime('2012-01-15 23:59:59', 'UTC'))), equals(e.event, '$pageview'), and(ifNull(less(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'int_value'), ''), 'null'), '^"|"$', ''), 'Int64'), 10), 0), ifNull(like(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.person_properties, 'fish'), ''), 'null'), '^"|"$', ''), '%fish%'), 0)))GROUP BY day_start)GROUP BY day_startORDER BY day_start ASC)diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/github/github.py b/products/warehouse_sources/backend/temporal/data_imports/sources/github/github.pyindex 6fd9f25e1279..983cc2b41a71 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/github/github.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/github/github.py@@ -1,4 +1,5 @@import re+import timeimport randomimport asyncioimport dataclasses@@ -12,9 +13,11 @@ import requestsfrom asgiref.sync import async_to_syncfrom dateutil import parser as dateutil_parserfrom structlog.types import FilteringBoundLogger+from temporalio import activityfrom tenacity import RetryCallState, retry, retry_if_exception_type, stop_after_attempt, wait_exponential_jitterfrom urllib3.util.retry import Retry+from posthog.egress.github.limiter import github_installation_pace_secondsfrom posthog.egress.github.transport import (GitHubEgressBudgetExhausted,GitHubRateLimitError,@@ -698,6 +701,7 @@ GITHUB_MAX_RETRY_AFTER_SECONDS = 300.0# us no reset to honor._github_backoff_wait = wait_exponential_jitter(initial=1, max=30)+# Disable the tracked session's default adapter retries on this path. That policy# retries 429/5xx and honors Retry-After *uncapped*, underneath _fetch_page — which# would defeat the 300s cap below and stack a second, untested retry layer. With@@ -823,6 +827,36 @@ def _github_retry_wait(state: RetryCallState) -> float:return _github_backoff_wait(state)+def _pace_before_request(installation_id: str, logger: FilteringBoundLogger) -> None:+ """Wait out this installation's share of the shared egress budget before the next request.++ A backfill spends one request per page and can run for hours, so at full speed it drains the+ installation's budget and is then shed for the rest of the window. Each shed page costs a retry+ attempt and a backoff that knows nothing about when the budget frees. Waiting first keeps the run+ inside the budget instead of recovering from it, and leaves the headroom the budget reserves for+ the interactive products that share this installation.++ The wait is bounded by the worker drain signal rather than by sleep. The pipeline tests for+ worker shutdown only between the chunks a source yields, so a plain sleep here would hold a+ draining pod for the full wait and delay the hand-off by that much. Waiting on the shutdown event+ returns as soon as the pod starts draining, so pacing costs the hand-off nothing.+ """+ # The same ceiling the Retry-After path honors, and safe here for the reason recorded on+ # GITHUB_MAX_RETRY_AFTER_SECONDS: this runs in the source thread pool, while the activity's+ # liveness heartbeat fires from the event loop.+ pace = min(+ github_installation_pace_seconds(installation_id, priority=Priority.BATCH), GITHUB_MAX_RETRY_AFTER_SECONDS+ )+ if pace <= 0:+ return++ logger.debug(f"Github: waiting {pace:.1f}s for egress budget before the next request")+ if activity.in_activity():+ activity.wait_for_worker_shutdown_sync(timeout=pace)+ else:+ time.sleep(pace)++@retry(retry=retry_if_exception_type((@@ -857,6 +891,13 @@ def _fetch_page(# this function's @retry backs off on; transport failures are recorded and re-raised for the same# retry. We keep our own tracked session and the GitHub response→exception mapping below.installation_id = egress_identity.installation_id if egress_identity is not None else None+ # Wait for budget before asking for it, so a long walk drips instead of draining its share and+ # being shed. Only the App path has a budget to pace against; the PAT path has no installation+ # and skips the gate too. On the rare page that is still shed, the retry backoff above applies+ # as well, which is the conservative order: the budget really is spent at that point.+ if installation_id is not None:+ _pace_before_request(installation_id, logger)+response = github_request("GET",page_url,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_fetch_page.py b/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_fetch_page.pyindex ab44b22ea54b..c2f0a74db4d5 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_fetch_page.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/github/tests/test_github_fetch_page.py@@ -19,9 +19,12 @@ def _ok_response() -> mock.Mock:response.status_code = 200response.ok = Trueresponse.text = ""- # The egress recorder reads response.request.{method,url}; a spec'd mock doesn't expose the- # instance attribute, so set it explicitly (None falls back to defaults in the recorder).+ # The egress recorder reads response.request.{method,url} and, for a known installation,+ # response.headers; a spec'd mock doesn't expose either instance attribute, so set them+ # explicitly (None falls back to defaults in the recorder, and no headers means no rate-limit+ # sample rather than a parse over a Mock).response.request = None+ response.headers = {}return response@@ -200,6 +203,73 @@ def test_fetch_page_gates_on_egress_budget_when_installation_known():}+ "installation_id,pace,expected_wait",+ [+ # Budget with room to spare, which is every sync short enough never to spend its share.+ # Waiting here would add latency to all of them and prevent nothing.+ ("123", 0.0, None),+ ("123", 12.5, 12.5),+ # Spreading a nearly spent budget can imply most of a window. A source that holds a worker+ # slot that long is worse than being shed and resuming, so the wait stops at the ceiling.+ ("123", 9_999.0, github.GITHUB_MAX_RETRY_AFTER_SECONDS),+ # PAT path: no installation, so no budget to pace against. Asking anyway would key the+ # lookup on a missing installation and wait on a budget that is not this caller's.+ (None, 12.5, None),+ ],+)+def test_fetch_page_waits_for_egress_budget_before_asking_for_it(installation_id, pace, expected_wait):+ # Waiting first is what keeps a long walk inside the budget rather than recovering from it. Every+ # way of breaking this is silent: no wait means the run drains its share and is shed for the rest+ # of the window, and waiting when there is headroom slows every small sync instead.+ session = mock.Mock()+ session.request.return_value = _ok_response()+ identity = github.GithubEgressIdentity(installation_id=installation_id)++ with (+ mock.patch.object(github, "github_installation_pace_seconds", return_value=pace) as pace_for,+ mock.patch.object(github, "activity") as temporal_activity,+ mock.patch.object(github, "make_tracked_session", return_value=session),+ ):+ temporal_activity.in_activity.return_value = True+ github._fetch_page("https://api.github.com/repos/o/r/issues", {}, mock.Mock(), identity)++ expected_waits = [] if expected_wait is None else [mock.call(timeout=expected_wait)]+ assert temporal_activity.wait_for_worker_shutdown_sync.call_args_list == expected_waits+ assert pace_for.called is (installation_id is not None)+ assert session.request.call_count == 1+++ "in_activity,expect_drain_wait,expect_sleep",+ [+ (True, True, False),+ # Outside an activity there is no worker to drain, so a plain sleep is the whole behavior.+ (False, False, True),+ ],+)+def test_fetch_page_budget_wait_yields_to_a_draining_worker(in_activity, expect_drain_wait, expect_sleep):+ # The pipeline tests for worker shutdown only between the chunks a source yields, so a wait that+ # slept would hold a draining pod for its full duration and delay the hand-off by that much.+ # Waiting on the shutdown event returns the moment the pod starts draining. Nothing about the+ # sync looks wrong when this regresses; drains just get slower.+ session = mock.Mock()+ session.request.return_value = _ok_response()+ identity = github.GithubEgressIdentity(installation_id="123")++ with (+ mock.patch.object(github, "github_installation_pace_seconds", return_value=30.0),+ mock.patch.object(github, "activity") as temporal_activity,+ mock.patch.object(github.time, "sleep") as sleep,+ mock.patch.object(github, "make_tracked_session", return_value=session),+ ):+ temporal_activity.in_activity.return_value = in_activity+ github._fetch_page("https://api.github.com/repos/o/r/issues", {}, mock.Mock(), identity)++ assert temporal_activity.wait_for_worker_shutdown_sync.called is expect_drain_wait+ assert sleep.called is expect_sleep++def _error_response(status_code: int, message: str, headers: dict[str, str] | None = None) -> mock.Mock:response = mock.Mock(spec=requests.Response)response.status_code = status_code