Skip to content

chore(frontend): inline all kea logic types - #71010

Closed
mariusandra wants to merge 1 commit into
masterfrom
typegen-inline-all-logics
Closed

chore(frontend): inline all kea logic types#71010
mariusandra wants to merge 1 commit into
masterfrom
typegen-inline-all-logics

Conversation

@mariusandra

@mariusandra mariusandra commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Problem

Kea logic types currently live in generated *LogicType.ts and *ModelType.ts files. That splits a logic from its inferred type and makes a clean typegen run regenerate roughly one thousand separate files.

This PR completes the inline-mode migration started by typegen-inline and measures its effect on typegen and TypeScript performance.

Changes

  • Converted all 1,041 discovered Kea logic types to inline MakeLogicType declarations.
  • Removed generated type-file imports and the remaining tracked generated type files.
  • Enabled inline mode in .kearc and updated the repo guidance for future logic changes.
  • Upgraded to kea@4.0.0-pre.6 and kea-typegen@3.8.3, which include the required metadata and inline import support from keajs/kea#167 and keajs/kea-typegen#58.

Benchmarks used three runs on the same local macOS checkout. Clean typegen deleted generated output before each uncached run. TypeScript used tsgo --noEmit --incremental false. Times are wall-clock seconds from /usr/bin/time -p.

Benchmark Before runs Before median After runs After median Change
Clean uncached typegen 225.25, 205.87, 190.35 205.87 17.79, 18.87, 18.97 18.87 -90.8%
Nonincremental TypeScript 16.58, 19.80, 15.93 16.58 21.17, 16.07, 18.24 18.24 +10.0%

The typegen improvement is clear. The TypeScript measurements do not demonstrate an improvement and remain within the observed run-to-run spread.

How did you test this code?

  • pnpm --filter=@posthog/frontend typegen:check using kea-typegen 3.8.3 and kea 4.0.0-pre.6
  • hogli test frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.test.ts
  • hogli test frontend/src/scenes/cohorts/cohortCountWarningLogic.test.ts
  • hogli ci:preflight --strict
  • yarn test --watchman=false and yarn build in kea-typegen (51 tests, including the pnpm physical-path regression)
  • pnpm run test:types and pnpm run test:tsd in kea
  • pnpm --filter=@posthog/frontend exec tsgo --noEmit --incremental false reaches only the pre-existing QuillDateFilter.tsx error for the removed DateTimePickerProps.ranges property. It is not newly green on this branch.

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Docs update

Updated frontend/src/AGENTS.md and the repo writing-kea-logics skill. No user-facing documentation changes are needed because this only changes generated TypeScript representation and developer workflow.

🤖 Agent context

Codex (GPT-5) implemented the migration under human direction. No shareable session URL is available. Repo skills used: /writing-kea-logics, /writing-skills, /writing-tests, and /running-ci-preflight.

The required Kea and kea-typegen support was developed and verified in their upstream repositories. I switched the monorepo to the published releases once they became available, leaving no local package patches for this migration.

Autonomy: Human-driven (agent-assisted)

@mariusandra mariusandra self-assigned this Jul 15, 2026
@mariusandra
mariusandra force-pushed the typegen-inline-all-logics branch 2 times, most recently from ef537fd to 0614aa4 Compare July 15, 2026 10:16
@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

🤖 CI report

ℹ️ Bundle size — no base branch to compare

Uncompressed size of every built .js bundle, compared against the base branch.

Total: 64.77 MiB (no base branch measurement to compare against yet)

Posted automatically by build-bundle-size-report · uncompressed bytes from dist-report

Eager graph — within budget

How much code each root ships on the eager path — downloaded and parsed before the surface is interactive. Measured from the esbuild output chunks (post-tree-shake, static imports only); lazy import() / React.lazy chunks are not counted.

Root Eager (shipped) Δ vs base Budget
entry (logged-out pages, app bootstrap)
src/index.tsx
1.22 MiB · 22 files (no base measurement) ███░░░░░░░ 28.4% of 4.29 MiB
authenticated shell (every logged-in page)
src/scenes/AuthenticatedShell.tsx
8.15 MiB · 2,979 files (no base measurement) █████████░ 88.1% of 9.25 MiB

🟢 node_modules/monaco-editor/ stays out of src/index.tsx
🟢 src/lib/components/ActivityLog/describers stays out of src/index.tsx
🟢 [object Object] stays out of src/index.tsx
🟢 [object Object] stays out of src/index.tsx
🟢 node_modules/monaco-editor/ stays out of src/scenes/AuthenticatedShell.tsx
🟢 src/lib/components/ActivityLog/describers stays out of src/scenes/AuthenticatedShell.tsx
🟢 [object Object] stays out of src/scenes/AuthenticatedShell.tsx
🟢 [object Object] stays out of src/scenes/AuthenticatedShell.tsx

Largest files eagerly shipped from src/index.tsx
Size File
126.8 KiB ../node_modules/.pnpm/react-dom@18.3.1_react@18.3.1/node_modules/react-dom/cjs/react-dom.production.min.js
24.6 KiB ../node_modules/.pnpm/buffer@6.0.3/node_modules/buffer/index.js
6.3 KiB ../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.production.min.js
4.5 KiB ../node_modules/.pnpm/@jspm+core@2.1.0/node_modules/@jspm/core/nodelibs/browser/process.js
3.9 KiB ../node_modules/.pnpm/scheduler@0.23.2/node_modules/scheduler/cjs/scheduler.production.min.js
1.4 KiB ../node_modules/.pnpm/base64-js@1.5.1/node_modules/base64-js/index.js
1.3 KiB src/RootErrorBoundary.tsx
912 B ../node_modules/.pnpm/ieee754@1.2.1/node_modules/ieee754/index.js
789 B src/scenes/ChunkLoadErrorBoundary.tsx
762 B src/index.tsx
Largest files eagerly shipped from src/scenes/AuthenticatedShell.tsx
Size File
281.1 KiB ../node_modules/.pnpm/posthog-js@1.401.0/node_modules/posthog-js/dist/rrweb.js
267.7 KiB ../node_modules/.pnpm/@posthog+icons@0.38.0_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@posthog/icons/dist/posthog-icons.es.js
235.5 KiB src/taxonomy/core-filter-definitions-by-group.json
222.7 KiB ../node_modules/.pnpm/posthog-js@1.401.0/node_modules/posthog-js/dist/module.js
164.0 KiB src/queries/validators.js
154.3 KiB ../node_modules/.pnpm/re2js@0.4.1/node_modules/re2js/build/index.esm.js
126.8 KiB ../node_modules/.pnpm/react-dom@18.3.1_react@18.3.1/node_modules/react-dom/cjs/react-dom.production.min.js
106.1 KiB src/lib/api.ts
93.3 KiB ../node_modules/.pnpm/prosemirror-view@1.40.1/node_modules/prosemirror-view/dist/index.js
92.7 KiB ../packages/quill/packages/quill/dist/index.js

Posted automatically by check-eager-graph · sizes are eager output bytes (shipped, post-tree-shake) from the esbuild metafile · part of #32479

ℹ️ Dist folder size — no base branch to compare

Total size of the built frontend/dist folder (all assets), compared against the base branch.

Total: 1316.69 MiB (no base branch measurement to compare against yet)

Playwright — all passed

All tests passed.

View test results →

@trunk-io

trunk-io Bot commented Jul 15, 2026

Copy link
Copy Markdown

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

@mariusandra
mariusandra marked this pull request as ready for review July 15, 2026 10:41
@greptile-apps

greptile-apps Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Too many files changed for review. (1068 files found, 100 file limit)

@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

🦔 Hogbox preview · ✅ ready

▶ Open the preview

🔑 Login test@posthog.com / 12345678 (demo data)
🧩 Running this PR's backend and frontend, on the PostHog :master base
🔗 Link stable across rebuilds — a re-push swaps the box underneath, the URL stays
🔒 Access tailnet only (PostHog VPN)
🛠️ Admin inspect & debug state in hogland
💤 Idle sleeps after ~30 min idle (snapshot to S3, zero node cost) and wakes on your next visit in ~30s, behind a brief "waking up" screen

commit 2114773 · box box-971697ac3540 · ready in 733s (push → usable) · build log · rebuilds on every push, torn down on close

@pr-assigner-resolver-posthog
pr-assigner-resolver-posthog Bot requested review from a team July 15, 2026 10:42
@pr-assigner-resolver-posthog

Copy link
Copy Markdown

👀 Auto-assigned reviewers

These soft owners were skipped because their changes are minor, or the reviewer list was getting long. Nothing blocks merge, so self-assign if you'd like a look:

  • @PostHog/team-workflows (frontend/src/scenes/data-pipelines/)
  • @PostHog/team-feature-flags (frontend/src/scenes/cohorts/)
  • @PostHog/team-billing (frontend/src/scenes/billing/, frontend/src/scenes/coupons/)
  • @PostHog/team-product-analytics (frontend/src/scenes/annotations/)
  • @PostHog/team-growth (frontend/src/scenes/agentic/)

Soft owners come from CODEOWNERS-soft and each product's product.yaml. Generated files and lockfiles are ignored when deciding ownership.

Base automatically changed from typegen-inline to master July 15, 2026 11:39
@mariusandra
mariusandra enabled auto-merge (squash) July 15, 2026 11:41
password: string
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are the block actually generated and injected in this file, or "generated" in the sense that an agent will write/update them? if the former they should probably be placed in their own type files to prevent conflicts, and if the latter i would remove the "generated" language.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they're both. They're autogenerated, like the current typegen does, but the expectation is that when an agent does work around this logic, it'll also update the file here. We would still run typegen at the end of it all in CI, but this time it would be more of a "typecheck". The goal/expectation is that 90% of the time when adding a thing or two to a logic, agents will correctly also update the type here (cause there really isn't much to do here for most things), saving a whole extra CI run in the process.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, i'd avoid separate files cause this just adds bloat to the codebase. the current generated *Logic.ts files are extremely verbose (duplicate things a lot). we could commit the MakeLogicType stuff to a different file as well, but since all logics are anyway large containers, it doesn't feel like a few extra lines of generated metadata at the top will impact the experience for anyone

@mariusandra
mariusandra force-pushed the typegen-inline-all-logics branch from 0614aa4 to ba77547 Compare July 15, 2026 11:52
@github-actions
github-actions Bot requested a deployment to preview-pr-71010 July 15, 2026 11:53 In progress

Copy link
Copy Markdown
Collaborator Author

Closing in favor of the smaller migration series above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants