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.

chore(ci): alert devex before quarantine entries fail ci (#98315)

Raúl Negrón-Otero4923057b77e9
diff --git a/.github/workflows/test-quarantine.yml b/.github/workflows/test-quarantine.yml
index 0b13511e731a..847ae7990f4c 100644
--- a/.github/workflows/test-quarantine.yml
+++ b/.github/workflows/test-quarantine.yml
@@ -7,6 +7,11 @@ on:
- tools/hogli-commands/hogli_commands/quarantine/**
- .github/workflows/test-quarantine.yml
- .github/actions/setup-uv/**
+ # Warn #alerts-devex before an expired entry starts failing `check`. That happens on a
+ # calendar date rather than on a commit, so nothing in a PR signals it coming.
+ schedule:
+ - cron: '37 8 * * *'
+ workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
@@ -19,6 +24,8 @@ jobs:
check-quarantine:
runs-on: ubuntu-latest
timeout-minutes: 5
+ env:
+ SLACK_CHANNEL: 'C0AS64N6DJL' # #alerts-devex
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
@@ -33,7 +40,64 @@ jobs:
enable-cache: false
- name: Check quarantine file
+ if: github.event_name == 'pull_request'
# Same as `hogli test:quarantine check`, without installing the dev
# environment: the quarantine core is stdlib-only and the CLI needs
# only click, so quarantine PRs stay decoupled from lockfile health.
run: PYTHONPATH=tools/hogli-commands uv run --no-project --with click python -m hogli_commands.quarantine.cli check
+
+ - name: List entries 7 days and 1 day from failing check
+ id: due
+ if: github.event_name != 'pull_request'
+ # Slack rejects a section block over 3000 characters.
+ run: |
+ delimiter="EOF_$(openssl rand -hex 16)"
+ {
+ echo "entries<<$delimiter"
+ PYTHONPATH=tools/hogli-commands uv run --no-project --with click python -m hogli_commands.quarantine.cli due --in-days 7 --in-days 1 --max-chars 3000
+ echo "$delimiter"
+ } >> "$GITHUB_OUTPUT"
+
+ - name: Notify Slack
+ if: steps.due.outputs.entries != ''
+ uses: slackapi/slack-github-action@af78098f536edbc4de71162a307590698245be95 # v3.0.1
+ with:
+ method: chat.postMessage
+ token: ${{ secrets.SLACK_DEVEX_BOT_TOKEN }}
+ errors: true
+ payload: |
+ channel: "${{ env.SLACK_CHANNEL }}"
+ text: ":hourglass_flowing_sand: Test quarantine entries will fail CI soon"
+ blocks:
+ - type: "section"
+ text:
+ type: "mrkdwn"
+ text: ":hourglass_flowing_sand: *Test quarantine entries will fail CI soon.* Remove or re-add each entry in <${{ github.server_url }}/${{ github.repository }}/blob/master/.test_quarantine.json|.test_quarantine.json> before `hogli test:quarantine check` fails on the date shown."
+ - type: "section"
+ text:
+ type: "mrkdwn"
+ text: ${{ toJSON(steps.due.outputs.entries) }}
+
+ # Nobody watches a scheduled run, and a broken alerter otherwise looks the same as nothing being due.
+ - name: Notify Slack on alert failure
+ if: failure() && github.event_name != 'pull_request'
+ uses: slackapi/slack-github-action@af78098f536edbc4de71162a307590698245be95 # v3.0.1
+ with:
+ method: chat.postMessage
+ token: ${{ secrets.SLACK_DEVEX_BOT_TOKEN }}
+ errors: true
+ payload: |
+ channel: "${{ env.SLACK_CHANNEL }}"
+ text: ":red_circle: Test quarantine expiry alert failed"
+ blocks:
+ - type: "section"
+ text:
+ type: "mrkdwn"
+ text: ":red_circle: *Test quarantine expiry alert failed.* Entries close to failing `hogli test:quarantine check` may not have been reported."
+ - type: "actions"
+ elements:
+ - type: "button"
+ text:
+ type: "plain_text"
+ text: "View run"
+ url: "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
diff --git a/products/engineering_analytics/backend/logic/quarantine.py b/products/engineering_analytics/backend/logic/quarantine.py
index 2d2f42a82d18..7479762c33e8 100644
--- a/products/engineering_analytics/backend/logic/quarantine.py
+++ b/products/engineering_analytics/backend/logic/quarantine.py
@@ -65,7 +65,7 @@ QUARANTINE_FILENAME = ".test_quarantine.json"
_SCHEMA_VERSION = 1
_DEFAULT_RUNNER = "pytest"
-# Matches DEFAULT_GRACE_DAYS in the quarantine contract: an expired entry stays
+# Matches GRACE_DAYS in the quarantine contract: an expired entry stays
# inert for this long before `quarantine check` makes its removal mandatory.
_GRACE_DAYS = 7
_EXPIRING_SOON_DAYS = 7
diff --git a/tools/hogli-commands/hogli_commands/quarantine/cli.py b/tools/hogli-commands/hogli_commands/quarantine/cli.py
index 0b244ee92108..347d5c8a81b3 100644
--- a/tools/hogli-commands/hogli_commands/quarantine/cli.py
+++ b/tools/hogli-commands/hogli_commands/quarantine/cli.py
@@ -6,7 +6,8 @@ Schema contract and selector grammar: ``hogli_commands.quarantine.core``.
hogli test:quarantine add <id> --reason ... --owner ... [--issue ...] [--days 14] [--mode run|skip]
hogli test:quarantine list [--json]
hogli test:quarantine remove <id>
- hogli test:quarantine check [--grace-days 7]
+ hogli test:quarantine check
+ hogli test:quarantine due --in-days 7 [--in-days 1] [--max-chars 3000]
"""
from __future__ import annotations
@@ -123,26 +124,61 @@ def list_entries(path: Path, as_json: bool) -> None:
@quarantine.command(name="check", help="Lint the quarantine file; exits 1 on violations (used by CI).")
- "--grace-days",
- type=click.IntRange(min=0),
- default=core.DEFAULT_GRACE_DAYS,
- show_default=True,
- help="Days an expired entry may linger before this check fails.",
-)
@click.pass_obj
-def check(path: Path, grace_days: int) -> None:
+def check(path: Path) -> None:
result = core.load(path)
- violations, warnings = core.check(result, today=core.today_utc(), grace_days=grace_days)
- for message in warnings:
+ check_result = core.check(result, today=core.today_utc())
+ for message in check_result.warnings:
click.secho(f"warning: {message}", fg="yellow", err=True)
- for message in violations:
+ for message in check_result.violations:
click.secho(f"error: {message}", fg="red", err=True)
- if violations:
+ if check_result.violations:
raise SystemExit(1)
click.echo(f"{path.name} OK ({len(result.entries)} entries).")
[email protected](name="due", help="List entries that start failing `check` in exactly the given number of days.")
+ "--in-days",
+ type=click.IntRange(min=1),
+ multiple=True,
+ required=True,
+ help="Days until `check` fails. Repeat to match several distances.",
+)
+ "--max-chars",
+ type=click.IntRange(min=1),
+ help="Keep the output within this many characters. The last line counts the entries left out.",
+)
+def due(path: Path, in_days: tuple[int, ...], max_chars: int | None) -> None:
+ result = core.load(path)
+ for message in result.errors:
+ click.secho(f"error: {message}", fg="red", err=True)
+ if result.errors:
+ raise SystemExit(1)
+
+ today = core.today_utc()
+ lines: list[str] = []
+ for entry in core.entries_failing_check_in(result.entries, today, in_days):
+ quarantine_state = "ends" if core.is_active(entry, today) else "ended"
+ lines.append(
+ f"• `{entry.id}` ({entry.owner}): quarantine {quarantine_state} {entry.expires.isoformat()}, "
+ f"`check` fails on {core.check_failure_date(entry).isoformat()}"
+ )
+ for line in _fit_within(lines, max_chars):
+ click.echo(line)
+
+
+def _fit_within(lines: list[str], max_chars: int | None) -> list[str]:
+ for shown in range(len(lines), -1, -1):
+ hidden = len(lines) - shown
+ fitted = lines[:shown] + ([f"• {hidden} more not shown"] if hidden else [])
+ if max_chars is None or len("\n".join(fitted)) <= max_chars:
+ return fitted
+ return []
+
+
# Direct invocation needs only click + stdlib (used by test-quarantine.yml to
# avoid installing the full dev environment): python -m hogli_commands.quarantine.cli
if __name__ == "__main__":
diff --git a/tools/hogli-commands/hogli_commands/quarantine/core.py b/tools/hogli-commands/hogli_commands/quarantine/core.py
index 107c06b9c27d..e8e35395a2cb 100644
--- a/tools/hogli-commands/hogli_commands/quarantine/core.py
+++ b/tools/hogli-commands/hogli_commands/quarantine/core.py
@@ -93,7 +93,7 @@ from typing import Any
SCHEMA_VERSION = 1
MAX_QUARANTINE_DAYS = 30
-DEFAULT_GRACE_DAYS = 7
+GRACE_DAYS = 7
PYTEST_RUNNER = "pytest" # also the schema default when an entry omits `runner`
JEST_RUNNER = "jest"
PLAYWRIGHT_RUNNER = "playwright"
@@ -140,6 +140,12 @@ class LoadResult:
extras: dict[str, Any] = field(default_factory=dict)
+@dataclass(frozen=True)
+class CheckResult:
+ violations: tuple[str, ...] = ()
+ warnings: tuple[str, ...] = ()
+
+
def today_utc() -> date:
return datetime.now(UTC).date()
@@ -221,8 +227,13 @@ def _parse_entry(raw: Any, index: int, result: LoadResult) -> Entry | None:
)
+def lapses_on(entry: Entry) -> date:
+ """First day ``entry`` no longer quarantines its tests."""
+ return entry.expires + timedelta(days=1)
+
+
def is_active(entry: Entry, today: date) -> bool:
- return today <= entry.expires
+ return today < lapses_on(entry)
def active_entries(entries: list[Entry], runner: str, today: date) -> list[Entry]:
@@ -332,8 +343,18 @@ def _validate_name_qualified_selector(selector: str) -> str | None:
return None
-def check(result: LoadResult, today: date, grace_days: int = DEFAULT_GRACE_DAYS) -> tuple[list[str], list[str]]:
- """Lint a loaded quarantine file; returns (violations, warnings).
+def check_failure_date(entry: Entry) -> date:
+ """First day ``check`` rejects ``entry`` for outliving the grace period."""
+ return lapses_on(entry) + timedelta(days=GRACE_DAYS)
+
+
+def entries_failing_check_in(entries: list[Entry], today: date, days: tuple[int, ...]) -> list[Entry]:
+ """Entries that start failing ``check`` exactly one of ``days`` after ``today``, sorted by id."""
+ return sorted((e for e in entries if (check_failure_date(e) - today).days in days), key=lambda e: e.id)
+
+
+def check(result: LoadResult, today: date) -> CheckResult:
+ """Lint a loaded quarantine file.
Violations: load errors, duplicate ids, ``expires`` before ``added`` or
more than ``MAX_QUARANTINE_DAYS`` after it, a future ``added`` (which
@@ -365,10 +386,11 @@ def check(result: LoadResult, today: date, grace_days: int = DEFAULT_GRACE_DAYS)
violations.append(f"{label}: added {entry.added} is in the future")
expired_for = (today - entry.expires).days
- if expired_for > grace_days:
- violations.append(f"{label}: expired {expired_for} days ago (grace is {grace_days}) — remove or re-triage")
- elif expired_for > 0:
- days_left = grace_days - expired_for
+ fails_on = check_failure_date(entry)
+ if today >= fails_on:
+ violations.append(f"{label}: expired {expired_for} days ago (grace is {GRACE_DAYS}) — remove or re-triage")
+ elif not is_active(entry, today):
+ days_left = (fails_on - today).days - 1
deadline = f"within {days_left} days" if days_left else "today — grace period ends"
warnings.append(f"{label}: expired {expired_for} days ago — remove {deadline}")
@@ -378,4 +400,4 @@ def check(result: LoadResult, today: date, grace_days: int = DEFAULT_GRACE_DAYS)
if selector_problem is not None:
violations.append(f"{label}: {selector_problem}")
- return violations, warnings
+ return CheckResult(violations=tuple(violations), warnings=tuple(warnings))
diff --git a/tools/hogli-commands/hogli_commands/tests/test_quarantine.py b/tools/hogli-commands/hogli_commands/tests/test_quarantine.py
index 2514aaf6b59e..34d99fec3ffc 100644
--- a/tools/hogli-commands/hogli_commands/tests/test_quarantine.py
+++ b/tools/hogli-commands/hogli_commands/tests/test_quarantine.py
@@ -459,6 +459,49 @@ def test_check_passes_on_missing_file(runner: CliRunner, tmp_path: Path) -> None
assert result.exit_code == 0
+DUE_TOMORROW = "• `posthog/test_tomorrow.py` (@team-devex): quarantine ended 2026-06-03, `check` fails on 2026-06-11"
+DUE_WEEK_OUT = "• `posthog/test_week_out.py` (@team-devex): quarantine ended 2026-06-09, `check` fails on 2026-06-17"
+
+
+ "args, expected_lines",
+ [
+ (("--in-days", "7", "--in-days", "1"), [DUE_TOMORROW, DUE_WEEK_OUT]),
+ (
+ ("--in-days", "9"),
+ ["• `posthog/test_active.py` (@team-devex): quarantine ends 2026-06-11, `check` fails on 2026-06-19"],
+ ),
+ (
+ ("--in-days", "7", "--in-days", "1", "--max-chars", str(len(f"{DUE_TOMORROW}\n• 1 more not shown"))),
+ [DUE_TOMORROW, "• 1 more not shown"],
+ ),
+ ],
+)
+def test_due_lists_entries_that_fail_check_in_the_requested_days(
+ runner: CliRunner, tmp_path: Path, args: tuple[str, ...], expected_lines: list[str]
+) -> None:
+ entries = [
+ raw_entry(
+ id=f"posthog/test_{name}.py",
+ added=(TODAY - timedelta(days=20)).isoformat(),
+ expires=(TODAY + timedelta(days=expires_in_days)).isoformat(),
+ )
+ for name, expires_in_days in (("week_out", -1), ("not_due", -3), ("tomorrow", -7), ("active", 1))
+ ]
+ path = write_file(tmp_path / "q.json", entries)
+ result = cli(runner, path, "due", *args)
+ assert result.exit_code == 0, result.output
+ assert result.output.splitlines() == expected_lines
+
+
+def test_due_fails_on_malformed_file(runner: CliRunner, tmp_path: Path) -> None:
+ path = tmp_path / "q.json"
+ path.write_text("not json{")
+ result = cli(runner, path, "due", "--in-days", "1")
+ assert result.exit_code == 1
+ assert "invalid JSON" in result.output
+
+
def test_repo_quarantine_file_is_valid(runner: CliRunner, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(core, "today_utc", WALL_CLOCK_TODAY_UTC)
assert core.QUARANTINE_PATH.name == ".test_quarantine.json"