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(tasks): stop bot comments waking the PR babysit loop (#96894)

Julian Bez930b431d96ec
diff --git a/posthog/models/github_integration_base.py b/posthog/models/github_integration_base.py
index 248f5259a860..839dbe5c938d 100644
--- a/posthog/models/github_integration_base.py
+++ b/posthog/models/github_integration_base.py
@@ -1716,15 +1716,15 @@ class GitHubIntegrationBase:
nodes {
id isResolved path
comments(last: 1) {
- nodes { id url body author { login } authorAssociation }
+ nodes { id url body author { login __typename } authorAssociation }
}
}
}
comments(last: 30) {
- nodes { id url body author { login } authorAssociation }
+ nodes { id url body author { login __typename } authorAssociation }
}
reviews(last: 10) {
- nodes { id url body author { login } authorAssociation }
+ nodes { id url body author { login __typename } authorAssociation }
}
commits(last: 1) {
nodes {
@@ -1790,6 +1790,12 @@ class GitHubIntegrationBase:
"url": node.get("url"),
}
+ @staticmethod
+ def _is_bot_author(node: dict[str, Any]) -> bool:
+ # GraphQL drops the `[bot]` login suffix REST adds, and authorAssociation says
+ # nothing about whether an author is automated.
+ return ((node.get("author") or {}).get("__typename")) == "Bot"
+
def get_pull_request_babysit_snapshot(self, pr_url: str) -> dict[str, Any]:
"""Fetch the per-item PR state the babysit loop dispatches on: every unresolved
review thread with its latest comment, top-level comments and review bodies,
@@ -1825,8 +1831,13 @@ class GitHubIntegrationBase:
if not isinstance(node, dict):
continue
item = self._feedback_item(node)
- if item["id"] and item["body"].strip() and item["author"] != author_login:
- feedback.append(item)
+ if not (item["id"] and item["body"].strip() and item["author"] != author_login):
+ continue
+ # A bot review is code feedback. A bot comment is merge-queue and CI chatter,
+ # and waking on it makes the agent push the PR out of the queue (#96393).
+ if connection == "comments" and self._is_bot_author(node):
+ continue
+ feedback.append(item)
rollup_nodes = ((pr.get("commits") or {}).get("nodes")) or []
rollup = ((rollup_nodes[0] or {}).get("commit") or {}).get("statusCheckRollup") if rollup_nodes else None
diff --git a/posthog/models/test/integration/test_github.py b/posthog/models/test/integration/test_github.py
index 3eb2bf2565bb..39dfe03c6a35 100644
--- a/posthog/models/test/integration/test_github.py
+++ b/posthog/models/test/integration/test_github.py
@@ -2179,7 +2179,14 @@ class TestGitHubIntegrationGraphQL(BaseTest):
BABYSIT_PR_URL = "https://github.com/acme/widgets/pull/7"
-def _babysit_thread(thread_id: str, *, is_resolved: bool = False, author: str = "reviewer", body: str = "fix this"):
+def _babysit_thread(
+ thread_id: str,
+ *,
+ is_resolved: bool = False,
+ author: str = "reviewer",
+ body: str = "fix this",
+ is_bot: bool = False,
+):
return {
"id": thread_id,
"isResolved": is_resolved,
@@ -2190,7 +2197,7 @@ def _babysit_thread(thread_id: str, *, is_resolved: bool = False, author: str =
"id": f"{thread_id}-C1",
"url": f"{BABYSIT_PR_URL}#discussion_{thread_id}",
"body": body,
- "author": {"login": author},
+ "author": {"login": author, "__typename": "Bot" if is_bot else "User"},
"authorAssociation": "MEMBER",
}
]
@@ -2198,12 +2205,12 @@ def _babysit_thread(thread_id: str, *, is_resolved: bool = False, author: str =
}
-def _babysit_feedback(node_id: str, *, author: str = "reviewer", body: str = "please rename"):
+def _babysit_feedback(node_id: str, *, author: str = "reviewer", body: str = "please rename", is_bot: bool = False):
return {
"id": node_id,
"url": f"{BABYSIT_PR_URL}#issuecomment-{node_id}",
"body": body,
- "author": {"login": author},
+ "author": {"login": author, "__typename": "Bot" if is_bot else "User"},
"authorAssociation": "MEMBER",
}
@@ -2256,6 +2263,34 @@ class TestGitHubIntegrationPullRequestBabysitSnapshot(BaseTest):
assert [thread["id"] for thread in result["unresolved_threads"]] == ["T2"]
assert [comment["id"] for comment in result["comments"]] == ["M3", "R2"]
+ def test_bot_comments_are_dropped_and_bot_reviews_are_kept(self):
+ """A merge-queue bot comments once per submission, each with a fresh id, so every one
+ wakes the loop. A review bot writes the feedback the loop exists to act on."""
+ payload = self._payload(
+ comments={
+ "nodes": [
+ _babysit_feedback("M1", author="talyn-app", body="/trunk merge", is_bot=True),
+ _babysit_feedback("M2", author="github-actions", body="CI report", is_bot=True),
+ _babysit_feedback("M3"),
+ ]
+ },
+ reviews={"nodes": [_babysit_feedback("R1", author="review-hog", body="rename this", is_bot=True)]},
+ )
+
+ with patch.object(GitHubIntegration, "_gh_graphql", return_value=payload):
+ result = self._github().get_pull_request_babysit_snapshot(BABYSIT_PR_URL)
+
+ assert [comment["id"] for comment in result["comments"]] == ["M3", "R1"]
+
+ def test_a_bot_review_thread_is_kept(self):
+ """An unresolved inline thread is work somebody waits on, whoever opened it."""
+ payload = self._payload(reviewThreads={"nodes": [_babysit_thread("T1", author="review-hog", is_bot=True)]})
+
+ with patch.object(GitHubIntegration, "_gh_graphql", return_value=payload):
+ result = self._github().get_pull_request_babysit_snapshot(BABYSIT_PR_URL)
+
+ assert [thread["id"] for thread in result["unresolved_threads"]] == ["T1"]
+
@parameterized.expand(
[
("MERGED", False, "merged"),