: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(signals): keep scout scratchpad writes on unverifiable run_id (#65077)
posthog[bot]58dd43da5772
diff --git a/products/signals/backend/scout_harness/serializers.py b/products/signals/backend/scout_harness/serializers.pyindex 67ca3bf90180..5aed85473ea5 100644--- a/products/signals/backend/scout_harness/serializers.py+++ b/products/signals/backend/scout_harness/serializers.py@@ -319,7 +319,8 @@ class RememberRequestSerializer(serializers.Serializer):allow_null=True,help_text=("Run that authored this memory; persisted as `created_by_run_id` for lineage. "- "Must reference a run on this same project — cross-project run UUIDs are rejected."+ "Best-effort — a `run_id` that isn't a run on this project is dropped (lineage left "+ "null), not rejected, so the memory write is never lost."),)diff --git a/products/signals/backend/scout_harness/views.py b/products/signals/backend/scout_harness/views.pyindex d6423e03ca75..a5106c20bf31 100644--- a/products/signals/backend/scout_harness/views.py+++ b/products/signals/backend/scout_harness/views.py@@ -530,16 +530,17 @@ class SignalScratchpadViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):def create(self, request: Request, *args, **kwargs) -> Response:data = request.validated_datarun_id = data.get("run_id") or None- # Verify the run is on this project before accepting cross-team lineage:- # the agent's MCP token already pins us to a team, but `run_id` is a free- # field on the request body and a foreign-team UUID would otherwise create- # a cross-team `created_by_run_id` reference on this team's memory row.+ # `run_id` only stamps best-effort `created_by_run_id` lineage — a memory write must+ # never be lost over it. So an unverifiable `run_id` is dropped (lineage left null),+ # not rejected. We still won't stamp a `run_id` that isn't a run on this project: the+ # agent's MCP token pins us to a team, but `run_id` is a free field on the body and a+ # foreign-team UUID would otherwise create a cross-team `created_by_run_id` reference.# Bad UUIDs are blocked by `UUIDField` in the serializer.if (run_id is not Noneand not SignalScoutRun.objects.filter(id=run_id, team_id=_canonical_team_id(self)).exists()):- raise exceptions.ValidationError({"run_id": "run_id does not reference a run on this project"})+ run_id = Nonetry:entry = remember(team_id=_canonical_team_id(self),diff --git a/products/signals/backend/test/test_scout_harness_api.py b/products/signals/backend/test/test_scout_harness_api.pyindex 4294dfe40320..29402254cf2b 100644--- a/products/signals/backend/test/test_scout_harness_api.py+++ b/products/signals/backend/test/test_scout_harness_api.py@@ -551,10 +551,10 @@ class TestScoutHarnessScratchpadAPI(APIBaseTest):row = SignalScratchpad.objects.get(team=self.team, key="k1")assert str(row.created_by_run_id) == str(run.id)- def test_remember_rejects_run_id_from_another_team(self) -> None:+ def test_remember_drops_run_id_from_another_team(self) -> None:# A run UUID from another team must not create cross-team lineage on this- # team's memory row — the agent's MCP token is team-scoped, but `run_id`- # is a free body field and previously had no validation.+ # team's memory row — but lineage is best-effort, so the write still lands+ # with `created_by_run_id` left null rather than being rejected.other = Team.objects.create(organization=self.organization, name="Other")other_run = _make_run(other)response = self.client.post(@@ -562,20 +562,21 @@ class TestScoutHarnessScratchpadAPI(APIBaseTest):data={"key": "k1", "content": "v", "run_id": str(other_run.id)},format="json",)- assert response.status_code == status.HTTP_400_BAD_REQUEST- assert response.json().get("attr") == "run_id"- assert not SignalScratchpad.objects.filter(team=self.team, key="k1").exists()+ assert response.status_code == status.HTTP_200_OK+ row = SignalScratchpad.objects.get(team=self.team, key="k1")+ assert row.created_by_run_id is None- def test_remember_rejects_unknown_run_id(self) -> None:- # A well-formed UUID that doesn't reference any run row should also bounce —- # don't let a typo silently produce orphan lineage on the memory table.+ def test_remember_drops_unknown_run_id(self) -> None:+ # A well-formed UUID that doesn't reference any run row is dropped (no orphan+ # lineage), but the memory write itself must never be lost over it.response = self.client.post(self._list_url(),data={"key": "k1", "content": "v", "run_id": "00000000-0000-0000-0000-000000000000"},format="json",)- assert response.status_code == status.HTTP_400_BAD_REQUEST- assert response.json().get("attr") == "run_id"+ assert response.status_code == status.HTTP_200_OK+ row = SignalScratchpad.objects.get(team=self.team, key="k1")+ assert row.created_by_run_id is Nonedef test_remember_rejects_malformed_run_id(self) -> None:# UUIDField in the serializer rejects non-UUID strings before the view runs.diff --git a/products/signals/frontend/generated/api.schemas.ts b/products/signals/frontend/generated/api.schemas.tsindex ec7f120d7ca5..1525dea14e96 100644--- a/products/signals/frontend/generated/api.schemas.ts+++ b/products/signals/frontend/generated/api.schemas.ts@@ -1216,7 +1216,7 @@ export interface RememberRequestApi {*/content: string/**- * Run that authored this memory; persisted as `created_by_run_id` for lineage. Must reference a run on this same project — cross-project run UUIDs are rejected.+ * Run that authored this memory; persisted as `created_by_run_id` for lineage. Best-effort — a `run_id` that isn't a run on this project is dropped (lineage left null), not rejected, so the memory write is never lost.* @nullable*/run_id?: string | nulldiff --git a/products/signals/frontend/generated/api.zod.ts b/products/signals/frontend/generated/api.zod.tsindex 90a547a06497..58ec22a7d4ae 100644--- a/products/signals/frontend/generated/api.zod.ts+++ b/products/signals/frontend/generated/api.zod.ts@@ -318,7 +318,7 @@ export const SignalsScoutScratchpadRememberBody = /* @__PURE__ */ zod.uuid().nullish().describe(- 'Run that authored this memory; persisted as `created_by_run_id` for lineage. Must reference a run on this same project — cross-project run UUIDs are rejected.'+ "Run that authored this memory; persisted as `created_by_run_id` for lineage. Best-effort — a `run_id` that isn't a run on this project is dropped (lineage left null), not rejected, so the memory write is never lost."),}).describe('Request body for `remember`.')diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex c32113c6b887..e87b87933a24 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -44538,7 +44538,7 @@ export namespace Schemas {*/content: string;/**- * Run that authored this memory; persisted as `created_by_run_id` for lineage. Must reference a run on this same project — cross-project run UUIDs are rejected.+ * Run that authored this memory; persisted as `created_by_run_id` for lineage. Best-effort — a `run_id` that isn't a run on this project is dropped (lineage left null), not rejected, so the memory write is never lost.* @nullable*/run_id?: string | null;diff --git a/services/mcp/src/generated/signals/api.ts b/services/mcp/src/generated/signals/api.tsindex 176a03a3df47..e0e72710bb68 100644--- a/services/mcp/src/generated/signals/api.ts+++ b/services/mcp/src/generated/signals/api.ts@@ -590,7 +590,7 @@ export const SignalsScoutScratchpadRememberBody = /* @__PURE__ */ zod.uuid().nullish().describe(- 'Run that authored this memory; persisted as `created_by_run_id` for lineage. Must reference a run on this same project — cross-project run UUIDs are rejected.'+ "Run that authored this memory; persisted as `created_by_run_id` for lineage. Best-effort — a `run_id` that isn't a run on this project is dropped (lineage left null), not rejected, so the memory write is never lost."),}).describe('Request body for `remember`.')diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/signals-scout-scratchpad-remember.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/signals-scout-scratchpad-remember.jsonindex ad5ff7f8338c..13b5087dbbb0 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/signals-scout-scratchpad-remember.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/signals-scout-scratchpad-remember.json@@ -23,7 +23,7 @@"type": "null"}],- "description": "Run that authored this memory; persisted as `created_by_run_id` for lineage. Must reference a run on this same project — cross-project run UUIDs are rejected."+ "description": "Run that authored this memory; persisted as `created_by_run_id` for lineage. Best-effort — a `run_id` that isn't a run on this project is dropped (lineage left null), not rejected, so the memory write is never lost."}},"required": ["key", "content"],