: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
fix(livestream): resync bot definitions and add a drift check (#94380)
Lucas Ricoycfbfa61e01af
diff --git a/livestream/bot/definitions.json b/livestream/bot/definitions.jsonindex 2b0904427378..19622912a247 100644--- a/livestream/bot/definitions.json+++ b/livestream/bot/definitions.json@@ -204,38 +204,26 @@"traffic_type": "AI Agent"},{- "pattern": "desktop\\.hog\\.dev",+ "pattern": "desktop.hog.dev","name": "PostHog Desktop","category": "ai_assistant","traffic_type": "AI Agent"},{- "pattern": "mobile\\.hog\\.dev",+ "pattern": "mobile.hog.dev","name": "PostHog Mobile","category": "ai_assistant","traffic_type": "AI Agent"},{- "pattern": "agent\\.hog\\.dev",- "name": "PostHog Code Agent",+ "pattern": "agent.hog.dev",+ "name": "PostHog Desktop Agent","category": "ai_assistant","traffic_type": "AI Agent"},{- "pattern": "cloud\\.hog\\.dev",- "name": "PostHog Code Cloud",- "category": "ai_assistant",- "traffic_type": "AI Agent"- },- {- "pattern": "Claude/.*Electron",- "name": "Claude Desktop",- "category": "ai_assistant",- "traffic_type": "AI Agent"- },- {- "pattern": "ChatGPT/.*Electron",- "name": "ChatGPT Desktop",+ "pattern": "cloud.hog.dev",+ "name": "PostHog Desktop Cloud","category": "ai_assistant","traffic_type": "AI Agent"},@@ -1176,7 +1164,7 @@"traffic_type": "Automation"},{- "pattern": "\\) AppleWebKit/537\\.36 Chrome/",+ "pattern": ") AppleWebKit/537.36 Chrome/","name": "Malformed Chrome UA","category": "headless_browser","traffic_type": "Automation"@@ -1211,6 +1199,18 @@"category": "headless_browser","traffic_type": "Automation"},+ {+ "pattern": "SlimerJS",+ "name": "SlimerJS",+ "category": "headless_browser",+ "traffic_type": "Automation"+ },+ {+ "pattern": "wkhtmltopdf",+ "name": "wkhtmltopdf",+ "category": "headless_browser",+ "traffic_type": "Automation"+ },{"pattern": "ClueWeb-Crawler","name": "ClueWeb",@@ -1236,7 +1236,7 @@"traffic_type": "Bot"},{- "pattern": "archive\\.org_bot",+ "pattern": "archive.org_bot","name": "Internet Archive","category": "search_crawler","traffic_type": "Bot"@@ -1456,5 +1456,539 @@"name": "Discord","category": "social_crawler","traffic_type": "Bot"+ },+ {+ "pattern": "VioscaleAIBot",+ "name": "Vioscale AI",+ "category": "ai_crawler",+ "traffic_type": "AI Agent"+ },+ {+ "pattern": "Amzn-SearchBot",+ "name": "Amazon Search",+ "category": "ai_crawler",+ "traffic_type": "AI Agent"+ },+ {+ "pattern": "LeapwaveVIP",+ "name": "Leapwave",+ "category": "ai_crawler",+ "traffic_type": "AI Agent"+ },+ {+ "pattern": "docs-puller",+ "name": "docs-puller",+ "category": "ai_crawler",+ "traffic_type": "AI Agent"+ },+ {+ "pattern": "ToolchestBot",+ "name": "Toolchest",+ "category": "ai_crawler",+ "traffic_type": "AI Agent"+ },+ {+ "pattern": "scopy-docs-crawler",+ "name": "scopy docs crawler",+ "category": "ai_crawler",+ "traffic_type": "AI Agent"+ },+ {+ "pattern": "llms-txt-sync",+ "name": "llms-txt-sync",+ "category": "ai_crawler",+ "traffic_type": "AI Agent"+ },+ {+ "pattern": "PromptingBot",+ "name": "PromptingBot",+ "category": "ai_crawler",+ "traffic_type": "AI Agent"+ },+ {+ "pattern": "llm-code-docs-scraper",+ "name": "LLM code docs scraper",+ "category": "ai_crawler",+ "traffic_type": "AI Agent"+ },+ {+ "pattern": "whichapi-bot",+ "name": "WhichAPI",+ "category": "ai_crawler",+ "traffic_type": "AI Agent"+ },+ {+ "pattern": "Codex-YCB2B",+ "name": "Codex public research",+ "category": "ai_crawler",+ "traffic_type": "AI Agent"+ },+ {+ "pattern": "PostHog-BusinessKnowledge",+ "name": "PostHog BusinessKnowledge",+ "category": "ai_crawler",+ "traffic_type": "AI Agent"+ },+ {+ "pattern": "LlmsTxtBot",+ "name": "LlmsTxtBot",+ "category": "ai_crawler",+ "traffic_type": "AI Agent"+ },+ {+ "pattern": "every-api/",+ "name": "Every API",+ "category": "ai_crawler",+ "traffic_type": "AI Agent"+ },+ {+ "pattern": "RightAIChoiceBot",+ "name": "Right AI Choice",+ "category": "ai_crawler",+ "traffic_type": "AI Agent"+ },+ {+ "pattern": "redCactiBot",+ "name": "redCactiBot",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "BelleaireCrawler",+ "name": "BelleaireCrawler",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "PersimmonDesignResearch",+ "name": "Persimmon Design Research",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "barkReleasesBot",+ "name": "barkReleasesBot",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "prospector/",+ "name": "Prospector",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "YandexRenderResourcesBot",+ "name": "Yandex Render Resources",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "YandexAccessibilityBot",+ "name": "Yandex Accessibility",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "rewebbot",+ "name": "rewebbot",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "Querit-SearchBot",+ "name": "Querit Search",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "ImpactVibeDesignResearch",+ "name": "ImpactVibe Design Research",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "crawl-engine",+ "name": "crawl-engine",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "CompanyFeedServer",+ "name": "CompanyFeedServer",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "BranchenbuchBot",+ "name": "BranchenbuchBot",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "ReachBot",+ "name": "ReachBot",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "IbouBot",+ "name": "IbouBot",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "Hypeline",+ "name": "Hypeline",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "OldSchoolBot",+ "name": "OldSchoolBot",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "TutusooBot",+ "name": "TutusooBot",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "HiringRadarBot",+ "name": "HiringRadar",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "slopsearch-linux-crawler",+ "name": "slopsearch",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "ForgeYourPathAiJobCrawler",+ "name": "ForgeYourPath Job Crawler",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "OkaraBot",+ "name": "OkaraBot",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "DesignMD-Extract-Bot",+ "name": "DesignMD Extract",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "LyonlBot",+ "name": "LyonlBot",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "Sokjan Crawler",+ "name": "Sokjan Crawler",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "ScryBot",+ "name": "ScryBot",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "Heexybot",+ "name": "Heexybot",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "bne.es_bot",+ "name": "Biblioteca Nacional de Espa\u00f1a",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "Zetlyn",+ "name": "Zetlyn",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "algorand-platform-newspaper",+ "name": "Algorand platform newspaper",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "VendiditBot",+ "name": "Vendidit",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "Zee Company Intelligence",+ "name": "Zee Company Intelligence",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "NicheStuffBot",+ "name": "NicheStuff",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "Axiom-DocBot",+ "name": "Axiom DocBot",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "RealPressBot",+ "name": "RealPressBot",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "StraddleLibraryBot",+ "name": "Straddle Library",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "LurantaBot",+ "name": "Luranta",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "UnstenciledBot",+ "name": "Unstenciled",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "InloraBot",+ "name": "Inlora",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "EfficientRustCrawler",+ "name": "Efficient Rust Crawler",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "DatalenkCreatorResearch",+ "name": "Datalenk Creator Research",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "Wrzutka-Bot",+ "name": "Wrzutka",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "Polon/",+ "name": "Polon",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "Babel42Bot",+ "name": "Babel42",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "jscrawler",+ "name": "jscrawler",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "PolycoreSupabaseDetector",+ "name": "Polycore Supabase Detector",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "UnboundCompute-PublicSnapshot",+ "name": "UnboundCompute Public Snapshot",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "swissAItalentBot",+ "name": "swissAItalentBot",+ "category": "search_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "LaunchReadyCodeBot",+ "name": "LaunchReadyCodeBot",+ "category": "seo_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "PricingArchiveBot",+ "name": "PricingArchiveBot",+ "category": "seo_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "SEOMasterBot",+ "name": "SEOMasterBot",+ "category": "seo_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "CanICancelIt-LinkCheck",+ "name": "CanICancelIt LinkCheck",+ "category": "seo_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "serpstatbot",+ "name": "Serpstat",+ "category": "seo_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "StackPick",+ "name": "StackPick",+ "category": "seo_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "UXXRAYBot",+ "name": "UXXRAY",+ "category": "seo_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "NoFluffGraderBot",+ "name": "NoFluff Grader",+ "category": "seo_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "PagePilot-SiteAudit",+ "name": "PagePilot Site Audit",+ "category": "seo_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "double-ats-customer-discoverer",+ "name": "Double ATS Customer Discoverer",+ "category": "seo_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "BenchRankBot",+ "name": "BenchRank",+ "category": "seo_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "PagePeeker",+ "name": "PagePeeker",+ "category": "social_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "Synapse (bot",+ "name": "Synapse",+ "category": "social_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "Unfurlist",+ "name": "Unfurlist",+ "category": "social_crawler",+ "traffic_type": "Bot"+ },+ {+ "pattern": "heap.page source monitor",+ "name": "heap.page",+ "category": "monitoring",+ "traffic_type": "Bot"+ },+ {+ "pattern": "PulseWatch-Prober",+ "name": "PulseWatch",+ "category": "monitoring",+ "traffic_type": "Bot"+ },+ {+ "pattern": "Scryer/",+ "name": "Scryer",+ "category": "monitoring",+ "traffic_type": "Bot"+ },+ {+ "pattern": "UnusualAgentAudit",+ "name": "UnusualAgentAudit",+ "category": "monitoring",+ "traffic_type": "Bot"+ },+ {+ "pattern": "VersionWatchBot",+ "name": "VersionWatch",+ "category": "monitoring",+ "traffic_type": "Bot"+ },+ {+ "pattern": "a14y/",+ "name": "a14y",+ "category": "monitoring",+ "traffic_type": "Bot"+ },+ {+ "pattern": "UptimeLensBot",+ "name": "UptimeLens",+ "category": "monitoring",+ "traffic_type": "Bot"+ },+ {+ "pattern": "InterruptIndexBot",+ "name": "InterruptIndex",+ "category": "monitoring",+ "traffic_type": "Bot"+ },+ {+ "pattern": "CurbCutScanner",+ "name": "CurbCut Scanner",+ "category": "monitoring",+ "traffic_type": "Bot"+ },+ {+ "pattern": "VantageBot",+ "name": "VantageBot",+ "category": "monitoring",+ "traffic_type": "Bot"+ },+ {+ "pattern": "NimbusBlocklistSync",+ "name": "Nimbus Blocklist Sync",+ "category": "monitoring",+ "traffic_type": "Bot"+ },+ {+ "pattern": "MrAnandPortfolio",+ "name": "MrAnandPortfolio",+ "category": "http_client",+ "traffic_type": "Bot"}]diff --git a/livestream/bot/generate_definitions.py b/livestream/bot/generate_definitions.pyindex f940adf78815..9b4ea94d3d55 100644--- a/livestream/bot/generate_definitions.py+++ b/livestream/bot/generate_definitions.py@@ -6,11 +6,13 @@ and writes livestream/bot/definitions.json.Run from repo root:python livestream/bot/generate_definitions.py++posthog/test/repo_invariants/test_bot_definitions_go_sync.py fails when the committed JSON drifts+from this output, so the generator is the only supported way to change the file."""from __future__ import annotations-import reimport sysimport jsonfrom pathlib import Path@@ -20,26 +22,78 @@ sys.path.insert(0, str(repo_root))from products.web_analytics.backend.hogql_queries.bot_definitions import BOT_DEFINITIONS # noqa: E402-# ClickHouse evaluates the patterns as regexes, but the Go classifier matches them as-# Aho-Corasick substrings, where a backslash is just another character to look for. So a-# pattern like `bne\.es_bot` would never match the user agent it was written for.-_REGEX_ESCAPE = re.compile(r"\\(.)")+output_path = Path(__file__).parent / "definitions.json"+# A substring matcher cannot represent these RE2 constructs: quantifiers, character classes,+# groups, alternation, and anchors all change what matches where.+_REGEX_METACHARACTERS = frozenset("*+?{}[]()|^$")-def as_literal(pattern: str) -> str:- return _REGEX_ESCAPE.sub(r"\1", pattern)+def to_substring(pattern: str) -> str | None:+ """Return the literal substring the Go classifier should look for, or None to drop the pattern.-entries = [- {- "pattern": as_literal(pattern),- "name": bot_def.name,- "category": bot_def.category,- "traffic_type": bot_def.traffic_type,- }- for pattern, bot_def in BOT_DEFINITIONS.items()-]+ ClickHouse reads BOT_DEFINITIONS keys as RE2 regexes, but the Go livestream classifier matches+ them as Aho-Corasick substrings, where every byte is literal. A pattern that only escapes+ literal characters (`desktop\\.hog\\.dev`) has a substring form and is de-escaped. A pattern+ that relies on a regex feature (`Chrome/1\\d\\d.*`, `Safari/537\\.3$`) has none, so it is+ dropped rather than turned into a substring that can never match. A bare `.` is kept as a+ literal dot, which is what these patterns intend and what the substring engine matches anyway.+ """+ result: list[str] = []+ index = 0+ while index < len(pattern):+ char = pattern[index]+ if char == "\\":+ if index + 1 >= len(pattern):+ return None # a dangling backslash is not a literal we can reproduce+ following = pattern[index + 1]+ if following.isalnum():+ return None # \d \s \w \b \1 — a class, anchor, or backreference+ result.append(following) # \. \) \/ … — the escaped literal character+ index += 2+ continue+ if char in _REGEX_METACHARACTERS:+ return None+ result.append(char)+ index += 1+ return "".join(result)-output_path = Path(__file__).parent / "definitions.json"-output_path.write_text(json.dumps(entries, indent=2) + "\n")-sys.stdout.write(f"Generated {output_path} with {len(entries)} bot definitions\n")++def build_entries() -> tuple[list[dict[str, str]], list[str]]:+ """Return the (entries, dropped patterns) derived from BOT_DEFINITIONS."""+ entries: list[dict[str, str]] = []+ dropped: list[str] = []+ for pattern, bot_def in BOT_DEFINITIONS.items():+ literal = to_substring(pattern)+ if literal is None:+ dropped.append(pattern)+ continue+ entries.append(+ {+ "pattern": literal,+ "name": bot_def.name,+ "category": bot_def.category,+ "traffic_type": bot_def.traffic_type,+ }+ )+ return entries, dropped+++def render() -> str:+ """The exact file contents the generator writes, so a test can compare without writing."""+ entries, _dropped = build_entries()+ return json.dumps(entries, indent=2) + "\n"+++def main() -> None:+ entries, dropped = build_entries()+ output_path.write_text(render())+ sys.stdout.write(f"Generated {output_path} with {len(entries)} bot definitions\n")+ if dropped:+ sys.stdout.write(f"Dropped {len(dropped)} regex-only patterns the substring matcher cannot represent:\n")+ for pattern in dropped:+ sys.stdout.write(f" {pattern}\n")+++if __name__ == "__main__":+ main()diff --git a/posthog/test/repo_invariants/test_bot_definitions_go_sync.py b/posthog/test/repo_invariants/test_bot_definitions_go_sync.pynew file mode 100644index 000000000000..3388aed9a359--- /dev/null+++ b/posthog/test/repo_invariants/test_bot_definitions_go_sync.py@@ -0,0 +1,46 @@+import importlib.util+from pathlib import Path++import pytest++REPO_ROOT = Path(__file__).resolve().parents[3]+GENERATOR_PATH = REPO_ROOT / "livestream" / "bot" / "generate_definitions.py"+DEFINITIONS_PATH = REPO_ROOT / "livestream" / "bot" / "definitions.json"+++def _load_generator():+ spec = importlib.util.spec_from_file_location("livestream_bot_generate_definitions", GENERATOR_PATH)+ assert spec is not None and spec.loader is not None+ module = importlib.util.module_from_spec(spec)+ spec.loader.exec_module(module)+ return module+++def test_go_definitions_match_generated_output():+ generator = _load_generator()+ expected = generator.render()+ actual = DEFINITIONS_PATH.read_text()+ assert actual == expected, (+ "livestream/bot/definitions.json is out of sync with BOT_DEFINITIONS. "+ "Run: python livestream/bot/generate_definitions.py"+ )+++ "pattern,expected",+ [+ # Plain tokens and escaped literals have a substring form the Go matcher can use.+ ("GPTBot", "GPTBot"),+ (r"desktop\.hog\.dev", "desktop.hog.dev"),+ (r"\) AppleWebKit/537\.36 Chrome/", ") AppleWebKit/537.36 Chrome/"),+ ("bne.es_bot", "bne.es_bot"), # a bare dot stays a literal dot+ # Regex features have no substring form, so the pattern is dropped rather than mangled.+ (r"Chrome/1\d\d.*Edge/1[2-8]\.", None), # character classes and a quantifier+ (r"Safari/537\.3$", None), # an anchor+ (r"^Mozilla/5\.0$", None), # anchors+ (r"(^\s|\s$)", None), # a group with alternation+ (r"Claude/.*Electron", None), # a quantifier+ ],+)+def test_to_substring_keeps_literals_and_drops_regex(pattern: str, expected: str | None):+ assert _load_generator().to_substring(pattern) == expected