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(devex): stop preflight claiming OpenAPI drift it never measured (#91694)

Julian Bezded26fc29a32
diff --git a/hogli.yaml b/hogli.yaml
index 3db0562c725d..4fbbc885005a 100644
--- a/hogli.yaml
+++ b/hogli.yaml
@@ -572,7 +572,9 @@ build:
- build:openapi-cli-agent-scopes
- build:openapi-scene-tool-context
- build:openapi-exec-docs
- description: Generate OpenAPI schema and TypeScript types from the backend
+ description: 'Generate OpenAPI schema and TypeScript types from the backend.
+ Needs the dev stack running (Postgres and ClickHouse): Django starts
+ before the schema is generated. Start it with hogli up -d'
build:grammar:
cmd: pnpm grammar:build
description: Generate HogQL grammar definitions (C++)
diff --git a/tools/hogli-commands/hogli_commands/ci_preflight.py b/tools/hogli-commands/hogli_commands/ci_preflight.py
index 3cdeab390a6b..695bc27ddeff 100644
--- a/tools/hogli-commands/hogli_commands/ci_preflight.py
+++ b/tools/hogli-commands/hogli_commands/ci_preflight.py
@@ -70,6 +70,16 @@ class DiffCheck:
workspace_scoped: bool = False
matched: list[str] = field(default_factory=list)
+ @property
+ def measures(self) -> bool:
+ """Whether this check runs something, or only advises.
+
+ A check that runs nothing has found nothing, so it must not be reported
+ as a finding whatever shape it takes: a nudge (``advice``) and a
+ guidance-only check (``verify is None``) are both unmeasured.
+ """
+ return self.advice is None and self.verify is not None
+
# Ordered cheapest-first. Grounded in failure classes seen in `hogli ci:insights`:
# broken lockfile blocking all CI, OpenAPI drift, formatting/lint/type checking,
@@ -205,10 +215,14 @@ DIFF_CHECKS: list[DiffCheck] = [
),
DiffCheck(
key="openapi",
- label="OpenAPI types out of date (frontend/MCP drift)",
+ # Measuring real drift means regenerating and diffing, which needs the dev stack.
+ # This check only knows that the diff touches files the generated types are built
+ # from, so the label names that trigger instead of asserting the types are stale.
+ # A branch keeps those source edits in its diff after a regen, so a label that
+ # claims staleness can never be cleared by running the fix.
+ label="OpenAPI sources changed (generated types may need a regen)",
# From build.py so preflight and build:openapi can't drift on which diffs need a regen.
triggers=list(BUILD_TRIGGERS["build:openapi"]),
- # Drift detection regenerates then diffs — needs the DB. Guidance-only here.
verify=None,
fix=["hogli", "build:openapi"],
requires=("stack",),
@@ -361,7 +375,10 @@ def _run_diff_check(chk: DiffCheck, do_fix: bool) -> tuple[Status, str]:
# Guidance-only (no runnable local check, or its fix needs an absent capability):
# advise regardless, so the hint still shows on a bare checkout — even with --fix.
# Ownership framing lives once in the advisory footer, not per check.
- return "advisory", f"run `{' '.join(chk.fix or [])}` and commit before pushing"
+ # Phrased as a condition the reader can check, because nothing here measured
+ # whether the fix is needed: an unconditional "run this and commit" reads as a
+ # finding, and sends anyone who already ran it looking for a diff that isn't there.
+ return "advisory", f"if you have not run `{' '.join(chk.fix or [])}` since changing them, run it and commit"
elif unmet:
return "skipped", f"needs {', '.join(unmet)}"
else:
@@ -667,7 +684,7 @@ def ci_preflight(do_fix: bool, strict: bool, against: str | None, as_json: bool)
failures += status == "fail"
# 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 None
+ advisories += status == "advisory" and chk.measures
results.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.py
index 460e18e1f3fc..7a8d4ddefcad 100644
--- a/tools/hogli-commands/hogli_commands/tests/test_ci_preflight.py
+++ b/tools/hogli-commands/hogli_commands/tests/test_ci_preflight.py
@@ -83,7 +83,26 @@ class TestStrictAndFixContracts:
) -> None:
result = runner.invoke(cli, ["ci:preflight", "--fix"])
assert result.exit_code == 0
- assert "run `hogli build:openapi` and commit before pushing" in result.output
+ assert "if you have not run `hogli build:openapi` since changing them, run it and commit" in result.output
+ # Nothing regenerated here, so the advisory must not claim the types are stale.
+ # A branch keeps its source edits in the diff after a regen, so a staleness claim
+ # can never be cleared by running the fix.
+ assert "out of date" not 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.changed_files", return_value=["posthog/api/does_not_exist.py"])
+ def test_guidance_only_check_is_not_counted_as_an_advisory(
+ self, mock_changed: MagicMock, mock_fetch: MagicMock, mock_stale: MagicMock, mock_emit: MagicMock
+ ) -> None:
+ result = runner.invoke(cli, ["ci:preflight", "--json"])
+ summary = json.loads(result.output)
+ assert "openapi" in summary["triggered"]
+ # A check that runs nothing has found nothing. Counting it puts an advisory on
+ # every push that touches an API file, which spends the weight the footer needs
+ # for the checks that did measure something.
+ assert summary["advisories"] == 0
@patch("hogli_commands.ci_preflight._emit_telemetry")
@patch("hogli_commands.ci_preflight._staleness", return_value=("pass", "even with master", {}))