Auditing warehouse source health

From PostHog/posthog · View interactive version

Auditing warehouse source health is an AI agent skill from the GitHub repository PostHog/posthog. Audit the health of a PostHog project's data warehouse sources and syncs — find every broken or degraded source connection, sync schema, and webhook channel. Use when the user asks "why are my imports failing?", "what's broken with my sources?", "why is my warehouse data stale?", or wants a one-shot

How to use this skill

Skill file

Auditing data warehouse source health

This skill produces a project-wide audit of the source and sync side of the data warehouse pipeline — source

connections, sync schemas, and webhook push channels. Use it when the user wants a **summary of what's broken with

their imports**, not a deep-dive on one sync. The deep-dive on individual failures is

diagnosing-failed-warehouse-syncs; this skill is the scan that tells them where to look first.

The same underlying endpoint (data-warehouse-data-health-issues-retrieve) also reports materialized-view,

batch-export-destination, and transformation issues. Materialized views are covered by

auditing-warehouse-view-health. Destinations (batch exports) and transformations are owned by other products — surface

them if they appear, but route them to the relevant team rather than diagnosing here.

When to use this skill

Available tools

| Tool | Purpose |

| --------------------------------------------- | --------------------------------------------------------------- |

| data-warehouse-data-health-issues-retrieve | One-shot: all failed/degraded items across the whole pipeline |

| external-data-sources-list | All sources with status and latest error |

| external-data-schemas-list | All schemas with status, last_checked_at, latest_error |

| external-data-sources-webhook-info-retrieve | Check per-source webhook state (not covered by the health tool) |

The data-warehouse-data-health-issues-retrieve endpoint aggregates across the whole pipeline — it's the fastest path to a summary. Filter

its results to the source and external_data_sync types for this audit. Use the list endpoints when you need more

context than the summary provides (row counts, non-failing items, schema-level detail).

What counts as a source/sync "issue"

From the data-health endpoint, this audit cares about two of the five categories:

| type | Trigger | Typical urgency |

| -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- | --------------- |

| source | ExternalDataSource.status = Error — whole source connection broken | High |

| external_data_sync | schema in Failed or BillingLimitReached state (the data-health endpoint returns status: "failed" or status: "billing_limit" respectively) | Medium–High |

Each entry includes id, name, type, status, error, failed_at, url, and source_type.

The other categories the endpoint returns are out of scope for this skill:

Note the data-health endpoint only reports _active failures_. For source/sync health it doesn't flag:

push channel is silently broken (deregistered, disabled on the remote side, failing signature verification).

These don't surface in data-warehouse-data-health-issues-retrieve — check per-source with external-data-sources-webhook-info-retrieve.

If the user asks about staleness or unused items, reach beyond this endpoint — see Step 4.

data-warehouse-data-health-issues-retrieve needs read access to sources, views, batch exports and transformations.

If the token lacks one of those, use health-issues-list (needs health_issue:read) with status=active and kind=external_data_failure

instead. That check runs once a day and reports tables only, not sources in Error. kind=webhook_subscription_stale

covers webhook tables whose events stopped arriving.

Workflow

Step 1 — One-shot pull

Call data-warehouse-data-health-issues-retrieve and keep the source and external_data_sync entries.

If there are no source/sync issues, tell the user their sources are healthy and stop. Don't invent problems. When the

user asked about stale data or for a broader audit, do not stop here: continue to Step 4, because this endpoint does

not report stale Completed schemas.

Step 2 — Group and prioritize

  1. Sources in Error first. A source failure cascades — every schema under it is effectively dead until the

source reconnects. Fix these first.

  1. Sync schemas next, in this order:

Step 3 — Present the audit

Render a prioritized report. Don't dump the raw JSON — human-readable table per category:

## Data warehouse source health — 4 issues

### 🔴 Sources (1)
- Stripe — authentication failed (failed 2h ago). All 8 tables under it are currently dead.
  → `diagnosing-failed-warehouse-syncs` on this source

### 🟠 Sync schemas (3)
- postgres_prod.orders (Failed 6h ago) — column "updated_at" does not exist
- postgres_prod.invoices (Failed 6h ago) — column "updated_at" does not exist
- hubspot.contacts (BillingLimitReached) — team quota exceeded

Recommended order:
1. Stripe auth (everything under it is dead)
2. Schema-drift on postgres_prod.orders / invoices — looks like upstream renamed a column
3. Billing limit on hubspot

The exact format is less important than: prioritized, grouped, actionable, and hinting at the right next skill.

Step 4 — Go beyond active failures (when asked)

If the user wants more than just "what's on fire" — e.g. "what else should I look at?" — cross-check:

Stale but "Completed" schemas:

Call external-data-schemas-list with compact: false, because the compact rows leave out sync_frequency. For each

enabled Completed schema, compare last_checked_at with sync_frequency. last_checked_at is the start of the last

successful sync, including syncs that found no new rows. A schema on 1hour frequency with a last_checked_at from 3

days ago is effectively broken, even if status says Completed.

A null sync_frequency on an enabled schema means the table has no sync frequency, so its sync cannot be scheduled.

No sync runs and nothing repairs it, so do not compare timestamps.

Report it as "no sync frequency, the sync cannot be scheduled", and tell the user to set a sync frequency.

Do not judge staleness by last_synced_at. It moves only when a sync loads new rows. A quiet source, such as a table

with few writes, can have an old last_synced_at while every sync succeeds. Report that as "no new data", not as a

broken sync.

last_checked_at is null until the first successful sync. For a schema whose last successful sync ran before PostHog

recorded last_checked_at, the API returns last_synced_at in its place. So when last_checked_at is null, or is old

and equal to last_synced_at, check the job history before you call the schema broken. Query

system.source_sync_jobs with execute-sql:

SELECT status, rows_synced, created_at, finished_at
FROM system.source_sync_jobs
WHERE schema_id = '<schema id>'
ORDER BY created_at DESC
LIMIT 10

Do not select latest_error from this table. It holds the raw job error, which can contain connection secrets. The

latest_error in external-data-schemas-list has the secrets removed, so quote that one.

Use the newest finished job (Completed or Failed), and compare its created_at with sync_frequency:

not change this. rows_synced = 0 only tells you that the source had no new data. This is not an issue.

diagnosing-failed-warehouse-syncs.

Sources with zero sync activity:

Sources where every schema has should_sync: false or status = Paused. These were set up and then abandoned —

candidates for cleanup via external-data-sources-destroy.

Broken webhooks on webhook-type schemas:

Iterate the sources that have any schema with sync_type: "webhook" (visible via external-data-schemas-list). For

each, call external-data-sources-webhook-info-retrieve({id}):

channel is dead; only the bulk fallback is ingesting.

deleted on their dashboard).

failures).

Report these separately from the primary audit — they're a different shape of problem than failed syncs, and the fix

is a different skill (diagnosing-failed-warehouse-syncs scenario I, or setting-up-a-data-warehouse-source step

5.5).

Only run these extra checks if the user explicitly asks for a broader audit — they involve more tool calls and

heuristics.

Step 5 — Offer the next step

End the audit with a clear hand-off:

expired OAuth token, hands off to diagnosing-failed-warehouse-syncs scenario B. It reconnects the source through

the MCP, so the user doesn't paste secrets into the chat or open the source settings page.

Never start applying fixes autonomously from an audit — the audit's job is to report and recommend, not remediate.

Any fix should be confirmed explicitly before executing.

Important notes

skills — which in turn confirm before acting.

(or will be, once they try to sync again). The user needs to understand the blast radius.

recovery action.

with last_checked_at, and check the job history when that field is null or a legacy value.

the list endpoints. Only do this when the user explicitly asks for a deeper audit.

When a user's request mentions "real-time", "Stripe webhook", or "why is data hours behind on a webhook

source", go straight to external-data-sources-webhook-info-retrieve rather than inferring from schema status.

endpoint but belong to other audits/products — route, don't diagnose.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.