: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
chore(warehouse_sources): tighten version-skill self-improvement gate (#74217)
Daniel RC3e54ed354cce
diff --git a/.agents/skills/warehouse-source-new-version/SKILL.md b/.agents/skills/warehouse-source-new-version/SKILL.mdindex ee88779ffb90..53eed4081bbd 100644--- a/.agents/skills/warehouse-source-new-version/SKILL.md+++ b/.agents/skills/warehouse-source-new-version/SKILL.md@@ -19,7 +19,7 @@ Use this skill when a vendor has released a new API version and an existing sour- Each `ExternalDataSource` row pins one version in its `api_version` column (NULL resolves to `default_version`). A schema may additionally carry a user-managed override in `ExternalDataSchema.api_version` (set from the schema's configuration page; not available for webhook-sync schemas) which wins over the source pin for that schema only. The sync pipeline resolves override → pin → default in `workflow_activities/import_data_sync.py` and hands the result to the source as `SourceInputs.api_version` — already resolved, never None there.- **A pinned source uses its version everywhere, not just at sync time.** Every vendor-touching surface on the source classes takes an `api_version: str | None = None` parameter carrying the source instance's resolved pin (`None` → `default_version`): `get_schemas`, `validate_credentials`, `get_endpoint_permissions`, and the `WebhookSource` management methods (`create_webhook`, `sync_webhook_events`, `webhook_inputs_updated`, `get_external_webhook_info`, `delete_webhook`). Callers with a source row (creation, `refresh_schemas`, background `sync_new_schemas`, webhook endpoints, schema-scoped probes) pass the resolved pin; pre-creation flows (wizard `database_schema`, one-shot `setup`) omit it, which resolves to `default_version` — the version the new row is stamped with (`get_endpoint_permissions` currently has only the pre-creation caller, so its parameter is always `None` today). Base-path/URL/header construction from it happens inside each source. Deliberately NOT version-threaded (pure mappings or version-independent surfaces — thread them if a real vendor version ever diverges there): `get_desired_webhook_events`/`webhook_resource_map` (event-name mappings), `get_connection_metadata`, and GitHub's per-repo webhook helpers in `github_warehouse_repos.py`.- These declarations are exposed publicly via `GET /api/public_source_configs/` (`versions`, `defaultVersion`, `apiDocsUrl`, `deprecatedVersions`) and per-instance via the source API (`api_version`, `api_version_deprecation`). The `api_version` pin is queryable in HogQL via the `data_warehouse_sources` system table.-- Registry-wide invariants are enforced by `sources/tests/test_source_versions.py`: default in supported, deprecated ⊆ supported, default never deprecated, https `api_docs_url`.+- Registry-wide invariants are enforced by `sources/tests/test_source_versions.py`: default in supported and always the last entry (declare `supported_versions` oldest→newest; flip the default in the same PR), deprecated ⊆ supported, default never deprecated, https `api_docs_url`.## First: does the version need to exist at all?@@ -63,8 +63,9 @@ 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. 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. Where migration is lossy or unsafe, do not script it — document the manual path in the PR. Do not execute migrations or backfills; humans review and run them.-5. **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.+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.+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.## Pinning semantics (do not break these)@@ -83,26 +84,11 @@ Add it when any of these hold:- 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.+- 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.## Self-improvement-After you finish a version-update or deprecation PR using this skill, **append what you learned** to the list below (vendor quirks, dispatch gotchas, test patterns). Keep entries one line each, pattern-focused, no changelog prose.--### Learnings--- (seed) Stripe: response shapes differ enough across date versions that canonical column hints must be gated per version; newer versions auto-infer schema instead.-- A new version label doesn't imply new paths: vendors ship a "v2" that still serves resources at `/v1/`, or replace the resource API entirely — check the docs per resource before building `/{version}/{resource}` URLs. A tell-tale in your own diff: needing a different probe/validation endpoint for the new version proves the resource sets diverge, so the sync paths need branching too.-- Grep every place the source builds a client or URL (sync, discovery, probes, error matchers, webhooks) when bumping — the ones outside the sync path silently stay on default/legacy versions.-- Simplecast: current API (api.simplecast.com + Bearer) _is_ "2.0" and the `UNVERSIONED_API_VERSION` ("v1") pin already hit it, so both labels resolve to the same live API and "2.0" shipped as a pure declaration change. That is exactly the shape the gate now skips — a renamed label over an unchanged API is not a version to support. Header-based version selection is announced but unshipped there, so if it ever ships, don't thread a speculative header ahead of the real contract (a no-op header ships risk with no present benefit).-- Two questions that resolve most "is this a real version?" calls fast: does the source send anything different on the wire, and does anything it reads come back different? Two nos and the only remaining reason to adopt the label is the old one being retired.-- Vendors rename versions for marketing (rebrands, docs-site restructures, "v2 developer platform" launches) far more often than they change the endpoints an ingest-only source reads. Diff resource by resource, not by announcement headline.-- Notion 2026-03-11: for read-only syncs a new version is often header-only — its breaking changes (`archived`->`in_trash`, `transcription`->`meeting_notes` block type, `after`->`position` on _append_ block children) only touch response fields or write paths we never call, so with an auto-inferred schema the sole dispatch is threading the resolved version into the request header. No per-version module needed.-- When the request layer hardcodes the version as a module constant (e.g. `NOTION_VERSION`), the dispatch is: add a param through the client/session builders (`notion_source` -> `get_rows` -> `_build_session` -> `_get_headers`), pass `self.resolve_api_version(inputs.api_version)` from `source_for_pipeline`, and give the standalone `validate_credentials(token, api_version)` `self.default_version` (creation-time, version-agnostic probe).-- Test pattern that stayed cheap: parameterize the header builder over supported versions (header carries requested version) + mock `notion_source` in the source module and assert `call_args.kwargs["api_version"]` for none/legacy/new pins (resolution + threading in one).-- Auto-inferred-schema sources (`has_managed_hogql_schema=False`) turn new attributes into new columns automatically, so a version bump whose breaking changes only touch fields the source never reads needs no data/schema transform — the repin migration is a plain idempotent `api_version` UPDATE. Verify field-by-field against the changelog instead of assuming a date bump is breaking.-- A repin migration's reverse must be a no-op: after repinning, rows on the new default are indistinguishable from natively-created ones, so a blanket downgrade would clobber legitimate native pins (same reasoning as the 0075 api_version backfill).-- A version bump can change the _auth scheme_, not just the wire format (Greenhouse Harvest v3 drops HTTP Basic API keys for OAuth2 client-credentials Bearer JWTs). Then the source config needs both credential shapes as optional fields, `_build_auth(api_version, ...)` picks one, and `validate_credentials` enforces the pair the resolved version needs — form-level `required` can't express "depends on the pin".-- When the new version's credentials can't be derived from the old ones, there is no repin migration to write: an `api_version` UPDATE would point existing rows at credentials they don't have. Ship the `deprecated_versions` banner and document the manual re-credential path instead.-- Keep the schema/table name set identical across versions even when the vendor renames a collection (Harvest `scheduled_interviews` -> v3 `interviews`): put the rename in a per-version path on the endpoint config, so discovery diffs can't orphan a table on repin.-- Vendor OpenAPI is often embedded in the docs pages themselves (`/reference/get_v3-<resource>.md`, indexed by `llms.txt`) — parse it to confirm paths, filter params, response envelope, and id types for all endpoints at once instead of trusting a prose migration guide.-- The registry invariant now enforces `default_version == supported_versions[-1]` (test_source_versions.py): declare versions oldest→newest and flip the default in the same PR — a held-back default fails CI, and `[-1]` is a trustworthy "latest" accessor.+The default outcome of a PR is that this skill does not change. Edit it only for a learning that clears all three bars: it generalizes across sources, it would change what a future agent does, and it is not already stated or derivable from the sections above. Vendor changelog details, per-source dispatch chains or code paths, and test specifics never qualify — that context lives in your PR, not here.++When something clears the bar, fold it into the section where an agent would need it (the gate, a step, a pitfall) as one vendor-neutral line. Do not append a learnings list, changelog, or dated notes anywhere in this file.