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.

feat(warehouse_sources): support Gusto API version 2026-06-15 (#80089)

Tom Owers6cc54bee8f6a
diff --git a/.agents/skills/warehouse-source-new-version/SKILL.md b/.agents/skills/warehouse-source-new-version/SKILL.md
index 3cc02aa49275..0eb9d8682912 100644
--- a/.agents/skills/warehouse-source-new-version/SKILL.md
+++ b/.agents/skills/warehouse-source-new-version/SKILL.md
@@ -63,7 +63,7 @@ Add it when any of these hold:
1. Implement the newer version first (steps above) if not already supported.
2. Add the old version to `deprecated_versions` with the vendor's announced sunset date (or `sunset_at=None` if none). Never deprecate `default_version` — flip the default to the new version in the same PR.
3. The in-product warning banner and API fields light up automatically from the metadata — zero per-source UI work.
-4. **Deprecated is not migrated.** Existing pins move only when the vendor has announced the version will stop being served (a sunset/removal date). A deprecation without a sunset date is advisory: mark it, leave every existing pin on it fully supported, and write no migration — repinning working customers off a version the vendor still serves is exactly the silent version move the pinning framework exists to prevent.
+4. **Deprecated is not migrated.** Existing pins move only when the vendor has announced the version will stop being served (a sunset/removal date). A deprecation without a sunset date is advisory: mark it, leave every existing pin on it fully supported, and write no migration — repinning working customers off a version the vendor still serves is exactly the silent version move the pinning framework exists to prevent. Two narrow cases still repin under an advisory (`sunset_at=None`) deprecation: the deprecated label resolves to a byte-identical request as the new default (a pure alias — no per-version dispatch — so the repin is not a move), or the vendor already errors on the old version (e.g. `410`/`406`) so leaving pins is worse than moving them. A source that sends a per-version header/URL for a version the vendor still serves is neither — stay advisory.
5. Only for a sunsetting version: include a **written-not-run** migration script that repins affected `ExternalDataSource` rows (`api_version` column) from the deprecated version to the new one, plus any safe data/schema transforms. It must be idempotent and reviewable, and its reverse must be a no-op — repinned rows are indistinguishable from natively-created ones, so a blanket downgrade would clobber legitimate native pins. Where migration is lossy or unsafe — including when the new version needs credentials that can't be derived from the stored ones — do not script it: document the manual path in the PR. Do not execute migrations or backfills; humans review and run them.
6. **Never touch `ExternalDataSchema.api_version` overrides** in migration scripts — they are user-managed by design. The schema-level deprecation warning covers them; the user migrates them from the schema's configuration page.
@@ -85,7 +85,7 @@ Add it when any of these hold:
- Parallel version-bump PRs grab the same next migration number; the second to merge becomes a conflicting leaf and `ci:preflight` blocks it. Check `max_migration.txt` and renumber.
- Don't regenerate schemas for existing customers as part of a version add; schema changes only apply to rows repinned via the (human-run) migration.
- Discovery diffs under the SOURCE pin (`sync_new_schemas`, `refresh_schemas`, bulk sync-defaults). A schema-level `api_version` override on a version whose table set differs from the source's version can be disabled/soft-deleted by that diff — keep overrides to short verification windows, not as a long-term way to hold one table on another version.
-- When a versioned source starts consuming the discovery `api_version` parameter, add the vendor's version-rejection error signature to `get_non_retryable_errors` — otherwise a retired pin turns the ~6h discovery cadence into a permanent retry/error loop with no user-facing surface.
+- When a versioned source sends the pin on any vendor call — discovery _or_ sync (a static endpoint catalog doesn't consume it at discovery, but `get_rows` still sends the version header) — add the vendor's version-rejection error signature (e.g. `406`/`410`) to `get_non_retryable_errors`, otherwise a retired pin turns the retry cadence into a permanent error loop with no user-facing surface.
- A version bump can change the auth scheme, not just the wire format. Then the source config needs both credential shapes as optional fields, auth construction dispatches on the resolved version, and `validate_credentials` enforces the pair that version needs — form-level `required` can't express "depends on the pin".
- When the vendor renames a collection between versions, keep the schema/table name set identical across versions and put the rename in a per-version path on the endpoint config — otherwise discovery diffs orphan the table on repin.
- When the new version has no equivalent for an old endpoint (a dropped collection, not a rename), keep that table only on the versions that serve it and let the table set differ by version — never map it to a guessed path just to keep the sets equal, since docs are the sole source of truth and an unverified path makes a new source surface a table that 404s at sync time.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gusto/gusto.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gusto/gusto.py
index 33d97e9da53a..8d71fc411ec2 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gusto/gusto.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gusto/gusto.py
@@ -23,9 +23,10 @@ GUSTO_HOSTS = {
"demo": "https://api.gusto-demo.com",
}
DEFAULT_ENVIRONMENT = "production"
-# Dated API version pinned via the `X-Gusto-API-Version` header. Everything below is written
-# against this contract; bumping it is a `warehouse-source-new-version` change.
-GUSTO_API_VERSION = "2024-04-01"
+# Dated API versions pinned via the `X-Gusto-API-Version` header. One constant per version so the
+# source's version declaration and the request layer share a single label — never parsed or ordered.
+GUSTO_API_VERSION_2024_04_01 = "2024-04-01"
+GUSTO_API_VERSION_2026_06_15 = "2026-06-15"
REQUEST_TIMEOUT_SECONDS = 60
# Source creation runs this synchronously, so keep the credential probe snappy.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gusto/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gusto/source.py
index 2f4325caa273..8d45c371a038 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gusto/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gusto/source.py
@@ -11,7 +11,11 @@ from posthog.schema import (
SourceFieldSelectConfigOption,
)
-from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import FieldType, ResumableSource
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import (
+ FieldType,
+ ResumableSource,
+ VersionDeprecation,
+)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.canonical_descriptions import (
CanonicalDescriptions,
)
@@ -24,7 +28,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.sch
from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceInputs, SourceResponse
from products.warehouse_sources.backend.temporal.data_imports.sources.generated_configs.gusto import GustoSourceConfig
from products.warehouse_sources.backend.temporal.data_imports.sources.gusto.gusto import (
- GUSTO_API_VERSION,
+ GUSTO_API_VERSION_2024_04_01,
+ GUSTO_API_VERSION_2026_06_15,
GustoResumeConfig,
gusto_source,
validate_credentials as validate_gusto_credentials,
@@ -41,9 +46,12 @@ from products.warehouse_sources.backend.types import ExternalDataSourceType
class GustoSource(ResumableSource[GustoSourceConfig, GustoResumeConfig]):
lists_tables_without_credentials = True # static endpoint catalog — safe for public docs
- supported_versions = (GUSTO_API_VERSION,)
- default_version = GUSTO_API_VERSION
+ supported_versions = (GUSTO_API_VERSION_2024_04_01, GUSTO_API_VERSION_2026_06_15)
+ default_version = GUSTO_API_VERSION_2026_06_15
api_docs_url = "https://docs.gusto.com/embedded-payroll/reference"
+ # Gusto gives a deprecated version 12 months of phased support before calls return 406, but
+ # publishes no end-of-life date for 2024-04-01 — advisory only, so existing pins are left in place.
+ deprecated_versions = (VersionDeprecation(version=GUSTO_API_VERSION_2024_04_01, sunset_at=None),)
@property
def source_type(self) -> ExternalDataSourceType:
@@ -118,6 +126,8 @@ Gusto rotates refresh tokens, so the token you paste here is exchanged on every
"400 Client Error: Bad Request for url: https://api.gusto": "Gusto rejected these OAuth credentials. Refresh tokens rotate on use — generate a new one and reconnect.",
"401 Client Error: Unauthorized for url: https://api.gusto": "Gusto authentication failed. Check your client ID and secret, then reconnect with a fresh refresh token.",
"403 Client Error: Forbidden for url: https://api.gusto": "Your Gusto app is not authorized to read this data. Reconnect with a payroll admin authorization for the company.",
+ # Gusto returns 406 once a pinned API version reaches end of life; retrying can't recover it.
+ "406 Client Error: Not Acceptable for url: https://api.gusto": "This Gusto API version is no longer supported. Reconnect the source to move to the current version.",
}
def get_schemas(
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gusto/tests/test_gusto.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gusto/tests/test_gusto.py
index f5677c44e87f..d410f5fa8a68 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gusto/tests/test_gusto.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gusto/tests/test_gusto.py
@@ -12,7 +12,8 @@ from parameterized import parameterized
from products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManager
from products.warehouse_sources.backend.temporal.data_imports.sources.gusto.gusto import (
DEFAULT_WINDOW_START,
- GUSTO_API_VERSION,
+ GUSTO_API_VERSION_2024_04_01,
+ GUSTO_API_VERSION_2026_06_15,
GustoClient,
GustoResumeConfig,
_window_bounds,
@@ -125,7 +126,7 @@ def _run(
client_secret="secret",
refresh_token="refresh",
endpoint=endpoint,
- api_version=GUSTO_API_VERSION,
+ api_version=GUSTO_API_VERSION_2026_06_15,
logger=MagicMock(),
resumable_source_manager=resume_manager,
db_incremental_field_last_value=db_incremental_field_last_value,
@@ -182,7 +183,7 @@ class TestListCompanies:
"products.warehouse_sources.backend.temporal.data_imports.sources.gusto.gusto.make_tracked_session",
return_value=session,
):
- return GustoClient("production", "cid", "secret", "refresh", GUSTO_API_VERSION)
+ return GustoClient("production", "cid", "secret", "refresh", GUSTO_API_VERSION_2026_06_15)
def test_returns_companies_sorted_by_uuid(self) -> None:
client = self._client(_me_body(["c-zeta", "c-alpha"]))
@@ -293,15 +294,17 @@ class TestGustoClient:
"products.warehouse_sources.backend.temporal.data_imports.sources.gusto.gusto.make_tracked_session",
return_value=session,
):
- return GustoClient(environment, "cid", "secret", "refresh", GUSTO_API_VERSION, MagicMock())
+ return GustoClient(environment, "cid", "secret", "refresh", GUSTO_API_VERSION_2026_06_15, MagicMock())
- def test_session_pins_the_api_version_and_redacts_secrets(self) -> None:
+ @parameterized.expand([(GUSTO_API_VERSION_2024_04_01,), (GUSTO_API_VERSION_2026_06_15,)])
+ def test_session_pins_the_api_version_and_redacts_secrets(self, api_version: str) -> None:
+ # Each supported version reaches the header verbatim, so a pinned source syncs under its pin.
with patch(
"products.warehouse_sources.backend.temporal.data_imports.sources.gusto.gusto.make_tracked_session"
) as make_session:
- GustoClient("production", "cid", "secret", "refresh", GUSTO_API_VERSION)
+ GustoClient("production", "cid", "secret", "refresh", api_version)
kwargs = make_session.call_args.kwargs
- assert kwargs["headers"]["X-Gusto-API-Version"] == GUSTO_API_VERSION
+ assert kwargs["headers"]["X-Gusto-API-Version"] == api_version
assert set(kwargs["redact_values"]) == {"secret", "refresh"}
# Payroll PII must never reach HTTP sample capture.
assert kwargs["capture"] is False
@@ -519,7 +522,7 @@ class TestGustoSourceResponse:
client_secret="secret",
refresh_token="refresh",
endpoint=endpoint,
- api_version=GUSTO_API_VERSION,
+ api_version=GUSTO_API_VERSION_2026_06_15,
logger=MagicMock(),
resumable_source_manager=_FakeResumableManager(),
)
@@ -540,7 +543,7 @@ class TestGustoSourceResponse:
client_secret="secret",
refresh_token="refresh",
endpoint="employees",
- api_version=GUSTO_API_VERSION,
+ api_version=GUSTO_API_VERSION_2026_06_15,
logger=MagicMock(),
resumable_source_manager=_FakeResumableManager(),
)
@@ -560,7 +563,7 @@ class TestValidateCredentials:
"products.warehouse_sources.backend.temporal.data_imports.sources.gusto.gusto.make_tracked_session",
return_value=session,
):
- return validate_credentials("production", "cid", "secret", "refresh", GUSTO_API_VERSION)
+ return validate_credentials("production", "cid", "secret", "refresh", GUSTO_API_VERSION_2026_06_15)
def test_accepts_credentials_that_reach_a_company(self) -> None:
assert self._validate({"/v1/me": [_FakeResponse(200, _me_body(["c-1"]))]}) == (True, None)
@@ -590,7 +593,7 @@ class TestValidateCredentials:
"products.warehouse_sources.backend.temporal.data_imports.sources.gusto.gusto.make_tracked_session",
return_value=_FakeSession({}),
):
- ok, message = validate_credentials("sandbox", "cid", "secret", "refresh", GUSTO_API_VERSION)
+ ok, message = validate_credentials("sandbox", "cid", "secret", "refresh", GUSTO_API_VERSION_2026_06_15)
assert ok is False
assert message is not None and "Invalid Gusto environment" in message
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/gusto/tests/test_gusto_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/gusto/tests/test_gusto_source.py
index 929008faa6ae..0c33c7ebfe69 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/gusto/tests/test_gusto_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/gusto/tests/test_gusto_source.py
@@ -13,7 +13,8 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.gusto.cano
CANONICAL_DESCRIPTIONS,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.gusto.gusto import (
- GUSTO_API_VERSION,
+ GUSTO_API_VERSION_2024_04_01,
+ GUSTO_API_VERSION_2026_06_15,
GustoResumeConfig,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.gusto.settings import (
@@ -73,10 +74,18 @@ class TestGustoSource:
assert field.defaultValue == "production"
def test_api_version_is_pinned_to_what_the_client_sends(self) -> None:
- assert self.source.supported_versions == (GUSTO_API_VERSION,)
- assert self.source.default_version == GUSTO_API_VERSION
+ # Declared oldest→newest; new sources start on the newest version.
+ assert self.source.supported_versions == (GUSTO_API_VERSION_2024_04_01, GUSTO_API_VERSION_2026_06_15)
+ assert self.source.default_version == GUSTO_API_VERSION_2026_06_15
assert self.source.api_docs_url.startswith("https://")
+ def test_older_version_is_deprecated_without_a_sunset_date(self) -> None:
+ # Gusto publishes no end-of-life date for 2024-04-01, so the deprecation is advisory only
+ # (sunset_at=None) and the default is never itself deprecated.
+ deprecation = self.source.get_version_deprecation(GUSTO_API_VERSION_2024_04_01)
+ assert deprecation is not None and deprecation.sunset_at is None
+ assert self.source.get_version_deprecation(GUSTO_API_VERSION_2026_06_15) is None
+
def test_lists_tables_without_credentials(self) -> None:
assert self.source.lists_tables_without_credentials is True
@@ -130,6 +139,8 @@ class TestGustoSource:
("unauthorized", "401 Client Error: Unauthorized for url: https://api.gusto.com/oauth/token"),
("bad_request", "400 Client Error: Bad Request for url: https://api.gusto.com/oauth/token"),
("forbidden", "403 Client Error: Forbidden for url: https://api.gusto.com/v1/companies/c-1/payrolls"),
+ # A pin that reaches end of life 406s; retrying can't recover it.
+ ("version_end_of_life", "406 Client Error: Not Acceptable for url: https://api.gusto.com/v1/me"),
]
)
def test_auth_failures_are_non_retryable(self, _name: str, observed_error: str) -> None:
@@ -155,7 +166,7 @@ class TestGustoSource:
"client_id": "cid",
"client_secret": "secret",
"refresh_token": "refresh",
- "api_version": GUSTO_API_VERSION,
+ "api_version": GUSTO_API_VERSION_2026_06_15,
}
@mock.patch(
@@ -191,9 +202,17 @@ class TestGustoSource:
assert kwargs["client_secret"] == "secret"
assert kwargs["refresh_token"] == "refresh"
assert kwargs["endpoint"] == "employees"
- assert kwargs["api_version"] == GUSTO_API_VERSION
+ assert kwargs["api_version"] == GUSTO_API_VERSION_2026_06_15
assert kwargs["resumable_source_manager"] is manager
+ @parameterized.expand([(GUSTO_API_VERSION_2024_04_01,), (GUSTO_API_VERSION_2026_06_15,)])
+ @mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.gusto.source.gusto_source")
+ def test_source_for_pipeline_honors_the_pinned_version(self, pin: str, mock_source: mock.MagicMock) -> None:
+ # A source pinned to a still-supported (including deprecated) version syncs under that pin,
+ # never silently on the new default.
+ self.source.source_for_pipeline(self.config, mock.MagicMock(), self._inputs(api_version=pin))
+ assert mock_source.call_args.kwargs["api_version"] == pin
+
@parameterized.expand(
[
("incremental_run_passes_the_watermark", True, "2024-05-06"),