: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(skills): page skill-get body by default so body_next_offset is truthful (#71973)
posthog[bot]2f68a97dfcec
diff --git a/products/skills/backend/api/skill_serializers.py b/products/skills/backend/api/skill_serializers.pyindex 423f7aded23d..67ee4ac09f38 100644--- a/products/skills/backend/api/skill_serializers.py+++ b/products/skills/backend/api/skill_serializers.py@@ -25,6 +25,14 @@ _LIST_EXCLUDED_FIELDS = ("body", "body_total_length", "body_next_offset", "filesMAX_SKILL_BODY_BYTES = 1_000_000MAX_SKILL_FILE_BYTES = 1_000_000MAX_SKILL_FILE_COUNT = 50+# skill-get returns the whole body when the caller doesn't page, but a large body is+# truncated by the MCP transport before it reaches an agent — and an un-paged response+# reported body_next_offset as null, so the agent had no valid offset to continue from and+# would treat a cut-off body as complete. get_by_name caps the first page at this length so+# body_next_offset is always a real continuation offset the caller can page from until it is+# null, never a guess. Sized to sit under observed transport truncation with room for the+# response envelope (outline, file manifest, metadata).+DEFAULT_BODY_PAGE_LENGTH = 8000SKILL_NAME_PATTERN = re.compile(r"^[a-z0-9]([a-z0-9-]*[a-z0-9])?$")diff --git a/products/skills/backend/api/skills.py b/products/skills/backend/api/skills.pyindex 0f99a33a01bf..69fd0e2ecca3 100644--- a/products/skills/backend/api/skills.py+++ b/products/skills/backend/api/skills.py@@ -43,6 +43,7 @@ from ..marketplace.credentials import (from ..marketplace.packaging import SkillImportError, build_skill_zip, parse_skill_zip, validate_for_exportfrom ..models.skills import LLMSkill, LLMSkillFilefrom .skill_serializers import (+ DEFAULT_BODY_PAGE_LENGTH,MAX_SKILL_FILE_BYTES,LLMSkillBodyFetchQuerySerializer,LLMSkillCreateSerializer,@@ -343,11 +344,17 @@ class LLMSkillViewSet(if skill is None:return self._skill_not_found_response(skill_name)+ # Cap the first page when the caller doesn't page explicitly, so body_next_offset is a+ # valid continuation offset even when the full body would be truncated in transit.+ body_length = cast(int | None, version_params.get("body_length"))+ if body_length is None:+ body_length = DEFAULT_BODY_PAGE_LENGTH+return Response(self._serialize_skill(skill,body_offset=cast(int | None, version_params.get("body_offset")),- body_length=cast(int | None, version_params.get("body_length")),+ body_length=body_length,))diff --git a/products/skills/backend/api/test/test_skills.py b/products/skills/backend/api/test/test_skills.pyindex f1f38e92ee80..ea2dafbebb73 100644--- a/products/skills/backend/api/test/test_skills.py+++ b/products/skills/backend/api/test/test_skills.py@@ -7,6 +7,7 @@ from rest_framework import statusfrom posthog.models import User+from ...api.skill_serializers import DEFAULT_BODY_PAGE_LENGTHfrom ...api.skill_services import MAX_SKILL_FILE_COUNTfrom ...models.skills import LLMSkill, LLMSkillFile@@ -347,16 +348,28 @@ class TestLLMSkillAPI(APIBaseTest):assert data["body"] == "# Fetch me body"assert "files" in data- def test_get_skill_by_name_reports_body_total_length_without_paging(self):+ def test_get_skill_by_name_returns_short_body_whole_without_paging(self):self.create_skill(name="whole-body", body="0123456789")data = self.client.get(self._url("name/whole-body")).json()assert data["body"] == "0123456789"assert data["body_total_length"] == 10- # Without paging params the whole body is returned, so there is nothing left to fetch.+ # A body under the default page cap fits in the first page, so nothing is left to fetch.assert data["body_next_offset"] is None+ def test_get_skill_by_name_caps_first_page_and_reports_next_offset_without_paging(self):+ # A body larger than the default page cap would be truncated in transit; the un-paged+ # response must hand back a valid continuation offset rather than claiming completeness.+ body = "x" * (DEFAULT_BODY_PAGE_LENGTH + 50)+ self.create_skill(name="huge-body", body=body)++ data = self.client.get(self._url("name/huge-body")).json()++ assert data["body"] == body[:DEFAULT_BODY_PAGE_LENGTH]+ assert data["body_total_length"] == DEFAULT_BODY_PAGE_LENGTH + 50+ assert data["body_next_offset"] == DEFAULT_BODY_PAGE_LENGTH+@parameterized.expand([# label, query, expected_body, expected_next_offset