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.

fix(ci): cut mypy memory so cold runs fit the 8 gb runner (#128471)

Raúl Negrón-Otero05b4f3eae8e5
diff --git a/.github/workflows/ci-python.yml b/.github/workflows/ci-python.yml
index da5b5ca51424..5978d3d8815f 100644
--- a/.github/workflows/ci-python.yml
+++ b/.github/workflows/ci-python.yml
@@ -393,8 +393,11 @@ jobs:
- name: Check static typing
shell: bash -e {0}
env:
- MYPY_NUM_WORKERS: 2
- run: mypy --version && mypy --cache-fine-grained .
+ # Each worker holds its own copy of the build graph, so the worker count follows
+ # the runner's memory. Keep this condition in sync with the job's runs-on: the
+ # 8 GB depot-ubuntu-24.04 fits one worker on a cold cache, the 16 GB -4 fits two.
+ MYPY_NUM_WORKERS: ${{ github.event_name == 'pull_request' && !startsWith(github.head_ref, 'trunk-merge/') && needs.changes.outputs.mypy_cache_key != 'true' && 1 || 2 }}
+ run: mypy --version && mypy .
- name: Save mypy cache
if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request'
diff --git a/AGENTS.md b/AGENTS.md
index 33a82cc349fd..bbd38bba6357 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -237,7 +237,7 @@ Same tags as above: `[lint: <id>]` is machine-enforced, `[review]` is not.
### Python
-- **Write as if mypy `--strict` were on.** `[review]` Annotate every signature, avoid `Any`, put type-only references under `TYPE_CHECKING`. The config is not fully strict yet; new code should be. When a change is type-risky run mypy the way CI does — `uv run mypy --cache-fine-grained .`, repo-wide, never a file subset. It follows imports, so a subset misses reverse-dependency breakage.
+- **Write as if mypy `--strict` were on.** `[review]` Annotate every signature, avoid `Any`, put type-only references under `TYPE_CHECKING`. The config is not fully strict yet; new code should be. When a change is type-risky run mypy the way CI does — `uv run mypy .`, repo-wide, never a file subset. It follows imports, so a subset misses reverse-dependency breakage.
- **Imports stay at module level.** `[review]` ruff's `PLC0415` catches this, but `posthog/**`, `ee/**`, `common/**`, `tools/**` and most of `products/` are on grandfathered exemption lists, so CI does not block it in the trees you are most likely to be editing. Defer one only to break a true unavoidable circular import, to reference types under `TYPE_CHECKING`, or to keep a heavy or optional dependency off the import path. For the last case add a justified `# noqa: PLC0415 — keeps the heavy dep off the import path` on the line. Never blanket-suppress the rule.
- **A stdlib `@dataclass` must declare `frozen=` explicitly.** `[lint: prefer-frozen-dataclasses, test_dataclass_defaults.py]` A bare `@dataclass` fails the ratchet; `@dataclass(frozen=False)` passes it, so intentional mutability is a choice you state.
- **The house decorator is `@frozen` from `posthog.dataclasses`.** `[review]` Neither check prefers it over a declared stdlib `@dataclass`. Invoke `/writing-dataclasses` before adding or changing one, before returning or passing several values together, and before passing a dataclass through layers.
diff --git a/pyproject.toml b/pyproject.toml
index 955e2f4623b4..b631ef0265c1 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -519,6 +519,10 @@ python_version = "3.14"
[tool.mypy]
python_version = "3.14"
+# CI runs in parallel mode, which forces the native parser. Setting it here keeps sequential
+# runs (local mypy, dmypy, reports) on the same parser as CI. Do not set num_workers here:
+# parallel mode breaks dmypy and report flags, so CI sets MYPY_NUM_WORKERS instead.
+native_parser = true
plugins = [
"mypy_django_plugin.main",
"mypy_drf_plugin.main",
diff --git a/tools/hogli-commands/hogli_commands/ci_preflight.py b/tools/hogli-commands/hogli_commands/ci_preflight.py
index 916e5838cfac..d4885452fa7b 100644
--- a/tools/hogli-commands/hogli_commands/ci_preflight.py
+++ b/tools/hogli-commands/hogli_commands/ci_preflight.py
@@ -218,7 +218,7 @@ DIFF_CHECKS: list[DiffCheck] = [
# changed-file subset both blames files outside the diff and misses reverse-dependency
# breakage), and that costs minutes cold. Naming the command lets the agent judge.
verify=None,
- advice="a type error costs a full CI re-run — consider `uv run mypy --cache-fine-grained .` (what CI runs)",
+ advice="a type error costs a full CI re-run — consider `uv run mypy .` (what CI runs)",
),
DiffCheck(
key="django-template-format",
diff --git a/tools/hogli-commands/hogli_commands/tests/test_ci_preflight.py b/tools/hogli-commands/hogli_commands/tests/test_ci_preflight.py
index e845a84d1051..dc1837b2f381 100644
--- a/tools/hogli-commands/hogli_commands/tests/test_ci_preflight.py
+++ b/tools/hogli-commands/hogli_commands/tests/test_ci_preflight.py
@@ -182,7 +182,7 @@ class TestStrictAndFixContracts:
result = runner.invoke(cli, ["ci:preflight", "--strict"])
assert result.exit_code == 0
- assert "uv run mypy --cache-fine-grained ." in result.output
+ assert "uv run mypy ." in result.output
# Giving the check a `verify` would tax every push with a repo-wide mypy run.
ran = [arg for call in mock_run.call_args_list for arg in call.args[0]]
assert "mypy" not in ran