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): recover a repository when Create PR meets a no-repo report (#92905)

posthog[bot]eb82a5606768
diff --git a/products/signals/backend/scout_harness/prompt.py b/products/signals/backend/scout_harness/prompt.py
index 3abb0fdd4e01..5e7bac9954b7 100644
--- a/products/signals/backend/scout_harness/prompt.py
+++ b/products/signals/backend/scout_harness/prompt.py
@@ -462,7 +462,7 @@ This is the single highest-leverage field you set. `suggested_reviewers` (a list
- **Set `reason` on every reviewer you name.** One sentence of the concrete evidence tying this person to the affected surface ("created the affected dashboard", "human correction on the prior tracing report routed to them"). It is persisted on the report, so humans and future runs can tell an evidence-backed route from a guess without replaying your transcript. A reviewer you can't write a reason for is a reviewer you haven't verified.
- **Check for human corrections first.** A human swapping a suggested reviewer for someone else is the strongest ownership evidence there is, so treat it as authoritative precedent over commit history and fold it into your `reviewer:` memory keys. The project profile's `recent_reviewer_corrections` carries the recent ones; for history beyond that window, query `advanced-activity-logs-list` with `scopes=["SignalReport"]`, `activities=["suggested_reviewers_changed"]` (on an org without the audit-logs feature that call fails with a payment-required error: skip it, don't retry).
- **Weigh other precedent by its evidence, not its existence.** A comparable report's reviewer entries (via `inbox-report-artefacts-list`) or your own `reviewer:` memory are strong precedent when they carry `relevant_commits`, a concrete `reason`, or a human correction behind them, and are an earlier run's unexplained guess when they carry none of those. Precedent is self-reinforcing, so every blind reuse becomes the next run's precedent and compounds a mis-route indefinitely: corroborate from what you gathered this run (an entity's `created_by`, the owning team, recent authors in the data), or say so in `reason` ("inherited from report X, unverified").
-- **Set `priority` + `priority_explanation`** when the issue is concrete and you can justify the urgency, since autostart needs a priority to consider a draft PR. **Set `repository`** (`owner/repo`) when you know where a fix would land, rather than leaving it to slower free-form selection, and pass the `NO_REPO` sentinel for a report with no code fix.
+- **Set `priority` + `priority_explanation`** when the issue is concrete and you can justify the urgency, since autostart needs a priority to consider a draft PR. **Set `repository`** (`owner/repo`) whenever you can say where a fix would land, including on a `requires_human_input` report — a repository does not open a PR by itself, it is what lets a person open one from the inbox later. Omit the field when your team has several repositories and you can't tell which one, so selection can find it. Keep the `NO_REPO` sentinel for the rare report where nothing under version control could change (a staffing or process finding, a data question with no artifact): a skill body, a config file, or a doc still lives in a repository, so "not code" is not the test.
A report that surfaces but routes nowhere is half-finished: 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 heuristics above are for when it says nothing."""
@@ -647,7 +647,8 @@ SELF_IMPROVEMENT_REPORT_TITLE_PREFIX = "Scout self-improvement:"
_SELF_IMPROVEMENT_REPORT_FIELDS = (
f"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), and "
+ "by your team), `repository` = the `NO_REPO` sentinel (a custom scout's skill body is a row in "
+ "your team's skills store, not a file in a repository, so a repository could not apply the fix), and "
"`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 none does; if "
"your skill body defines its own reviewer routing, follow the skill instead)."
diff --git a/products/signals/backend/scout_harness/serializers.py b/products/signals/backend/scout_harness/serializers.py
index a6c1b4113f11..e829b1eefc32 100644
--- a/products/signals/backend/scout_harness/serializers.py
+++ b/products/signals/backend/scout_harness/serializers.py
@@ -1165,10 +1165,11 @@ class EmitReportRequestSerializer(serializers.Serializer):
required=False,
allow_null=True,
help_text=(
- "Optional repo for autostart (opening a draft PR): `owner/repo` targets that repo, the "
- "`NO_REPO` sentinel opts out (report lands without a PR), and omitting it triggers free-form "
- "selection across the team's repos — the slow path on a many-repo team, so pass `owner/repo` "
- "when you know it."
+ "Optional repo for opening a draft PR, by autostart or by a person from the inbox. Pass "
+ "`owner/repo` whenever you can say where a fix would land. Omit the field when you can't, "
+ "which triggers free-form selection across the team's repos (the slow path on a many-repo "
+ "team). Keep the `NO_REPO` sentinel for the rare report where nothing under version control "
+ "could change, since a skill body, a config file, or a doc still lives in a repo."
),
)
priority = serializers.ChoiceField(
diff --git a/products/signals/frontend/generated/api.schemas.ts b/products/signals/frontend/generated/api.schemas.ts
index e4da92491653..7804d6a2ae5f 100644
--- a/products/signals/frontend/generated/api.schemas.ts
+++ b/products/signals/frontend/generated/api.schemas.ts
@@ -3589,7 +3589,7 @@ export interface EmitReportRequestApi {
/** Whether the issue is already being handled — fixed in recent changes, or with a fix in flight (an open PR, a recently active branch, an assigned / in-progress issue or agent task). Gates autostart, so a wrong `false` opens a duplicate PR. Tracked separately. */
already_addressed?: boolean
/**
- * Optional repo for autostart (opening a draft PR): `owner/repo` targets that repo, the `NO_REPO` sentinel opts out (report lands without a PR), and omitting it triggers free-form selection across the team's repos — the slow path on a many-repo team, so pass `owner/repo` when you know it.
+ * Optional repo for opening a draft PR, by autostart or by a person from the inbox. Pass `owner/repo` whenever you can say where a fix would land. Omit the field when you can't, which triggers free-form selection across the team's repos (the slow path on a many-repo team). Keep the `NO_REPO` sentinel for the rare report where nothing under version control could change, since a skill body, a config file, or a doc still lives in a repo.
* @nullable
*/
repository?: string | null
diff --git a/products/signals/frontend/generated/api.zod.ts b/products/signals/frontend/generated/api.zod.ts
index 0aadcea82d73..01fdb39b2dd0 100644
--- a/products/signals/frontend/generated/api.zod.ts
+++ b/products/signals/frontend/generated/api.zod.ts
@@ -1147,7 +1147,7 @@ export const SignalsScoutEmitReportBody = /* @__PURE__ */ zod
.string()
.nullish()
.describe(
- "Optional repo for autostart (opening a draft PR): `owner\/repo` targets that repo, the `NO_REPO` sentinel opts out (report lands without a PR), and omitting it triggers free-form selection across the team's repos — the slow path on a many-repo team, so pass `owner\/repo` when you know it."
+ "Optional repo for opening a draft PR, by autostart or by a person from the inbox. Pass `owner\/repo` whenever you can say where a fix would land. Omit the field when you can't, which triggers free-form selection across the team's repos (the slow path on a many-repo team). Keep the `NO_REPO` sentinel for the rare report where nothing under version control could change, since a skill body, a config file, or a doc still lives in a repo."
),
priority: zod
.union([
diff --git a/products/signals/skills/authoring-scouts/references/report-contract.md b/products/signals/skills/authoring-scouts/references/report-contract.md
index 7ff142820ec4..acbdf3d479a3 100644
--- a/products/signals/skills/authoring-scouts/references/report-contract.md
+++ b/products/signals/skills/authoring-scouts/references/report-contract.md
@@ -163,12 +163,17 @@ Cap is **3 questions per report**, each **≤200 characters**, and duplicates ar
A surfaced, immediately-actionable report can open a draft PR automatically — the same autostart path the pipeline uses.
It's opt-in per report via three more `emit_report` fields; supply them only when the report is a concrete, fixable issue you'd want a PR for:
-| Field | Type | Notes |
-| ---------------------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| `repository` | string | `"owner/repo"` targets that repo; the `NO_REPO` sentinel opts out; **omitting it** falls back to free-form selection across the team's repos — the slow path on a many-repo team (it spawns a selection sandbox), so pass `owner/repo` when you know it. |
-| `priority` | `P0`-`P4` | Required for a PR. Pair with `priority_explanation`. |
-| `priority_explanation` | string | Required when `priority` is set. |
-| `suggested_reviewers` | list of obj | Reviewers to consider, each `{github_login?, user_uuid?}` (at least one per entry; see the section below). A PR opens only if at least one clears their autonomy threshold. |
+| Field | Type | Notes |
+| ---------------------- | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| `repository` | string | `"owner/repo"` targets that repo; **omitting it** falls back to free-form selection; the `NO_REPO` sentinel opts out. See _Choosing a repository_ below. |
+| `priority` | `P0`-`P4` | Required for a PR. Pair with `priority_explanation`. |
+| `priority_explanation` | string | Required when `priority` is set. |
+| `suggested_reviewers` | list of obj | Reviewers to consider, each `{github_login?, user_uuid?}` (at least one per entry; see the section below). A PR opens only if at least one clears their autonomy threshold. |
+
+**Choosing a repository.** Prefer `owner/repo` whenever you can say where a fix would land, including on a `requires_human_input` report — a repository does not open a PR by itself, it is what lets a person open one from the inbox later.
+Omit the field when your team has several repositories and you can't tell which one, so selection can find it; that is the slow path on a many-repo team, since it spawns a selection sandbox.
+Keep `NO_REPO` for the rare report where nothing under version control could change, such as a staffing finding or a data question with no artifact.
+A skill body, a config file, and a doc all live in a repository, so "not code" is not the test.
Full repo selection only runs when you signal PR intent — an explicit `repository`, or both `priority` and `suggested_reviewers`.
A report that supplies none of these just surfaces in the inbox: no repo sandbox, and no PR.
diff --git a/products/tasks/backend/facade/api.py b/products/tasks/backend/facade/api.py
index 966eab4be2a8..7ec8fc9a9c51 100644
--- a/products/tasks/backend/facade/api.py
+++ b/products/tasks/backend/facade/api.py
@@ -5547,6 +5547,28 @@ def compute_repository_readiness(team_id: int, *, repository: str, window_days:
return _compute(team=team, repository=repository, window_days=window_days, refresh=refresh)
+def _capture_no_repo_selection_override(*, team: Team, report_id: str, resolved_repository: str | None) -> None:
+ """Record a person starting work on a report whose scout chose no repository.
+
+ The count tells the signals team how often the scouts' `NO_REPO` default disagrees with what a
+ person wanted, and `resolved_repository` separates a recovery from a cascade that also found
+ nothing. Keyed on the team, like the other scout events. Best-effort: a capture failure must
+ never fail the task creation."""
+ try:
+ posthoganalytics.capture(
+ distinct_id=str(team.uuid),
+ event="signal_report_no_repo_selection_overridden",
+ properties={
+ "report_id": report_id,
+ "team_id": team.id,
+ "resolved_repository": resolved_repository,
+ },
+ groups=groups(team=team),
+ )
+ except Exception as e:
+ logger.warning("signal_report_no_repo_selection_overridden capture failed for report %s: %s", report_id, e)
+
+
def create_task(
team_id: int,
user_id: int | None,
@@ -5715,13 +5737,18 @@ def create_task(
# Popped so it isn't forwarded to the model; the link itself is recorded by record_report_task below.
signal_report_task_relationship = validated_data.pop("signal_report_task_relationship", None)
- # Inbox "Create PR" / "Discuss" don't pre-select a repo, so resolve one here rather than
- # creating a report-linked task that can never open a PR.
+ # Inbox "Create PR" doesn't pre-select a repo, so resolve one here rather than creating a
+ # report-linked task that can never open a PR. Only "implementation" (Create PR) and legacy
+ # clients (no relationship) resolve one: "Discuss" (and any other non-implementation label)
+ # must stay repo-less to keep the code-access exemption (`task_exempt_from_code_access`).
+ # Giving a discussion a repository would 403 a caller without Desktop access on the very click
+ # this path exists to unblock.
signal_report = validated_data.get("signal_report")
if (
signal_report is not None
and not validated_data.get("repository")
and validated_data.get("origin_product") == Task.OriginProduct.SIGNAL_REPORT
+ and signal_report_task_relationship in (None, "implementation")
):
from products.signals.backend.facade.api import ( # noqa: PLC0415 — cross-product read kept off the api import path
persisted_repo_selection,
@@ -5730,13 +5757,14 @@ def create_task(
cascade_select_repository,
)
- # The report's own selection is authoritative — including a scout's deliberate no-repo
- # (`repository=None`), which must not fall through to the cascade.
+ # A named selection wins. A no-repo selection (`repository=None`) does not: autostart
+ # already honors it in signals (it never creates a task without a repository), so reaching
+ # here means a person clicked "Create PR", which is the stronger signal. Fall through to
+ # the cascade rather than create a task whose sandbox can only read, never push.
selection = persisted_repo_selection(str(signal_report.id))
- resolved_repository = (
- selection.repository
- if selection is not None
- else cascade_select_repository(
+ resolved_repository = selection.repository if selection is not None else None
+ if not resolved_repository:
+ resolved_repository = cascade_select_repository(
team_id,
user_id,
validated_data.get("description") or "",
@@ -5744,7 +5772,10 @@ def create_task(
single_repo_wins=True,
allow_refresh=False,
)
- )
+ if selection is not None:
+ _capture_no_repo_selection_override(
+ team=team, report_id=str(signal_report.id), resolved_repository=resolved_repository
+ )
if resolved_repository:
validated_data["repository"] = resolved_repository
diff --git a/products/tasks/backend/logic/repo_selection/cascade.py b/products/tasks/backend/logic/repo_selection/cascade.py
index 7078d2c56df0..746fe519a679 100644
--- a/products/tasks/backend/logic/repo_selection/cascade.py
+++ b/products/tasks/backend/logic/repo_selection/cascade.py
@@ -36,7 +36,9 @@ def cascade_select_repository(
github = resolve_team_github_integration(team_id, team=team, requester_user_id=user_id)
if github is None:
return None
- candidates = _list_candidate_repos(github, team_id, allow_refresh=allow_refresh)
+ # Drop archived repos: they accept no pull request, so the single_repo_wins shortcut below
+ # must not hand back a lone archived repo as a target the caller can never push to.
+ candidates = _list_candidate_repos(github, team_id, allow_refresh=allow_refresh, exclude_archived=True)
if not candidates:
return None
if single_repo_wins and len(candidates) == 1:
diff --git a/products/tasks/backend/tests/test_api.py b/products/tasks/backend/tests/test_api.py
index 4600bb27473e..55ddcf42c19a 100644
--- a/products/tasks/backend/tests/test_api.py
+++ b/products/tasks/backend/tests/test_api.py
@@ -1827,8 +1827,9 @@ class TestTaskAPI(BaseTaskAPITest):
("no_selection", False, None, "acme/web"),
# a persisted selection wins over the cascade, even when it names another repo
("persisted_repo", True, "acme/api", "acme/api"),
- # a scout's deliberate no-repo must not fall through to the cascade
- ("persisted_no_repo", True, None, None),
+ # a scout's no-repo selection is not authoritative for a human "Create PR" click, so it
+ # falls through to the cascade rather than making a task that can never push
+ ("persisted_no_repo", True, None, "acme/web"),
]
)
def test_create_signal_report_task_resolves_repository_when_none_provided(
@@ -1868,6 +1869,45 @@ class TestTaskAPI(BaseTaskAPITest):
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(response.json()["repository"], expected_repository)
+ def test_discussion_from_no_repo_report_stays_repo_less_and_exempt(self):
+ # A "Discuss" kickoff must not resolve a repository, even on a one-repo team with a NO_REPO
+ # selection artefact. A repository-backed report task loses the code-access exemption, so a
+ # caller without Desktop access would 403 on the discussion — the dead-end this path removes.
+ from products.signals.backend.models import SignalReport, SignalReportArtefact
+
+ Integration.objects.create(
+ team=self.team,
+ kind="github",
+ integration_id="gh-cascade",
+ config={"installation_id": "gh-cascade"},
+ sensitive_config={},
+ repository_cache=[{"full_name": "acme/web", "name": "web", "id": 1}],
+ repository_cache_updated_at=django_timezone.now(),
+ )
+ report = SignalReport.objects.create(team=self.team)
+ SignalReportArtefact.objects.create(
+ team=self.team,
+ report=report,
+ type=SignalReportArtefact.ArtefactType.REPO_SELECTION,
+ content=RepoSelectionResult(repository=None, reason="test").model_dump_json(),
+ )
+
+ response = self.client.post(
+ "/api/projects/@current/tasks/",
+ {
+ "title": "Discuss report",
+ "description": "Let's discuss this report",
+ "origin_product": "signal_report",
+ "signal_report": str(report.id),
+ "signal_report_task_relationship": "discussion",
+ },
+ format="json",
+ )
+
+ self.assertEqual(response.status_code, status.HTTP_201_CREATED)
+ self.assertIsNone(response.json()["repository"])
+ self.assertTrue(tasks_facade.task_exempt_from_code_access(response.json()["id"], self.team.id))
+
def test_create_task_with_signal_report_discussion_records_artefact_without_gate_row(self):
from products.signals.backend.models import SignalReport, SignalReportTask
from products.signals.backend.task_run_artefacts import (
diff --git a/products/tasks/backend/tests/test_repo_selection_cascade.py b/products/tasks/backend/tests/test_repo_selection_cascade.py
index 2d7e841d97da..433b2e72c15a 100644
--- a/products/tasks/backend/tests/test_repo_selection_cascade.py
+++ b/products/tasks/backend/tests/test_repo_selection_cascade.py
@@ -53,6 +53,18 @@ class TestCascadeSelectRepository:
with resolve, list_repos:
assert cascade_select_repository(1, 2, "", single_repo_wins=single_repo_wins) == expected
+ def test_archived_lone_repo_is_not_taken(self):
+ # An archived repo accepts no pull request, so single_repo_wins must drop it before the
+ # lone-repo shortcut. Dropping the team's only repo leaves no candidate, so the caller starts
+ # repo-less rather than targeting an unpushable repo. A repo cached before the flag existed
+ # carries no `archived` and stays a candidate.
+ github = MagicMock()
+ github.list_all_cached_repositories.return_value = [
+ {"full_name": "owner/retired", "archived": True},
+ ]
+ with patch(f"{_CASCADE}.resolve_team_github_integration", return_value=github):
+ assert cascade_select_repository(1, 2, "", single_repo_wins=True) is None
+
@pytest.mark.django_db
def test_unsynced_cache_is_read_without_a_live_sync(self, team):
# Request-path callers pass allow_refresh=False, so a never-synced cache
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 40b1f00307a9..56ab7bfadb66 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -30189,7 +30189,7 @@ export namespace Schemas {
/** Whether the issue is already being handled — fixed in recent changes, or with a fix in flight (an open PR, a recently active branch, an assigned / in-progress issue or agent task). Gates autostart, so a wrong `false` opens a duplicate PR. Tracked separately. */
already_addressed?: boolean;
/**
- * Optional repo for autostart (opening a draft PR): `owner/repo` targets that repo, the `NO_REPO` sentinel opts out (report lands without a PR), and omitting it triggers free-form selection across the team's repos — the slow path on a many-repo team, so pass `owner/repo` when you know it.
+ * Optional repo for opening a draft PR, by autostart or by a person from the inbox. Pass `owner/repo` whenever you can say where a fix would land. Omit the field when you can't, which triggers free-form selection across the team's repos (the slow path on a many-repo team). Keep the `NO_REPO` sentinel for the rare report where nothing under version control could change, since a skill body, a config file, or a doc still lives in a repo.
* @nullable
*/
repository?: string | null;
diff --git a/services/mcp/src/generated/signals/api.ts b/services/mcp/src/generated/signals/api.ts
index e369838bf846..b9d0faac9025 100644
--- a/services/mcp/src/generated/signals/api.ts
+++ b/services/mcp/src/generated/signals/api.ts
@@ -1570,7 +1570,7 @@ export const SignalsScoutEmitReportBody = () => zod
.string()
.nullish()
.describe(
- "Optional repo for autostart (opening a draft PR): `owner\/repo` targets that repo, the `NO_REPO` sentinel opts out (report lands without a PR), and omitting it triggers free-form selection across the team's repos — the slow path on a many-repo team, so pass `owner\/repo` when you know it."
+ "Optional repo for opening a draft PR, by autostart or by a person from the inbox. Pass `owner\/repo` whenever you can say where a fix would land. Omit the field when you can't, which triggers free-form selection across the team's repos (the slow path on a many-repo team). Keep the `NO_REPO` sentinel for the rare report where nothing under version control could change, since a skill body, a config file, or a doc still lives in a repo."
),
priority: zod
.union([