: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(devex): advise running mypy in ci preflight (#71328)
Raúl Negrón-Otero92d3d7d8f58a
diff --git a/.agents/skills/running-ci-preflight/SKILL.md b/.agents/skills/running-ci-preflight/SKILL.mdindex e7d08d00780a..e05561adc50b 100644--- a/.agents/skills/running-ci-preflight/SKILL.md+++ b/.agents/skills/running-ci-preflight/SKILL.md@@ -32,6 +32,7 @@ hogli ci:preflight --fix## Notes- **Strict = failures only.** `--strict` (what the hook runs) exits non-zero only on `✗ fail` — advisories are unverifiable-locally classes, so they warn without blocking. A clean exit means "nothing left to fix", not "CI will pass" — CI stays the authoritative gate. Non-blocking is a mechanism limit, not permission to skip.+- **`type-check` is a nudge, not a run.** Only a repo-wide mypy run matches CI (mypy follows imports, so a changed-file subset misses reverse-dependency breakage), and that costs minutes cold — too much to tax every push with. So preflight names the command instead of running it: judge whether your change is type-risky and run it yourself. CI blocks on the same command, so a type error you skip here comes back as a full re-run.- **Staleness is risk-based.** It fires when merging master _now_ would actually break something — textual merge conflicts (computed via `git merge-tree`, working tree untouched), migrations added on both sides, generated-file inputs changed on both sides, or CI workflows changed on master — plus a behind/age backstop, aggressive by default (5 commits / 2 days; env-tunable via `HOGLI_PREFLIGHT_STALE_COMMITS`/`HOGLI_PREFLIGHT_STALE_DAYS`) so we over-warn to start and tune down from telemetry. Merge master in when it fires. Advisory only, never auto-merged.- **`· skipped (needs stack/node)`** is expected on a bare checkout or sandbox. Start the stack with `hogli start` to run those, or let CI cover them. No hooks in your environment (no `node_modules`)? Run the loop yourself before pushing.- **Flags.** `--against <ref>` diffs against an explicit base; `--json` emits a machine-readable summary.diff --git a/AGENTS.md b/AGENTS.mdindex d021754a7970..6357be4a7c92 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -140,7 +140,7 @@ See [.agents/security.md](.agents/security.md) for security guidelines — least## Code Style-- Python: Write as if mypy `--strict` is enabled — annotate all function signatures (arguments + return types), avoid `Any`, use `TYPE_CHECKING` imports for type-only references. Do not run mypy locally (too slow); CI runs it on every PR. The config isn't fully strict yet, but new code should be+- Python: Write as if mypy `--strict` is enabled — annotate all function signatures (arguments + return types), avoid `Any`, use `TYPE_CHECKING` imports for type-only references. 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); `hogli ci:preflight` reminds you, and CI blocks on the same command. The config isn't fully strict yet, but new code should be- Python imports: keep imports at module level — not inside functions, methods, or conditionals. Inline imports hide dependencies from static analysis, slow hot paths with repeated lookups, and mask circular-import problems instead of fixing them; ruff's `PLC0415` enforces this. Defer an import only to (1) break a true unavoidable circular import (fix the structure first if you can), (2) reference types under `TYPE_CHECKING`, or (3) keep a heavy/optional dependency off the import path so it loads only when its code runs. For (3), add a justified `# noqa: PLC0415` on the import line (e.g. `# noqa: PLC0415 — keeps the heavy dep off the import path`) — never blanket-suppress the rule- Frontend: for any frontend work — the main app (`frontend/src/`) **or** a product frontend (`products/*/frontend/`) — follow [frontend/src/AGENTS.md](frontend/src/AGENTS.md): reuse existing Lemon/quill components instead of hand-rolling tables/badges/labels, import generated `*Api` types instead of handwriting them, and run typecheck/typegen at the right moments. Product frontends share the same components and generated types, so the same rules apply there- Frontend: TypeScript required, explicit return typesdiff --git a/tools/hogli-commands/hogli_commands/ci_preflight.py b/tools/hogli-commands/hogli_commands/ci_preflight.pyindex de82c61d7593..4f6242c368f3 100644--- a/tools/hogli-commands/hogli_commands/ci_preflight.py+++ b/tools/hogli-commands/hogli_commands/ci_preflight.py@@ -59,14 +59,15 @@ class DiffCheck:triggers: list[str] # fnmatch globs against changed paths (`*` spans `/`, as in build.py)verify: list[str] | None # advisory command; None = guidance only (no runnable local check)fix: list[str] | None = None # remediation for --fix+ advice: str | None = None # nudge-only: preflight never runs this check, it just says what to runrequires: tuple[Requirement, ...] = () # capabilities the check needs, else it skipstakes_files: bool = False # append matched files to the commandmatched: list[str] = field(default_factory=list)# Ordered cheapest-first. Grounded in failure classes seen in `hogli ci:insights`:-# broken lockfile blocking all CI, OpenAPI drift, formatting/lint, flag sort,-# workflow-convention failures, migration conflicts.+# broken lockfile blocking all CI, OpenAPI drift, formatting/lint/type checking,+# flag sort, workflow-convention failures, migration conflicts.DIFF_CHECKS: list[DiffCheck] = [DiffCheck(key="lockfile",@@ -102,6 +103,16 @@ DIFF_CHECKS: list[DiffCheck] = [fix=["ruff", "format"],takes_files=True,),+ DiffCheck(+ key="type-check",+ label="Python type checking (mypy)",+ triggers=["*.py", "*.pyi"],+ # A nudge, not a run: mypy is only meaningful repo-wide (it follows imports, so a+ # 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)",+ ),DiffCheck(key="markdown-format",label="markdown formatting (oxfmt)",@@ -181,6 +192,9 @@ _CHECK_TIMEOUT_SECONDS = 600def _run_diff_check(chk: DiffCheck, do_fix: bool) -> tuple[Status, str]:+ if chk.advice is not None:+ # Nudge-only: nothing to run, nothing to auto-fix — the advisory *is* the check.+ return "advisory", chk.adviceunmet = _unmet(chk)if do_fix and chk.fix is not None and not unmet:cmd = list(chk.fix)@@ -455,7 +469,9 @@ def ci_preflight(do_fix: bool, strict: bool, against: str | None, as_json: bool)for chk in triggered:status, detail = _run_diff_check(chk, do_fix)failures += status == "fail"- advisories += status == "advisory"+ # Nudges say "consider this", not "this is drift" — counting them would cry wolf in+ # the footer on every matching push and cost the detected advisories their weight.+ advisories += status == "advisory" and chk.advice is Noneresults.append({"check": chk.key, "status": status, "files": len(chk.matched), "detail": detail})if not as_json:click.secho(f" {_ICON[status]} [{chk.key}] {chk.label}", fg=_COLOR[status])diff --git a/tools/hogli-commands/hogli_commands/tests/test_ci_preflight.py b/tools/hogli-commands/hogli_commands/tests/test_ci_preflight.pyindex 6192eb12488e..622ca62058fe 100644--- a/tools/hogli-commands/hogli_commands/tests/test_ci_preflight.py+++ b/tools/hogli-commands/hogli_commands/tests/test_ci_preflight.py@@ -79,6 +79,26 @@ class TestStrictAndFixContracts:assert result.exit_code == 0assert "run `hogli build:openapi` and commit before pushing" in result.output+ @patch("hogli_commands.ci_preflight._emit_telemetry")+ @patch("hogli_commands.ci_preflight._staleness", return_value=("pass", "even with master", {}))+ @patch("hogli_commands.ci_preflight._fetch_master")+ @patch("hogli_commands.ci_preflight.subprocess.run")+ @patch("hogli_commands.ci_preflight.changed_files", return_value=["posthog/api/does_not_exist.py"])+ def test_type_check_names_the_mypy_command_without_running_it(+ self,+ mock_changed: MagicMock,+ mock_run: MagicMock,+ mock_fetch: MagicMock,+ mock_stale: MagicMock,+ mock_emit: MagicMock,+ ) -> None:+ result = runner.invoke(cli, ["ci:preflight", "--strict"])++ assert result.exit_code == 0+ assert "uv run mypy --cache-fine-grained ." in result.output+ # Giving this check a `verify` would tax every Python push with a repo-wide run.+ assert not any("mypy" in call.args[0] for call in mock_run.call_args_list)+class TestStalenessRisks:@pytest.mark.parametrize(