: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
feat(eval): add sandboxed evals for error-tracking MCP query tools (#59114)
Catalin Irimiee535ea0ccd74
diff --git a/ee/hogai/eval/sandboxed/conftest.py b/ee/hogai/eval/sandboxed/conftest.pyindex 6972992230f2..64e04677a505 100644--- a/ee/hogai/eval/sandboxed/conftest.py+++ b/ee/hogai/eval/sandboxed/conftest.py@@ -7,6 +7,7 @@ import loggingimport threadingimport subprocessfrom collections.abc import Generator+from datetime import timedeltafrom pathlib import Pathimport pytest@@ -578,6 +579,39 @@ class SandboxedDemoData:)+# Event-level properties the error-tracking ``searchQuery`` test cases match on+# (see ``products/error_tracking/backend/hogql_queries/error_tracking_query_runner_utils.py``).+# These are stored as JSON arrays (``["TypeError"]``); without materialized+# columns the bare ``properties.$exception_types`` lookup goes through+# ``JSONExtractString`` which returns ``""`` for non-string JSON values, so+# ``searchQuery`` filtering on these properties silently never matches anything.+# Materializing and backfilling once per session makes the sandbox behave like+# prod for error-tracking searchQuery, including reused local ClickHouse state+# where the columns already exist but older demo rows still need values.+_EVAL_MATERIALIZED_EVENT_PROPERTIES: tuple[str, ...] = (+ "$exception_types",+ "$exception_values",+)+++def _ensure_event_search_columns_materialized(django_db_blocker) -> None:+ from ee.clickhouse.materialized_columns.columns import (+ backfill_materialized_columns,+ get_materialized_columns,+ materialize,+ )++ with django_db_blocker.unblock():+ existing_columns = get_materialized_columns("events")+ columns = []+ for property_name in _EVAL_MATERIALIZED_EVENT_PROPERTIES:+ column = existing_columns.get((property_name, "properties"))+ if column is None:+ column = materialize("events", property_name)+ columns.append(column)+ backfill_materialized_columns("events", columns, timedelta(days=180))++@pytest.fixture(scope="session", autouse=True)def sandboxed_demo_data(set_up_evals, # noqa: F811@@ -588,6 +622,7 @@ def sandboxed_demo_data(from posthog.clickhouse.client import sync_executemaster_team_id = ensure_master_demo_team(django_db_blocker)+ _ensure_event_search_columns_materialized(django_db_blocker)with django_db_blocker.unblock():rows = sync_execute("SELECT event, count() FROM events WHERE team_id = %(team_id)s GROUP BY event ORDER BY 2 DESC LIMIT 20",diff --git a/ee/hogai/eval/sandboxed/error_tracking/eval_events_sampling.py b/ee/hogai/eval/sandboxed/error_tracking/eval_events_sampling.pynew file mode 100644index 000000000000..22a895e7d1ad--- /dev/null+++ b/ee/hogai/eval/sandboxed/error_tracking/eval_events_sampling.py@@ -0,0 +1,123 @@+"""Argument-hygiene eval for ``query-error-tracking-issue-events``.++The events tool defaults ``limit=1`` and exposes ``verbosity`` plus+``searchQuery`` / ``filterGroup`` because pulling many sampled events+or asking for raw payloads is expensive (each row carries the full+exception payload, including stack frames). Agents that crank ``limit``+to 20 by default, default to ``verbosity=raw``, or skip the narrowing+filter when the user clearly described one are the regressions this+suite is meant to catch.++Each case names a seeded issue verbatim; ``IssueIdMatchesTarget``+verifies the call used the right per-case UUID. The LLM-judge+``EventsArgsAlignment`` grades the sampled-event arguments against the+case's expected shape.++To run::++ pytest ee/hogai/eval/sandboxed/error_tracking/eval_events_sampling.py+"""++from __future__ import annotations++from typing import Any++import pytest++from ee.hogai.eval.sandboxed.base import SandboxedPublicEval+from ee.hogai.eval.sandboxed.config import SandboxedEvalCase+from ee.hogai.eval.sandboxed.error_tracking.scorers import (+ ERROR_TRACKING_WRITE_TOOLS,+ EventsArgsAlignment,+ EventsToolUsed,+ IssueIdMatchesTarget,+)+from ee.hogai.eval.sandboxed.error_tracking.seeders import seed_error_tracking_issues+from ee.hogai.eval.sandboxed.scorers import ExitCodeZero, NoToolCall+++def _events_case(+ *,+ name: str,+ prompt: str,+ target_issue_name: str,+ events_args: dict[str, Any],+) -> SandboxedEvalCase:+ return SandboxedEvalCase(+ name=name,+ prompt=prompt,+ expected={+ "target_issue": {"name": target_issue_name},+ "events_args": events_args,+ },+ setup=seed_error_tracking_issues,+ )+++async def eval_events_sampling(sandboxed_demo_data, pytestconfig, posthog_client, mcp_mode):+ cases = [+ # One example, modest verbosity — the prompt only asks for "an example",+ # so cranking limit > 3 or asking for raw is wasteful. Issue described+ # by searchable event fields (team-invite TypeError) rather than the+ # PSQL-only issue name.+ _events_case(+ name="events_default_limit_low",+ prompt="Get me an example exception event for the team-invite TypeError.",+ target_issue_name="Team invite rejected",+ events_args={"limit": "<=3", "verbosity": "summary_or_stack"},+ ),+ # Explicit "raw" ask — the agent should pick verbosity=raw here.+ _events_case(+ name="events_raw_when_asked",+ prompt=(+ "Pull the raw exception payload for one event of the checkout "+ "TimeoutError — I want the full untruncated data."+ ),+ target_issue_name="Checkout API timeout",+ events_args={"limit": "<=3", "verbosity": "raw"},+ ),+ # URL-narrowing ask — `searchQuery` on this endpoint only matches+ # exception-level fields ($exception_types/values/sources/functions+ # + email), NOT $current_url, so the product-correct way to filter+ # by URL here is `filterGroup` with $current_url. The judge prompt+ # accepts an equivalent searchQuery too, but the canonical+ # expectation is the property filter.+ _events_case(+ name="events_search_filter",+ prompt="Find an event for the PDF preview RenderError where the URL contained `/files/preview`.",+ target_issue_name="File preview render failure",+ events_args={+ "filterGroup": [+ {+ "key": "$current_url",+ "type": "event",+ "operator": "icontains",+ "value": "/files/preview",+ }+ ],+ },+ ),+ # Multi-example ask — limit should be at least 3 but not maxed out.+ _events_case(+ name="events_three_examples",+ prompt="Show me three different exception events for the checkout TimeoutError.",+ target_issue_name="Checkout API timeout",+ events_args={"limit": "between_2_and_5"},+ ),+ ]++ await SandboxedPublicEval(+ experiment_name=f"sandboxed-error-tracking-events-sampling-{mcp_mode}",+ cases=cases,+ scorers=[+ ExitCodeZero(),+ NoToolCall(forbidden=ERROR_TRACKING_WRITE_TOOLS, name="no_error_tracking_write"),+ EventsToolUsed(),+ EventsArgsAlignment(),+ IssueIdMatchesTarget(),+ ],+ pytestconfig=pytestconfig,+ sandboxed_demo_data=sandboxed_demo_data,+ posthog_client=posthog_client,+ )diff --git a/ee/hogai/eval/sandboxed/error_tracking/eval_issue_drilldown.py b/ee/hogai/eval/sandboxed/error_tracking/eval_issue_drilldown.pynew file mode 100644index 000000000000..ed5c8546057d--- /dev/null+++ b/ee/hogai/eval/sandboxed/error_tracking/eval_issue_drilldown.py@@ -0,0 +1,137 @@+"""Drill-down ordering eval cases for the error-tracking sandboxed agent.++Targets the canonical workflow encoded in the new error-tracking MCP+prompts:++ query-error-tracking-issues-list+ ↓ (agent picks the right issueId)+ query-error-tracking-issue ← cheap details (impact, top frame, latest release)+ ↓ (only when concrete examples / replay context are needed)+ query-error-tracking-issue-events ← sampled exception events+ ↓ ($session_id surfaces here)+ query-session-recordings-list++Each case names a specific seeded issue verbatim and asks for+something that should drive the agent through one or more drill-down+steps. ``IssueDrilldownOrder`` enforces the call sequence;+``IssueIdMatchesTarget`` verifies the agent passed the *per-case* UUID+of the named issue (not the master team's UUID, not a hallucinated+one). Together those two scorers catch the most common regressions:+agents skipping the cheap detail call, agents asking for raw events+when they didn't need them, and agents drilling into the wrong issue.++To run::++ pytest ee/hogai/eval/sandboxed/error_tracking/eval_issue_drilldown.py+"""++from __future__ import annotations++from typing import Any++import pytest++from ee.hogai.eval.sandboxed.base import SandboxedPublicEval+from ee.hogai.eval.sandboxed.config import SandboxedEvalCase+from ee.hogai.eval.sandboxed.error_tracking.scorers import (+ ERROR_TRACKING_WRITE_TOOLS,+ IssueDrilldownOrder,+ IssueIdMatchesTarget,+ IssueInputAlignment,+)+from ee.hogai.eval.sandboxed.error_tracking.seeders import seed_error_tracking_issues+from ee.hogai.eval.sandboxed.scorers import ExitCodeZero, NoToolCall+++def _drilldown_case(+ *,+ name: str,+ prompt: str,+ target_issue_name: str,+ requires_issue: bool = True,+ requires_events: bool = False,+ requires_recordings: bool = False,+ forbids_events: bool = False,+ forbids_recordings: bool = False,+ issue_input: dict[str, Any] | None = None,+) -> SandboxedEvalCase:+ expected: dict[str, Any] = {+ "target_issue": {"name": target_issue_name},+ "drilldown": {+ "requires_issue": requires_issue,+ "requires_events": requires_events,+ "requires_recordings": requires_recordings,+ "forbids_events": forbids_events,+ "forbids_recordings": forbids_recordings,+ },+ }+ if issue_input is not None:+ expected["issue_input"] = issue_input+ return SandboxedEvalCase(+ name=name,+ prompt=prompt,+ expected=expected,+ setup=seed_error_tracking_issues,+ )+++async def eval_issue_drilldown(sandboxed_demo_data, pytestconfig, posthog_client, mcp_mode):+ cases = [+ # Detail-only — impact numbers + a glance at the issue. Should not+ # trigger the heavier events tool or fan out to session recordings.+ # Phrased as a discoverable symptom (TimeoutError on the checkout+ # flow) rather than the PSQL-only issue name; searchQuery on the+ # list tool matches event $exception_types / $exception_values, not+ # ErrorTrackingIssue.name.+ _drilldown_case(+ name="drilldown_checkout_timeout_impact",+ prompt="Tell me the impact (users / sessions / occurrences) of the checkout TimeoutError in the last 14 days.",+ target_issue_name="Checkout API timeout",+ forbids_events=True,+ forbids_recordings=True,+ issue_input={"dateRange": {"date_from": "-14d"}},+ ),+ # Stack-trace ask — requires query-error-tracking-issue-events to pull+ # the sampled exception payload. No replay context asked for, so+ # fanning into session recordings would be wasteful.+ _drilldown_case(+ name="drilldown_pdf_preview_show_examples",+ prompt="Show me an example exception event with stack trace for the PDF preview RenderError.",+ target_issue_name="File preview render failure",+ requires_issue=False,+ requires_events=True,+ forbids_recordings=True,+ ),+ # Pre-error behavior — events first (to extract $session_id), then a+ # session-recordings lookup. The drill-down ordering check insists on+ # all three.+ _drilldown_case(+ name="drilldown_typeerror_session_replay",+ prompt=(+ "Find a session recording where a user hit the team-invite "+ 'TypeError ("Cannot read properties of undefined (reading '+ "'email')\") so I can see what they were doing right before "+ "it happened."+ ),+ target_issue_name="Team invite rejected",+ requires_issue=False,+ requires_events=True,+ requires_recordings=True,+ ),+ ]++ await SandboxedPublicEval(+ experiment_name=f"sandboxed-error-tracking-issue-drilldown-{mcp_mode}",+ cases=cases,+ scorers=[+ ExitCodeZero(),+ NoToolCall(forbidden=ERROR_TRACKING_WRITE_TOOLS, name="no_error_tracking_write"),+ IssueDrilldownOrder(),+ IssueIdMatchesTarget(),+ IssueInputAlignment(),+ ],+ pytestconfig=pytestconfig,+ sandboxed_demo_data=sandboxed_demo_data,+ posthog_client=posthog_client,+ )diff --git a/ee/hogai/eval/sandboxed/error_tracking/eval_issues_list.py b/ee/hogai/eval/sandboxed/error_tracking/eval_issues_list.pynew file mode 100644index 000000000000..84a3b9dea737--- /dev/null+++ b/ee/hogai/eval/sandboxed/error_tracking/eval_issues_list.py@@ -0,0 +1,101 @@+"""Error-tracking issues-list eval cases for the sandboxed agent.++Targets ``query-error-tracking-issues-list`` (added in+``feat(mcp): add generated error tracking query tools``). Each case asks+a broad "what's broken" / "which errors" style question and grades the+agent on:++* whether it called the new typed list tool at all (vs. hallucinating or+ reaching for a generic SQL workaround), and+* whether the filters it passed line up with what the user actually asked+ for (status, search, url substring, ordering, etc.).++``seed_error_tracking_issues`` (see ``seeders.py``) owns the full setup+per-case: it wipes the stale Hedgebox PSQL rows (whose CH events never+land in the sandboxed-eval environment), creates three deterministic+issues with fresh UUIDs, and writes the matching ``$exception`` events+directly to ClickHouse so the MCP tools resolve them. Cases that name a+specific seeded issue (e.g. "Team invite rejected" for the TypeError+search case) work out of the box, and the returned ``lookup_issues`` map+lets a future ``LookupIssueIdInOutput`` extension verify the agent's+final message references the per-case UUID.++To run::++ pytest ee/hogai/eval/sandboxed/error_tracking/eval_issues_list.py+"""++from __future__ import annotations++from typing import Any++import pytest++from ee.hogai.eval.sandboxed.base import SandboxedPublicEval+from ee.hogai.eval.sandboxed.config import SandboxedEvalCase+from ee.hogai.eval.sandboxed.error_tracking.scorers import (+ ERROR_TRACKING_WRITE_TOOLS,+ IssuesListInputAlignment,+ IssuesListToolUsed,+)+from ee.hogai.eval.sandboxed.error_tracking.seeders import seed_error_tracking_issues+from ee.hogai.eval.sandboxed.scorers import ExitCodeZero, NoToolCall+++def _list_case(+ *,+ name: str,+ prompt: str,+ expected_input: dict[str, Any],+) -> SandboxedEvalCase:+ return SandboxedEvalCase(+ name=name,+ prompt=prompt,+ expected={"issues_list_input": expected_input},+ setup=seed_error_tracking_issues,+ )+++async def eval_issues_list(sandboxed_demo_data, pytestconfig, posthog_client, mcp_mode):+ cases = [+ _list_case(+ name="issues_list_active_default",+ prompt="Which errors are happening in production right now?",+ expected_input={},+ ),+ _list_case(+ name="issues_list_top_by_users",+ prompt="What's the error affecting the most users this week? Just give me the issue name.",+ expected_input={"orderBy": "users", "dateRange": {"date_from": "-7d"}},+ ),+ _list_case(+ name="issues_list_filter_by_url_substring",+ prompt="Show me errors that happened on the /app/files page in the last week.",+ expected_input={"url": "/app/files", "dateRange": {"date_from": "-7d"}},+ ),+ _list_case(+ name="issues_list_resolved",+ prompt="List the errors we've already resolved.",+ expected_input={"status": "resolved"},+ ),+ _list_case(+ name="issues_list_search_typeerror",+ prompt="Find error issues related to TypeError.",+ expected_input={"searchQuery": "TypeError"},+ ),+ ]++ await SandboxedPublicEval(+ experiment_name=f"sandboxed-error-tracking-issues-list-{mcp_mode}",+ cases=cases,+ scorers=[+ ExitCodeZero(),+ NoToolCall(forbidden=ERROR_TRACKING_WRITE_TOOLS, name="no_error_tracking_write"),+ IssuesListToolUsed(),+ IssuesListInputAlignment(),+ ],+ pytestconfig=pytestconfig,+ sandboxed_demo_data=sandboxed_demo_data,+ posthog_client=posthog_client,+ )diff --git a/ee/hogai/eval/sandboxed/error_tracking/scorers.py b/ee/hogai/eval/sandboxed/error_tracking/scorers.pynew file mode 100644index 000000000000..dc3276b3ab95--- /dev/null+++ b/ee/hogai/eval/sandboxed/error_tracking/scorers.py@@ -0,0 +1,902 @@+"""Scorers for the error-tracking sandboxed evals.++Three families of scorer:++* **Tool-presence** — did the agent call the expected query tool at all?+* **Filter / argument alignment** — does the input the agent passed+ match what the user asked for? Implemented as binary LLM-judge yes/no+ classifiers, mirroring ``RetentionSchemaAlignment``.+* **Ordering + ID resolution** — for drill-down prompts, did the agent+ go list → issue (→ optional events → optional recordings), and did it+ pass the correct per-case ``issueId`` for the named seeded issue?++All scorers build a single ``LogParser`` from ``output["raw_log"]`` so they+work identically in ``mcp_mode=tools`` (per-tool MCP) and ``mcp_mode=cli``+(single-``exec`` wrapper) — the parser handles exec-unwrapping.+"""++from __future__ import annotations++import re+import json+from typing import Any++from autoevals.llm import LLMClassifier+from braintrust import Score+from braintrust_core.score import Scorer++from ee.hogai.eval.sandboxed.log_parser import LogParser, ToolCall++__all__ = [+ "BINARY_CHOICE_SCORES",+ "ERROR_TRACKING_WRITE_TOOLS",+ "EventsArgsAlignment",+ "EventsToolUsed",+ "IssueDrilldownOrder",+ "IssueInputAlignment",+ "IssueIdMatchesTarget",+ "IssuesListInputAlignment",+ "IssuesListToolUsed",+ "QUERY_ISSUE_EVENTS_TOOL",+ "QUERY_ISSUE_TOOL",+ "QUERY_ISSUES_LIST_TOOL",+ "SESSION_RECORDINGS_LIST_TOOL",+ "extract_last_query_issue_events_input",+ "extract_last_query_issue_input",+ "extract_last_query_issues_list_input",+]++# Error-tracking MCP tools that mutate state. The sandbox is disposable+# but these still hit real PSQL rows, so any successful call for a "just+# answer the question" prompt is a regression we want to catch.+ERROR_TRACKING_WRITE_TOOLS = frozenset(+ {+ "error-tracking-issues-merge-create",+ "error-tracking-issues-partial-update",+ "error-tracking-issues-split-create",+ "error-tracking-grouping-rules-create",+ "error-tracking-grouping-rules-update",+ "error-tracking-suppression-rules-create",+ "error-tracking-suppression-rules-update",+ "error-tracking-assignment-rules-create",+ }+)++QUERY_ISSUES_LIST_TOOL = "query-error-tracking-issues-list"+QUERY_ISSUE_TOOL = "query-error-tracking-issue"+QUERY_ISSUE_EVENTS_TOOL = "query-error-tracking-issue-events"+SESSION_RECORDINGS_LIST_TOOL = "query-session-recordings-list"++BINARY_CHOICE_SCORES = {"yes": 1.0, "no": 0.0}++_JUDGE_MODEL = "gpt-5.4"+_SESSION_ID_TEXT_RE = re.compile(r"""["']?\$?session_id["']?\s*[:=]\s*["']?([^"',\s}\]]+)""")+_TOON_NON_EMPTY_RESULTS_RE = re.compile(r"""(?m)^\s*results\[[1-9]\d*\](?:\{[^}]*\})?:""")+++# ---------------------------------------------------------------------------+# Tool-call extraction helpers+# ---------------------------------------------------------------------------+++def _parser_for(output: dict[str, Any] | None) -> LogParser | None:+ if not output:+ return None+ raw_log = output.get("raw_log")+ if not raw_log:+ return None+ return LogParser(raw_log, initial_prompt=output.get("prompt", "") or "")+++def _last_successful_input(parser: LogParser | None, tool_name: str) -> dict[str, Any] | None:+ """Return the input dict of the most recent successful call to ``tool_name``."""+ if parser is None:+ return None+ successful = [c for c in parser.get_tool_calls(tool_name) if not c.is_error]+ if not successful:+ return None+ raw = successful[-1].input+ return raw if isinstance(raw, dict) else None+++def _successful_inputs(parser: LogParser | None, tool_name: str) -> list[dict[str, Any]]:+ if parser is None:+ return []+ return [+ call.input for call in parser.get_tool_calls(tool_name) if not call.is_error and isinstance(call.input, dict)+ ]+++def _collect_session_ids(value: Any) -> set[str]:+ if isinstance(value, dict):+ session_ids: set[str] = set()+ for key, nested in value.items():+ if key in {"$session_id", "session_id"}:+ if isinstance(nested, str):+ session_ids.add(nested)+ elif isinstance(nested, list):+ session_ids.update(item for item in nested if isinstance(item, str))+ session_ids.update(_collect_session_ids(nested))+ return session_ids+ if isinstance(value, list):+ session_ids = set()+ for item in value:+ session_ids.update(_collect_session_ids(item))+ return session_ids+ if isinstance(value, str):+ return {+ match.group(1)+ for match in _SESSION_ID_TEXT_RE.finditer(value)+ if match.group(1) not in {"", "null", "None"}+ }+ return set()+++def _session_ids_from_output(raw_output: str) -> set[str]:+ try:+ decoded = json.loads(raw_output)+ except json.JSONDecodeError:+ return {+ match.group(1)+ for match in _SESSION_ID_TEXT_RE.finditer(raw_output)+ if match.group(1) not in {"", "null", "None"}+ }+ return _collect_session_ids(decoded)+++def _session_ids_from_recordings_input(tool_input: dict[str, Any]) -> set[str]:+ raw_session_ids = tool_input.get("session_ids")+ if isinstance(raw_session_ids, str):+ return {raw_session_ids}+ if isinstance(raw_session_ids, list):+ return {item for item in raw_session_ids if isinstance(item, str)}+ return set()+++def _has_results_list(value: Any) -> bool:+ if isinstance(value, dict):+ results = value.get("results")+ if isinstance(results, list):+ return bool(results)+ return any(_has_results_list(nested) for nested in value.values())+ if isinstance(value, list):+ return bool(value) and any(_has_results_list(item) for item in value)+ if isinstance(value, str):+ return bool(_TOON_NON_EMPTY_RESULTS_RE.search(value))+ return False+++def _query_output_has_results(raw_output: str) -> bool:+ try:+ decoded = json.loads(raw_output)+ except json.JSONDecodeError:+ return bool(_TOON_NON_EMPTY_RESULTS_RE.search(raw_output))+ return _has_results_list(decoded)+++def _has_recordings_result(value: Any) -> bool:+ if isinstance(value, dict):+ if isinstance(value.get("id"), str):+ return True+ results = value.get("results")+ if isinstance(results, list):+ return bool(results)+ return any(_has_recordings_result(nested) for nested in value.values())+ if isinstance(value, list):+ return bool(value) and any(_has_recordings_result(item) for item in value)+ if isinstance(value, str):+ return _recordings_text_has_results(value)+ return False+++def _recordings_text_has_results(raw_output: str) -> bool:+ return bool(+ re.search(r"""(?m)^\s*(?:id|session_id)\s*[:=]\s*["']?[^"',\s}\]]+""", raw_output)+ or _TOON_NON_EMPTY_RESULTS_RE.search(raw_output)+ )+++def _recordings_output_has_results(raw_output: str) -> bool:+ try:+ decoded = json.loads(raw_output)+ except json.JSONDecodeError:+ return _recordings_text_has_results(raw_output)+ return _has_recordings_result(decoded)+++def extract_last_query_issues_list_input(output: dict[str, Any] | None) -> dict[str, Any] | None:+ return _last_successful_input(_parser_for(output), QUERY_ISSUES_LIST_TOOL)+++def extract_last_query_issue_input(output: dict[str, Any] | None) -> dict[str, Any] | None:+ return _last_successful_input(_parser_for(output), QUERY_ISSUE_TOOL)+++def extract_last_query_issue_events_input(output: dict[str, Any] | None) -> dict[str, Any] | None:+ return _last_successful_input(_parser_for(output), QUERY_ISSUE_EVENTS_TOOL)+++def _user_prompt(output: dict[str, Any] | None) -> str:+ parser = _parser_for(output)+ if parser is not None:+ return parser.get_user_prompt()+ if output:+ prompt = output.get("prompt")+ if isinstance(prompt, str):+ return prompt+ return ""+++# ---------------------------------------------------------------------------+# Tool-presence+# ---------------------------------------------------------------------------+++class _ToolUsedScorer(Scorer):+ """Binary deterministic floor: did the agent successfully call ``_tool_name`` at least once?++ Used as the entry-point floor for evals whose other scorers short-circuit+ with ``score=None`` when the target tool was never called — without this+ floor, an agent that never reaches the tool would pass the suite with no+ negative signal.+ """++ _tool_name: str = ""+ _empty_result_reason: str | None = None++ def __init__(self, *, name: str):+ self._label = name++ def _name(self) -> str:+ return self._label++ async def _run_eval_async(self, output, expected=None, **kwargs):+ return self._evaluate(output)++ def _run_eval_sync(self, output, expected=None, **kwargs):+ return self._evaluate(output)++ def _evaluate(self, output: dict | None) -> Score:+ parser = _parser_for(output)+ if parser is None:+ return Score(name=self._name(), score=None, metadata={"reason": "No raw log to parse"})+ successful_calls = [call for call in parser.get_tool_calls(self._tool_name) if not call.is_error]+ if not successful_calls:+ return Score(+ name=self._name(),+ score=0.0,+ metadata={"reason": f"Agent never ran {self._tool_name} successfully"},+ )+ if self._empty_result_reason is None:+ return Score(name=self._name(), score=1.0, metadata={"tool": self._tool_name})+ non_empty_positions = [call.position for call in successful_calls if _query_output_has_results(call.output)]+ if not non_empty_positions:+ return Score(+ name=self._name(),+ score=0.0,+ metadata={+ "reason": self._empty_result_reason,+ "successful_call_positions": [call.position for call in successful_calls],+ },+ )+ return Score(+ name=self._name(),+ score=1.0,+ metadata={"tool": self._tool_name, "non_empty_positions": non_empty_positions},+ )+++class IssuesListToolUsed(_ToolUsedScorer):+ """Floor scorer for ``query-error-tracking-issues-list``.++ Entry point for "what's broken / which errors" questions. Catches the+ agent hallucinating without querying, or falling back to a generic+ SQL/HogQL workaround instead of the typed tool.+ """++ _tool_name = QUERY_ISSUES_LIST_TOOL+ _empty_result_reason = f"{QUERY_ISSUES_LIST_TOOL} returned no issues"++ def __init__(self, *, name: str = "issues_list_tool_used"):+ super().__init__(name=name)+++class EventsToolUsed(_ToolUsedScorer):+ """Floor scorer for ``query-error-tracking-issue-events``.++ Required for ``eval_events_sampling.py`` so the suite can't pass when+ the agent never reaches the events tool — without this floor,+ ``EventsArgsAlignment`` and ``IssueIdMatchesTarget`` both short-circuit+ with ``score=None`` and the run produces no failing signal.+ """++ _tool_name = QUERY_ISSUE_EVENTS_TOOL+ _empty_result_reason = f"{QUERY_ISSUE_EVENTS_TOOL} returned no sampled events"++ def __init__(self, *, name: str = "events_tool_used"):+ super().__init__(name=name)+++# ---------------------------------------------------------------------------+# Filter / argument alignment (LLM judge)+# ---------------------------------------------------------------------------+++class _AlignmentClassifier(LLMClassifier):+ """Shared boilerplate for binary alignment classifiers.++ Subclasses provide the prompt template, the per-tool input extractor,+ and the expected-payload key on ``case.expected``. The base class+ handles the "agent never ran the tool" / "no expected provided"+ short-circuits by returning ``Score(score=None, ...)`` before+ delegating to the LLM judge — scoring uncalled tools as 0 would+ drown out signal from cases that did call the tool with a wrong+ shape.+ """++ _expected_key: str = ""++ def _extract_actual(self, output: dict[str, Any] | None) -> dict[str, Any] | None:+ raise NotImplementedError++ async def _run_eval_async(self, output, expected=None, **kwargs):+ prepared = self._prepare(output, expected)+ if isinstance(prepared, Score):+ return prepared+ try:+ return await super()._run_eval_async(prepared["output"], prepared["expected"], **kwargs)+ except Exception as exc:+ return Score(name=self._name(), score=0.0, metadata={"reason": f"judge error: {exc}"})++ def _run_eval_sync(self, output, expected=None, **kwargs):+ prepared = self._prepare(output, expected)+ if isinstance(prepared, Score):+ return prepared+ try:+ return super()._run_eval_sync(prepared["output"], prepared["expected"], **kwargs)+ except Exception as exc:+ return Score(name=self._name(), score=0.0, metadata={"reason": f"judge error: {exc}"})++ def _prepare(self, output: dict[str, Any] | None, expected: dict[str, Any] | None) -> dict[str, Any] | Score:+ actual = self._extract_actual(output)+ if actual is None:+ return Score(+ name=self._name(),+ score=None,+ metadata={"reason": "Agent never ran the expected tool successfully"},+ )+ expected_payload = (expected or {}).get(self._expected_key) if isinstance(expected, dict) else None+ if not isinstance(expected_payload, dict):+ return Score(+ name=self._name(),+ score=None,+ metadata={"reason": f"No expected.{self._expected_key} provided"},+ )+ return {+ "output": {"actual": actual, "prompt": _user_prompt(output)},+ "expected": {"expected": expected_payload},+ }+++class IssuesListInputAlignment(_AlignmentClassifier):+ """Binary yes/no: do the filters the agent passed match the user prompt?++ Reads ``expected.issues_list_input``. Treat fields the case left+ unset as "either match or sensible default is fine" so we don't+ penalize the agent for using the API's defaults.+ """++ _expected_key = "issues_list_input"++ def _extract_actual(self, output: dict[str, Any] | None) -> dict[str, Any] | None:+ return extract_last_query_issues_list_input(output)++ def __init__(self, **kwargs):+ super().__init__(+ name="issues_list_input_alignment",+ prompt_template="""+You are comparing two argument shapes for the PostHog `query-error-tracking-issues-list` MCP tool.+The ACTUAL was produced by an agent in response to USER_PROMPT. The EXPECTED is the shape we want.++Treat these fields as material when EXPECTED sets them:+- `status` — `active` / `resolved` / `suppressed` / `pending_release` / `archived` / `all`. If EXPECTED omits it, ACTUAL omitting it OR setting `active` are both fine.+- `searchQuery` — free-text search; substring/word overlap with EXPECTED is sufficient.+- `library` — exact `$lib` match.+- `release` — exact release id, version, or git commit ID.+- `fingerprint` — exact `$exception_fingerprint` match.+- `url` — substring match on `$current_url`. Treat ACTUAL as material if it contains EXPECTED's substring.+- `personId` — exact UUID.+- `user` — user/email text match.+- `filePath` — stack-frame file path text match.+- `orderBy` — when EXPECTED sets it, ACTUAL must match. Treat `occurrences` as the default when EXPECTED omits.+- `orderDirection` — only material when EXPECTED sets it.+- `dateRange.date_from` / `dateRange.date_to` — relative windows like `-7d`, `-1w`, `-30d` are acceptable when equivalent. EXPECTED omitting `dateRange` means the API default `last 7 days` is fine.+- `assignee` — type and id must match if EXPECTED sets it.++Ignore `filterTestAccounts`, `volumeResolution`, `limit`, `offset` unless EXPECTED set them explicitly. Ignore `filterGroup` when EXPECTED uses a typed equivalent (e.g. `library`).++<user_prompt>+{{output.prompt}}+</user_prompt>++<expected_input>+{{expected.expected}}+</expected_input>++<actual_input>+{{output.actual}}+</actual_input>++Does the actual input match the expected one on the material fields above? Answer `yes` or `no`.+""".strip(),+ choice_scores=BINARY_CHOICE_SCORES,+ model=_JUDGE_MODEL,+ max_completion_tokens=512,+ **kwargs,+ )+++class IssueInputAlignment(_AlignmentClassifier):+ """Binary yes/no: do `query-error-tracking-issue` args match the prompt?"""++ _expected_key = "issue_input"++ def _extract_actual(self, output: dict[str, Any] | None) -> dict[str, Any] | None:+ return extract_last_query_issue_input(output)++ def __init__(self, **kwargs):+ super().__init__(+ name="issue_input_alignment",+ prompt_template="""+You are comparing the ACTUAL arguments an agent passed to PostHog's `query-error-tracking-issue` MCP tool against the EXPECTED shape, given the USER_PROMPT.++Material fields when EXPECTED sets them:+- `dateRange.date_from` / `dateRange.date_to` — relative windows like `-14d`, `-2w`, `-7d`, and explicit dates are acceptable when equivalent. EXPECTED omitting `dateRange` means the API default range is fine.++Ignore `issueId` for this check (covered by a separate scorer). Ignore `filterTestAccounts`, `volumeResolution`, and response-shaping fields unless EXPECTED set them.++<user_prompt>+{{output.prompt}}+</user_prompt>++<expected_input>+{{expected.expected}}+</expected_input>++<actual_input>+{{output.actual}}+</actual_input>++Does the actual issue input match the expected one on the material fields above? Answer `yes` or `no`.+""".strip(),+ choice_scores=BINARY_CHOICE_SCORES,+ model=_JUDGE_MODEL,+ max_completion_tokens=512,+ **kwargs,+ )+++class EventsArgsAlignment(_AlignmentClassifier):+ """Binary yes/no: are `query-error-tracking-issue-events` args sane for the prompt?++ Reads ``expected.events_args``. Specifically watches:+ - ``limit`` — defaults to 1, max 20. Asking for many examples+ without prompting is wasteful.+ - ``verbosity`` — `summary` / `stack` / `raw`. `raw` should only+ appear when the user explicitly asked for raw payload data.+ - ``searchQuery`` / ``filterGroup`` — when the user described a+ narrowing filter, one of these should reflect it.+ """++ _expected_key = "events_args"++ def _extract_actual(self, output: dict[str, Any] | None) -> dict[str, Any] | None:+ calls = _successful_inputs(_parser_for(output), QUERY_ISSUE_EVENTS_TOOL)+ return {"calls": calls} if calls else None++ def _prepare(self, output: dict[str, Any] | None, expected: dict[str, Any] | None) -> dict[str, Any] | Score:+ prepared = super()._prepare(output, expected)+ if isinstance(prepared, Score):+ return prepared++ expected_payload = prepared["expected"]["expected"]+ actual = prepared["output"]["actual"]+ reason = self._first_expensive_call_reason(actual["calls"], expected_payload)+ if reason is not None:+ return Score(name=self._name(), score=0.0, metadata=reason)+ return prepared++ @staticmethod+ def _expected_limit_max(expected_payload: dict[str, Any]) -> int:+ raw_limit = expected_payload.get("limit")+ if isinstance(raw_limit, int) and not isinstance(raw_limit, bool):+ return raw_limit+ if isinstance(raw_limit, str):+ if match := re.fullmatch(r"<=\s*(\d+)", raw_limit):+ return int(match.group(1))+ if match := re.fullmatch(r"between_\d+_and_(\d+)", raw_limit):+ return int(match.group(1))+ return 5++ @staticmethod+ def _input_limit(raw_limit: Any) -> int | None:+ if isinstance(raw_limit, int) and not isinstance(raw_limit, bool):+ return raw_limit+ if isinstance(raw_limit, str) and raw_limit.isdigit():+ return int(raw_limit)+ return None++ def _first_expensive_call_reason(+ self, calls: list[dict[str, Any]], expected_payload: dict[str, Any]+ ) -> dict[str, Any] | None:+ max_limit = self._expected_limit_max(expected_payload)+ expects_raw = expected_payload.get("verbosity") == "raw"+ for index, call in enumerate(calls, start=1):+ limit = self._input_limit(call.get("limit"))+ if limit is not None and limit > max_limit:+ return {+ "reason": f"{QUERY_ISSUE_EVENTS_TOOL} call over-fetched sampled events",+ "call_index": index,+ "limit": limit,+ "max_limit": max_limit,+ }+ verbosity = call.get("verbosity")+ if isinstance(verbosity, str) and verbosity.lower() == "raw" and not expects_raw:+ return {+ "reason": f"{QUERY_ISSUE_EVENTS_TOOL} call requested raw payload without a raw prompt",+ "call_index": index,+ "verbosity": verbosity,+ }+ return None++ def __init__(self, **kwargs):+ super().__init__(+ name="events_args_alignment",+ prompt_template="""+You are comparing the ACTUAL arguments an agent passed to PostHog's `query-error-tracking-issue-events` MCP tool against the EXPECTED shape, given the USER_PROMPT. ACTUAL may contain multiple successful calls; every call must be consistent with EXPECTED.++Material fields when EXPECTED sets them:+- `limit` — integer; treat as material when EXPECTED specifies a max or a range. The tool defaults `limit=1`; `limit > 5` without an explicit "show me many" prompt is wrong.+- `verbosity` — one of `summary` / `stack` / `raw`. EXPECTED sets the value the agent should pick. The special EXPECTED value `summary_or_stack` means ACTUAL may omit verbosity (tool default), set `summary`, or set `stack`; `raw` is wrong unless the prompt asks for raw / untruncated / full payload.+- `searchQuery` — substring/word overlap with EXPECTED is sufficient.+- `filterGroup` — when EXPECTED uses a `searchQuery` and ACTUAL uses an equivalent property filter (or vice versa), that's also fine.+- `dateRange.date_from` / `dateRange.date_to` — only material when EXPECTED sets them.++Ignore `issueId` for this check (covered by a separate scorer). Ignore `filterTestAccounts`, `onlyAppFrames`, `offset`, `orderDirection` unless EXPECTED set them.++<user_prompt>+{{output.prompt}}+</user_prompt>++<expected_input>+{{expected.expected}}+</expected_input>++<actual_input>+{{output.actual}}+</actual_input>++Are all actual events arguments consistent with the expected ones? Answer `yes` or `no`.+""".strip(),+ choice_scores=BINARY_CHOICE_SCORES,+ model=_JUDGE_MODEL,+ max_completion_tokens=512,+ **kwargs,+ )+++# ---------------------------------------------------------------------------+# Drill-down ordering + target ID resolution+# ---------------------------------------------------------------------------+++def _resolve_target_issue(seed: Any, expected: dict[str, Any] | None) -> dict[str, Any] | None:+ """Find the seeded ``ErrorTrackingIssue`` the case is targeting.++ Resolution order:+ 1. ``expected.target_issue.name`` (or ``expected.<scorer_name>.target_issue_name``)+ — explicit override the case author can set.+ 2. Substring match: the seeded issue whose name appears in+ ``expected.target_issue.name`` if missing, or in the user+ prompt — used by literal-name cases like+ "Tell me the impact of the 'Checkout API timeout' error".+ """+ if not isinstance(seed, dict):+ return None+ lookups = seed.get("lookup_issues")+ if not isinstance(lookups, list) or not lookups:+ return None++ target_name = None+ if isinstance(expected, dict):+ for key in ("target_issue", "issue_id_matches_target"):+ spec = expected.get(key)+ if isinstance(spec, dict):+ candidate = spec.get("name") or spec.get("target_issue_name")+ if isinstance(candidate, str) and candidate:+ target_name = candidate+ break++ if target_name is not None:+ target_lower = target_name.lower()+ for lookup in lookups:+ if isinstance(lookup, dict) and isinstance(lookup.get("name"), str):+ if lookup["name"].lower() == target_lower:+ return lookup+ return None++ return None+++class IssueIdMatchesTarget(Scorer):+ """Binary deterministic: did the agent pass the right ``issueId`` to drill-down tools?++ Resolves the case's target seeded issue, then checks whether *every*+ successful ``query-error-tracking-issue`` and+ ``query-error-tracking-issue-events`` call used that issue's ID.+ Returns ``score=None`` when the case has no target configured (e.g.+ a list-only eval), and ``score=None`` when the agent never ran a+ drill-down tool — that's the ``IssueDrilldownOrder`` scorer's job to+ catch.+ """++ def __init__(self, *, name: str = "issue_id_matches_target"):+ self._label = name++ def _name(self) -> str:+ return self._label++ async def _run_eval_async(self, output, expected=None, **kwargs):+ return self._evaluate(output, expected)++ def _run_eval_sync(self, output, expected=None, **kwargs):+ return self._evaluate(output, expected)++ def _evaluate(self, output: dict | None, expected: dict | None) -> Score:+ if not output:+ return Score(name=self._name(), score=None, metadata={"reason": "No output"})+ target = _resolve_target_issue(output.get("seed"), expected)+ if target is None:+ return Score(+ name=self._name(),+ score=None,+ metadata={"reason": "No target_issue configured / seeded"},+ )+ target_id = str(target.get("id", ""))+ if not target_id:+ return Score(name=self._name(), score=None, metadata={"reason": "Target issue has no id"})++ parser = _parser_for(output)+ if parser is None:+ return Score(name=self._name(), score=None, metadata={"reason": "No raw log to parse"})++ observed: list[tuple[str, str]] = []+ for call in parser.get_tool_calls():+ if call.is_error or call.name not in {QUERY_ISSUE_TOOL, QUERY_ISSUE_EVENTS_TOOL}:+ continue+ issue_id = call.input.get("issueId") if isinstance(call.input, dict) else None+ if isinstance(issue_id, str):+ observed.append((call.name, issue_id))++ if not observed:+ return Score(+ name=self._name(),+ score=None,+ metadata={+ "reason": "No drill-down call observed (covered by issue_drilldown_order)",+ "target_id": target_id,+ "target_name": target.get("name"),+ },+ )++ mismatches = [(name, issue_id) for name, issue_id in observed if issue_id != target_id]+ if mismatches:+ return Score(+ name=self._name(),+ score=0.0,+ metadata={+ "reason": "Drill-down used a different issueId than the named target",+ "target_id": target_id,+ "target_name": target.get("name"),+ "observed": observed,+ "mismatches": mismatches,+ },+ )+ return Score(+ name=self._name(),+ score=1.0,+ metadata={+ "target_id": target_id,+ "target_name": target.get("name"),+ "observed": observed,+ },+ )+++class IssueDrilldownOrder(Scorer):+ """Binary deterministic: did the agent walk list → optional issue → events → recordings?++ Verifies the canonical drill-down flow:++ 1. ``query-error-tracking-issues-list`` was called successfully.+ 2. **Default-required** when ``expected.drilldown.requires_issue`` is+ omitted or true: ``query-error-tracking-issue`` was called successfully+ after step 1, and with the target issue's per-case UUID (when a target+ is configured). Cases can set ``requires_issue=False`` when list →+ events is a valid cheaper route.+ 3. **Optional** when ``expected.drilldown.requires_events`` is true:+ ``query-error-tracking-issue-events`` was called after the latest+ required predecessor (the issue call when required/present, otherwise+ the list call).+ 4. **Optional** when ``expected.drilldown.requires_recordings`` is+ true: ``query-session-recordings-list`` was called after step 3+ (the events response is what surfaces the ``$session_id`` values+ to feed it).++ The case can additionally set ``forbids_events`` / ``forbids_recordings``+ to catch over-fetching: detail-only prompts ("just tell me the impact"+ of an issue) shouldn't trigger the heavier sampled-events query, and+ impact-only prompts shouldn't fan out into session recordings. When+ set, a successful call to the corresponding tool fails the scorer.+ ``requires_*`` and ``forbids_*`` for the same tool are mutually+ exclusive — when both are true, ``forbids_*`` is ignored.+ """++ def __init__(self, *, name: str = "issue_drilldown_order"):+ self._label = name++ def _name(self) -> str:+ return self._label++ async def _run_eval_async(self, output, expected=None, **kwargs):+ return self._evaluate(output, expected)++ def _run_eval_sync(self, output, expected=None, **kwargs):+ return self._evaluate(output, expected)++ def _evaluate(self, output: dict | None, expected: dict | None) -> Score:+ if not output:+ return Score(name=self._name(), score=None, metadata={"reason": "No output"})+ parser = _parser_for(output)+ if parser is None:+ return Score(name=self._name(), score=None, metadata={"reason": "No raw log to parse"})++ spec = expected.get("drilldown") if isinstance(expected, dict) else None+ if not isinstance(spec, dict):+ return Score(+ name=self._name(),+ score=None,+ metadata={"reason": "No expected.drilldown spec provided"},+ )+ requires_issue = bool(spec.get("requires_issue", True))+ requires_events = bool(spec.get("requires_events", False))+ requires_recordings = bool(spec.get("requires_recordings", False))+ forbids_events = bool(spec.get("forbids_events", False)) and not requires_events+ forbids_recordings = bool(spec.get("forbids_recordings", False)) and not requires_recordings++ list_pos = self._first_pos(parser, QUERY_ISSUES_LIST_TOOL)+ issue_pos = self._first_pos(parser, QUERY_ISSUE_TOOL)+ events_pos = self._first_pos(parser, QUERY_ISSUE_EVENTS_TOOL)+ recordings_pos = self._first_pos(parser, SESSION_RECORDINGS_LIST_TOOL)++ metadata: dict[str, Any] = {+ "list_pos": list_pos,+ "issue_pos": issue_pos,+ "events_pos": events_pos,+ "recordings_pos": recordings_pos,+ "requires_issue": requires_issue,+ "requires_events": requires_events,+ "requires_recordings": requires_recordings,+ "forbids_events": forbids_events,+ "forbids_recordings": forbids_recordings,+ }++ if list_pos is None:+ metadata["reason"] = f"{QUERY_ISSUES_LIST_TOOL} was never called successfully"+ return Score(name=self._name(), score=0.0, metadata=metadata)+ if requires_issue and issue_pos is None:+ metadata["reason"] = f"{QUERY_ISSUE_TOOL} was never called successfully"+ return Score(name=self._name(), score=0.0, metadata=metadata)+ if issue_pos is not None and issue_pos <= list_pos:+ metadata["reason"] = f"{QUERY_ISSUE_TOOL} did not run after {QUERY_ISSUES_LIST_TOOL}"+ return Score(name=self._name(), score=0.0, metadata=metadata)++ if requires_events:+ if events_pos is None:+ metadata["reason"] = f"{QUERY_ISSUE_EVENTS_TOOL} was never called successfully"+ return Score(name=self._name(), score=0.0, metadata=metadata)+ events_prerequisite_pos = issue_pos if issue_pos is not None else list_pos+ events_prerequisite_tool = QUERY_ISSUE_TOOL if issue_pos is not None else QUERY_ISSUES_LIST_TOOL+ events_after_prerequisite = [+ call+ for call in parser.get_tool_calls(QUERY_ISSUE_EVENTS_TOOL)+ if not call.is_error and call.position > events_prerequisite_pos+ ]+ if not events_after_prerequisite:+ metadata["reason"] = f"{QUERY_ISSUE_EVENTS_TOOL} did not run after {events_prerequisite_tool}"+ return Score(name=self._name(), score=0.0, metadata=metadata)+ event_result_positions = [+ call.position for call in events_after_prerequisite if _query_output_has_results(call.output)+ ]+ metadata["events_result_positions"] = event_result_positions+ if not event_result_positions:+ metadata["reason"] = f"{QUERY_ISSUE_EVENTS_TOOL} returned no sampled events"+ return Score(name=self._name(), score=0.0, metadata=metadata)+ elif forbids_events and events_pos is not None:+ metadata["reason"] = (+ f"{QUERY_ISSUE_EVENTS_TOOL} was called for a prompt that did not ask for sampled events"+ )+ return Score(name=self._name(), score=0.0, metadata=metadata)++ if requires_recordings:+ if recordings_pos is None:+ metadata["reason"] = f"{SESSION_RECORDINGS_LIST_TOOL} was never called successfully"+ return Score(name=self._name(), score=0.0, metadata=metadata)+ # When recordings are required, events should also have been called,+ # because that's where `$session_id`s come from. Don't enforce a+ # strict events→recordings ordering when only recordings is+ # requested without events — the agent might pull the session id+ # from a different surface.+ min_pred = (+ events_pos+ if requires_events and events_pos is not None+ else issue_pos+ if issue_pos is not None+ else list_pos+ )+ if recordings_pos <= min_pred:+ metadata["reason"] = f"{SESSION_RECORDINGS_LIST_TOOL} did not run after its prerequisite drill-down"+ return Score(name=self._name(), score=0.0, metadata=metadata)+ recordings_call = self._first_successful_call(parser, SESSION_RECORDINGS_LIST_TOOL)+ if recordings_call is None:+ metadata["reason"] = f"{SESSION_RECORDINGS_LIST_TOOL} was never called successfully"+ return Score(name=self._name(), score=0.0, metadata=metadata)+ recordings_session_ids = _session_ids_from_recordings_input(recordings_call.input)+ metadata["recordings_session_ids"] = sorted(recordings_session_ids)+ if not recordings_session_ids:+ metadata["reason"] = f"{SESSION_RECORDINGS_LIST_TOOL} did not include session_ids from sampled events"+ return Score(name=self._name(), score=0.0, metadata=metadata)+ if not _recordings_output_has_results(recordings_call.output):+ metadata["reason"] = f"{SESSION_RECORDINGS_LIST_TOOL} returned no recordings"+ return Score(name=self._name(), score=0.0, metadata=metadata)+ event_session_ids = self._event_session_ids_before(parser, recordings_pos)+ metadata["event_session_ids"] = sorted(event_session_ids)+ if not event_session_ids:+ metadata["reason"] = f"{QUERY_ISSUE_EVENTS_TOOL} output did not expose $session_id values"+ return Score(name=self._name(), score=0.0, metadata=metadata)+ unexpected_session_ids = recordings_session_ids - event_session_ids+ if unexpected_session_ids:+ metadata["reason"] = f"{SESSION_RECORDINGS_LIST_TOOL} used session_ids not returned by sampled events"+ metadata["unexpected_session_ids"] = sorted(unexpected_session_ids)+ return Score(name=self._name(), score=0.0, metadata=metadata)+ elif forbids_recordings and recordings_pos is not None:+ metadata["reason"] = (+ f"{SESSION_RECORDINGS_LIST_TOOL} was called for a prompt that did not ask for replay context"+ )+ return Score(name=self._name(), score=0.0, metadata=metadata)++ return Score(name=self._name(), score=1.0, metadata=metadata)++ @staticmethod+ def _first_pos(parser: LogParser, tool_name: str) -> int | None:+ """Earliest position of a successful call to ``tool_name``."""+ for call in parser.get_tool_calls(tool_name):+ if not call.is_error:+ return call.position+ return None++ @staticmethod+ def _first_successful_call(parser: LogParser, tool_name: str) -> ToolCall | None:+ for call in parser.get_tool_calls(tool_name):+ if not call.is_error:+ return call+ return None++ @staticmethod+ def _event_session_ids_before(parser: LogParser, position: int) -> set[str]:+ session_ids: set[str] = set()+ for call in parser.get_tool_calls(QUERY_ISSUE_EVENTS_TOOL):+ if call.is_error or call.position > position:+ continue+ session_ids.update(_session_ids_from_output(call.output))+ return session_idsdiff --git a/ee/hogai/eval/sandboxed/error_tracking/seeders.py b/ee/hogai/eval/sandboxed/error_tracking/seeders.pynew file mode 100644index 000000000000..ba6e2e1779ff--- /dev/null+++ b/ee/hogai/eval/sandboxed/error_tracking/seeders.py@@ -0,0 +1,375 @@+"""Per-case seeder for the error-tracking sandboxed evals.++Owns the entire error-tracking surface for a per-case team:++ * Wipes any pre-existing ``ErrorTrackingIssue`` rows so the Hedgebox+ demo seed (which writes events through Kafka and never lands in the+ sandboxed-eval ClickHouse) can't leave stale, empty issues lying+ around to confuse the agent.+ * Creates deterministic ``ErrorTrackingIssue`` PSQL rows with+ fresh UUIDs and matching ``ErrorTrackingIssueFingerprintV2`` rows.+ * Writes matching ``error_tracking_fingerprint_issue_state`` rows directly to+ ClickHouse so V3 queries don't depend on the async Kafka/backfill path.+ * Creates matching ClickHouse person rows for the synthetic distinct IDs so+ person joins and test-account filters can't drop seeded events.+ * Writes the matching ``$exception`` events directly to ClickHouse so+ concurrent setup hooks don't depend on the process-global ``settings.TEST``+ value used by ``ClickhouseProducer``. That makes the seed self-contained —+ no Kafka consumer, no fingerprint-override materialized view, no implicit+ dependency on the demo matrix.++Returned dict is merged into the task output under ``seed`` by+``base.py:task()`` so scorers reach it via ``output["seed"]``.+"""++from __future__ import annotations++import json+import uuid+import logging+from datetime import UTC, datetime, timedelta+from typing import Any, Protocol+from zoneinfo import ZoneInfo++from posthog.clickhouse.client import sync_execute+from posthog.models import Team+from posthog.models.event.sql import INSERT_EVENT_SQL+from posthog.models.event.util import format_clickhouse_timestamp+from posthog.models.person.sql import INSERT_PERSON_DISTINCT_ID2, INSERT_PERSON_SQL+from posthog.models.utils import uuid7+from posthog.session_recordings.queries.test.session_replay_sql import INSERT_SINGLE_SESSION_REPLAY++from products.error_tracking.backend.models import ErrorTrackingIssue, ErrorTrackingIssueFingerprintV2+from products.error_tracking.backend.sql import INSERT_ERROR_TRACKING_FINGERPRINT_ISSUE_STATE++logger = logging.getLogger(__name__)+++__all__ = ["EVAL_ISSUE_NAMES", "seed_error_tracking_issues"]+++# Distinct-id pool used for the seeded ``$exception`` events.+_EVAL_DISTINCT_IDS: tuple[str, ...] = (+ "eval-user-1",+ "eval-user-2",+ "eval-user-3",+ "eval-user-4",+)+# Stable namespace so the same distinct_id always resolves to the same+# synthetic person_id across cases. Keeps ``users`` aggregations realistic.+_EVAL_PERSON_NAMESPACE = uuid.UUID("3f7c8b1e-2d3a-4f5b-8c7d-9e0f1a2b3c4d")+_ZERO_CLICKHOUSE_TIMESTAMP = "1970-01-01 00:00:00.000000"+++def _person_id_for(distinct_id: str) -> str:+ return str(uuid.uuid5(_EVAL_PERSON_NAMESPACE, distinct_id))+++def _seed_eval_persons(team: Team, timestamp: datetime) -> None:+ timestamp_utc = timestamp.astimezone(UTC)+ created_at = timestamp_utc.strftime("%Y-%m-%d %H:%M:%S.%f")+ timestamp_value = timestamp_utc.strftime("%Y-%m-%d %H:%M:%S")+ last_seen_at = timestamp_utc.replace(minute=0, second=0, microsecond=0).strftime("%Y-%m-%d %H:%M:%S.%f")++ for distinct_id in _EVAL_DISTINCT_IDS:+ person_id = _person_id_for(distinct_id)+ sync_execute(+ INSERT_PERSON_SQL,+ {+ "id": person_id,+ "created_at": created_at,+ "team_id": team.id,+ "properties": json.dumps({"email": f"{distinct_id}@hedgebox.example"}),+ "is_identified": 1,+ "_timestamp": timestamp_value,+ "is_deleted": 0,+ "version": 1,+ "last_seen_at": last_seen_at,+ },+ )+ sync_execute(+ INSERT_PERSON_DISTINCT_ID2,+ {+ "distinct_id": distinct_id,+ "person_id": person_id,+ "team_id": team.id,+ "is_deleted": 0,+ "version": 1,+ },+ )+++# Issue specs. Names are the strings scorers match against via+# ``expected.target_issue.name`` (case-insensitive substring against the+# ``lookup_issues`` entries returned below). The exception ``type``/``value``+# strings are what the agent's ``searchQuery`` can actually find — those+# search the CH event-level columns ``$exception_types`` / ``$exception_values``+# / ``$exception_sources`` / ``$exception_functions``, not the PSQL+# ``ErrorTrackingIssue.name`` field.+_ISSUE_SPECS: tuple[dict[str, Any], ...] = (+ {+ "name": "Checkout API timeout",+ "fingerprint": "eval-checkout-api-timeout-v1",+ "type": "TimeoutError",+ "value": "Request timed out while creating checkout session",+ "url": "https://app.hedgebox.test/app/files",+ "function": "submitPayment",+ "source": "https://app.hedgebox.test/static/js/checkout.js",+ "days_ago": (1, 2, 5, 11, 18),+ },+ {+ "name": "File preview render failure",+ "fingerprint": "eval-file-preview-render-failure-v1",+ "type": "RenderError",+ "value": "Failed to render PDF preview",+ "url": "https://app.hedgebox.test/app/files/preview/file-abc123",+ "function": "renderPdfPreview",+ "source": "https://app.hedgebox.test/static/js/file-preview.js",+ "days_ago": (1, 4, 9),+ },+ {+ "name": "Team invite rejected",+ "fingerprint": "eval-team-invite-rejected-v1",+ "type": "TypeError",+ "value": "Cannot read properties of undefined (reading 'email')",+ "url": "https://app.hedgebox.test/settings/team",+ "function": "submitInvite",+ "source": "https://app.hedgebox.test/static/js/team-invite.js",+ "days_ago": (1, 3),+ "seed_replay": True,+ },+ {+ "name": "Legacy billing alert",+ "fingerprint": "eval-legacy-billing-alert-v1",+ "type": "BillingAlertError",+ "value": "Legacy billing alert already resolved",+ "url": "https://app.hedgebox.test/billing/history",+ "function": "renderBillingAlert",+ "source": "https://app.hedgebox.test/static/js/billing.js",+ "days_ago": (6,),+ "status": ErrorTrackingIssue.Status.RESOLVED,+ },+)++EVAL_ISSUE_NAMES: tuple[str, ...] = tuple(spec["name"] for spec in _ISSUE_SPECS)+++class _ErrorTrackingSeedContext(Protocol):+ @property+ def team_id(self) -> int: ...+++def _build_exception_properties(spec: dict[str, Any], issue_id: str, session_id: str) -> dict[str, Any]:+ """Construct the ``$exception`` event payload for one occurrence.++ Mirrors the shape Hedgebox's demo seed writes (see+ ``posthog/demo/products/hedgebox/matrix.py:_set_up_error_tracking_demo_data``)+ so the query runner's frame-extraction (``innermost_frame_attribute``)+ and the events tool's ``$exception_list`` rendering both work. Stack+ frames are inlined as ``resolved=True``; we deliberately skip the+ ``ErrorTrackingStackFrame`` PSQL rows since the agent only needs the+ top frame surfaced by ``query-error-tracking-issue``.+ """+ frame: dict[str, Any] = {+ "in_app": True,+ "resolved": True,+ "resolved_name": spec["function"],+ "mangled_name": spec["function"],+ "source": spec["source"],+ "lang": "javascript",+ "line": 42,+ "column": 7,+ }+ return {+ "$lib": "web",+ "$lib_version": "1.298.0",+ "$current_url": spec["url"],+ "$host": "app.hedgebox.test",+ "$pathname": spec["url"].split("hedgebox.test", 1)[-1] or "/",+ "$session_id": session_id,+ "$exception_level": "error",+ "$exception_handled": False,+ "$exception_issue_id": issue_id,+ "$exception_fingerprint": spec["fingerprint"],+ "$exception_proposed_fingerprint": spec["fingerprint"],+ "$exception_fingerprint_record": [{"type": "manual"}],+ "$exception_types": [spec["type"]],+ "$exception_values": [spec["value"]],+ "$exception_sources": [spec["source"]],+ "$exception_functions": [spec["function"]],+ "$exception_list": [+ {+ "type": spec["type"],+ "value": spec["value"],+ "mechanism": {"handled": False, "synthetic": False},+ "stacktrace": {"type": "resolved", "frames": [frame]},+ }+ ],+ }+++def _insert_exception_event(+ *,+ team: Team,+ distinct_id: str,+ timestamp: datetime,+ properties: dict[str, Any],+) -> None:+ timestamp_utc = timestamp.astimezone(ZoneInfo("UTC")).strftime("%Y-%m-%d %H:%M:%S.%f")+ sync_execute(+ INSERT_EVENT_SQL(),+ {+ "uuid": str(uuid.uuid4()),+ "event": "$exception",+ "properties": json.dumps(properties),+ "timestamp": timestamp_utc,+ "team_id": team.id,+ "distinct_id": distinct_id,+ "elements_chain": "",+ "created_at": timestamp_utc,+ "person_id": _person_id_for(distinct_id),+ "person_properties": "{}",+ "person_created_at": _ZERO_CLICKHOUSE_TIMESTAMP,+ "group0_properties": "{}",+ "group1_properties": "{}",+ "group2_properties": "{}",+ "group3_properties": "{}",+ "group4_properties": "{}",+ "group0_created_at": _ZERO_CLICKHOUSE_TIMESTAMP,+ "group1_created_at": _ZERO_CLICKHOUSE_TIMESTAMP,+ "group2_created_at": _ZERO_CLICKHOUSE_TIMESTAMP,+ "group3_created_at": _ZERO_CLICKHOUSE_TIMESTAMP,+ "group4_created_at": _ZERO_CLICKHOUSE_TIMESTAMP,+ "person_mode": "full",+ },+ )+++def _insert_fingerprint_issue_state(+ *,+ issue: ErrorTrackingIssue,+ fingerprint: ErrorTrackingIssueFingerprintV2,+) -> None:+ first_seen = fingerprint.first_seen or issue.created_at+ sync_execute(+ INSERT_ERROR_TRACKING_FINGERPRINT_ISSUE_STATE,+ {+ "fingerprint": fingerprint.fingerprint,+ "issue_id": str(issue.id),+ "team_id": issue.team_id,+ "issue_name": issue.name,+ "issue_description": issue.description,+ "issue_status": issue.status,+ "assigned_user_id": None,+ "assigned_role_id": None,+ "first_seen": format_clickhouse_timestamp(first_seen) if first_seen else None,+ "is_deleted": 0,+ "version": int(fingerprint.created_at.timestamp() * 1000),+ },+ )+++def _insert_session_replay_summary(+ *,+ team: Team,+ distinct_id: str,+ session_id: str,+ first_timestamp: datetime,+ last_timestamp: datetime,+ first_url: str,+) -> None:+ first_timestamp_utc = first_timestamp.astimezone(ZoneInfo("UTC")).strftime("%Y-%m-%d %H:%M:%S.%f")+ last_timestamp_utc = last_timestamp.astimezone(ZoneInfo("UTC")).strftime("%Y-%m-%d %H:%M:%S.%f")+ sync_execute(+ INSERT_SINGLE_SESSION_REPLAY,+ {+ "session_id": session_id,+ "team_id": team.id,+ "distinct_id": distinct_id,+ "first_timestamp": first_timestamp_utc,+ "last_timestamp": last_timestamp_utc,+ "first_url": first_url,+ "all_urls": [first_url],+ "click_count": 2,+ "keypress_count": 1,+ "mouse_activity_count": 4,+ "active_milliseconds": 45_000,+ "console_log_count": 0,+ "console_warn_count": 0,+ "console_error_count": 1,+ "snapshot_source": "web",+ "snapshot_library": "web",+ "size": 1024,+ "block_urls": [first_url],+ "block_first_timestamps": [first_timestamp],+ "block_last_timestamps": [last_timestamp],+ "retention_period_days": 30,+ "is_deleted": 0,+ "_timestamp": first_timestamp.timestamp(),+ },+ )+++def seed_error_tracking_issues(context: _ErrorTrackingSeedContext) -> dict[str, Any]:+ """Seed deterministic error-tracking issues + events on the per-case team.++ Synchronous — runs in a worker thread via ``asyncio.to_thread`` from+ ``base.py:task()``. Returns+ ``{"lookup_issues": [{"id": <uuid_str>, "name": <name>}, ...]}`` so+ deterministic scorers can resolve a target name back to the concrete+ UUID the agent should have passed as ``issueId``.+ """+ team = Team.objects.get(id=context.team_id)+ # Cascade kills any matching ``ErrorTrackingIssueFingerprintV2`` rows.+ # Hedgebox's demo seed creates rows here whose CH events never land in+ # the sandboxed eval environment — wiping them keeps the issues-list+ # response deterministic and free of confusing empty duplicates.+ ErrorTrackingIssue.objects.filter(team=team).delete()++ now = datetime.now(tz=UTC)+ _seed_eval_persons(team, now)+ lookup: list[dict[str, str]] = []++ for spec in _ISSUE_SPECS:+ issue_id = str(uuid7())+ issue = ErrorTrackingIssue.objects.create(+ id=issue_id,+ team=team,+ name=spec["name"],+ status=spec.get("status", ErrorTrackingIssue.Status.ACTIVE),+ )+ fingerprint = ErrorTrackingIssueFingerprintV2.objects.create(+ team=team,+ issue_id=issue_id,+ fingerprint=spec["fingerprint"],+ )+ _insert_fingerprint_issue_state(issue=issue, fingerprint=fingerprint)++ for index, days_ago in enumerate(spec["days_ago"]):+ distinct_id = _EVAL_DISTINCT_IDS[index % len(_EVAL_DISTINCT_IDS)]+ timestamp = now - timedelta(days=days_ago, hours=index % 5)+ session_id = str(uuid.uuid4())+ _insert_exception_event(+ team=team,+ distinct_id=distinct_id,+ timestamp=timestamp,+ properties=_build_exception_properties(spec, issue_id, session_id),+ )+ if spec.get("seed_replay"):+ _insert_session_replay_summary(+ team=team,+ distinct_id=distinct_id,+ session_id=session_id,+ first_timestamp=timestamp - timedelta(minutes=12),+ last_timestamp=timestamp + timedelta(minutes=3),+ first_url=spec["url"],+ )++ lookup.append({"id": issue_id, "name": spec["name"]})++ logger.info(+ "Seeded %d error-tracking issues + events for team_id=%s",+ len(lookup),+ context.team_id,+ )+ return {"lookup_issues": lookup}diff --git a/products/error_tracking/backend/hogql_queries/test/__snapshots__/test_error_tracking_query_runner.ambr b/products/error_tracking/backend/hogql_queries/test/__snapshots__/test_error_tracking_query_runner.ambrindex 54d43c41fee0..97ea8f65abb1 100644--- a/products/error_tracking/backend/hogql_queries/test/__snapshots__/test_error_tracking_query_runner.ambr+++ b/products/error_tracking/backend/hogql_queries/test/__snapshots__/test_error_tracking_query_runner.ambr@@ -270,7 +270,7 @@WHERE equals(person.team_id, 99999)GROUP BY person.idHAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(if(not(empty(e__exception_issue_override.issue_id)), e__exception_issue_override.issue_id, accurateCastOrNull(e.`mat_$exception_issue_id`, 'UUID'))), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('explicit_redacted_timestamp', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), and(or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_types'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_values'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('probs')), 0), 0)), or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_types'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_values'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('not')), 0), 0)), or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_types'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_values'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('found')), 0), 0))))+ WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(if(not(empty(e__exception_issue_override.issue_id)), e__exception_issue_override.issue_id, accurateCastOrNull(e.`mat_$exception_issue_id`, 'UUID'))), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('explicit_redacted_timestamp', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), and(or(ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_types`, ''), 'null')), lower('probs')), 0), 0), ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_values`, ''), 'null')), lower('probs')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('probs')), 0), 0)), or(ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_types`, ''), 'null')), lower('not')), 0), 0), ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_values`, ''), 'null')), lower('not')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('not')), 0), 0)), or(ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_types`, ''), 'null')), lower('found')), 0), 0), ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_values`, ''), 'null')), lower('found')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('found')), 0), 0))))GROUP BY idORDER BY last_seen DESCLIMIT 101@@ -845,7 +845,7 @@WHERE equals(person.team_id, 99999)GROUP BY person.idHAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(if(not(empty(e__exception_issue_override.issue_id)), e__exception_issue_override.issue_id, accurateCastOrNull(e.`mat_$exception_issue_id`, 'UUID'))), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('explicit_redacted_timestamp', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_types'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_values'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('[email protected]')), 0), 0)))+ WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(if(not(empty(e__exception_issue_override.issue_id)), e__exception_issue_override.issue_id, accurateCastOrNull(e.`mat_$exception_issue_id`, 'UUID'))), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('explicit_redacted_timestamp', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), or(ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_types`, ''), 'null')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_values`, ''), 'null')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('[email protected]')), 0), 0)))GROUP BY idORDER BY last_seen DESCLIMIT 101@@ -898,7 +898,7 @@WHERE equals(person.team_id, 99999)GROUP BY person.idHAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(if(not(empty(e__exception_issue_override.issue_id)), e__exception_issue_override.issue_id, accurateCastOrNull(e.`mat_$exception_issue_id`, 'UUID'))), ifNull(notILike(toString(e__person.properties___email), '%@posthog.com%'), 1), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_types'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_values'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('databasenot')), 0), 0)))+ WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(if(not(empty(e__exception_issue_override.issue_id)), e__exception_issue_override.issue_id, accurateCastOrNull(e.`mat_$exception_issue_id`, 'UUID'))), ifNull(notILike(toString(e__person.properties___email), '%@posthog.com%'), 1), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), or(ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_types`, ''), 'null')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_values`, ''), 'null')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('databasenot')), 0), 0)))GROUP BY idORDER BY last_seen DESCLIMIT 101@@ -951,7 +951,7 @@WHERE equals(person.team_id, 99999)GROUP BY person.idHAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(if(not(empty(e__exception_issue_override.issue_id)), e__exception_issue_override.issue_id, accurateCastOrNull(e.`mat_$exception_issue_id`, 'UUID'))), ifNull(notILike(toString(e__person.properties___email), '%@posthog.com%'), 1), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('explicit_redacted_timestamp', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), and(or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_types'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_values'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('databasenotfoundX')), 0), 0)), or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_types'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_values'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('clickhouse/client/execute.py')), 0), 0))))+ WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(if(not(empty(e__exception_issue_override.issue_id)), e__exception_issue_override.issue_id, accurateCastOrNull(e.`mat_$exception_issue_id`, 'UUID'))), ifNull(notILike(toString(e__person.properties___email), '%@posthog.com%'), 1), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('explicit_redacted_timestamp', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), and(or(ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_types`, ''), 'null')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_values`, ''), 'null')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('databasenotfoundX')), 0), 0)), or(ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_types`, ''), 'null')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_values`, ''), 'null')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('clickhouse/client/execute.py')), 0), 0))))GROUP BY idORDER BY last_seen DESCLIMIT 101diff --git a/products/error_tracking/backend/hogql_queries/test/__snapshots__/test_error_tracking_query_runner_v2.ambr b/products/error_tracking/backend/hogql_queries/test/__snapshots__/test_error_tracking_query_runner_v2.ambrindex e993ed3d4903..4dbf19b8e43c 100644--- a/products/error_tracking/backend/hogql_queries/test/__snapshots__/test_error_tracking_query_runner_v2.ambr+++ b/products/error_tracking/backend/hogql_queries/test/__snapshots__/test_error_tracking_query_runner_v2.ambr@@ -480,7 +480,7 @@WHERE equals(person.team_id, 99999)GROUP BY person.idHAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(if(not(empty(e__exception_issue_override.issue_id)), e__exception_issue_override.issue_id, accurateCastOrNull(e.`mat_$exception_issue_id`, 'UUID'))), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('explicit_redacted_timestamp', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), and(or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_types'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_values'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('probs')), 0), 0)), or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_types'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_values'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('not')), 0), 0)), or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_types'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_values'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('found')), 0), 0))))+ WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(if(not(empty(e__exception_issue_override.issue_id)), e__exception_issue_override.issue_id, accurateCastOrNull(e.`mat_$exception_issue_id`, 'UUID'))), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('explicit_redacted_timestamp', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), and(or(ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_types`, ''), 'null')), lower('probs')), 0), 0), ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_values`, ''), 'null')), lower('probs')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('probs')), 0), 0)), or(ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_types`, ''), 'null')), lower('not')), 0), 0), ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_values`, ''), 'null')), lower('not')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('not')), 0), 0)), or(ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_types`, ''), 'null')), lower('found')), 0), 0), ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_values`, ''), 'null')), lower('found')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('found')), 0), 0))))GROUP BY if(not(empty(e__exception_issue_override.issue_id)), e__exception_issue_override.issue_id, accurateCastOrNull(e.`mat_$exception_issue_id`, 'UUID')))SELECT agg.id AS id,issues.status AS status,@@ -525,7 +525,7 @@WHERE equals(person.team_id, 99999)GROUP BY person.idHAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(if(not(empty(e__exception_issue_override.issue_id)), e__exception_issue_override.issue_id, accurateCastOrNull(e.`mat_$exception_issue_id`, 'UUID'))), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('explicit_redacted_timestamp', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), and(or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_types'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_values'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('probs')), 0), 0)), or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_types'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_values'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('not')), 0), 0)), or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_types'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_values'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('found')), 0), 0))))+ WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(if(not(empty(e__exception_issue_override.issue_id)), e__exception_issue_override.issue_id, accurateCastOrNull(e.`mat_$exception_issue_id`, 'UUID'))), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('explicit_redacted_timestamp', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), and(or(ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_types`, ''), 'null')), lower('probs')), 0), 0), ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_values`, ''), 'null')), lower('probs')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('probs')), 0), 0)), or(ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_types`, ''), 'null')), lower('not')), 0), 0), ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_values`, ''), 'null')), lower('not')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('not')), 0), 0)), or(ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_types`, ''), 'null')), lower('found')), 0), 0), ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_values`, ''), 'null')), lower('found')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('found')), 0), 0))))GROUP BY id) AS aggINNER JOIN(SELECT system__error_tracking_issues.id AS id,@@ -1810,7 +1810,7 @@WHERE equals(person.team_id, 99999)GROUP BY person.idHAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(if(not(empty(e__exception_issue_override.issue_id)), e__exception_issue_override.issue_id, accurateCastOrNull(e.`mat_$exception_issue_id`, 'UUID'))), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('explicit_redacted_timestamp', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_types'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_values'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('[email protected]')), 0), 0)))+ WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(if(not(empty(e__exception_issue_override.issue_id)), e__exception_issue_override.issue_id, accurateCastOrNull(e.`mat_$exception_issue_id`, 'UUID'))), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('explicit_redacted_timestamp', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), or(ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_types`, ''), 'null')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_values`, ''), 'null')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('[email protected]')), 0), 0)))GROUP BY if(not(empty(e__exception_issue_override.issue_id)), e__exception_issue_override.issue_id, accurateCastOrNull(e.`mat_$exception_issue_id`, 'UUID')))SELECT agg.id AS id,issues.status AS status,@@ -1855,7 +1855,7 @@WHERE equals(person.team_id, 99999)GROUP BY person.idHAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(if(not(empty(e__exception_issue_override.issue_id)), e__exception_issue_override.issue_id, accurateCastOrNull(e.`mat_$exception_issue_id`, 'UUID'))), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('explicit_redacted_timestamp', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_types'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_values'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('[email protected]')), 0), 0)))+ WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(if(not(empty(e__exception_issue_override.issue_id)), e__exception_issue_override.issue_id, accurateCastOrNull(e.`mat_$exception_issue_id`, 'UUID'))), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('explicit_redacted_timestamp', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), or(ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_types`, ''), 'null')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_values`, ''), 'null')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('[email protected]')), 0), 0)))GROUP BY id) AS aggINNER JOIN(SELECT system__error_tracking_issues.id AS id,@@ -1925,7 +1925,7 @@WHERE equals(person.team_id, 99999)GROUP BY person.idHAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(if(not(empty(e__exception_issue_override.issue_id)), e__exception_issue_override.issue_id, accurateCastOrNull(e.`mat_$exception_issue_id`, 'UUID'))), ifNull(notILike(toString(e__person.properties___email), '%@posthog.com%'), 1), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_types'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_values'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('databasenot')), 0), 0)))+ WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(if(not(empty(e__exception_issue_override.issue_id)), e__exception_issue_override.issue_id, accurateCastOrNull(e.`mat_$exception_issue_id`, 'UUID'))), ifNull(notILike(toString(e__person.properties___email), '%@posthog.com%'), 1), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), or(ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_types`, ''), 'null')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_values`, ''), 'null')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('databasenot')), 0), 0)))GROUP BY if(not(empty(e__exception_issue_override.issue_id)), e__exception_issue_override.issue_id, accurateCastOrNull(e.`mat_$exception_issue_id`, 'UUID')))SELECT agg.id AS id,issues.status AS status,@@ -1978,7 +1978,7 @@WHERE equals(person.team_id, 99999)GROUP BY person.idHAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(if(not(empty(e__exception_issue_override.issue_id)), e__exception_issue_override.issue_id, accurateCastOrNull(e.`mat_$exception_issue_id`, 'UUID'))), ifNull(notILike(toString(e__person.properties___email), '%@posthog.com%'), 1), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_types'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_values'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('databasenot')), 0), 0)))+ WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(if(not(empty(e__exception_issue_override.issue_id)), e__exception_issue_override.issue_id, accurateCastOrNull(e.`mat_$exception_issue_id`, 'UUID'))), ifNull(notILike(toString(e__person.properties___email), '%@posthog.com%'), 1), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), or(ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_types`, ''), 'null')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_values`, ''), 'null')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('databasenot')), 0), 0)))GROUP BY id) AS aggINNER JOIN(SELECT system__error_tracking_issues.id AS id,@@ -2048,7 +2048,7 @@WHERE equals(person.team_id, 99999)GROUP BY person.idHAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(if(not(empty(e__exception_issue_override.issue_id)), e__exception_issue_override.issue_id, accurateCastOrNull(e.`mat_$exception_issue_id`, 'UUID'))), ifNull(notILike(toString(e__person.properties___email), '%@posthog.com%'), 1), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('explicit_redacted_timestamp', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), and(or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_types'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_values'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('databasenotfoundX')), 0), 0)), or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_types'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_values'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('clickhouse/client/execute.py')), 0), 0))))+ WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(if(not(empty(e__exception_issue_override.issue_id)), e__exception_issue_override.issue_id, accurateCastOrNull(e.`mat_$exception_issue_id`, 'UUID'))), ifNull(notILike(toString(e__person.properties___email), '%@posthog.com%'), 1), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('explicit_redacted_timestamp', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), and(or(ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_types`, ''), 'null')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_values`, ''), 'null')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('databasenotfoundX')), 0), 0)), or(ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_types`, ''), 'null')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_values`, ''), 'null')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('clickhouse/client/execute.py')), 0), 0))))GROUP BY if(not(empty(e__exception_issue_override.issue_id)), e__exception_issue_override.issue_id, accurateCastOrNull(e.`mat_$exception_issue_id`, 'UUID')))SELECT agg.id AS id,issues.status AS status,@@ -2101,7 +2101,7 @@WHERE equals(person.team_id, 99999)GROUP BY person.idHAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(if(not(empty(e__exception_issue_override.issue_id)), e__exception_issue_override.issue_id, accurateCastOrNull(e.`mat_$exception_issue_id`, 'UUID'))), ifNull(notILike(toString(e__person.properties___email), '%@posthog.com%'), 1), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('explicit_redacted_timestamp', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), and(or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_types'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_values'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('databasenotfoundX')), 0), 0)), or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_types'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_values'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('clickhouse/client/execute.py')), 0), 0))))+ WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(if(not(empty(e__exception_issue_override.issue_id)), e__exception_issue_override.issue_id, accurateCastOrNull(e.`mat_$exception_issue_id`, 'UUID'))), ifNull(notILike(toString(e__person.properties___email), '%@posthog.com%'), 1), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('explicit_redacted_timestamp', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), and(or(ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_types`, ''), 'null')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_values`, ''), 'null')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('databasenotfoundX')), 0), 0)), or(ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_types`, ''), 'null')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_values`, ''), 'null')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('clickhouse/client/execute.py')), 0), 0))))GROUP BY id) AS aggINNER JOIN(SELECT system__error_tracking_issues.id AS id,diff --git a/products/error_tracking/backend/hogql_queries/test/__snapshots__/test_error_tracking_query_runner_v3.ambr b/products/error_tracking/backend/hogql_queries/test/__snapshots__/test_error_tracking_query_runner_v3.ambrindex bbd748c4c337..8f3d65de7b93 100644--- a/products/error_tracking/backend/hogql_queries/test/__snapshots__/test_error_tracking_query_runner_v3.ambr+++ b/products/error_tracking/backend/hogql_queries/test/__snapshots__/test_error_tracking_query_runner_v3.ambr@@ -172,7 +172,7 @@WHERE equals(person.team_id, 99999)GROUP BY person.idHAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('explicit_redacted_timestamp', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), and(or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_types'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_values'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('probs')), 0), 0)), or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_types'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_values'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('not')), 0), 0)), or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_types'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_values'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('found')), 0), 0))))+ WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('explicit_redacted_timestamp', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), and(or(ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_types`, ''), 'null')), lower('probs')), 0), 0), ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_values`, ''), 'null')), lower('probs')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('probs')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('probs')), 0), 0)), or(ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_types`, ''), 'null')), lower('not')), 0), 0), ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_values`, ''), 'null')), lower('not')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('not')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('not')), 0), 0)), or(ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_types`, ''), 'null')), lower('found')), 0), 0), ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_values`, ''), 'null')), lower('found')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('found')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('found')), 0), 0))))GROUP BY fp_hash) AS evINNER JOIN(SELECT cityHash64(error_tracking_fingerprint_issue_state.fingerprint) AS fp_hash,@@ -988,7 +988,7 @@WHERE equals(person.team_id, 99999)GROUP BY person.idHAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('explicit_redacted_timestamp', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_types'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_values'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('[email protected]')), 0), 0)))+ WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('explicit_redacted_timestamp', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), or(ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_types`, ''), 'null')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_values`, ''), 'null')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('[email protected]')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('[email protected]')), 0), 0)))GROUP BY fp_hash) AS evINNER JOIN(SELECT cityHash64(error_tracking_fingerprint_issue_state.fingerprint) AS fp_hash,@@ -1065,7 +1065,7 @@WHERE equals(person.team_id, 99999)GROUP BY person.idHAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')), ifNull(notILike(toString(e__person.properties___email), '%@posthog.com%'), 1), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_types'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_values'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('databasenot')), 0), 0)))+ WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')), ifNull(notILike(toString(e__person.properties___email), '%@posthog.com%'), 1), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), or(ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_types`, ''), 'null')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_values`, ''), 'null')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('databasenot')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('databasenot')), 0), 0)))GROUP BY fp_hash,bin_idx) AS evINNER JOIN@@ -1143,7 +1143,7 @@WHERE equals(person.team_id, 99999)GROUP BY person.idHAVING and(ifNull(equals(argMax(person.is_deleted, person.version), 0), 0), ifNull(less(argMax(toTimeZone(person.created_at, 'UTC'), person.version), plus(now64(6, 'UTC'), toIntervalDay(1))), 0))))) SETTINGS optimize_aggregation_in_order=1) AS e__person ON equals(if(not(empty(e__override.distinct_id)), e__override.person_id, e.person_id), e__person.id)- WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')), ifNull(notILike(toString(e__person.properties___email), '%@posthog.com%'), 1), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('explicit_redacted_timestamp', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), and(or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_types'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_values'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('databasenotfoundX')), 0), 0)), or(ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_types'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_values'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('clickhouse/client/execute.py')), 0), 0))))+ WHERE and(equals(e.team_id, 99999), equals(e.event, '$exception'), isNotNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_fingerprint'), ''), 'null'), '^"|"$', '')), ifNull(notILike(toString(e__person.properties___email), '%@posthog.com%'), 1), greaterOrEquals(e.timestamp, toDateTime(toDateTime64('explicit_redacted_timestamp', 6, 'UTC'), 'UTC')), lessOrEquals(e.timestamp, toDateTime(toDateTime64('today', 6, 'UTC'), 'UTC')), and(or(ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_types`, ''), 'null')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_values`, ''), 'null')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('databasenotfoundX')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('databasenotfoundX')), 0), 0)), or(ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_types`, ''), 'null')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(nullIf(nullIf(e.`mat_$exception_values`, ''), 'null')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_sources'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, '$exception_functions'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(e.properties, 'email'), ''), 'null'), '^"|"$', '')), lower('clickhouse/client/execute.py')), 0), 0), ifNull(greater(position(lower(e__person.properties___email), lower('clickhouse/client/execute.py')), 0), 0))))GROUP BY fp_hash,bin_idx) AS evINNER JOINdiff --git a/products/error_tracking/backend/hogql_queries/test/test_error_tracking_query_runner.py b/products/error_tracking/backend/hogql_queries/test/test_error_tracking_query_runner.pyindex 4faa802523b9..7c8c36dcb0b8 100644--- a/products/error_tracking/backend/hogql_queries/test/test_error_tracking_query_runner.py+++ b/products/error_tracking/backend/hogql_queries/test/test_error_tracking_query_runner.py@@ -123,8 +123,10 @@ class ErrorTrackingQueryRunnerTestsMixin:def setUpClass(cls) -> None:from ee.clickhouse.materialized_columns.columns import get_materialized_columns, materialize- if ("$exception_issue_id", "properties") not in get_materialized_columns("events"):- materialize("events", "$exception_issue_id", is_nullable=True)+ materialized_columns = get_materialized_columns("events")+ for property_name in ("$exception_issue_id", "$exception_types", "$exception_values"):+ if (property_name, "properties") not in materialized_columns:+ materialize("events", property_name, is_nullable=property_name == "$exception_issue_id")super(ErrorTrackingQueryRunnerTestsMixin, cls).setUpClass() # type: ignore[misc] # noqa: UP008def setUp(self):diff --git a/products/error_tracking/backend/hogql_queries/test/test_eval_scorers.py b/products/error_tracking/backend/hogql_queries/test/test_eval_scorers.pynew file mode 100644index 000000000000..e567f86526ff--- /dev/null+++ b/products/error_tracking/backend/hogql_queries/test/test_eval_scorers.py@@ -0,0 +1,144 @@+from __future__ import annotations++import json+from typing import Any++from ee.hogai.eval.sandboxed.error_tracking.scorers import (+ ERROR_TRACKING_WRITE_TOOLS,+ QUERY_ISSUE_EVENTS_TOOL,+ QUERY_ISSUES_LIST_TOOL,+ EventsToolUsed,+ IssueDrilldownOrder,+ IssuesListToolUsed,+ _recordings_text_has_results,+)+++def _raw_tool_log(calls: list[tuple[str, dict[str, Any], object]]) -> str:+ lines = []+ for index, (name, raw_input, raw_output) in enumerate(calls, start=1):+ call_id = f"call-{index}"+ lines.append(+ {+ "timestamp": f"2026-01-01T00:00:{index:02d}Z",+ "notification": {+ "method": "session/update",+ "params": {+ "update": {+ "sessionUpdate": "tool_call",+ "toolCallId": call_id,+ "title": name,+ "rawInput": raw_input,+ "_meta": {"claudeCode": {"toolName": name}},+ }+ },+ },+ }+ )+ lines.append(+ {+ "timestamp": f"2026-01-01T00:00:{index:02d}Z",+ "notification": {+ "method": "session/update",+ "params": {+ "update": {+ "sessionUpdate": "tool_call_update",+ "toolCallId": call_id,+ "status": "completed",+ "rawOutput": raw_output,+ }+ },+ },+ }+ )+ return "\n".join(json.dumps(line) for line in lines)+++def test_write_tool_blocklist_includes_enabled_rule_update_tools() -> None:+ assert {+ "error-tracking-grouping-rules-update",+ "error-tracking-suppression-rules-update",+ }.issubset(ERROR_TRACKING_WRITE_TOOLS)+++def test_recordings_text_has_results_accepts_toon_lists() -> None:+ assert _recordings_text_has_results(+ """+results[1]:+ - id: 019e4f6a-b3d7-7000-8a3a-f18fc1f9d80a+ session_id: session-1+hasMore: false+"""+ )+++def test_recordings_text_has_results_rejects_empty_toon_lists() -> None:+ assert not _recordings_text_has_results(+ """+results:+hasMore: false+"""+ )+++def test_events_tool_used_rejects_empty_results() -> None:+ score = EventsToolUsed()._run_eval_sync(+ {+ "raw_log": _raw_tool_log(+ [(QUERY_ISSUE_EVENTS_TOOL, {"issueId": "issue-1"}, {"results": [], "hasMore": False})]+ )+ }+ )++ assert score.score == 0.0+ assert score.metadata["reason"] == f"{QUERY_ISSUE_EVENTS_TOOL} returned no sampled events"+++def test_issues_list_tool_used_rejects_empty_results() -> None:+ score = IssuesListToolUsed()._run_eval_sync(+ {+ "raw_log": _raw_tool_log(+ [(QUERY_ISSUES_LIST_TOOL, {"searchQuery": "TypeError"}, {"results": [], "hasMore": False})]+ )+ }+ )++ assert score.score == 0.0+ assert score.metadata["reason"] == f"{QUERY_ISSUES_LIST_TOOL} returned no issues"+++def test_issue_drilldown_order_requires_non_empty_events() -> None:+ score = IssueDrilldownOrder()._run_eval_sync(+ {+ "raw_log": _raw_tool_log(+ [+ (QUERY_ISSUES_LIST_TOOL, {}, {"results": [{"id": "issue-1"}], "hasMore": False}),+ (QUERY_ISSUE_EVENTS_TOOL, {"issueId": "issue-1"}, {"results": [], "hasMore": False}),+ ]+ )+ },+ {"drilldown": {"requires_issue": False, "requires_events": True}},+ )++ assert score.score == 0.0+ assert score.metadata["reason"] == f"{QUERY_ISSUE_EVENTS_TOOL} returned no sampled events"+++def test_issue_drilldown_order_accepts_non_empty_events() -> None:+ score = IssueDrilldownOrder()._run_eval_sync(+ {+ "raw_log": _raw_tool_log(+ [+ (QUERY_ISSUES_LIST_TOOL, {}, {"results": [{"id": "issue-1"}], "hasMore": False}),+ (+ QUERY_ISSUE_EVENTS_TOOL,+ {"issueId": "issue-1"},+ {"results": [{"uuid": "event-1"}], "hasMore": False},+ ),+ ]+ )+ },+ {"drilldown": {"requires_issue": False, "requires_events": True}},+ )++ assert score.score == 1.0diff --git a/products/error_tracking/backend/hogql_queries/test/test_eval_seeders.py b/products/error_tracking/backend/hogql_queries/test/test_eval_seeders.pynew file mode 100644index 000000000000..b61651eac971--- /dev/null+++ b/products/error_tracking/backend/hogql_queries/test/test_eval_seeders.py@@ -0,0 +1,104 @@+from __future__ import annotations++from dataclasses import dataclass++from freezegun import freeze_time+from posthog.test.base import APIBaseTest, ClickhouseTestMixin++from parameterized import parameterized++from posthog.schema import DateRange, ErrorTrackingQuery++from posthog.clickhouse.client import sync_execute+from posthog.models.cohort.cohort import get_or_create_internal_test_users_cohort++from products.error_tracking.backend.hogql_queries.error_tracking_query_runner import ErrorTrackingQueryRunner++from ee.hogai.eval.sandboxed.error_tracking.seeders import _EVAL_DISTINCT_IDS, seed_error_tracking_issues+++@dataclass(frozen=True)+class _EvalSeedContext:+ team_id: int+ user_id: int+ repository: str+++class TestErrorTrackingEvalSeeders(ClickhouseTestMixin, APIBaseTest):+ @classmethod+ def setUpClass(cls) -> None:+ from ee.clickhouse.materialized_columns.columns import get_materialized_columns, materialize++ for property_name in ("$exception_types", "$exception_values"):+ if (property_name, "properties") not in get_materialized_columns("events"):+ materialize("events", property_name)+ super().setUpClass()++ @parameterized.expand(+ [+ ("v1", False),+ ("v3", True),+ ]+ )+ @freeze_time("2026-05-22T12:00:00Z")+ def test_error_tracking_seeded_events_survive_person_filters(self, _query_version: str, use_query_v3: bool) -> None:+ test_users_cohort = get_or_create_internal_test_users_cohort(+ self.team, initiating_user_email="[email protected]"+ )+ self.team.test_account_filters = [+ {"key": "id", "type": "cohort", "value": test_users_cohort.pk, "operator": "not_in"}+ ]+ self.team.save(update_fields=["test_account_filters"])++ seed = seed_error_tracking_issues(+ _EvalSeedContext(team_id=self.team.id, user_id=self.user.id, repository="posthog/hedgebox")+ )+ target_id = next(item["id"] for item in seed["lookup_issues"] if item["name"] == "Team invite rejected")++ person_rows = sync_execute(+ """+ SELECT distinct_id+ FROM person_distinct_id2+ WHERE team_id = %(team_id)s AND distinct_id IN %(distinct_ids)s+ """,+ {"team_id": self.team.id, "distinct_ids": list(_EVAL_DISTINCT_IDS)},+ )+ assert {row[0] for row in person_rows} == set(_EVAL_DISTINCT_IDS)+ issue_state_rows = sync_execute(+ """+ SELECT issue_id+ FROM error_tracking_fingerprint_issue_state+ WHERE team_id = %(team_id)s+ """,+ {"team_id": self.team.id},+ )+ assert {str(row[0]) for row in issue_state_rows} == {item["id"] for item in seed["lookup_issues"]}++ response = (+ ErrorTrackingQueryRunner(+ team=self.team,+ query=ErrorTrackingQuery(+ kind="ErrorTrackingQuery",+ dateRange=DateRange(),+ status="active",+ searchQuery="team-invite TypeError",+ filterTestAccounts=True,+ orderBy="occurrences",+ volumeResolution=1,+ useQueryV3=use_query_v3 or None,+ withAggregations=True,+ withFirstEvent=False,+ withLastEvent=False,+ ),+ )+ .calculate()+ .model_dump()+ )++ assert [(result["id"], result["function"], result["source"]) for result in response["results"]] == [+ (+ target_id,+ "submitInvite",+ "https://app.hedgebox.test/static/js/team-invite.js",+ )+ ]