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(skills): apply metadata policy during creation (#126166)

Georgiy Tarasoveae9ba09c513
diff --git a/products/skills/backend/api/skill_serializers.py b/products/skills/backend/api/skill_serializers.py
index 85786f296a81..e5eb24e02373 100644
--- a/products/skills/backend/api/skill_serializers.py
+++ b/products/skills/backend/api/skill_serializers.py
@@ -40,6 +40,7 @@ from .skill_services import (
compute_spec_problems,
normalize_skill_file_path,
resolve_owner_users,
+ resolve_skill_metadata,
resolve_skill_owners,
seed_skill_owner,
set_skill_owners,
@@ -817,6 +818,7 @@ class LLMSkillCreateSerializer(LLMSkillSerializer):
team = self.context["get_team"]()
files = validated_data.pop("files", None)
owner_uuids = validated_data.pop("owners", None)
+ validated_data["metadata"] = resolve_skill_metadata(validated_data.get("metadata"), None)
with transaction.atomic():
# `category` is read-only on the serializer, so it can never arrive in validated_data —
diff --git a/products/skills/backend/api/skill_services.py b/products/skills/backend/api/skill_services.py
index 13e69aee6d39..fcef406d1ed1 100644
--- a/products/skills/backend/api/skill_services.py
+++ b/products/skills/backend/api/skill_services.py
@@ -448,8 +448,8 @@ def _carry_forward(payload_value: Any, current_value: Any) -> Any:
HARNESS_OWNED_METADATA_KEYS = frozenset({"seeded_by", "canonical_hash", "source"})
-def _resolve_published_metadata(payload_value: dict[str, Any] | None, current_value: dict | None) -> dict[str, Any]:
- """Caller metadata for a new version, with the harness-owned provenance pinned to the current row."""
+def resolve_skill_metadata(payload_value: dict[str, Any] | None, current_value: dict | None) -> dict[str, Any]:
+ """Server-owned provenance comes only from the current persisted row."""
current = dict(current_value or {})
if payload_value is None:
return current
@@ -549,7 +549,7 @@ def publish_skill_version(
license=_carry_forward(license, current_latest.license),
compatibility=_carry_forward(compatibility, current_latest.compatibility),
allowed_tools=_carry_forward(allowed_tools, current_latest.allowed_tools),
- metadata=_resolve_published_metadata(metadata, current_latest.metadata),
+ metadata=resolve_skill_metadata(metadata, current_latest.metadata),
# Categorization is a property of the skill, not the version — carry it forward so editing
# a scout (or any categorized skill) doesn't drop it out of its tab.
category=current_latest.category,
@@ -676,7 +676,7 @@ def create_skill(
license=license or "",
compatibility=compatibility or "",
allowed_tools=allowed_tools or [],
- metadata=metadata or {},
+ metadata=resolve_skill_metadata(metadata, None),
version=1,
is_latest=True,
created_by=user,
diff --git a/products/skills/backend/api/test/test_skills.py b/products/skills/backend/api/test/test_skills.py
index b0836f27a7c7..47a29020d1b2 100644
--- a/products/skills/backend/api/test/test_skills.py
+++ b/products/skills/backend/api/test/test_skills.py
@@ -132,7 +132,13 @@ class TestLLMSkillAPI(APIBaseTest):
"license": "Apache-2.0",
"compatibility": "Requires Python 3.12+",
"allowed_tools": ["Bash", "Read"],
- "metadata": {"author": "test-org", "version": "1.0"},
+ "metadata": {
+ "author": "test-org",
+ "version": "1.0",
+ "seeded_by": "example-harness",
+ "canonical_hash": "example-hash",
+ "source": "example-source",
+ },
},
format="json",
)
@@ -143,6 +149,7 @@ class TestLLMSkillAPI(APIBaseTest):
assert data["compatibility"] == "Requires Python 3.12+"
assert data["allowed_tools"] == ["Bash", "Read"]
assert data["metadata"] == {"author": "test-org", "version": "1.0"}
+ assert LLMSkill.objects.get(team=self.team, name="full-skill").metadata == data["metadata"]
@parameterized.expand(
[
@@ -3500,12 +3507,18 @@ class TestSkillContentDigests(APIBaseTest):
# A jsonb column keeps object keys sorted by length and then bytewise, so these come
# back in neither the written order nor alphabetical order. The digest is stamped
# before the insert, so it has to describe bytes that do not depend on that order.
- metadata={"seeded_by": "review_hog", "source": "products/skills", "nested": {"z": "1", "a": "2"}},
+ metadata={
+ "seeded_by": "example-harness",
+ "canonical_hash": "example-hash",
+ "source": "example-source",
+ "nested": {"z": "1", "a": "2"},
+ },
files=[{"path": "references/guide.md", "content": "# Guía ✅"}],
)
# `create_skill` returns the stored row, which is what the store renders its SKILL.md from.
assert created.skill_md_sha256 == self._digest_of(created.rendered_skill_md())
+ assert created.metadata == {"nested": {"z": "1", "a": "2"}}
assert created.skill_md_size == len(created.rendered_skill_md().encode())
created_file = LLMSkillFile.objects.get(skill=created)
assert created_file.content_sha256 == self._digest_of("# Guía ✅")