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.

feat(signals): name custom scout skill authors in the run prompt (#71912)

Andrew Maguirea72de5600c1d
diff --git a/products/signals/backend/scout_harness/AGENTS.md b/products/signals/backend/scout_harness/AGENTS.md
index e47be758c928..73e0c2906278 100644
--- a/products/signals/backend/scout_harness/AGENTS.md
+++ b/products/signals/backend/scout_harness/AGENTS.md
@@ -51,12 +51,25 @@ it is exercised via the `run_signals_scout` management command (see `../manageme
pristine canonical scout never sees
it — applying such a suggestion would mark the seeded row diverged and cut it off from
upstream sync; canonical-skill defects route upstream via the operational-friction
- (`agent-feedback`) section instead.
+ (`agent-feedback`) section instead. A _report-channel_ custom scout's run identity also
+ carries a **skill authors** line (`LoadedSkill.authors`, rendered by `_skill_authors_line`):
+ creator + recent editors resolved server-side from the skill's version rows, which the
+ escalation guidance points `suggested_reviewers` at (creator first, via `scout-members-list`) —
+ without it a scout only sees its pinned version's `created_by`, i.e. the last editor,
+ and would route ownership to whoever most recently touched the skill. The line is gated on
+ the report channel: a signal-channel scout has no `suggested_reviewers` field, so member
+ names/emails (PII) must not reach its prompt.
- `skill_loader.py`
Resolves `signals-scout-*` skills from the team's `LLMSkill` rows. Defines
- `SIGNALS_SCOUT_SKILL_PREFIX` and `LoadedSkill` (body + version + allowed_tools + origin), plus
+ `SIGNALS_SCOUT_SKILL_PREFIX` and `LoadedSkill` (body + version + allowed_tools + origin + authors), plus
`REPORT_CHANNEL_TOOLS` / `skill_uses_report_channel` — the shared report-channel opt-in
predicate the runner (scope posture) and prompt builder (persona fork) both resolve from.
+ `resolve_skill_authors` aggregates distinct non-null `created_by` across a skill's version rows
+ (creator = earliest first-authored, then editors by last-edit recency, capped), restricted to
+ `team.all_users_with_access()` so a revoked author's profile stops flowing into a privileged
+ prompt. Resolution is opt-in via `load_skill_for_run(..., include_authors=True)` — only the
+ runner's prompt-building path pays for it; the report-authorization gate in `views.py` loads
+ the skill per report write just to check `allowed_tools` and skips it.
- `lazy_seed.py`
Canonical skill sync. Reads `products/signals/skills/signals-scout-*/` from disk and
reconciles them against the team's `LLMSkill` rows: creates missing rows, updates
diff --git a/products/signals/backend/scout_harness/prompt.py b/products/signals/backend/scout_harness/prompt.py
index f2a37ef2c3b9..2655223008b7 100644
--- a/products/signals/backend/scout_harness/prompt.py
+++ b/products/signals/backend/scout_harness/prompt.py
@@ -5,7 +5,7 @@ from datetime import datetime
from pydantic import BaseModel, Field
-from products.signals.backend.scout_harness.skill_loader import LoadedSkill, skill_uses_report_channel
+from products.signals.backend.scout_harness.skill_loader import LoadedSkill, SkillAuthor, skill_uses_report_channel
class SignalScoutRunSummary(BaseModel):
@@ -193,7 +193,9 @@ This is the single highest-leverage field you set. `suggested_reviewers` (a list
- **No owner in your evidence? List the members.** When the owner isn't already named in what you gathered, call `scout-members-list` to get this project's members — each row carries the member's `email`, name, and resolved `github_login` (pass `search` to narrow a big project). Match the owner by email/name and use their `github_login`; a member whose `github_login` is null can't be routed to at all, so pick a different owner or leave the field empty. The org-scoped `org-member-get-github-login` / `org-members-list` tools are not available in a scout run — this is the in-run lookup path.
- **Set `priority` + `priority_explanation`** when the issue is concrete and you can justify the urgency — autostart needs a priority to consider a draft PR.
- **Set `repository`** (`owner/repo`) when you know where a fix would land — pass it explicitly rather than leaving it to slower free-form selection. Pass the `NO_REPO` sentinel for a report with no code fix.
-- A report that surfaces but routes nowhere is a half-finished report. The whole point of authoring directly is to deliver something actionable end to end."""
+- A report that surfaces but routes nowhere is a half-finished report. The whole point of authoring directly is to deliver something actionable end to end.
+
+If your skill body defines its own reviewer routing (a named owner, a team convention, per-topic rules), follow that instead — the skill body owns routing, and the heuristics above are for when it says nothing."""
_WRITING_REPORT = """# Writing the report
@@ -256,9 +258,9 @@ SELF_IMPROVEMENT_REPORT_TITLE_PREFIX = "Scout self-improvement:"
# tools they already hold. Two variants because an emit-only scout must never be pointed at
# `edit_report` (the endpoint fails closed on the exact tool); a signal-channel custom scout gets
# neither — it has no report tools at all, so the scratchpad stays its only self-improvement record.
-_SELF_IMPROVEMENT_ESCALATE_BOTH = f"""- **Recurring or material? File an inbox report too.** A scratchpad entry is only seen when the owner goes looking; a report is routed to them. When a suggestion re-confirms across runs (your `improve:` entry has accumulated several dated lines), or this run's failure was material (it wasted most of your budget, or steered you into emitting something wrong), surface it with the same report tools you use for findings. If the `improve:` entry already carries a `report_id`, `append_note` the fresh evidence onto that report with `scout-edit-report`; otherwise author one with `scout-emit-report` — title `{SELF_IMPROVEMENT_REPORT_TITLE_PREFIX} <your-skill-name> – <topic>`, the suggested skill change plus the evidence in the summary, `actionability` = `requires_human_input` (applying it is a skill edit by your team), `repository` = the `NO_REPO` sentinel (the fix is a skill edit, not code), `suggested_reviewers` = whoever owns this scout when you know — and stash the returned `report_id` in the `improve:` entry so later runs update that report instead of authoring a duplicate. It lands in the inbox like any other report; your team decides whether to apply it."""
+_SELF_IMPROVEMENT_ESCALATE_BOTH = f"""- **Recurring or material? File an inbox report too.** A scratchpad entry is only seen when the owner goes looking; a report is routed to them. When a suggestion re-confirms across runs (your `improve:` entry has accumulated several dated lines), or this run's failure was material (it wasted most of your budget, or steered you into emitting something wrong), surface it with the same report tools you use for findings. If the `improve:` entry already carries a `report_id`, `append_note` the fresh evidence onto that report with `scout-edit-report`; otherwise author one with `scout-emit-report` — title `{SELF_IMPROVEMENT_REPORT_TITLE_PREFIX} <your-skill-name> – <topic>`, the suggested skill change plus the evidence in the summary, `actionability` = `requires_human_input` (applying it is a skill edit by your team), `repository` = the `NO_REPO` sentinel (the fix is a skill edit, not code), `suggested_reviewers` = the skill authors listed under *Your run identity*, creator first (match each to a `scout-members-list` row; skip anyone who doesn't resolve, and leave it empty only when no author resolves at all — and if your skill body defines its own reviewer routing, follow the skill instead) — and stash the returned `report_id` in the `improve:` entry so later runs update that report instead of authoring a duplicate. It lands in the inbox like any other report; your team decides whether to apply it."""
-_SELF_IMPROVEMENT_ESCALATE_EMIT_ONLY = f"""- **Recurring or material? File an inbox report too.** A scratchpad entry is only seen when the owner goes looking; a report is routed to them. When a suggestion re-confirms across runs (your `improve:` entry has accumulated several dated lines), or this run's failure was material (it wasted most of your budget, or steered you into emitting something wrong), surface it with `scout-emit-report` — title `{SELF_IMPROVEMENT_REPORT_TITLE_PREFIX} <your-skill-name> – <topic>`, the suggested skill change plus the evidence in the summary, `actionability` = `requires_human_input` (applying it is a skill edit by your team), `repository` = the `NO_REPO` sentinel (the fix is a skill edit, not code), `suggested_reviewers` = whoever owns this scout when you know. Stash the returned `report_id` in the `improve:` entry — this run can't edit reports, so once the entry carries a `report_id` the report exists: keep fresh evidence in the entry rather than authoring a duplicate. It lands in the inbox like any other report; your team decides whether to apply it."""
+_SELF_IMPROVEMENT_ESCALATE_EMIT_ONLY = f"""- **Recurring or material? File an inbox report too.** A scratchpad entry is only seen when the owner goes looking; a report is routed to them. When a suggestion re-confirms across runs (your `improve:` entry has accumulated several dated lines), or this run's failure was material (it wasted most of your budget, or steered you into emitting something wrong), surface it with `scout-emit-report` — title `{SELF_IMPROVEMENT_REPORT_TITLE_PREFIX} <your-skill-name> – <topic>`, the suggested skill change plus the evidence in the summary, `actionability` = `requires_human_input` (applying it is a skill edit by your team), `repository` = the `NO_REPO` sentinel (the fix is a skill edit, not code), `suggested_reviewers` = the skill authors listed under *Your run identity*, creator first (match each to a `scout-members-list` row; skip anyone who doesn't resolve, and leave it empty only when no author resolves at all — and if your skill body defines its own reviewer routing, follow the skill instead). Stash the returned `report_id` in the `improve:` entry — this run can't edit reports, so once the entry carries a `report_id` the report exists: keep fresh evidence in the entry rather than authoring a duplicate. It lands in the inbox like any other report; your team decides whether to apply it."""
_SELF_IMPROVEMENT_TAIL = """- The bar is a concrete failure or waste observed this run. Generic polish ("the wording could be clearer") is noise — don't write it.
- Routing: a problem with the tools, the harness, or these shared instructions still goes to `agent-feedback` (it reaches the PostHog team, not your team). An `improve:` entry is only for changes to your own skill body — your team reviews it and decides whether to apply it.
@@ -374,6 +376,33 @@ def _render_tail(sections: list[str], *, schema_json: str) -> str:
return "\n\n".join(rendered)
+def _skill_authors_line(authors: list[SkillAuthor]) -> str:
+ """Run-identity line naming the custom skill's creator and recent editors, or empty.
+
+ Version rows only record who published each version, so without this line a scout that
+ reads its own (latest) version via `skill-get` sees the last editor's name and would route
+ ownership there — e.g. a bulk cleanup pass over every custom scout makes the cleaner look
+ like the owner of all of them. Resolving authorship server-side also spares the scout a
+ tool call per version; a long-lived skill can carry hundreds.
+ """
+ if not authors:
+ return ""
+ parts = []
+ creator = next((a for a in authors if a.role == "creator"), None)
+ if creator is not None:
+ parts.append(f"created by {creator.name} ({creator.email})")
+ editors = [a for a in authors if a.role == "editor"]
+ if editors:
+ edited = ", ".join(f"{a.name} ({a.email}, last edit {a.last_authored_at.date().isoformat()})" for a in editors)
+ parts.append(f"since edited by {edited}")
+ return (
+ f"\n- **skill authors**: {'; '.join(parts)} — the humans who own your skill body. "
+ "When a report needs someone who owns this scout (a self-improvement report especially), "
+ "route to them, creator first — unless your skill body defines its own reviewer routing, "
+ "which takes precedence."
+ )
+
+
def build_run_prompt(skill: LoadedSkill, *, run_id: str, team_id: int, started_at: datetime) -> str:
"""Render the opening prompt for one scout run.
@@ -428,12 +457,16 @@ def build_run_prompt(skill: LoadedSkill, *, run_id: str, team_id: int, started_a
self_improvement = _self_improvement_section(can_emit_report=can_emit_report, can_edit_report=can_edit_report)
sections = [*sections[:-1], self_improvement, sections[-1]]
tail = _render_tail(sections, schema_json=schema_json)
+ # Report-channel scouts only: the authors line exists to steer `suggested_reviewers`, and a
+ # signal-channel scout has no reviewers field — member names/emails are PII that shouldn't
+ # flow into a prompt with no feature path to use them.
+ authors_line = _skill_authors_line(skill.authors) if report_channel else ""
return f"""{intro}
# Your run identity
- **run_id**: `{run_id}` — pass this when calling `{emit_tool}`.
- **team_id**: `{team_id}` — implicit on every MCP call.
-- **skill**: `{skill.name}` (v{skill.version}) — your steering layer.
+- **skill**: `{skill.name}` (v{skill.version}) — your steering layer.{authors_line}
- **started_at**: `{started_at_iso}` — when this run began (UTC). Informational; use current clock time for queries about "now".
# How to call tools
diff --git a/products/signals/backend/scout_harness/runner.py b/products/signals/backend/scout_harness/runner.py
index 356ab7e2851c..38e1c88d04ca 100644
--- a/products/signals/backend/scout_harness/runner.py
+++ b/products/signals/backend/scout_harness/runner.py
@@ -145,7 +145,7 @@ async def arun_signals_scout(
extra={"team_id": team_id},
)
skill = await database_sync_to_async(load_skill_for_run, thread_sensitive=False)(
- team, skill_name, version=skill_version
+ team, skill_name, version=skill_version, include_authors=True
)
config = await database_sync_to_async(_resolve_config, thread_sensitive=False)(team, skill.name)
diff --git a/products/signals/backend/scout_harness/skill_loader.py b/products/signals/backend/scout_harness/skill_loader.py
index 7bf072c33703..dd36b57741bc 100644
--- a/products/signals/backend/scout_harness/skill_loader.py
+++ b/products/signals/backend/scout_harness/skill_loader.py
@@ -1,8 +1,11 @@
from __future__ import annotations
from dataclasses import dataclass
+from datetime import datetime
from typing import Literal
+from django.db.models import Max, Min
+
from posthog.models.team.team import Team
from products.skills.backend.models.skills import LLMSkill, LLMSkillFile
@@ -33,6 +36,21 @@ class LoadedSkillFile:
content_type: str
+# Editors surfaced in the prompt beyond the creator. Distinct authors per skill are few in
+# practice; the cap only guards the prompt against a pathologically churned skill.
+MAX_SKILL_EDITORS_IN_PROMPT = 5
+
+
+@dataclass(frozen=True)
+class SkillAuthor:
+ """One human who published at least one version of the skill, for reviewer routing."""
+
+ name: str
+ email: str
+ role: Literal["creator", "editor"]
+ last_authored_at: datetime
+
+
@dataclass(frozen=True)
class LoadedSkill:
name: str
@@ -57,17 +75,78 @@ class LoadedSkill:
# suggestions for its own body (the team owns that body and can apply them); a pristine
# canonical scout is not, so the prompt never nudges a team into diverging a seeded row.
origin: Literal["canonical", "custom"]
+ # The humans who own the skill body, resolved from its version rows: creator first (the
+ # earliest version with a known author — a seeded row's v1 is system-authored with no
+ # `created_by`, so a diverged canonical's creator is whoever first edited it), then editors
+ # ordered most-recent-edit first. Custom scouts only (empty for canonical) — the prompt
+ # renders it into the run identity so the scout can route self-improvement reports to the
+ # skill's owners instead of guessing. Version rows can't reveal authorship any other way:
+ # each row's `created_by` is whoever published *that* version, so the pinned (latest)
+ # version alone would misattribute the skill to its last editor.
+ authors: list[SkillAuthor]
def is_signals_scout_skill(skill: LLMSkill) -> bool:
return skill.name.startswith(SIGNALS_SCOUT_SKILL_PREFIX)
-def load_skill_for_run(team: Team, skill_name: str, *, version: int | None = None) -> LoadedSkill:
+def resolve_skill_authors(team: Team, skill_name: str) -> list[SkillAuthor]:
+ """Distinct humans across the skill's version rows: creator first, then editors by recency.
+
+ One indexed aggregate over all version rows for `(team, name)` — versions are capped at
+ `MAX_SKILL_VERSION`, so this stays cheap regardless of edit churn. Rows with a null
+ `created_by` (system-seeded versions, deleted users) carry no routable identity and are
+ skipped; a skill with only such rows resolves to no authors.
+
+ Authors are restricted to `team.all_users_with_access()` — the same boundary the
+ `scout-members-list` reviewer roster uses. A former member's profile (notably the
+ self-editable display name) must not keep flowing into a privileged prompt after their
+ access is revoked, and an unroutable author would only waste an editor slot anyway.
+ """
+ rows = (
+ LLMSkill.objects.filter(
+ team=team,
+ name=skill_name,
+ deleted=False,
+ created_by__isnull=False,
+ created_by__in=team.all_users_with_access(),
+ )
+ .values("created_by__uuid", "created_by__first_name", "created_by__last_name", "created_by__email")
+ .annotate(first_authored_at=Min("created_at"), last_authored_at=Max("created_at"))
+ .order_by("first_authored_at")
+ )
+ people = list(rows)
+ if not people:
+ return []
+
+ def to_author(person: dict, role: Literal["creator", "editor"]) -> SkillAuthor:
+ # Collapse whitespace so a multi-line display name can't break out of the prompt's
+ # one-line list-item structure.
+ name = " ".join(f"{person['created_by__first_name']} {person['created_by__last_name']}".split())
+ return SkillAuthor(
+ name=name or person["created_by__email"],
+ email=person["created_by__email"],
+ role=role,
+ last_authored_at=person["last_authored_at"],
+ )
+
+ creator, *editors = people
+ editors.sort(key=lambda p: p["last_authored_at"], reverse=True)
+ return [to_author(creator, "creator")] + [to_author(p, "editor") for p in editors[:MAX_SKILL_EDITORS_IN_PROMPT]]
+
+
+def load_skill_for_run(
+ team: Team, skill_name: str, *, version: int | None = None, include_authors: bool = False
+) -> LoadedSkill:
"""Resolve a skill on the team's namespace and load its body + file manifest.
Pass `version=None` to follow-latest. The `signals-scout-*` prefix is not enforced
here — the management command can hand-trigger any skill on the team.
+
+ `include_authors` is for the prompt-building path only (the runner). Other callers —
+ notably the report-authorization gate in `views._assert_report_tool_opted_in`, which loads
+ the skill on every report write just to check `allowed_tools` — must not pay for the
+ membership + version-history author scan, so it defaults off.
"""
# Lazy imports, both to break cycles: `lazy_seed` imports this module at top level
# (SIGNALS_SCOUT_SKILL_PREFIX), and `products.skills.backend.api` triggers a temporal module
@@ -82,6 +161,7 @@ def load_skill_for_run(team: Team, skill_name: str, *, version: int | None = Non
+ (f" (version {version})" if version is not None else "")
)
file_rows = LLMSkillFile.objects.filter(skill=skill).only("path", "content_type").order_by("path")
+ origin = scout_skill_row_origin(skill)
return LoadedSkill(
name=skill.name,
version=skill.version,
@@ -90,5 +170,8 @@ def load_skill_for_run(team: Team, skill_name: str, *, version: int | None = Non
allowed_tools=list(skill.allowed_tools or []),
files=[LoadedSkillFile(path=f.path, content_type=f.content_type) for f in file_rows],
skill_id=str(skill.id),
- origin=scout_skill_row_origin(skill),
+ origin=origin,
+ # Only a custom scout's prompt renders authorship (canonical bodies are PostHog-owned),
+ # so skip the extra queries unless the caller builds a prompt and the row is custom.
+ authors=resolve_skill_authors(team, skill_name) if include_authors and origin == "custom" else [],
)
diff --git a/products/signals/backend/test/test_scout_harness.py b/products/signals/backend/test/test_scout_harness.py
index b9d4f3e43109..19d95a188e1b 100644
--- a/products/signals/backend/test/test_scout_harness.py
+++ b/products/signals/backend/test/test_scout_harness.py
@@ -2,6 +2,7 @@ from __future__ import annotations
import random
import asyncio
+from dataclasses import replace
from datetime import UTC, datetime, timedelta
from typing import TYPE_CHECKING
@@ -17,7 +18,7 @@ from asgiref.sync import sync_to_async
from parameterized import parameterized
from temporalio.testing import ActivityEnvironment
-from posthog.models import Organization, Team
+from posthog.models import Organization, OrganizationMembership, Team, User
from posthog.models.scoping import team_scope
from posthog.sync import database_sync_to_async
@@ -126,6 +127,94 @@ class TestSkillLoader(BaseTest):
with pytest.raises(SkillNotFoundError):
load_skill_for_run(self.team, "signals-scout-does-not-exist")
+ def test_authors_lead_with_creator_not_last_editor(self) -> None:
+ # Each version row's `created_by` is whoever published that version, so the pinned
+ # (latest) row alone attributes the skill to its last editor. A regression back to
+ # reading the loaded row's `created_by` flips this ordering.
+ ben = User.objects.create_and_join(self.organization, "[email protected]", None, "Ben")
+ v1 = self._create_skill("signals-scout-errors")
+ v1.created_by = ben
+ v1.is_latest = False
+ v1.save()
+ LLMSkill.objects.create(
+ team=self.team,
+ name="signals-scout-errors",
+ description="A test skill",
+ body="edited body",
+ version=2,
+ is_latest=True,
+ created_by=self.user,
+ )
+ loaded = load_skill_for_run(self.team, "signals-scout-errors", include_authors=True)
+ assert [(a.role, a.email) for a in loaded.authors] == [
+ ("creator", "[email protected]"),
+ ("editor", self.user.email),
+ ]
+ # Off by default: the report-authorization path in views loads the skill on every report
+ # write just to check allowed_tools and must not pay the author scan.
+ assert load_skill_for_run(self.team, "signals-scout-errors").authors == []
+
+ def test_diverged_seeded_skill_creator_is_first_human_author(self) -> None:
+ # A seeded row's v1 is system-authored (`created_by=None`); the creator of the diverged
+ # skill is whoever first edited it, not "the author of version 1".
+ seeded_metadata = {"seeded_by": HARNESS_SEEDED_BY, "canonical_hash": "0" * 64}
+ LLMSkill.objects.create(
+ team=self.team,
+ name="signals-scout-general",
+ description="d",
+ body="b",
+ metadata=seeded_metadata,
+ is_latest=False,
+ )
+ LLMSkill.objects.create(
+ team=self.team,
+ name="signals-scout-general",
+ description="d",
+ body="edited",
+ version=2,
+ is_latest=True,
+ created_by=self.user,
+ metadata=seeded_metadata,
+ )
+ loaded = load_skill_for_run(self.team, "signals-scout-general", include_authors=True)
+ assert [(a.role, a.email) for a in loaded.authors] == [("creator", self.user.email)]
+
+ def test_authors_exclude_users_without_project_access(self) -> None:
+ # An author's display name is self-editable and flows into a privileged prompt, so a
+ # former member must stop resolving the moment their access is revoked — otherwise they
+ # keep a post-revocation steering channel into scheduled runs (and waste an editor slot
+ # on someone reviewer routing can't reach anyway).
+ ben = User.objects.create_and_join(self.organization, "[email protected]", None, "Ben")
+ v1 = self._create_skill("signals-scout-errors")
+ v1.created_by = ben
+ v1.is_latest = False
+ v1.save()
+ LLMSkill.objects.create(
+ team=self.team,
+ name="signals-scout-errors",
+ description="A test skill",
+ body="edited body",
+ version=2,
+ is_latest=True,
+ created_by=self.user,
+ )
+ OrganizationMembership.objects.filter(user=ben).delete()
+ loaded = load_skill_for_run(self.team, "signals-scout-errors", include_authors=True)
+ assert [(a.role, a.email) for a in loaded.authors] == [("creator", self.user.email)]
+
+ def test_authors_empty_for_pristine_canonical_skill(self) -> None:
+ skill = LLMSkill.objects.create(
+ team=self.team,
+ name="signals-scout-general",
+ description="d",
+ body="b",
+ created_by=self.user,
+ metadata={"seeded_by": HARNESS_SEEDED_BY},
+ )
+ skill.metadata["canonical_hash"] = _compute_row_hash(skill, [])
+ skill.save()
+ assert load_skill_for_run(self.team, "signals-scout-general", include_authors=True).authors == []
+
def test_signals_scout_prefix_check(self) -> None:
match = self._create_skill("signals-scout-errors")
non_match = self._create_skill("custom-research-helper")
@@ -309,6 +398,10 @@ class TestPromptBuilder(BaseTest):
# has neither, so pointing it at `emit_report` would steer it into a PermissionDenied.
expect_escalation = expect_section and "emit_report" in allowed_tools
assert ("Scout self-improvement:" in prompt) is expect_escalation
+ # Reviewer routing for self-improvement reports points at the run-identity authors line,
+ # not at "whoever owns this scout" guesswork — dropping the reference re-opens the
+ # last-editor-becomes-the-assignee failure mode.
+ assert ("the skill authors listed under *Your run identity*" in prompt) is expect_escalation
if _name == "custom_report_scout_emit_only":
# The emit-only variant must never name the edit tool it lacks (fails closed).
assert "scout-edit-report" not in prompt
@@ -335,6 +428,55 @@ class TestPromptBuilder(BaseTest):
started_at=datetime(2026, 5, 1, 12, 34, 56, tzinfo=UTC),
)
assert "Suggest improvements to your own skill" not in prompt
+ # A canonical skill body is PostHog-owned — the run identity must not name the seeding
+ # row's incidental `created_by` as a skill author.
+ assert "skill authors" not in prompt
+
+ def test_run_identity_names_skill_authors_creator_first(self) -> None:
+ # The rendered line is what the escalation guidance points `suggested_reviewers` at;
+ # if it drops the creator, or renders for a skill with no known authors, routing
+ # falls back to the last editor (the exact misattribution this line exists to fix).
+ ben = User.objects.create_and_join(self.organization, "[email protected]", None, "Ben")
+ LLMSkill.objects.create(
+ team=self.team,
+ name="signals-scout-errors",
+ description="d",
+ body="b",
+ created_by=ben,
+ is_latest=False,
+ )
+ LLMSkill.objects.create(
+ team=self.team,
+ name="signals-scout-errors",
+ description="d",
+ body="edited",
+ version=2,
+ is_latest=True,
+ created_by=self.user,
+ allowed_tools=["emit_report"],
+ )
+ loaded = load_skill_for_run(self.team, "signals-scout-errors", include_authors=True)
+ prompt = build_run_prompt(
+ loaded,
+ run_id="00000000-0000-0000-0000-000000000abc",
+ team_id=self.team.id,
+ started_at=datetime(2026, 5, 1, 12, 34, 56, tzinfo=UTC),
+ )
+ assert "**skill authors**: created by Ben ([email protected]); since edited by" in prompt
+ assert self.user.email in prompt
+ # The authors line is a default, not an override — dropping the precedence hedge would
+ # set the harness up to fight a skill body that defines its own reviewer routing.
+ assert "unless your skill body defines its own reviewer routing" in prompt
+ # A signal-channel scout has no `suggested_reviewers` field, so member names/emails must
+ # not reach its prompt — there is no feature path that could use them.
+ signal_prompt = build_run_prompt(
+ replace(loaded, allowed_tools=[]),
+ run_id="00000000-0000-0000-0000-000000000abc",
+ team_id=self.team.id,
+ started_at=datetime(2026, 5, 1, 12, 34, 56, tzinfo=UTC),
+ )
+ assert "skill authors" not in signal_prompt
+ assert "[email protected]" not in signal_prompt
def _report_prompt_for(self, allowed_tools: list[str]) -> str:
name = "signals-scout-" + "-".join(allowed_tools)