Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(signals): skip bytecode caches when bundling canonical skill files (#107654)

Alessandro Pogliaghid18cda526f4b
diff --git a/products/review_hog/backend/reviewer/lazy_seed.py b/products/review_hog/backend/reviewer/lazy_seed.py
index ce62d6c3dec0..361e1ea16a2a 100644
--- a/products/review_hog/backend/reviewer/lazy_seed.py
+++ b/products/review_hog/backend/reviewer/lazy_seed.py
@@ -53,6 +53,7 @@ _SKILLS_DIR = Path(__file__).resolve().parent.parent.parent / "skills"
_FRONTMATTER_RE = re.compile(r"^---\s*\n(.*?)\n---\s*\n", re.DOTALL)
# Bundled subdirs walked recursively, in lockstep with the scout sync's `_ALLOWED_BUNDLE_SUBDIRS`.
_ALLOWED_BUNDLE_SUBDIRS = ("references", "scripts")
+_BYTECODE_CACHE_DIR = "__pycache__"
# Per-skill contract limits, mirroring `products/skills/backend/api/skill_services.py` (the seed
# bypasses the service layer, so they're checked at parse time).
_MAX_SKILL_BODY_BYTES = 1_000_000
@@ -165,7 +166,7 @@ def _parse_canonical_skill(skill_dir: Path, *, prefix: str) -> CanonicalSkill:
if not subdir.is_dir():
continue
for file_path in sorted(subdir.rglob("*")):
- if not file_path.is_file():
+ if not file_path.is_file() or _BYTECODE_CACHE_DIR in file_path.relative_to(subdir).parts:
continue
rel_path = file_path.relative_to(skill_dir).as_posix()
if len(rel_path) > _MAX_SKILL_FILE_PATH_LENGTH:
diff --git a/products/review_hog/backend/tests/test_authoring_skill.py b/products/review_hog/backend/tests/test_authoring_skill.py
index a0d94f733b73..88d29eb45c82 100644
--- a/products/review_hog/backend/tests/test_authoring_skill.py
+++ b/products/review_hog/backend/tests/test_authoring_skill.py
@@ -1,3 +1,5 @@
+from pathlib import Path
+
from posthog.test.base import BaseTest
from products.review_hog.backend.reviewer.lazy_seed import (
@@ -5,7 +7,10 @@ from products.review_hog.backend.reviewer.lazy_seed import (
REVIEW_HOG_SKILL_CATEGORY,
discover_canonical_authoring,
)
-from products.review_hog.backend.reviewer.skill_loader import REVIEW_HOG_AUTHORING_SKILL_NAME
+from products.review_hog.backend.reviewer.skill_loader import (
+ REVIEW_HOG_AUTHORING_PREFIX,
+ REVIEW_HOG_AUTHORING_SKILL_NAME,
+)
from products.review_hog.backend.temporal.activities import _sync_review_skills
from products.skills.backend.models.skills import LLMSkill
@@ -17,6 +22,20 @@ def test_discover_finds_the_authoring_skill() -> None:
assert {s.name for s in discover_canonical_authoring()} == {REVIEW_HOG_AUTHORING_SKILL_NAME}
+def test_discover_skips_bytecode_caches_under_bundled_scripts(tmp_path: Path) -> None:
+ skill_dir = tmp_path / f"{REVIEW_HOG_AUTHORING_PREFIX}-guide"
+ (skill_dir / "scripts" / "__pycache__").mkdir(parents=True)
+ (skill_dir / "SKILL.md").write_text(
+ f"---\nname: {REVIEW_HOG_AUTHORING_PREFIX}-guide\ndescription: guide\n---\n# Guide\n", encoding="utf-8"
+ )
+ (skill_dir / "scripts" / "check.py").write_text("print('hi')\n", encoding="utf-8")
+ (skill_dir / "scripts" / "__pycache__" / "check.cpython-313.pyc").write_bytes(b"\x00\xff\x0d\x0a")
+
+ (skill,) = discover_canonical_authoring(skills_dir=tmp_path)
+
+ assert [f.path for f in skill.files] == ["scripts/check.py"]
+
+
class TestAuthoringSkillSync(BaseTest):
def test_run_sync_seeds_the_authoring_skill(self) -> None:
# The run path is the recurring reconciliation moment — dropping the authoring sync from it
diff --git a/products/signals/backend/scout_harness/lazy_seed.py b/products/signals/backend/scout_harness/lazy_seed.py
index 077b6db9cba2..7c23a4e31255 100644
--- a/products/signals/backend/scout_harness/lazy_seed.py
+++ b/products/signals/backend/scout_harness/lazy_seed.py
@@ -67,6 +67,7 @@ _FRONTMATTER_RE = re.compile(r"^---\s*\n(.*?)\n---\s*\n", re.DOTALL)
# (or vice versa). The agentskills.io spec also defines `assets/`; if we ever want to
# support binary attachments, add to both consumers in the same change.
_ALLOWED_BUNDLE_SUBDIRS = ("references", "scripts")
+_BYTECODE_CACHE_DIR = "__pycache__"
# Mirror the per-skill contract limits enforced by the REST API at
# `products/skills/backend/api/skill_services.py` (`MAX_SKILL_*`). The seed
# bypasses the service layer (no "create from scratch with files" helper exists), so
@@ -432,7 +433,7 @@ def _parse_canonical_skill(skill_dir: Path, *, is_scout: bool = True) -> Canonic
if not subdir.is_dir():
continue
for file_path in sorted(subdir.rglob("*")):
- if not file_path.is_file():
+ if not file_path.is_file() or _BYTECODE_CACHE_DIR in file_path.relative_to(subdir).parts:
continue
rel_path = file_path.relative_to(skill_dir).as_posix()
if len(rel_path) > _MAX_SKILL_FILE_PATH_LENGTH:
diff --git a/products/signals/backend/test/test_scout_harness_lazy_seed.py b/products/signals/backend/test/test_scout_harness_lazy_seed.py
index 32de7556692c..71dcdeacd7a7 100644
--- a/products/signals/backend/test/test_scout_harness_lazy_seed.py
+++ b/products/signals/backend/test/test_scout_harness_lazy_seed.py
@@ -468,11 +468,15 @@ class TestDiscoverCanonicalSkills:
"extras/notes.txt": "ignored\n",
},
)
+ bytecode = tmp_path / "signals-scout-bar" / "scripts" / "__pycache__" / "check.cpython-313.pyc"
+ bytecode.parent.mkdir()
+ bytecode.write_bytes(b"\x00\xff\x0d\x0a")
skills = discover_canonical_skills(tmp_path)
files_by_path = {f.path: f for f in skills[0].files}
assert "references/playbook.md" in files_by_path
assert files_by_path["references/playbook.md"].content == "# Playbook\n"
assert "scripts/check.py" in files_by_path
+ assert not any(path.startswith("scripts/__pycache__/") for path in files_by_path)
# Files outside the allowlist must not leak in — guards the consumer divergence.
assert "assets/template.txt" not in files_by_path
assert "extras/notes.txt" not in files_by_path