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): skip reusing a saved repo when github is disconnected (#125859)

Dylan Martin2dafa8bf90ee
diff --git a/products/signals/backend/temporal/agentic/select_repository.py b/products/signals/backend/temporal/agentic/select_repository.py
index 764ca9c20a85..fb287ca0fa74 100644
--- a/products/signals/backend/temporal/agentic/select_repository.py
+++ b/products/signals/backend/temporal/agentic/select_repository.py
@@ -139,6 +139,23 @@ async def select_repository_activity(input: SelectRepositoryInput) -> RepoSelect
previous = await aretry_on_db_connection_drop(
lambda: database_sync_to_async(persisted_repo_selection, thread_sensitive=False)(input.report_id)
)
+ # Outside the pilot, research resolves its sandbox user from the team's GitHub integration
+ # and raises when there is none. A team that disconnected GitHub after the first run must
+ # go back through selection, which returns no repository and asks for a selection.
+ if (
+ previous is not None
+ and previous.repository is not None
+ and not input.github_optional
+ and await database_sync_to_async(resolve_team_github_integration, thread_sensitive=False)(input.team_id)
+ is None
+ ):
+ logger.info(
+ "signals repo selection reuse skipped: no GitHub integration",
+ report_id=input.report_id,
+ team_id=input.team_id,
+ repository=previous.repository,
+ )
+ previous = None
if previous is not None and previous.repository is not None:
logger.info(
"signals repo selection reused from previous run",
diff --git a/products/signals/backend/test/test_agentic_report_activity.py b/products/signals/backend/test/test_agentic_report_activity.py
index 2ee77dace29a..9b8fba44d210 100644
--- a/products/signals/backend/test/test_agentic_report_activity.py
+++ b/products/signals/backend/test/test_agentic_report_activity.py
@@ -688,9 +688,23 @@ async def test_select_repository_activity_returns_repo(monkeypatch, ateam):
@pytest.mark.asyncio
@pytest.mark.django_db
[email protected]("github_optional", [False, True])
-async def test_select_repository_activity_reuses_previous_selection(monkeypatch, ateam, github_optional):
+ "github_optional,connected,reused",
+ [
+ (False, True, True),
+ (False, False, False),
+ (True, True, True),
+ (True, False, True),
+ ],
+)
+async def test_select_repository_activity_reuses_previous_selection(
+ monkeypatch, ateam, github_optional, connected, reused
+):
previous = RepoSelectionResult(repository="posthog/posthog", reason="Previously selected")
+ if connected:
+ await Integration.objects.acreate(
+ team=ateam, kind="github", integration_id="123", config={"installation_id": 123}
+ )
monkeypatch.setattr(
"products.signals.backend.temporal.agentic.select_repository.persisted_repo_selection",
@@ -716,7 +730,11 @@ async def test_select_repository_activity_reuses_previous_selection(monkeypatch,
)
)
- assert result is previous
+ if reused:
+ assert result is previous
+ else:
+ assert result.repository is None
+ assert "No GitHub integration" in result.reason
assert not select_repo_called
@@ -727,6 +745,7 @@ async def test_select_repository_activity_retries_transient_db_drop(monkeypatch,
# activity's early read. The retry-once guard must evict the dead connection and
# succeed on the second attempt rather than letting it escape as error-tracking noise.
previous = RepoSelectionResult(repository="posthog/posthog", reason="Previously selected")
+ await Integration.objects.acreate(team=ateam, kind="github", integration_id="123", config={"installation_id": 123})
attempts = {"n": 0}
def flaky_load(report_id):