Repository navigation
Description
Problem
Patchy sends its production request events and business events to PostHog. We want internal patches, such as dashboards, that read that data to show how production is doing. Today a patch can read only one kind of outside source: company Postgres. This adds a second integration: PostHog, read-only. It does not send events anywhere; it lets a patch query a company's PostHog project.
Today
Integrations have one seam (defineIntegration in packages/integrations/src/definition.ts), but about 20 files outside the Postgres module assume Postgres:
- the connection schema and migration (
CHECK (integration = 'postgres')) - wire schemas, runtime op routing and the callback gateway
- SDK generation, the CLI's
addand config, and the portal log - the connections page
Handle uniqueness is per company in SQL (UNIQUE (company_id, handle)) but per integration in docs/product.md. Deletion protection and runtime-log query text only recognise Postgres.
Decisions
-
Surface. One operation,
connections.<alias>.query({ name, query, values, shape }).queryis HogQL, PostHog's SQL dialect.valuesfills its{placeholder}s.shapeuses the same column language as Postgres's raw query.namelabels the call in the call log and in PostHog's own query log.
Patchy builds the upstream request itself, so patch code can only send read queries. There is no typed client per event in v1. Tier 1 calls go through the broker as the viewer; tier 2 calls go in actions only, like Postgres today.
-
Credential. An admin pastes a PostHog personal API key in a browser-only form, with a region and project id.
- The form asks for a key limited to that one project and to Read on Query, Event definitions and Property definitions. Connect proves that access with a test query and discovery. Patchy doesn't claim to verify that broader access is absent; PostHog has no supported way to check.
- Only
us.posthog.comandeu.posthog.comare allowed: no self-hosted host field, and no redirects anywhere else. - PostHog's project secret keys can't run queries yet; when they can, they fit better, since they're tied to the project rather than a person.
-
Metadata. Discovery reads event definitions and event and person property definitions, with their descriptions and types, never event rows. It is stored as an immutable snapshot with a revision. Publish binds
{ kind: "posthog", handle, id, revision }and fails withstale_generated, exactly like Postgres. New events don't move the revision until someone refreshes discovery. Types are hints for the agent writing HogQL; queries aren't refused for naming something outside the snapshot. -
Dev is decided per integration.
- Postgres keeps local fixtures, the default from Dev is local, on real code, with fixtures; the dev runtime is pinned in the repo #169.
- PostHog reads the real connection in
patchy dev. Its shapes can't be known ahead of time, and the integration is read-only, so dev can't be destructive. The reads go through a separate, narrow endpoint on the instance, as the machine token's person, with the credentials staying server-side. The published runtime keeps refusing bearer tokens. Each read shows in the connection's recent calls as a dev call. - The connect form says so, so the admin knows before connecting.
- Future integrations choose for themselves: a fake binding where the shapes are known, real reads where they aren't and the integration can't write.
-
Limits.
- PostHog allows 240 queries a minute and 2,400 an hour (some legacy projects 120 an hour), 3 running at once and up to 30 seconds queued, with 10 seconds of execution, all per project.
- Patchy caps concurrent queries per region and project in each process, shared across dev and production calls, and gives each call 15 seconds bounded by the caller's remaining time. Upstream work may outlive that timeout; Patchy accepts this and sends no cancellation.
- When PostHog refuses for rate, budget or concurrency, the call fails with one typed error, carrying Retry-After only when PostHog sent one. Patchy never replays a call automatically.
- Results are refused rather than silently truncated. PostHog returns only 100 rows by default and flags
hasMore; Patchy fails that call and tells the author to add a LIMIT or aggregate. - PostHog's own result cache stays on; Patchy adds no cache.
-
Connections page. It is redone as direction B from the mocks: https://post.patchyhq.com/d/hf514qsoozwu. Prototype: the connections page with a second integration and the card's Triggers block, as static mocks #640 stays open to refine the page for Webhook, starting from this design.
-
Older CLIs. Today's
GET /connectionsandGET /connections/:handlekeep their Postgres-only shape, so a CLI from before this work still decodes them. The new CLI uses integration-qualified routes. PostHog is additive within wire version 1. -
Release. Tickets 3 and 4 ship in the same release, with no feature flag: PostHog reaches production only once
patchy devcan use it.
Build order
- Connections become integration-aware, with no behaviour change for Postgres.
- The connections page is redone for no connections, one, or thirty.
- PostHog: connect, discovery,
query, the wire, the CLI and generation. - PostHog reads real data in
patchy dev.
Not in this work
- OAuth or project secret keys, and self-hosted PostHog.
- Typed clients per event.
- A Patchy-side cache.
- A
patchy querycommand for agents to explore data. It would reuse 4's path, so it's a natural follow-up. - A "Key rejected" status for sources that refuse their credentials. The mocks show it; it needs Patchy to record credential refusals, so it's its own follow-up.
- Live dev reads for Postgres, which keeps fixtures by decision.
Planned with Claude Opus 5.5 in Claude Code (T3 Code). GPT 6.1 Sol in Codex reviewed the design and the final plan.
Activity
refactor(integrations): connections know their integration, ready for…
feat(integrations): the connections page works for no connections, on…
feat(patchy): PostHog patches read real data in patchy dev (#664)
feat(integrations): patches can query a company's PostHog, read-only,…
allisonmahmood commentedon Oct 13, 2026
Shipped to main:
patchy devNot deployed yet. For a safe rollback, release c1e7de9 before a253cb2.
Follow-ups: #663 (tier 2 Postgres size limit), #665 (flaky Supervisor test), #666 (NUL bytes in logged query text). #640 stays open to bring Webhook to the new connections page.