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(warehouse-sources): fail Aircall syncs that truncate silently (#91894)

posthog[bot]6069051976dc
diff --git a/products/warehouse_sources/backend/presentation/views/external_data_schema.py b/products/warehouse_sources/backend/presentation/views/external_data_schema.py
index 17dcb238c756..2a8b899d2bb9 100644
--- a/products/warehouse_sources/backend/presentation/views/external_data_schema.py
+++ b/products/warehouse_sources/backend/presentation/views/external_data_schema.py
@@ -1656,6 +1656,11 @@ class ExternalDataSchemaViewset(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):
@extend_schema(
request=None,
+ description=(
+ "Trigger a sync for the schema using its configured sync method. Most methods keep the "
+ "existing warehouse table and add or merge new rows, but a full-refresh schema rebuilds "
+ "the whole table on every run. To force a rebuild from the source, use resync."
+ ),
responses={
200: OpenApiResponse(description="The sync was triggered."),
400: OpenApiResponse(
@@ -1697,6 +1702,12 @@ class ExternalDataSchemaViewset(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):
@extend_schema(
request=None,
+ description=(
+ "Request a full resync of the schema. For sources that can backfill, this drops the "
+ "warehouse table and re-imports every row from the source, so existing data is deleted "
+ "first. A webhook-only schema cannot backfill, so it keeps its existing table and "
+ "resumes ingestion instead. To sync without requesting a rebuild, use reload."
+ ),
responses={
200: OpenApiResponse(description="The full resync was triggered."),
400: OpenApiResponse(
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aircall/aircall.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aircall/aircall.py
index 89b86e9796c1..3235fa8f605a 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aircall/aircall.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aircall/aircall.py
@@ -1,4 +1,3 @@
-import logging
import dataclasses
from collections.abc import Iterable
from datetime import UTC, date, datetime
@@ -30,8 +29,6 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.res
from products.warehouse_sources.backend.temporal.data_imports.sources.common.source_helpers import validate_via_probe
from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponse
-logger = logging.getLogger(__name__)
-
AIRCALL_BASE_URL = "https://api.aircall.io/v1"
# Aircall refuses to serve any record past the 10,000th of a single query and answers with a
# 400. It keeps advertising a `meta.next_page_link` across that boundary, so the link cannot be
@@ -39,6 +36,17 @@ AIRCALL_BASE_URL = "https://api.aircall.io/v1"
MAX_RECORDS_PER_QUERY = 10_000
+class AircallTruncationError(Exception):
+ """Raised when a capped window cannot advance, so the rest of it is unreachable.
+
+ Aircall serves at most 10,000 records per query. The paginator moves past that cap by
+ re-anchoring `from` on the latest cursor value seen. When every record in the filled window
+ shares the boundary timestamp, the cursor cannot move, the next window would repeat the same
+ query, and the remaining records are lost. Failing here surfaces that loss as a failed sync
+ instead of letting the run report success with missing data.
+ """
+
+
@dataclasses.dataclass
class AircallResumeConfig:
next_url: str
@@ -115,8 +123,9 @@ class AircallPaginator(BasePaginator):
rejects that page with a 400: waiting for the page chain to end would never re-anchor the
tables that actually need it. The end of a page chain re-anchors too, since a chain that ends
at the cap boundary is indistinguishable from one that ends because the window is exhausted.
- The strict-advance guard prevents an infinite loop when many records share the boundary
- timestamp.
+ When many records share the boundary timestamp the cursor cannot advance, so a fresh window
+ would repeat the same query forever. The paginator raises `AircallTruncationError` there
+ rather than loop or drop the rest of the window silently.
"""
def __init__(
@@ -190,14 +199,12 @@ class AircallPaginator(BasePaginator):
if capped:
# A window that fills the cap without its cursor advancing cannot be moved forward,
# because the next window would open on the same timestamp and return the same
- # records. Stop rather than loop, and make the truncation visible in the job logs.
- logger.warning(
- "Aircall: %s reached the %s-record query cap without %s advancing past %s, "
- "so the rest of this window is unreachable and the table is truncated",
- self._config.path,
- MAX_RECORDS_PER_QUERY,
- self._config.reanchor_field,
- self._from_value,
+ # records. Fail rather than drop the rest of the window silently: a warning-only stop
+ # let the run finalize as complete with missing data, which is invisible to the user.
+ raise AircallTruncationError(
+ f"Aircall {self._config.path}: {self._config.reanchor_field} did not advance past "
+ f"{self._from_value} within the {MAX_RECORDS_PER_QUERY}-record query limit, so the "
+ "rest of this window cannot be fetched. The sync stopped to avoid losing data."
)
self._has_next_page = False
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aircall/tests/test_aircall.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aircall/tests/test_aircall.py
index 9dd50982275a..d5fe0ef38b55 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aircall/tests/test_aircall.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aircall/tests/test_aircall.py
@@ -9,6 +9,7 @@ from requests import Response
from products.warehouse_sources.backend.temporal.data_imports.sources.aircall.aircall import (
AircallResumeConfig,
+ AircallTruncationError,
_build_params,
_build_url,
_reaches_record_cap,
@@ -293,25 +294,26 @@ class TestPagination:
assert "from=10000" in requests_seen[200]["url"]
@mock.patch(CLIENT_SESSION_PATCH)
- def test_stops_when_a_capped_window_cursor_cannot_advance(self, MockSession):
+ def test_raises_when_a_capped_window_cursor_cannot_advance(self, MockSession):
# Every record in the capped window shares the boundary timestamp, so a re-anchored
- # window would repeat the same query forever. Truncate instead of looping.
+ # window would repeat the same query forever and the rest of the window is unreachable.
+ # Raise so the run fails visibly instead of finalizing as complete with missing data.
session = MockSession.return_value
over_cap_link = "https://api.aircall.io/v1/contacts?order=asc&per_page=50&page=201"
- requests_seen = _wire(session, [_response("contacts", [{"id": 1, "created_at": 200}], over_cap_link)])
+ _wire(session, [_response("contacts", [{"id": 1, "created_at": 200}], over_cap_link)])
manager = _make_manager()
- _rows(
- _source(
- "contacts",
- manager,
- should_use_incremental_field=True,
- db_incremental_field_last_value=200,
- incremental_field="created_at",
+ with pytest.raises(AircallTruncationError):
+ _rows(
+ _source(
+ "contacts",
+ manager,
+ should_use_incremental_field=True,
+ db_incremental_field_last_value=200,
+ incremental_field="created_at",
+ )
)
- )
- assert len(requests_seen) == 1
manager.save_state.assert_not_called()
@mock.patch(CLIENT_SESSION_PATCH)
diff --git a/products/warehouse_sources/frontend/generated/api.ts b/products/warehouse_sources/frontend/generated/api.ts
index 7f10bc06dba0..92e52fbd9d69 100644
--- a/products/warehouse_sources/frontend/generated/api.ts
+++ b/products/warehouse_sources/frontend/generated/api.ts
@@ -439,6 +439,9 @@ export const getExternalDataSchemasReloadCreateUrl = (projectId: string, id: str
return `/api/projects/${projectId}/external_data_schemas/${id}/reload/`
}
+/**
+ * Trigger a sync for the schema using its configured sync method. Most methods keep the existing warehouse table and add or merge new rows, but a full-refresh schema rebuilds the whole table on every run. To force a rebuild from the source, use resync.
+ */
export const externalDataSchemasReloadCreate = async (
projectId: string,
id: string,
@@ -454,6 +457,9 @@ export const getExternalDataSchemasResyncCreateUrl = (projectId: string, id: str
return `/api/projects/${projectId}/external_data_schemas/${id}/resync/`
}
+/**
+ * Request a full resync of the schema. For sources that can backfill, this drops the warehouse table and re-imports every row from the source, so existing data is deleted first. A webhook-only schema cannot backfill, so it keeps its existing table and resumes ingestion instead. To sync without requesting a rebuild, use reload.
+ */
export const externalDataSchemasResyncCreate = async (
projectId: string,
id: string,
diff --git a/services/mcp/src/generated/warehouse_sources/api.ts b/services/mcp/src/generated/warehouse_sources/api.ts
index 1a994bef2d37..7fb2c26c38d8 100644
--- a/services/mcp/src/generated/warehouse_sources/api.ts
+++ b/services/mcp/src/generated/warehouse_sources/api.ts
@@ -317,6 +317,9 @@ export const ExternalDataSchemasIncrementalFieldsCreateBody = () => zod
})
.describe('A schema of an external data source: its sync configuration and the warehouse table it syncs into.')
+/**
+ * Trigger a sync for the schema using its configured sync method. Most methods keep the existing warehouse table and add or merge new rows, but a full-refresh schema rebuilds the whole table on every run. To force a rebuild from the source, use resync.
+ */
export const ExternalDataSchemasReloadCreateParams = () => zod.object({
id: zod.string().describe('A UUID string identifying this external data schema.'),
project_id: zod
@@ -326,6 +329,9 @@ export const ExternalDataSchemasReloadCreateParams = () => zod.object({
),
})
+/**
+ * Request a full resync of the schema. For sources that can backfill, this drops the warehouse table and re-imports every row from the source, so existing data is deleted first. A webhook-only schema cannot backfill, so it keeps its existing table and resumes ingestion instead. To sync without requesting a rebuild, use reload.
+ */
export const ExternalDataSchemasResyncCreateParams = () => zod.object({
id: zod.string().describe('A UUID string identifying this external data schema.'),
project_id: zod